@opencraw/studio 0.0.40 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +5 -3
- package/dist/page-snapshot/detect-url.use-case.d.ts +2 -2
- package/dist/src/page-snapshot/detect-url.use-case.d.ts +2 -2
- package/dist/src/studio-api/detect-url-view.contract.d.ts +1 -0
- package/dist/src/studio-api/snapshot-view.contract.d.ts +1 -0
- package/dist/studio-api/detect-url-view.contract.d.ts +1 -0
- package/dist/studio-api/snapshot-view.contract.d.ts +1 -0
- package/dist/ui/assets/{index-BXVxv7aJ.js → index-CxuuImQ0.js} +2 -2
- package/dist/ui/assets/{pdf-iL5qSZ5O.js → pdf-DlUV3lLg.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/package.json +3 -3
|
@@ -15,8 +15,8 @@ Error generating stack: `+e.message+`
|
|
|
15
15
|
${String(e.value)}`:r?`Hidden row
|
|
16
16
|
${String(e.value)}`:String(e.value),truncate:!0,children:String(e.value)})}function WU({match:e}){let t=e.rows.slice(0,kU);return(0,F.jsxs)(I,{borderTopWidth:`1px`,maxH:`160px`,overflow:`auto`,flexShrink:0,children:[(0,F.jsx)(W,{px:2,py:1,gap:2,children:(0,F.jsx)(V,{fontSize:`xs`,color:`fg.muted`,children:`Live preview: ${String(e.rows.length)} row${e.rows.length===1?``:`s`} matched${e.title===``?``:` ("${e.title}")`}`})}),(0,F.jsxs)(hT,{size:`sm`,variant:`outline`,children:[(0,F.jsx)(vT,{children:(0,F.jsx)(gT,{children:e.header.map(e=>(0,F.jsx)(yT,{fontSize:`2xs`,children:e},e))})}),(0,F.jsx)(xT,{children:t.map((t,n)=>(0,F.jsx)(gT,{children:e.header.map(e=>(0,F.jsx)(bT,{fontSize:`2xs`,children:String(t[e]??``)},e))},n))})]})]})}function GU({format:e,override:t,onChange:n}){let r=t?.delimiter??e.delimiter,i=t?.encoding??e.encoding;return(0,F.jsxs)(W,{gap:2,children:[(0,F.jsx)(V,{fontSize:`xs`,color:`fg.muted`,children:`Delimiter`}),(0,F.jsx)(Dw,{size:`xs`,width:`40px`,defaultValue:r,onBlur:e=>{let i=e.target.value;i!==``&&i!==r&&n({delimiter:i,encoding:t?.encoding})}},r),(0,F.jsx)(V,{fontSize:`xs`,color:`fg.muted`,children:`Encoding`}),(0,F.jsx)(Dw,{size:`xs`,width:`110px`,defaultValue:i,onBlur:e=>{let r=e.target.value;r!==``&&r!==i&&n({delimiter:t?.delimiter,encoding:r})}},i)]})}var KU=2,qU=.15,JU=.6,YU=3,XU=40,ZU=1.15,QU=.95;function $U(e,t){let n=iW(t),r=e.rows.findIndex(e=>e.cells.includes(t));if(r===-1||e.rows[r]?.cells.length!==1)return n;let i=n,a=t;for(let t=r+1;t<e.rows.length;t+=1){let n=nW(e,t);if(n===void 0||!rW(a,n))break;i=aW(i,iW(n)),a=n}a=t;for(let t=r-1;t>=0;--t){let n=nW(e,t);if(n===void 0||!rW(n,a))break;i=aW(i,iW(n)),a=n}return i}function eW(e){let t=/^([A-Z][\w &()./-]*):\s*(\S.*)$/i.exec(e.trim());if(t===null)return;let[,n=``,r=``]=t,i=n.trim();if(!(i.length>XU||r.startsWith(`//`)))return{label:i,value:r.trim()}}function tW(e){let[t,...n]=e.toLowerCase().split(/[^\da-z]+/).filter(e=>e!==``);if(t===void 0)return`value`;let r=t+n.map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return/^\d/.test(r)?`value${r.charAt(0).toUpperCase()}${r.slice(1)}`:r}function nW(e,t){let n=e.rows[t]?.cells;return n?.length===1?n[0]:void 0}function rW(e,t){let n=e.y-(t.y+t.height),r=Math.abs(e.height-t.height)<=Math.max(e.height,t.height)*qU,i=Math.abs(e.x-t.x)<=KU,a=Math.abs(e.x+e.width/2-(t.x+t.width/2))<=YU;return(i||a)&&r&&n<=e.height*JU}function iW(e){return{x1:e.x,y1:e.y,x2:e.x+Math.max(e.width,1),y2:e.y+e.height}}function aW(e,t){return{x1:Math.min(e.x1,t.x1),y1:Math.min(e.y1,t.y1),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}}function oW(e,t,n){let r=e.flatMap(e=>e.rows.filter(e=>e.running!==!0).map(t=>({page:e.number,row:t}))),i=r.findIndex(e=>e.row.cells.includes(n)),a=r[i]?.row;if(a===void 0||sW(a))return;let o=cW(r,i,n.height);return o===-1?dW(t,r,i):uW(r,o,t.number,e.some(e=>e.rows.some(e=>e.running===!0)),n)}function sW(e){return e.cells.length>1&&e.cells.every(e=>eW(e.text)!==void 0)}function cW(e,t,n){for(let r=t-1;r>=0;--r){let t=e[r]?.row.cells??[],i=t[0];if(i!==void 0&&i.height>n*ZU&&t.length===1&&lW(e,r))return r}return-1}function lW(e,t){let n=e[t]?.row.cells[0]?.height??0;return e.some((e,r)=>r!==t&&e.row.cells.length===1&&Math.abs((e.row.cells[0]?.height??0)-n)<=n*.050000000000000044)}function uW(e,t,n,r,i){let a=e[t]?.row,o=a?.cells[0]?.height??0,s=a?.cells[0]?.text;if(s===void 0)return;let c=e.slice(t+1),l=c.findIndex(e=>Math.max(...e.row.cells.map(e=>e.height))>=o*QU),u=l===-1?c:c.slice(0,l),[d,...f]=u.filter(e=>e.page===n).flatMap(e=>e.row.cells).map(e=>iW(e));if(d===void 0)return;let p=l===-1?void 0:c[l]?.row.cells.map(e=>e.text).join(` `),m=u.map(e=>e.row),h=m.every(e=>e.cells.length===1)?m.findIndex(e=>e.cells[0]===i)+1:0;return{kind:`section`,heading:s,...p!==void 0&&{until:p},box:f.reduce((e,t)=>aW(e,t),d),ignoreHeadersFooters:r,...h>0&&{clickedLine:h}}}function dW(e,t,n){let r=t.filter(t=>t.page===e.number).map(e=>e.row),i=r.indexOf(t[n]?.row);if(r[i]?.cells.length!==1)return;let a=i;for(;a>0&&fW(r[a-1],r[a]);)--a;let o=i;for(;o<r.length-1&&fW(r[o],r[o+1]);)o+=1;let s=r[a-1],c=r.slice(a,o+1).map(e=>e.cells[0]).filter(e=>e!==void 0),[l,...u]=c;if(s!==void 0&&l!==void 0&&!(c.length>1&&l.height<=pW(r)*ZU))return{kind:`after`,previous:s.cells.map(e=>e.text).join(` `),lines:c.length,box:u.reduce((e,t)=>aW(e,iW(t)),iW(l)),page:e.number}}function fW(e,t){let n=e?.cells.length===1?e.cells[0]:void 0,r=t?.cells.length===1?t.cells[0]:void 0;return n!==void 0&&r!==void 0&&!n.text.trimEnd().endsWith(`:`)&&rW(n,r)}function pW(e){let t=e.map(e=>Math.max(...e.cells.map(e=>e.height))).sort((e,t)=>e-t);return t[Math.floor(t.length/2)]??0}var mW=[{name:`date`,test:/\b\d{1,2}\s+[A-Z]{3,9}\s+\d{4}\b/i,pattern:String.raw`(\d{1,2} [A-Za-z]{3,9} \d{4})`},{name:`date`,test:/\b\d{4}-\d{2}-\d{2}\b/,pattern:String.raw`(\d{4}-\d{2}-\d{2})`},{name:`email address`,test:/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/,pattern:String.raw`([\w.+-]+@[\w-]+(?:\.[\w-]+)+)`},{name:`amount`,test:/[£$€]\s?\d[\d,.]*/,pattern:String.raw`([£$€]\s?\d[\d,.]*)`}];function hW(e){let t=mW.find(t=>t.test.test(e));return t===void 0?void 0:{name:t.name,pattern:t.pattern}}function gW(e,t,n,r){let i=oW(e,t,n),a=[{...i!==void 0&&{anchor:i},box:nH(i?.kind===`section`||i?.kind===`after`&&i.lines>1?i.box:r)}];if(i?.kind===`section`){let e=tH(n),t=hW(n.text);i.clickedLine!==void 0&&a.push({anchor:{...i,line:i.clickedLine,box:e},box:e}),t!==void 0&&a.push({anchor:{...i,match:t.pattern,matchName:t.name,box:e},box:e})}return i!==void 0&&a.push({box:nH(r)}),a}var _W=`modulepreload`,vW=function(e){return`/`+e},yW={},bW=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),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?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=vW(t,n),t=s(t),t in yW)return;yW[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:_W,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).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)})},xW=[],SW=1.5,CW=20,wW=`#8a8d94`,TW=1.2,EW=24,DW=4,OW=[`#2e86ab`,`#3bb273`],kW=`#e4572e`,AW=`rgba(59, 178, 115, 0.18)`,jW=`#1d4ed8`,MW=`#ea580c`;function NW({recipeId:e,stepPath:t,view:n,bytesUrl:r,zoom:i=1,onTablePick:a,onRegionPick:o,steps:s=xW,hoveredStepId:c,onHoverStepId:l}){let[u,d]=(0,P.useState)(0),[f,p]=(0,P.useState)(`text`),[m,h]=(0,P.useState)({}),[g,_]=(0,P.useState)(void 0),[v,y]=(0,P.useState)(void 0),[b,x]=(0,P.useState)(void 0),S=(0,P.useRef)(null),C=(0,P.useRef)(null),[w,T]=(0,P.useState)(1),E=w*i,D=(0,P.useRef)(void 0),O=n.pages[u],k=(0,P.useMemo)(()=>zH(s,`page`,O?.number??-1),[s,O?.number]),A=O===void 0?0:Math.ceil(O.width*SW),ee=O===void 0?0:Math.ceil(O.height*SW),te=sO(e,t,m.header===void 0?void 0:{header:m.header,until:m.until,columns:m.columns}),ne=(0,P.useMemo)(()=>te.data?.matches.find(e=>e.page===O?.number),[te.data,O?.number]),re=v===void 0?void 0:eH(`page`,v.page,v.box),ie=cO(e,t,re),ae=ie.data?.matches.find(e=>e.page===v?.page),oe=ae?.text;if((0,P.useEffect)(()=>{m.header!==void 0&&a($V(m,t,void 0,n.pages.some(e=>e.rows.some(e=>e.running===!0))))},[m]),(0,P.useEffect)(()=>{let e=C.current;if(e===null||A===0||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=e.clientWidth-CW;T(t>0?Math.min(1,t/A):1)});return t.observe(e),()=>{t.disconnect()}},[A]),(0,P.useEffect)(()=>{let e=S.current;if(e===null||O===void 0)return;let t=new AbortController;return(async()=>{try{await YW(e,r,O.number,SW,t.signal)}catch(e){t.signal.aborted||console.error(`PDF canvas: could not render the page`,e)}})(),()=>{t.abort()}},[r,O?.number]),O===void 0)return(0,F.jsx)(I,{p:4,color:`fg.muted`,children:(0,F.jsx)(V,{children:`This PDF has no pages.`})});function se(e){let t=e.cells[0]?.text??``;if(f===`header`){h({header:ZV(t)});return}f===`until`&&m.header!==void 0&&h(e=>({...e,until:ZV(t)}))}function ce(e){m.header!==void 0&&h(t=>({...t,columns:{...t.columns,[QV(e)]:ZV(e)}}))}function j(e,t,n){let r=v;if(t&&r!==void 0&&r.page===O.number){y({page:O.number,box:rH(r.box,e)});return}let i=n?.[0];y({page:O.number,box:e,...i?.anchor!==void 0&&{anchor:i.anchor},...n!==void 0&&{choices:n,choice:0}})}function le(e){let t=v,n=t?.choices?.[e];t!==void 0&&n!==void 0&&y({page:t.page,box:n.box,choices:t.choices,choice:e,...n.anchor!==void 0&&{anchor:n.anchor}})}function ue(e){l!==void 0&&D.current!==e&&(D.current=e,l(e))}function de(e){if(f!==`text`)return;let t=zW(e);if(b!==void 0){x({...b,currentX:t.x,currentY:t.y});return}let n=WW(O,t);_(n),ue(n===void 0?void 0:VH(tH(n),k)[0])}function fe(e){if(f!==`text`||e.button!==0)return;let t=zW(e);x({startX:t.x,startY:t.y,currentX:t.x,currentY:t.y})}function pe(e){if(f!==`text`||b===void 0)return;let t=zW(e);if(x(void 0),Math.abs(t.x-b.startX)+Math.abs(t.y-b.startY)>DW){j(UW(O,b.startX,b.startY,t.x,t.y),e.shiftKey);return}let r=WW(O,t);if(r===void 0){e.shiftKey||y(void 0);return}if(e.shiftKey){j(nH($U(O,r)),!0);return}let i=gW(n.pages,O,r,$U(O,r));j(i[0]?.box??nH($U(O,r)),!1,i)}function me(){if(re===void 0||oe===void 0)return;let e=v?.anchor;if(e?.kind===`section`)return sH(e.heading,e.until,e.ignoreHeadersFooters,t,tW(e.matchName??(e.line===void 0?e.heading:`${e.heading} line ${String(e.line)}`)),{...e.line!==void 0&&{line:e.line},...e.match!==void 0&&{match:e.match}});if(e===void 0&&(v?.choices?.length??0)>1)return aH(re,t,iH(oe));let n=oe.includes(`
|
|
17
17
|
`)?void 0:eW(oe);return n===void 0?e?.kind===`after`?cH(e.previous,t,tW(e.previous),e.lines):aH(re,t,iH(oe)):oH(n.label,t,tW(n.label))}function he(){let e=me();e!==void 0&&(o(e),y(void 0))}function ge(e){let t=me();t!==void 0&&oe!==void 0&&(e.dataTransfer.setData(mk,hk(t)),e.dataTransfer.setData(`text/plain`,oe),e.dataTransfer.effectAllowed=`copy`)}let _e=f===`text`,ve=v!==void 0&&v.page===O.number?v:void 0;return(0,F.jsxs)(I,{h:`full`,display:`flex`,flexDirection:`column`,children:[(0,F.jsxs)(W,{px:3,py:2,borderBottomWidth:`1px`,gap:3,flexShrink:0,flexWrap:`wrap`,children:[n.pages.length>1&&(0,F.jsx)(KW,{pages:n.pages.length,value:u,onChange:d}),n.pages.length>1&&(0,F.jsx)(V,{fontSize:`sm`,color:`fg.muted`,children:`of ${String(n.pages.length)}`}),(0,F.jsx)(GW,{label:`Text`,active:_e,onClick:()=>{p(`text`)}}),(0,F.jsx)(GW,{label:`Header row`,tip:`The row that names the columns of a table: click it to say where the table starts.`,active:f===`header`,onClick:()=>{p(`header`)}}),(0,F.jsx)(GW,{label:`Last row (until)`,tip:`The line that comes right after the table: click it to say where the table stops.`,active:f===`until`,onClick:()=>{p(`until`)}}),(0,F.jsx)(GW,{label:`Column`,tip:`Click a column to collect everything under it.`,active:f===`column`,onClick:()=>{p(`column`)}}),(0,F.jsx)(V,{fontSize:`xs`,color:`fg.muted`,children:`${String(O.rowCount)} rows, ${String(O.cellCount)} cells${O.hasTextLayer?``:` — no text layer (a scan?)`}`}),_e&&(0,F.jsx)(V,{fontSize:`xs`,color:`fg.muted`,visibility:v===void 0?`visible`:`hidden`,children:`Click a line (shift+click to extend) or drag a box, then add it to the recipe or drag it onto the Steps tab.`}),m.header!==void 0&&(0,F.jsx)(LC,{size:`sm`,colorPalette:`green`,children:`table: ${m.header}${m.until===void 0?``:` until ${m.until}`}`}),te.data?.error!==void 0&&(0,F.jsx)(LC,{size:`sm`,colorPalette:`orange`,children:te.data.error}),ie.data?.error!==void 0&&(0,F.jsx)(LC,{size:`sm`,colorPalette:`orange`,children:ie.data.error})]}),(0,F.jsx)(I,{ref:C,flex:`1`,minH:`0`,overflow:`auto`,position:`relative`,style:{background:wW},onContextMenu:e=>{e.preventDefault()},children:(0,F.jsx)(I,{position:`relative`,width:`${String(Math.ceil(A*E))}px`,height:`${String(Math.ceil(ee*E))}px`,style:{boxShadow:`0 0 0 1px rgba(128,128,128,0.5), 0 2px 10px rgba(0,0,0,0.22)`},children:(0,F.jsxs)(I,{position:`absolute`,top:0,left:0,width:`${String(A)}px`,height:`${String(ee)}px`,style:{transform:`scale(${String(E)})`,transformOrigin:`top left`},children:[(0,F.jsx)(`canvas`,{ref:S,width:A,height:ee,style:{position:`absolute`,top:0,left:0}}),(0,F.jsxs)(`svg`,{"data-testid":`pdf-overlay`,width:A,height:ee,style:{position:`absolute`,top:0,left:0,cursor:_e?`crosshair`:`pointer`},onMouseMove:de,onMouseDown:fe,onMouseUp:pe,onMouseLeave:()=>{_(void 0),ue(void 0)},children:[k.map(e=>(0,F.jsx)(`rect`,{"data-testid":`recipe-region`,"data-step-id":e.id,"data-highlighted":e.id===c,...HW(e.box,O.height),fill:e.id===c?`rgba(234, 88, 12, 0.22)`:`rgba(234, 88, 12, 0.05)`,stroke:MW,strokeWidth:e.id===c?2:1,strokeDasharray:e.id===c?void 0:`4 3`,pointerEvents:`none`,children:(0,F.jsx)(`title`,{children:`In the recipe: ${e.id}`})},`recipe:${e.id}`)),O.rows.map((e,t)=>(0,F.jsx)(qW,{row:e,colour:e.cells[0]?.text!==void 0&&ne?.headerRowIndex===t?kW:OW[t%2],highlighted:ne?.matchedRowIndices.includes(t)??!1,scale:SW,pageHeight:O.height,cursor:_e?`crosshair`:`pointer`,onClick:_e?void 0:()=>{se(e)}},`${String(e.top)}:${String(e.bottom)}`)),f===`column`&&ne!==void 0&&ne.bands.map(e=>(0,F.jsx)(JW,{band:e,scale:SW,pageHeight:O.height,onClick:()=>{ce(e.name)}},e.column)),_e&&g!==void 0&&b===void 0&&(0,F.jsx)(`rect`,{"data-testid":`snap-target`,...VW(g,O.height),fill:`rgba(29, 78, 216, 0.08)`,stroke:jW,strokeWidth:1.5,strokeDasharray:`3 2`,pointerEvents:`none`}),ve!==void 0&&(0,F.jsx)(`rect`,{"data-testid":`staged-region`,...HW(ve.box,O.height),fill:`rgba(155, 93, 229, 0.12)`,stroke:`#9b5de5`,strokeWidth:1.5,pointerEvents:`none`}),ve!==void 0&&ae?.cells.map(e=>(0,F.jsx)(`rect`,{"data-testid":`staged-cell`,...VW(e,O.height),fill:`rgba(155, 93, 229, 0.28)`,pointerEvents:`none`},BW(e))),b!==void 0&&(0,F.jsx)(`rect`,{x:Math.min(b.startX,b.currentX),y:Math.min(b.startY,b.currentY),width:Math.abs(b.currentX-b.startX),height:Math.abs(b.currentY-b.startY),fill:`rgba(155, 93, 229, 0.2)`,stroke:`#9b5de5`,strokeDasharray:`4 2`,pointerEvents:`none`})]}),ve!==void 0&&(0,F.jsx)(MH,{left:Math.min(ve.box.x1,ve.box.x2)*SW,top:FW(ve.box,O.height),text:IW(ve.anchor,oe),note:RW(ve.anchor,oe),choices:ve.choices?.map(e=>LW(e)),choice:ve.choice,onChoose:le,loading:ie.isPending,onAdd:he,onClear:()=>{y(void 0)},onDragStart:ge})]})})})]})}var PW=56;function FW(e,t){let n=(t-Math.max(e.y1,e.y2))*SW,r=(t-Math.min(e.y1,e.y2))*SW;return n>=PW?n-PW:r+6}function IW(e,t){if(t===void 0||e?.kind!==`section`||e.match===void 0)return t;let n=new RegExp(e.match,`i`).exec(t);return n===null?void 0:n[1]??n[0]}function LW(e){let{anchor:t}=e;return t?.kind===`section`?t.line===void 0?t.matchName===void 0?t.until===void 0?`The whole block below “${t.heading}”`:`The whole block between “${t.heading}” and “${t.until}”`:`Only the ${t.matchName} in the block`:`Only this line (line ${String(t.line)} of the block)`:t?.kind===`after`?t.lines>1?`The ${String(t.lines)} lines after “${t.previous}”`:`The line after “${t.previous}”`:`A fixed position on the page (breaks if the layout moves)`}function RW(e,t){let n=t!==void 0&&!t.includes(`
|
|
18
|
-
`)&&eW(t)!==void 0;return e?.kind===`section`&&e.line!==void 0?`Reads line ${String(e.line)} of what is between “${e.heading}” and ${e.until===void 0?`the end`:`“${e.until}”`}`:e?.kind===`section`&&e.matchName!==void 0?`Reads the ${e.matchName} in what is below “${e.heading}”, wherever it sits`:e?.kind===`section`?e.until===void 0?`Reads everything below “${e.heading}”`:`Reads what is between “${e.heading}” and “${e.until}”`:n?`Reads the value after its label`:e?.kind===`after`?e.lines>1?`Reads the ${String(e.lines)} lines after “${e.previous}”`:`Reads the line after “${e.previous}”`:`Reads a fixed position on the page: it breaks when the layout moves`}function zW(e){let t=e.currentTarget.getBoundingClientRect(),n=Number(e.currentTarget.getAttribute(`width`)),r=t.width>0&&n>0?t.width/n:1;return{x:(e.clientX-t.left)/r,y:(e.clientY-t.top)/r}}function BW(e){return`staged:${String(e.x)}:${String(e.y)}`}function VW(e,t){return{x:e.x*SW,y:(t-e.y-e.height)*SW,width:Math.max(e.width,1)*SW,height:e.height*SW*TW}}function HW(e,t){let[n,r]=[Math.min(e.x1,e.x2),Math.max(e.x1,e.x2)],[i,a]=[Math.min(e.y1,e.y2),Math.max(e.y1,e.y2)];return{x:n*SW,y:(t-a)*SW,width:(r-n)*SW,height:(a-i)*SW}}function UW(e,t,n,r,i){return{x1:t/SW,y1:e.height-n/SW,x2:r/SW,y2:e.height-i/SW}}function WW(e,t){let n;for(let r of e.rows)for(let i of r.cells){let r=VW(i,e.height),a=Math.max(r.x-t.x,0,t.x-(r.x+r.width)),o=Math.max(r.y-t.y,0,t.y-(r.y+r.height)),s=Math.hypot(a,o);s<=EW&&(n===void 0||s<n.distance)&&(n={cell:i,distance:s})}return n?.cell}function GW({label:e,tip:t,active:n,onClick:r}){return(0,F.jsx)(V,{as:`button`,title:t,fontSize:`sm`,fontWeight:n?`semibold`:`normal`,color:n?`colorPalette.fg`:`fg`,colorPalette:`brand`,cursor:`pointer`,onClick:r,children:e})}function KW({pages:e,value:t,onChange:n}){let r=a_({items:Array.from({length:e},(e,t)=>({label:`Page ${String(t+1)}`,value:String(t)}))});return(0,F.jsxs)(Hw,{collection:r,size:`sm`,width:`140px`,value:[String(t)],onValueChange:e=>{n(Number(e.value[0]))},children:[(0,F.jsx)(Yw,{}),(0,F.jsx)(Jw,{children:(0,F.jsx)(Uw,{children:(0,F.jsx)(Kw,{})})}),(0,F.jsx)(Ww,{children:(0,F.jsx)(Gw,{children:r.items.map(e=>(0,F.jsx)(qw,{item:e,children:e.label},e.value))})})]})}function qW({row:e,colour:t,highlighted:n,scale:r,pageHeight:i,cursor:a,onClick:o}){return(0,F.jsxs)(`g`,{onClick:o,style:{cursor:a},children:[n&&e.cells.length>0&&(0,F.jsx)(`rect`,{x:Math.min(...e.cells.map(e=>e.x))*r,y:(i-e.top)*r,width:(Math.max(...e.cells.map(e=>e.x+e.width))-Math.min(...e.cells.map(e=>e.x)))*r,height:(e.top-e.bottom)*r,fill:AW}),e.cells.map(e=>(0,F.jsx)(`rect`,{x:e.x*r,y:(i-e.y-e.height)*r,width:Math.max(e.width,1)*r,height:e.height*r*TW,fill:`transparent`,stroke:t,strokeWidth:1.5},`${String(e.x)}:${String(e.y)}`))]})}function JW({band:e,scale:t,pageHeight:n,onClick:r}){return(0,F.jsx)(`rect`,{x:e.start*t,y:0,width:Math.max(e.end-e.start,1)*t,height:n*t,fill:`rgba(46, 134, 171, 0.08)`,stroke:`#2e86ab`,strokeDasharray:`4 2`,onClick:r,style:{cursor:`pointer`},children:(0,F.jsx)(`title`,{children:e.name})})}async function YW(e,t,n,r,i){let a=await bW(()=>import(`./pdf-
|
|
19
|
-
`)}var cG=1e3,lG=`data-oc-node`,uG=`opencraw-picker-style`;function dG({html:e,pickMode:t,showHidden:n,hoveredSelector:r,onHoverNode:i,onPickNode:a}){let o=(0,P.useRef)(null),s=(0,P.useRef)(null),[c,l]=(0,P.useState)({width:0,height:0}),u=(0,P.useRef)({onHoverNode:i,onPickNode:a});u.current={onHoverNode:i,onPickNode:a},(0,P.useEffect)(()=>{let e=o.current;if(e===null)return;let t,n=e=>{u.current.onHoverNode(pG(e.target))},r=()=>{u.current.onHoverNode(void 0)},i=e=>{fG(e.target)!==void 0&&e.preventDefault();let t=pG(e.target);t!==void 0&&(e.preventDefault(),e.stopPropagation(),u.current.onPickNode(t))},a=e=>{e.preventDefault()},s=()=>{let o=e.contentDocument;o!==null&&(o.addEventListener(`mouseover`,n),o.addEventListener(`mouseout`,r),o.addEventListener(`click`,i,{capture:!0}),o.addEventListener(`contextmenu`,a),t=()=>{o.removeEventListener(`contextmenu`,a),o.removeEventListener(`mouseover`,n),o.removeEventListener(`mouseout`,r),o.removeEventListener(`click`,i,{capture:!0})})};return e.addEventListener(`load`,s),()=>{e.removeEventListener(`load`,s),t?.()}},[e]),(0,P.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{l({width:e.clientWidth,height:e.clientHeight})});return t.observe(e),()=>{t.disconnect()}},[]),(0,P.useEffect)(()=>{let e=o.current?.contentDocument;if(e==null)return;let i=e.getElementById(uG);i===null&&(i=e.createElement(`style`),i.id=uG,e.head?.append(i)),i.textContent=sG(t,n,r)});let d=c.width>0,f=d?Math.max(c.width,cG):0,p=d?c.width/f:1,m=d&&p<1?{width:`${String(f)}px`,height:`${String(c.height/p)}px`,transform:`scale(${String(p)})`,transformOrigin:`top left`}:{width:`100%`,height:`100%`};return(0,F.jsx)(`div`,{ref:s,style:{width:`100%`,height:`100%`,overflow:`hidden`},children:(0,F.jsx)(`iframe`,{ref:o,title:`Snapshot`,sandbox:`allow-same-origin`,srcDoc:e,style:{...m,border:`none`,background:`white`}})})}function fG(e){return(e?.nodeType===Node.ELEMENT_NODE?e.closest(`a[href], area[href]`):null)??void 0}function pG(e){return(e?.nodeType===Node.ELEMENT_NODE?e.closest(`[${CSS.escape(lG)}]`):null)?.getAttribute(lG)??void 0}var mG=[],hG={object:`purple.fg`,array:`purple.fg`,element:`purple.fg`,string:`green.fg`,number:`orange.fg`,boolean:`blue.fg`,null:`fg.muted`},gG=(0,P.memo)(SG),_G=6;function vG(e){let t=new Set,n=(e,r)=>{if(e.children.length===0)return;let i=/^\[?(\d+)\]?$/.exec(e.label)?.[1];if(i!==void 0&&Number(i)>0||r>=_G){t.add(e.id);return}for(let t of e.children)n(t,r+1)};return n(e,0),t}function yG(e,t){let n=[],r=[{node:e,depth:0}];for(let e=r.pop();e!==void 0;e=r.pop())if(n.push(e),!(e.node.children.length===0||t.has(e.node.id)))for(let t=e.node.children.length-1;t>=0;--t)r.push({node:e.node.children[t],depth:e.depth+1});return n}var bG=20,xG=20;function SG({tree:e,onPick:t,steps:n=mG,hoveredStepId:r,onHoverStepId:i}){let[a,o]=(0,P.useState)(()=>vG(e.root)),s=(0,P.useRef)(null),c=yG(e.root,a),l=BO({count:c.length,getScrollElement:()=>s.current,estimateSize:()=>bG,overscan:xG});function u(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,F.jsxs)(I,{ref:s,h:`full`,overflow:`auto`,fontFamily:`mono`,fontSize:`xs`,py:2,children:[e.namespaces!==void 0&&Object.keys(e.namespaces).length>0&&(0,F.jsxs)(W,{px:2,pb:2,gap:2,flexWrap:`wrap`,children:[(0,F.jsx)(V,{color:`fg.muted`,children:`Namespaces:`}),Object.entries(e.namespaces).map(([e,t])=>(0,F.jsx)(LC,{size:`xs`,colorPalette:`gray`,children:`${e}: ${t}`},e))]}),(0,F.jsx)(I,{position:`relative`,style:{height:`${String(l.getTotalSize())}px`},children:l.getVirtualItems().map(e=>{let o=c[e.index];return(0,F.jsx)(I,{position:`absolute`,top:0,left:0,w:`full`,style:{transform:`translateY(${String(e.start)}px)`,height:`${String(bG)}px`},children:(0,F.jsx)(CG,{node:o.node,depth:o.depth,collapsed:a,onToggle:u,onPick:t,steps:n,hoveredStepId:r,onHoverStepId:i})},o.node.id)})})]})}function CG({node:e,depth:t,collapsed:n,onToggle:r,onPick:i,steps:a,hoveredStepId:o,onHoverStepId:s}){let c=e.children.length>0,l=n.has(e.id),u=e.valueType!==`object`&&e.valueType!==`array`&&e.valueType!==`element`,d=LH(e,a),f=o!==void 0&&d.includes(o);return(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)(W,{"data-testid":`tree-node`,"data-highlighted":f,"data-step-ids":d.length===0?void 0:d.join(` `),gap:1,pl:`${t*14+4}px`,pr:2,minH:`20px`,cursor:`pointer`,bg:f?`orange.subtle`:void 0,_hover:{bg:f?`orange.subtle`:`bg.emphasized`},onClick:()=>{i(e,`value`)},onMouseEnter:s===void 0?void 0:()=>{s(d[0])},onMouseLeave:s===void 0?void 0:()=>{s(void 0)},children:[c?(0,F.jsx)(V,{as:`button`,w:`12px`,flexShrink:0,color:`fg.muted`,onClick:t=>{t.stopPropagation(),r(e.id)},children:l?`▸`:`▾`}):(0,F.jsx)(I,{w:`12px`,flexShrink:0}),(0,F.jsx)(V,{as:`span`,color:hG[e.valueType],fontWeight:`medium`,children:e.label}),u&&e.preview!==void 0&&(0,F.jsx)(V,{as:`span`,color:`fg.muted`,truncate:!0,children:e.preview}),d.map(e=>(0,F.jsx)(LC,{size:`xs`,colorPalette:`orange`,variant:f?`solid`:`subtle`,title:`Already in the recipe: the step reading this`,flexShrink:0,children:e},e)),e.listPath!==void 0&&(0,F.jsx)(LC,{as:`button`,size:`xs`,colorPalette:`brand`,onClick:t=>{t.stopPropagation(),i(e,`list`)},title:`Collect this for every one of the ${String(e.listCount??0)} items of the list`,children:`[*] ×${String(e.listCount??0)}`}),u&&e.jsonpath!==void 0&&(0,F.jsx)(V,{as:`button`,fontSize:`2xs`,color:`fg.muted`,_hover:{color:`fg`,textDecoration:`underline`},onClick:t=>{t.stopPropagation(),i(e,`next`)},title:`Use this value to reach the next page of results (for data that comes in pages)`,children:`next →`})]})})}function wG(e){return(e.textContent??``).replace(/\s+/g,` `).trim()}function TG(e){let t=e?.closest(`[data-oc-node]`),n=t instanceof HTMLElement?t.dataset.ocNode:void 0;return t==null||n===void 0?{reason:`that element is not part of the page snapshot`}:{nodeId:n,text:wG(t).slice(0,160)}}function EG(e,t){let n=t.replace(/\s+/g,` `).trim().toLowerCase(),r,i;for(let t of e.body.querySelectorAll(`[data-oc-node]`)){let e=wG(t),a=e.toLowerCase();a===n&&(r===void 0||e.length<r.length)?r={element:t,length:e.length}:a.includes(n)&&(i===void 0||e.length<i.length)&&(i={element:t,length:e.length})}return r?.element??i?.element??null}function DG(e,t){let n=new DOMParser().parseFromString(e,`text/html`);if(t.selector!==void 0)try{let e=n.querySelector(t.selector);return e===null?{reason:`nothing on the page matches ${t.selector}`}:TG(e)}catch{return{reason:`${t.selector} is not a valid CSS selector`}}if(t.text===void 0)return{reason:`say what to pick: a CSS selector or the text it shows`};let r=EG(n,t.text);return r===null?{reason:`no element on the page shows "${t.text}"`}:TG(r)}function OG(e,t){return{pick:e,fieldSelector:e.field.selector,...e.kind===`list`&&{itemSelector:e.item.selector},...t!==void 0&&{text:t}}}function kG(e,t,n){return t?.find(t=>t.selector===e)?.matches??n}function AG(e,t){return{...e,selector:t,matches:kG(t,e.alternatives,e.matches)}}function jG(e){let{pick:t}=e,n=AG(t.field,e.fieldSelector);if(t.kind!==`list`)return{...t,field:n};let r=e.itemSelector??t.item.selector;return{...t,field:n,item:{...t.item,selector:r,matches:kG(r,t.item.alternatives,t.item.matches)}}}function MG(e){if(e.pick.kind===`list`)return;let t=AG(e.pick.field,e.fieldSelector).matches;return t>1?t:void 0}function NG(e){return e.many===!0&&MG(e)!==void 0}function PG(e,t){return e!==void 0&&e.length>0?e:[{selector:t.selector,tier:t.tier,matches:t.matches}]}function FG(e){let{pick:t}=e,n={title:t.kind===`list`?`Value in each item`:`How to find it`,options:PG(t.field.alternatives,t.field),selected:e.fieldSelector,target:`field`,...t.field.generatedId!==void 0&&{generatedId:t.field.generatedId}};return t.kind===`list`?[{title:`Each item of the list`,options:PG(t.item.alternatives,t.item),selected:e.itemSelector??t.item.selector,target:`item`},n]:[n]}function IG(e){return e.pick.kind===`list`?`Collect this for every one of the ${String(e.pick.item.matches)} items`:e.pick.kind===`item-field`?`Collect this from each item of the list`:`Collect this value`}function LG(e){if(e.pick.kind===`field`)return`Click a similar item as well to collect the whole list. Pick the way to find it that will keep working.`;if(e.pick.kind===`list`)return`Pick the ways to find the items and the value that will keep working.`}var RG=100,zG=`img, picture, video, canvas, svg, iframe, object, embed, input, select, textarea, table`,BG=`h1, h2, h3, h4, h5, h6, li, a[href]`;function VG(e){let t=new DOMParser().parseFromString(e,`text/html`).body;for(let e of t.querySelectorAll(`script, style, noscript, template`))e.remove();return(t.textContent??``).trim().length>=RG||t.querySelector(`${zG}, ${BG}`)!==null}function HG({zoom:e,zoomIn:t,zoomOut:n,reset:r}){return(0,F.jsxs)(W,{gap:0,role:`group`,"aria-label":`Zoom`,flexShrink:0,children:[(0,F.jsx)(UC,{size:`2xs`,variant:`outline`,"aria-label":`Zoom out`,title:`Zoom out (ctrl + wheel)`,onClick:n,children:`−`}),(0,F.jsx)(UC,{size:`2xs`,variant:`outline`,"aria-label":`Reset zoom`,title:`Back to 100%`,minW:`3.5em`,onClick:r,children:`${String(Math.round(e*100))}%`}),(0,F.jsx)(UC,{size:`2xs`,variant:`outline`,"aria-label":`Zoom in`,title:`Zoom in (ctrl + wheel)`,onClick:t,children:`+`})]})}var UG=[.5,.67,.8,1,1.25,1.5,2,3];function WG(e,t){let n=UG.findIndex(t=>t>=e),r=n===-1?UG.length-1:n;return UG[Math.min(Math.max(r+t,0),UG.length-1)]??1}function GG(e){let[t,n]=(0,P.useState)(1),r=(0,P.useCallback)(()=>{n(e=>WG(e,1))},[]),i=(0,P.useCallback)(()=>{n(e=>WG(e,-1))},[]),a=(0,P.useCallback)(()=>{n(1)},[]);return(0,P.useEffect)(()=>{let t=e.current;if(t===null)return;let n=e=>{e.ctrlKey&&(e.preventDefault(),e.deltaY<0?r():i())};return t.addEventListener(`wheel`,n,{passive:!1}),()=>{t.removeEventListener(`wheel`,n)}},[e,r,i]),{zoom:t,zoomIn:r,zoomOut:i,reset:a}}function KG(e,t){let n=OD(e,t)?.step.selector;return typeof n==`string`?n:void 0}function qG(e,t,n){if(e!==void 0&&t!==void 0)for(let r of AD(e)){let e=r.step.selector,i=r.step.id;if(typeof e==`string`&&typeof i==`string`&&$O(t,e).has(n))return i}}var JG=`start`,YG=new Set([`json`,`yaml`,`jsonl`,`xml`]),XG=new Set([`csv`,`xlsx`]),ZG=new Set([`pptx`]);function QG({recipe:e,onSaveOutline:t,onSaveRecipe:n}){let r=e?.id,i=Kte(r,r===void 0?void 0:JG),a=oO(),[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(`tree`),u=BD(),d=i.data?.format,f=d!==void 0&&YG.has(d),p=d===`pdf`,m=d!==void 0&&XG.has(d),h=d!==void 0&&ZG.has(d),g=!f&&!p&&!m&&!h,_=i.data?.html,v=(0,P.useMemo)(()=>_===void 0||VG(_),[_]),y=Zte(r,r===void 0?void 0:JG,f),b=Qte(r,r===void 0?void 0:JG,p),[x,S]=(0,P.useState)(void 0),C=lO(r,r===void 0?void 0:JG,m,x),w=dO(r,r===void 0?void 0:JG,h),T=G(e=>e.pickTarget),E=G(e=>e.showHidden),D=G(e=>e.hoveredStepId),O=G(e=>e.startPicking),k=G(e=>e.stopPicking),A=G(e=>e.registerPick),ee=G(e=>e.setShowHidden),te=G(e=>e.setHoveredNodeId),ne=G(e=>e.setHoveredStepId),re=(0,P.useMemo)(()=>KG(e?.outline,D),[e?.outline,D]),ie=(0,P.useMemo)(()=>IH(e?.outline),[e?.outline]),ae=(0,P.useRef)(Ne);ae.current=Ne;let oe=(0,P.useCallback)((e,t)=>{ae.current(e,t)},[]),se=t=>{te(t),ne(t===void 0?void 0:qG(e?.outline,i.data?.html,t))},ce=GD(e=>e.recipeId),j=GD(e=>e.active),le=GD(e=>e.cards.length),ue=GD(e=>e.stoppedSteps),de=GD(e=>e.error),fe=GD(e=>e.dismissStopped),pe=pO(),me=mO(),he=ce===r&&j,ge=ce===r?ue:void 0,[_e,ve]=(0,P.useState)(void 0),M=e=>{ve(e===void 0?void 0:{text:e,ok:!0})},N=e=>{ve(e===void 0?void 0:{text:e,ok:!1})},ye=(0,P.useRef)(void 0),[be,xe]=(0,P.useState)(void 0),Se=(0,P.useRef)(null),Ce=GG(Se),we=(0,P.useRef)(void 0),Te=T!==void 0&&T.recipeId===r,Ee=ZD(e=>e.pick),De=ZD(e=>e.finishPick),Oe=(0,P.useRef)(void 0);(0,P.useEffect)(()=>{we.current=void 0,S(void 0),xe(void 0)},[r]);async function ke(t){if(r===void 0)return;Te||(ye.current=void 0,O(r,JG));let n=A(t);if(n.kind===`first`){let n=e?.outline===void 0?void 0:hD(e.outline.steps),i=await a.mutateAsync({recipeId:r,path:JG,nodeIds:[t],...n!==void 0&&{within:n}});if(i.kind!==`field`&&i.kind!==`item-field`){N(i.kind===`unsupported`?i.reason:void 0);return}let o=OG(i,Ae(t));return xe(o),o}let i=await a.mutateAsync({recipeId:r,path:JG,nodeIds:[n.firstNodeId,t]});if(i.kind!==`list`){N(i.kind===`unsupported`?i.reason:void 0);return}xe(e=>OG(i,e?.text))}function Ae(e){let t=i.data?.html;if(t===void 0)return;let n=new DOMParser().parseFromString(t,`text/html`).querySelector(`[data-oc-node="${CSS.escape(e)}"]`)?.textContent?.replace(/\s+/g,` `).trim();return n===void 0||n===``?void 0:n.slice(0,160)}async function je(e=be){if(r===void 0||e===void 0)return;let t=jG(e),n=NG(e);if(xe(void 0),k(),t.kind===`item-field`){await Re(e=>{let r=Ite(e,t.field,n);return r===void 0?e:(M(`Added to the list: ${t.field.selector}`),r)});return}if(t.kind===`field`){await Re(e=>(M(`Read card: ${t.field.selector} (${t.field.matches} match${t.field.matches===1?``:`es`})`),vD(e,void 0,[dD(t.field,`steps.${e.length}`,void 0,n)])));return}await Re(e=>{let n=_D(e);return M(`List: ${t.item.selector} (${t.item.matches} items) → ${t.field.selector}`),vD(e,void 0,Nte(t,`steps.${n}`))})}function Me(){xe(void 0),k()}(0,P.useEffect)(()=>{let e=Ee,t=i.data?.html;if(!g||t===void 0||e===void 0||e.recipeId!==r||Oe.current===e.requestId)return;if(Te||be!==void 0){Me();return}Oe.current=e.requestId;let n=async(t,n,r)=>{De(e.requestId);try{await u.reportUiOutcome(e.requestId,t,n,r)}catch{}};(async()=>{let r=DG(t,e);if(`reason`in r){await n(!1,`Could not pick: ${r.reason}.`);return}let i=await ke(r.nodeId);if(i===void 0){await n(!1,`Studio could not turn that element into a selector.`,{text:r.text});return}let{field:a}=jG(i),o={text:r.text,selector:a.selector,matches:a.matches,alternatives:(a.alternatives??[]).map(e=>({selector:e.selector,matches:e.matches}))};if(e.add===!0){await je(i),await n(!0,`Added to the recipe: ${a.selector}`,o);return}await n(!0,`Staged: the person can choose a selector and press Add to recipe.`,o)})()});async function Ne(e,t){if(r!==void 0)try{if(t===`next`){await Re(t=>{let n=Mte(e,`steps.${t.length}`);return M(`Paginate: next from ${e.jsonpath}`),vD(t,void 0,[n])});return}await Re(n=>{if(t===`list`){let t=Fte(n,e);if(t!==void 0)return M(`Added to the list: ${String(e.listPath)}`),t;let r=Pte(e,`steps.${_D(n)}`);if(r!==void 0)return M(`List: ${String(e.listPath)} (${String(e.listCount??0)} items)`),vD(n,void 0,r)}let r=jte(e,`steps.${n.length}`,{generalize:t===`list`,namespaces:y.data?.namespaces});return M(`Read card: ${r.step.selector}${t===`list`?` (${String(e.listCount??0)} items)`:``}`),vD(n,void 0,[r])})}catch(e){N(e instanceof Error?e.message:String(e))}}async function Pe(e){await Re(t=>{let n=we.current,r=n??_D(t);return we.current=r,M(`table: ${String(e.step.selector)}`),vD(t,n,[{...e,path:`steps.${r}`}])})}async function Fe(e){await Re(t=>(M(`${String(e.step.kind)}: ${String(e.step.id)} ← ${String(e.step.selector)}`),vD(t,void 0,[{...e,path:`steps.${t.length}`}])))}async function Ie(e){await Re(t=>(M(`jsonpath: ${String(e.step.selector)}`),vD(t,void 0,[{...e,path:`steps.${t.length}`}])))}let Le=(0,P.useRef)(void 0);async function Re(n){if(t===void 0||e?.outline===void 0)return;let r=Le.current,i=n(r!==void 0&&r.file===e.file&&r.basedOn===e.outline?r.steps:e.outline.steps);Le.current={basedOn:e.outline,file:e.file,steps:i},await t(e.file,{...e.outline,steps:i})}function ze(){if(r===void 0||e?.outline===void 0)return;let t=$W(e.outline.recipe);if(t===void 0){N(`this recipe has no start point to record from`);return}pe.mutate({recipeId:r,startUrl:t})}async function Be(){if(ge===void 0||e?.outline===void 0)return;let n=GD.getState().startUrl;if(n===void 0)return;let i=e.outline.recipe.session,a=$G(i)?i:{},o=a.bootstrap,s=$G(o)?o:void 0,c=eG(e.file,r??`recipe`),l={...a,bootstrap:QW(n,ge,s,c)};await t?.(e.file,{...e.outline,recipe:{...e.outline.recipe,session:l}}),M(`Made the login: session.bootstrap, ${ge.length} step${ge.length===1?``:`s`}`),fe()}async function Ve(){if(ge===void 0||e?.outline===void 0)return;let t=GD.getState().startUrl;if(t===void 0)return;let n=GD.getState().cards;await Re(e=>vD(e,void 0,[XW(t,`steps.${e.length}`),...n.map(e=>e.node)])),M(`Kept as steps: ${ge.length} step${ge.length===1?``:`s`}`),fe()}if(r===void 0)return(0,F.jsx)(I,{p:4,color:`fg.muted`,children:(0,F.jsx)(V,{children:`Pick a recipe to see its snapshot here.`})});function He(){if(Te){k();return}ye.current=void 0,O(r,JG)}return(0,F.jsxs)(I,{h:`full`,display:`flex`,flexDirection:`column`,children:[(0,F.jsxs)(W,{px:3,py:2,borderBottomWidth:`1px`,gap:3,flexShrink:0,minH:`38px`,children:[!f&&!p&&!m&&!h&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{as:`button`,fontSize:`sm`,fontWeight:Te?`semibold`:`normal`,whiteSpace:`nowrap`,color:Te?`colorPalette.fg`:`fg`,colorPalette:`brand`,cursor:`pointer`,title:`Pick data from the page: click here, then click the text you want to collect (click two similar things to collect a whole list)`,onClick:He,children:Te?`Cancel pick`:`Read`}),(0,F.jsxs)(oT,{checked:E,onCheckedChange:e=>{ee(e.checked)},size:`sm`,title:`Also show the parts of the page that are normally out of sight (menus, pop-ups, tabs that are not open)`,children:[(0,F.jsx)(uT,{}),(0,F.jsx)(lT,{}),(0,F.jsx)(sT,{fontSize:`sm`,whiteSpace:`nowrap`,children:`Show hidden`})]}),(0,F.jsx)(V,{as:`button`,fontSize:`sm`,fontWeight:o?`semibold`:`normal`,color:o?`colorPalette.fg`:`fg`,colorPalette:`purple`,cursor:`pointer`,title:`See how the page is built, and the data it loads: for things that are hard to click`,onClick:()=>{s(e=>!e)},children:o?`Hide inspector`:`Inspect`}),(0,F.jsx)(V,{as:`button`,fontSize:`sm`,fontWeight:he?`semibold`:`normal`,color:he?`red.fg`:`fg`,colorPalette:`red`,cursor:`pointer`,title:`Open a real browser window and record what you click and type (to log in, open a menu or fill a form), as steps`,onClick:()=>{he?me.mutate():ze()},children:he?`Stop recording`:`Record`})]}),f&&(d===`json`||d===`yaml`)&&(0,F.jsx)(KV,{value:c,onChange:l}),f&&(0,F.jsx)(V,{fontSize:`sm`,color:`fg.muted`,children:`Click a value to collect it. Click [*] beside a field to collect it for every item of a list.`}),(i.isFetching||f&&y.isFetching||p&&b.isFetching||m&&C.isFetching||h&&w.isFetching)&&(0,F.jsx)(zC,{size:`xs`}),_e!==void 0&&(0,F.jsx)(LC,{size:`sm`,colorPalette:_e.ok?`green`:`orange`,children:_e.text}),(0,F.jsx)(I,{ml:`auto`,children:(0,F.jsx)(HG,{...Ce})})]}),he&&(0,F.jsxs)(W,{px:3,py:2,bg:`red.subtle`,color:`red.fg`,fontSize:`sm`,gap:3,flexShrink:0,"data-testid":`recording-banner`,children:[(0,F.jsx)(I,{w:`8px`,h:`8px`,borderRadius:`full`,bg:`red.solid`,flexShrink:0}),(0,F.jsx)(V,{children:`Recording — a browser window opened for you to drive; interact with it, not with the snapshot below.`}),(0,F.jsxs)(LC,{size:`sm`,colorPalette:`red`,children:[le,` step`,le===1?``:`s`]})]}),de!==void 0&&ce===r&&(0,F.jsx)(I,{px:3,py:1,bg:`red.subtle`,color:`red.fg`,fontSize:`sm`,flexShrink:0,children:de}),ge!==void 0&&(0,F.jsxs)(W,{px:3,py:2,borderBottomWidth:`1px`,gap:3,flexShrink:0,"data-testid":`recording-stopped-bar`,children:[(0,F.jsxs)(V,{fontSize:`sm`,children:[`Recording stopped: `,ge.length,` step`,ge.length===1?``:`s`,` recorded.`]}),(0,F.jsx)(UC,{size:`xs`,colorPalette:`brand`,onClick:()=>{Be()},disabled:ge.length===0,children:`Make this the login`}),(0,F.jsx)(UC,{size:`xs`,variant:`outline`,onClick:()=>{Ve()},disabled:ge.length===0,children:`Keep as steps`}),(0,F.jsx)(UC,{size:`xs`,variant:`ghost`,onClick:fe,children:`Discard`})]}),i.data?.notice!==void 0&&(0,F.jsx)(GV,{text:i.data.notice}),be!==void 0&&r!==void 0&&!f&&!p&&!m&&!h&&(0,F.jsx)(rG,{recipeId:r,stepPath:JG,heading:IG(be),hint:LG(be),preview:be.text,groups:FG(be).map(e=>({title:e.title,options:e.options,selected:e.selected,onSelect:t=>{xe(n=>n===void 0?n:e.target===`item`?{...n,itemSelector:t}:{...n,fieldSelector:t})},...e.generatedId!==void 0&&{generatedId:e.generatedId}})),collect:MG(be)===void 0?void 0:{matches:MG(be),many:NG(be),onChange:e=>{xe(t=>t===void 0?t:{...t,many:e})}},onAdd:()=>{je()},onCancel:Me}),g&&i.data!==void 0&&i.data.notice===void 0&&!v&&(0,F.jsx)(WV,{}),(0,F.jsxs)(I,{ref:Se,flex:`1`,minH:`0`,overflow:`auto`,style:p?void 0:{zoom:Ce.zoom},onContextMenu:e=>{e.preventDefault()},children:[f&&c===`text`&&i.data!==void 0&&(0,F.jsx)(dG,{html:i.data.html,pickMode:!1,showHidden:!1,onHoverNode:()=>{},onPickNode:()=>{}}),f&&c===`tree`&&y.data!==void 0&&(0,F.jsx)(gG,{tree:y.data,onPick:oe,steps:ie,hoveredStepId:D,onHoverStepId:ne}),f&&y.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:y.error.message})}),p&&b.data!==void 0&&(0,F.jsx)(NW,{recipeId:r,stepPath:JG,view:b.data,zoom:Ce.zoom,bytesUrl:u.pdfBytesUrl(r,JG,i.data?.baseUrl),onTablePick:e=>{Pe(e)},onRegionPick:e=>{Fe(e)},steps:ie,hoveredStepId:D,onHoverStepId:ne},u.pdfBytesUrl(r,JG,i.data?.baseUrl)),p&&b.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:b.error.message})}),m&&C.data!==void 0&&(0,F.jsx)(AU,{recipeId:r,stepPath:JG,view:C.data,onTablePick:e=>{Pe(e)},onCellPick:e=>{Fe(e)},steps:ie,hoveredStepId:D,onHoverStepId:ne,csvOverride:x,onCsvOverrideChange:S}),m&&C.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:C.error.message})}),h&&w.data!==void 0&&(0,F.jsx)($H,{recipeId:r,stepPath:JG,view:w.data,onTablePick:e=>{Pe(e)},onChartPick:e=>{Ie(e)},onRegionPick:e=>{Fe(e)},steps:ie,hoveredStepId:D,onHoverStepId:ne}),h&&w.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:w.error.message})}),!f&&!p&&!m&&!h&&i.data!==void 0&&!o&&(0,F.jsx)(dG,{html:i.data.html,pickMode:Te,showHidden:E,hoveredSelector:re,onHoverNode:se,onPickNode:e=>{ke(e)}}),!f&&!p&&!m&&!h&&i.data!==void 0&&o&&(0,F.jsxs)(Qw,{panels:[{id:`snapshot`,minSize:15},{id:`inspect`,minSize:20}],h:`full`,children:[(0,F.jsx)($w,{id:`snapshot`,overflow:`hidden`,children:(0,F.jsx)(dG,{html:i.data.html,pickMode:Te,showHidden:E,hoveredSelector:re,onHoverNode:se,onPickNode:e=>{ke(e)}})}),(0,F.jsx)(nT,{id:`snapshot:inspect`}),(0,F.jsx)($w,{id:`inspect`,overflow:`hidden`,children:(0,F.jsx)(uk,{recipeId:r,recipe:e,snapshot:i.data,onSaveOutline:t,onSaveRecipe:n})})]}),i.isError&&(0,F.jsxs)(I,{p:4,color:`fg.error`,role:`alert`,children:[(0,F.jsx)(V,{fontWeight:`semibold`,children:`Could not take a snapshot of this recipe's page.`}),(0,F.jsx)(V,{children:FD(i.error.message)})]}),!i.isFetching&&!i.isError&&i.data===void 0&&(0,F.jsx)(I,{p:4,color:`fg.muted`,children:(0,F.jsx)(V,{children:`Run a sample, or open a recipe, to see its snapshot here.`})})]})]})}function $G(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var eK=1024,tK=0,nK=class{constructor(e,t){this.from=e,this.to=t}},rK=class{constructor(e={}){this.id=tK++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw Error(`This node type doesn't define a deserialize function`)}),this.combine=e.combine||null}add(e){if(this.perNode)throw RangeError(`Can't add per-node props to node types`);return typeof e!=`function`&&(e=oK.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};rK.closedBy=new rK({deserialize:e=>e.split(` `)}),rK.openedBy=new rK({deserialize:e=>e.split(` `)}),rK.group=new rK({deserialize:e=>e.split(` `)}),rK.isolate=new rK({deserialize:e=>{if(e&&e!=`rtl`&&e!=`ltr`&&e!=`auto`)throw RangeError(`Invalid value for isolate: `+e);return e||`auto`}}),rK.contextHash=new rK({perNode:!0}),rK.lookAhead=new rK({perNode:!0}),rK.mounted=new rK({perNode:!0});var iK=class{constructor(e,t,n,r=!1){this.tree=e,this.overlay=t,this.parser=n,this.bracketed=r}static get(e){return e&&e.props&&e.props[rK.mounted.id]}},aK=Object.create(null),oK=class e{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(t){let n=t.props&&t.props.length?Object.create(null):aK,r=+!!t.top|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new e(t.name||``,n,t.id,r);if(t.props){for(let e of t.props)if(Array.isArray(e)||(e=e(i)),e){if(e[0].perNode)throw RangeError(`Can't store a per-node prop on a node type`);n[e[0].id]=e[1]}}return i}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e==`string`){if(this.name==e)return!0;let t=this.prop(rK.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(` `))t[r]=e[n];return e=>{for(let n=e.prop(rK.group),r=-1;r<(n?n.length:0);r++){let i=t[r<0?e.name:n[r]];if(i)return i}}}};oK.none=new oK(``,Object.create(null),0,8);var sK=class e{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw RangeError(`Node type ids should correspond to array positions when creating a node set`)}extend(...t){let n=[];for(let e of this.types){let r=null;for(let n of t){let t=n(e);if(t){r||=Object.assign({},e.props);let n=t[1],i=t[0];i.combine&&i.id in r&&(n=i.combine(r[i.id],n)),r[i.id]=n}}n.push(r?new oK(e.name,r,e.id,e.flags):e)}return new e(n)}},cK=new WeakMap,lK=new WeakMap,uK;(function(e){e[e.ExcludeBuffers=1]=`ExcludeBuffers`,e[e.IncludeAnonymous=2]=`IncludeAnonymous`,e[e.IgnoreMounts=4]=`IgnoreMounts`,e[e.IgnoreOverlays=8]=`IgnoreOverlays`,e[e.EnterBracketed=16]=`EnterBracketed`})(uK||={});var dK=class e{constructor(e,t,n,r,i){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)this.props[typeof e==`number`?e:e.id]=t}}toString(){let e=iK.get(this);if(e&&!e.overlay)return e.tree.toString();let t=``;for(let e of this.children){let n=e.toString();n&&(t&&(t+=`,`),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?`(`+t+`)`:``):t}cursor(e=0){return new TK(this.topNode,e)}cursorAt(e,t=0,n=0){let r=new TK(cK.get(this)||this.topNode);return r.moveTo(e,t),cK.set(this,r._tree),r}get topNode(){return new _K(this,0,0,null)}resolve(e,t=0){let n=hK(cK.get(this)||this.topNode,e,t,!1);return cK.set(this,n),n}resolveInner(e,t=0){let n=hK(lK.get(this)||this.topNode,e,t,!0);return lK.set(this,n),n}resolveStack(e,t=0){return wK(this,e,t)}iterate(e){let{enter:t,leave:n,from:r=0,to:i=this.length}=e,a=e.mode||0,o=(a&uK.IncludeAnonymous)>0;for(let e=this.cursor(a|uK.IncludeAnonymous);;){let a=!1;if(e.from<=i&&e.to>=r&&(!o&&e.type.isAnonymous||t(e)!==!1)){if(e.firstChild())continue;a=!0}for(;a&&n&&(o||!e.type.isAnonymous)&&n(e),!e.nextSibling();){if(!e.parent())return;a=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(t={}){return this.children.length<=8?this:AK(oK.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new e(this.type,t,n,r,this.propValues),t.makeTree||((t,n,r)=>new e(oK.none,t,n,r)))}static build(e){return DK(e)}};dK.empty=new dK(oK.none,[],[],0);var fK=class e{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new e(this.buffer,this.index)}},pK=class e{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return oK.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(`,`)}childString(e){let t=this.buffer[e],n=this.buffer[e+3],r=this.set.types[t],i=r.name;if(/\W/.test(i)&&!r.isError&&(i=JSON.stringify(i)),e+=4,n==e)return i;let a=[];for(;e<n;)a.push(this.childString(e)),e=this.buffer[e+3];return i+`(`+a.join(`,`)+`)`}findChild(e,t,n,r,i){let{buffer:a}=this,o=-1;for(let s=e;s!=t&&!(mK(i,r,a[s+1],a[s+2])&&(o=s,n>0));s=a[s+3]);return o}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let e=t,s=0;e<n;){a[s++]=i[e++],a[s++]=i[e++]-r;let n=a[s++]=i[e++]-r;a[s++]=i[e++]-t,o=Math.max(o,n)}return new e(a,o,this.set)}};function mK(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function hK(e,t,n,r){for(;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let t=!r&&e instanceof _K&&e.index<0?null:e.parent;if(!t)return e;e=t}let i=r?0:uK.IgnoreOverlays;if(r)for(let r=e,a=r.parent;a;r=a,a=r.parent)r instanceof _K&&r.index<0&&a.enter(t,n,i)?.from!=r.from&&(e=a);for(;;){let r=e.enter(t,n,i);if(!r)return e;e=r}}var gK=class{cursor(e=0){return new TK(this,e)}getChild(e,t=null,n=null){let r=vK(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return vK(this,e,t,n)}resolve(e,t=0){return hK(this,e,t,!1)}resolveInner(e,t=0){return hK(this,e,t,!0)}matchContext(e){return yK(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),n=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(n=t,t=e.prevSibling):t=e}return n}get node(){return this}get next(){return this.parent}},_K=class e extends gK{constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,i,a=0){for(let o=this;;){for(let{children:s,positions:c}=o._tree,l=n>0?s.length:-1;t!=l;t+=n){let l=s[t],u=c[t]+o.from,d;if(a&uK.EnterBracketed&&l instanceof dK&&(d=iK.get(l))&&!d.overlay&&d.bracketed&&r>=u&&r<=u+l.length||mK(i,r,u,u+l.length)){if(l instanceof pK){if(a&uK.ExcludeBuffers)continue;let e=l.findChild(0,l.buffer.length,n,r-u,i);if(e>-1)return new xK(new bK(o,l,t,u),null,e)}else if(a&uK.IncludeAnonymous||!l.type.isAnonymous||EK(l)){let s;if(!(a&uK.IgnoreMounts)&&(s=iK.get(l))&&!s.overlay)return new e(s.tree,u,t,o);let c=new e(l,u,t,o);return a&uK.IncludeAnonymous||!c.type.isAnonymous?c:c.nextChild(n<0?l.children.length-1:0,n,r,i,a)}}}if(a&uK.IncludeAnonymous||!o.type.isAnonymous||(t=o.index>=0?o.index+n:n<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(t,n,r=0){let i;if(!(r&uK.IgnoreOverlays)&&(i=iK.get(this._tree))&&i.overlay){let a=t-this.from,o=r&uK.EnterBracketed&&i.bracketed;for(let{from:t,to:r}of i.overlay)if((n>0||o?t<=a:t<a)&&(n<0||o?r>=a:r>a))return new e(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function vK(e,t,n,r){let i=e.cursor(),a=[];if(!i.firstChild())return a;if(n!=null){for(let e=!1;!e;)if(e=i.type.is(n),!i.nextSibling())return a}for(;;){if(r!=null&&i.type.is(r))return a;if(i.type.is(t)&&a.push(i.node),!i.nextSibling())return r==null?a:[]}}function yK(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}var bK=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},xK=class e extends gK{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new e(this.context,this,a)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(t,n,r=0){if(r&uK.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new e(this.context,this,a)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new e(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new e(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let a=n.buffer[this.index+1];e.push(n.slice(r,i,a)),t.push(0)}return new dK(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function SK(e){if(!e.length)return null;let t=0,n=e[0];for(let r=1;r<e.length;r++){let i=e[r];(i.from>n.from||i.to<n.to)&&(n=i,t=r)}let r=n instanceof _K&&n.index<0?null:n.parent,i=e.slice();return r?i[t]=r:i.splice(t,1),new CK(i,n)}var CK=class{constructor(e,t){this.heads=e,this.node=t}get next(){return SK(this.heads)}};function wK(e,t,n){let r=e.resolveInner(t,n),i=null;for(let e=r instanceof _K?r:r.context.parent;e;e=e.parent)if(e.index<0){let a=e.parent;(i||=[r]).push(a.resolve(t,n)),e=a}else{let a=iK.get(e.tree);if(a&&a.overlay&&a.overlay[0].from<=t&&a.overlay[a.overlay.length-1].to>=t){let o=new _K(a.tree,a.overlay[0].from+e.from,-1,e);(i||=[r]).push(hK(o,t,n,!1))}}return i?SK(i):r}var TK=class{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~uK.EnterBracketed,e instanceof _K)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof _K?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&uK.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&uK.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&uK.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let e=n<0?0:this.stack[n]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(e)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(r.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let r=t+e,i=e<0?-1:n._tree.children.length;r!=i;r+=e){let e=n._tree.children[r];if(this.mode&uK.IncludeAnonymous||e instanceof pK||!e.type.isAnonymous||EK(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)scan:for(let r=this.index,i=this.stack.length;i>=0;){for(let a=e;a;a=a._parent)if(a.index==r){if(r==this.index)return a;t=a,n=i+1;break scan}r=this.stack[--i]}for(let e=n;e<this.stack.length;e++)t=new xK(this.buffer,t,this.stack[e]);return this.bufferNode=new xK(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!n)return;if(this.nextSibling())break;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return yK(this.node.parent,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,i=this.stack.length-1;r>=0;i--){if(i<0)return yK(this._tree,e,r);let a=n[t.buffer[this.stack[i]]];if(!a.isAnonymous){if(e[r]&&e[r]!=a.name)return!1;r--}}return!0}};function EK(e){return e.children.some(e=>e instanceof pK||!e.type.isAnonymous||EK(e))}function DK(e){let{buffer:t,nodeSet:n,maxBufferLength:r=eK,reused:i=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(t)?new fK(t,t.length):t,s=n.types,c=0,l=0;function u(e,t,_,v,y,b){let{id:x,start:S,end:C,size:w}=o,T=l,E=c;if(w<0){if(o.next(),w==-1){let t=i[x];_.push(t),v.push(S-e);return}if(w==-3){c=x;return}if(w==-4){l=x;return}throw RangeError(`Unrecognized record size: ${w}`)}let D=s[x],O,k,A=S-e;if(C-S<=r&&(k=h(o.pos-t,y))){let t=new Uint16Array(k.size-k.skip),r=o.pos-k.size,i=t.length;for(;o.pos>r;)i=g(k.start,t,i);O=new pK(t,C-k.start,n),A=k.start-e}else{let e=o.pos-w;o.next();let t=[],n=[],i=x>=a?x:-1,s=0,c=C;for(;o.pos>e;)i>=0&&o.id==i&&o.size>=0?(o.end<=c-r&&(p(t,n,S,s,o.end,c,i,T,E),s=t.length,c=o.end),o.next()):b>2500?d(S,e,t,n):u(S,e,t,n,i,b+1);if(i>=0&&s>0&&s<t.length&&p(t,n,S,s,S,c,i,T,E),t.reverse(),n.reverse(),i>-1&&s>0){let e=f(D,E);O=AK(D,t,n,0,t.length,0,C-S,e,e)}else O=m(D,t,n,C-S,T-C,E)}_.push(O),v.push(A)}function d(e,t,i,a){let s=[],c=0,l=-1;for(;o.pos>t;){let{id:e,start:t,end:n,size:i}=o;if(i>4)o.next();else if(l>-1&&t<l)break;else l<0&&(l=n-r),s.push(e,t,n),c++,o.next()}if(c){let t=new Uint16Array(c*4),r=s[s.length-2];for(let e=s.length-3,n=0;e>=0;e-=3)t[n++]=s[e],t[n++]=s[e+1]-r,t[n++]=s[e+2]-r,t[n++]=n;i.push(new pK(t,s[2]-r,n)),a.push(r-e)}}function f(e,t){return(n,r,i)=>{let a=0,o=n.length-1,s,c;if(o>=0&&(s=n[o])instanceof dK){if(!o&&s.type==e&&s.length==i)return s;(c=s.prop(rK.lookAhead))&&(a=r[o]+s.length+c)}return m(e,n,r,i,a,t)}}function p(e,t,r,i,a,o,s,c,l){let u=[],d=[];for(;e.length>i;)u.push(e.pop()),d.push(t.pop()+r-a);e.push(m(n.types[s],u,d,o-a,c-o,l)),t.push(a-r)}function m(e,t,n,r,i,a,o){if(a){let e=[rK.contextHash,a];o=o?[e].concat(o):[e]}if(i>25){let e=[rK.lookAhead,i];o=o?[e].concat(o):[e]}return new dK(e,t,n,r,o)}function h(e,t){let n=o.fork(),i=0,s=0,c=0,l=n.end-r,u={size:0,start:0,skip:0};scan:for(let r=n.pos-e;n.pos>r;){let e=n.size;if(n.id==t&&e>=0){u.size=i,u.start=s,u.skip=c,c+=4,i+=4,n.next();continue}let o=n.pos-e;if(e<0||o<r||n.start<l)break;let d=n.id>=a?4:0,f=n.start;for(n.next();n.pos>o;){if(n.size<0){if(n.size==-3||n.size==-4)d+=4;else break scan}else n.id>=a&&(d+=4);n.next()}s=f,i+=e,c+=d}return(t<0||i==e)&&(u.size=i,u.start=s,u.skip=c),u.size>4?u:void 0}function g(e,t,n){let{id:r,start:i,end:s,size:u}=o;if(o.next(),u>=0&&r<a){let a=n;if(u>4){let r=o.pos-(u-4);for(;o.pos>r;)n=g(e,t,n)}t[--n]=a,t[--n]=s-e,t[--n]=i-e,t[--n]=r}else u==-3?c=r:u==-4&&(l=r);return n}let _=[],v=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,_,v,-1,0);let y=e.length??(_.length?v[0]+_[0].length:0);return new dK(s[e.topID],_.reverse(),v.reverse(),y)}var OK=new WeakMap;function kK(e,t){if(!e.isAnonymous||t instanceof pK||t.type!=e)return 1;let n=OK.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof dK)){n=1;break}n+=kK(e,r)}OK.set(t,n)}return n}function AK(e,t,n,r,i,a,o,s,c){let l=0;for(let n=r;n<i;n++)l+=kK(e,t[n]);let u=Math.ceil(l*1.5/8),d=[],f=[];function p(t,n,r,i,o){for(let s=r;s<i;){let r=s,l=n[s],m=kK(e,t[s]);for(s++;s<i;s++){let n=kK(e,t[s]);if(m+n>=u)break;m+=n}if(s==r+1){if(m>u){let e=t[r];p(e.children,e.positions,0,e.children.length,n[r]+o);continue}d.push(t[r])}else{let i=n[s-1]+t[s-1].length-l;d.push(AK(e,t,n,r,s,l,i,null,c))}f.push(l+o-a)}}return p(t,n,r,i,0),(s||c)(d,f,o)}var jK=class e{constructor(e,t,n,r,i=!1,a=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=!!i|(a?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let i=[new e(0,t.length,t,0,!1,r)];for(let e of n)e.to>t.length&&i.push(e);return i}static applyChanges(t,n,r=128){if(!n.length)return t;let i=[],a=1,o=t.length?t[0]:null;for(let s=0,c=0,l=0;;s++){let u=s<n.length?n[s]:null,d=u?u.fromA:1e9;if(d-c>=r)for(;o&&o.from<d;){let n=o;if(c>=n.from||d<=n.to||l){let t=Math.max(n.from,c)-l,r=Math.min(n.to,d)-l;n=t>=r?null:new e(t,r,n.tree,n.offset+l,s>0,!!u)}if(n&&i.push(n),o.to>d)break;o=a<t.length?t[a++]:null}if(!u)break;c=u.toA,l=u.toA-u.toB}return i}},MK=class{startParse(e,t,n){return typeof e==`string`&&(e=new NK(e)),n=n?n.length?n.map(e=>new nK(e.from,e.to)):[new nK(0,0)]:[new nK(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let e=r.advance();if(e)return e}}},NK=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};new rK({perNode:!0});var PK=class e{constructor(e,t,n,r,i,a,o,s,c,l=0,u){this.p=e,this.stack=t,this.state=n,this.reducePos=r,this.pos=i,this.score=a,this.buffer=o,this.bufferBase=s,this.curContext=c,this.lookAhead=l,this.parent=u}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?`!`+this.score:``}`}static start(t,n,r=0){let i=t.parser.context;return new e(t,[],n,r,r,0,[],0,i?new FK(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){let t=e>>19,n=e&65535,{parser:r}=this.p,i=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),a=r.dynamicPrecedence(n);if(a&&(this.score+=a),t==0){n<r.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,i?8:4,!0),this.reduceContext(n,this.reducePos);return}let o=this.stack.length-(t-1)*3-(e&262144?6:0),s=o?this.stack[o-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&s==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let c=this.reducePos-s;c>=2e3&&!this.p.parser.nodeSet.types[n]?.isAnonymous&&(s==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=s,this.p.lastBigReductionSize=c));let l=o?this.stack[o-1]:0,u=this.bufferBase+this.buffer.length-l;if(n<r.minRepeatTerm||e&131072){let e=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,s,e,u+4,!0)}if(e&262144)this.state=this.stack[o];else{let e=this.stack[o-3];this.state=r.getGoto(e,n,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(n,s)}storeNode(e,t,n,r=4,i=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let e=this.buffer.length;if(e>0&&this.buffer[e-4]==0&&this.buffer[e-1]>-1){if(t==n)return;if(this.buffer[e-2]>=t){this.buffer[e-2]=n;return}}}if(!i||this.pos==n)this.buffer.push(e,t,n,r);else{let i=this.buffer.length;if(i>0&&(this.buffer[i-4]!=0||this.buffer[i-1]<0)){let e=!1;for(let t=i;t>0&&this.buffer[t-2]>n;t-=4)if(this.buffer[t-1]>=0){e=!0;break}if(e)for(;i>0&&this.buffer[i-2]>n;)this.buffer[i]=this.buffer[i-4],this.buffer[i+1]=this.buffer[i-3],this.buffer[i+2]=this.buffer[i-2],this.buffer[i+3]=this.buffer[i-1],i-=4,r>4&&(r-=4)}this.buffer[i]=e,this.buffer[i+1]=t,this.buffer[i+2]=n,this.buffer[i+3]=r}}shift(e,t,n,r){if(e&131072)this.pushState(e&65535,this.pos);else if(e&262144)this.pos=r,this.shiftContext(t,n),t<=this.p.parser.maxNode&&this.buffer.push(t,n,r,4);else{let i=e,{parser:a}=this.p;this.pos=r;let o=a.stateFlag(i,1);!o&&(r>n||t<=a.maxNode)&&(this.reducePos=r),this.pushState(i,o?n:Math.min(n,this.reducePos)),this.shiftContext(t,n),t<=a.maxNode&&this.buffer.push(t,n,r,4)}}apply(e,t,n,r){e&65536?this.reduce(e):this.shift(e,t,n,r)}useNode(e,t){let n=this.p.reused.length-1;(n<0||this.p.reused[n]!=e)&&(this.p.reused.push(e),n++);let r=this.pos;this.reducePos=this.pos=r+e.length,this.pushState(t,r),this.buffer.push(n,r,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let t=this,n=t.buffer.length;for(n&&t.buffer[n-4]==0&&(n-=4);n>0&&t.buffer[n-2]>t.reducePos;)n-=4;let r=t.buffer.slice(n),i=t.bufferBase+n;for(;t&&i==t.bufferBase;)t=t.parent;return new e(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,r,i,this.curContext,this.lookAhead,t)}recoverByDelete(e,t){let n=e<=this.p.parser.maxNode;n&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,n?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new IK(this);;){let n=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(n==0)return!1;if(!(n&65536))return!0;t.reduce(n)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let n=[];for(let r=0,i;r<t.length;r+=2)(i=t[r+1])!=this.state&&this.p.parser.hasAction(i,e)&&n.push(t[r],i);if(this.stack.length<120)for(let e=0;n.length<8&&e<t.length;e+=2){let r=t[e+1];n.some((e,t)=>t&1&&e==r)||n.push(t[e],r)}t=n}let n=[];for(let e=0;e<t.length&&n.length<4;e+=2){let r=t[e+1];if(r==this.state)continue;let i=this.split();i.pushState(r,this.pos),i.storeNode(0,i.pos,i.pos,4,!0),i.shiftContext(t[e],this.pos),i.reducePos=this.pos,i.score-=200,n.push(i)}return n}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if(!(t&65536))return!1;if(!e.validAction(this.state,t)){let n=t>>19,r=t&65535,i=this.stack.length-n*3;if(i<0||e.getGoto(this.stack[i],r,!1)<0){let e=this.findForcedReduction();if(e==null)return!1;t=e}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],n=(r,i)=>{if(!t.includes(r))return t.push(r),e.allActions(r,t=>{if(!(t&393216)){if(t&65536){let n=(t>>19)-i;if(n>1){let r=t&65535,i=this.stack.length-n*3;if(i>=0&&e.getGoto(this.stack[i],r,!1)>=0)return n<<19|65536|r}}else{let e=n(t,i+1);if(e!=null)return e}}})};return n(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new FK(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},FK=class{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}},IK=class{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,n=e>>19;n==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(n-1)*3;let r=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=r}},LK=class e{constructor(e,t,n){this.stack=e,this.pos=t,this.index=n,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(t,n=t.bufferBase+t.buffer.length){return new e(t,n,n-t.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new e(this.stack,this.pos,this.index)}};function RK(e,t=Uint16Array){if(typeof e!=`string`)return e;let n=null;for(let r=0,i=0;r<e.length;){let a=0;for(;;){let t=e.charCodeAt(r++),n=!1;if(t==126){a=65535;break}t>=92&&t--,t>=34&&t--;let i=t-32;if(i>=46&&(i-=46,n=!0),a+=i,n)break;a*=46}n?n[i++]=a:n=new t(a)}return n}var zK=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},BK=new zK,VK=class{constructor(e,t){this.input=e,this.ranges=t,this.chunk=``,this.chunkOff=0,this.chunk2=``,this.chunk2Pos=0,this.next=-1,this.token=BK,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let n=this.range,r=this.rangeIndex,i=this.pos+e;for(;i<n.from;){if(!r)return null;let e=this.ranges[--r];i-=n.from-e.to,n=e}for(;t<0?i>n.to:i>=n.to;){if(r==this.ranges.length-1)return null;let e=this.ranges[++r];i+=e.from-n.to,n=e}return i}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,n,r;if(t>=0&&t<this.chunk.length)n=this.pos+e,r=this.chunk.charCodeAt(t);else{let t=this.resolveOffset(e,1);if(t==null)return-1;if(n=t,n>=this.chunk2Pos&&n<this.chunk2Pos+this.chunk2.length)r=this.chunk2.charCodeAt(n-this.chunk2Pos);else{let e=this.rangeIndex,t=this.range;for(;t.to<=n;)t=this.ranges[++e];this.chunk2=this.input.chunk(this.chunk2Pos=n),n+this.chunk2.length>t.to&&(this.chunk2=this.chunk2.slice(0,t.to-n)),r=this.chunk2.charCodeAt(0)}}return n>=this.token.lookAhead&&(this.token.lookAhead=n+1),r}acceptToken(e,t=0){let n=t?this.resolveOffset(t,-1):this.pos;if(n==null||n<this.token.start)throw RangeError(`Token end out of bounds`);this.token.value=e,this.token.end=n}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.next=this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?-1:this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk=``,this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=BK,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk=``,this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let n=``;for(let r of this.ranges){if(r.from>=t)break;r.to>e&&(n+=this.input.read(Math.max(r.from,e),Math.min(r.to,t)))}return n}},HK=class{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:n}=t.p;WK(this.data,e,t,this.id,n.data,n.tokenPrecTable)}};HK.prototype.contextual=HK.prototype.fallback=HK.prototype.extend=!1;var UK=class{constructor(e,t,n){this.precTable=t,this.elseToken=n,this.data=typeof e==`string`?RK(e):e}token(e,t){let n=e.pos,r=0;for(;;){let n=e.next<0,i=e.resolveOffset(1,1);if(WK(this.data,e,t,0,this.data,this.precTable),e.token.value>-1)break;if(this.elseToken==null)return;if(n||r++,i==null)break;e.reset(i,e.token)}r&&(e.reset(n,e.token),e.acceptToken(this.elseToken,r))}};UK.prototype.contextual=HK.prototype.fallback=HK.prototype.extend=!1;function WK(e,t,n,r,i,a){let o=0,s=1<<r,{dialect:c}=n.p.parser;scan:for(;(s&e[o])!=0;){let n=e[o+1];for(let r=o+3;r<n;r+=2)if((e[r+1]&s)>0){let n=e[r];if(c.allows(n)&&(t.token.value==-1||t.token.value==n||KK(n,t.token.value,i,a))){t.acceptToken(n);break}}let r=t.next,l=0,u=e[o+2];if(t.next<0&&u>l&&e[n+u*3-3]==65535){o=e[n+u*3-1];continue scan}for(;l<u;){let i=l+u>>1,a=n+i+(i<<1),s=e[a],c=e[a+1]||65536;if(r<s)u=i;else if(r>=c)l=i+1;else{o=e[a+2],t.advance();continue scan}}break}}function GK(e,t,n){for(let r=t,i;(i=e[r])!=65535;r++)if(i==n)return r-t;return-1}function KK(e,t,n,r){let i=GK(n,r,t);return i<0||GK(n,r,e)<i}var qK=typeof process<`u`&&/\bparse\b/.test({}.LOG),JK=null;function YK(e,t,n){let r=e.cursor(uK.IncludeAnonymous);for(r.moveTo(t);;)if(!(n<0?r.childBefore(t):r.childAfter(t)))for(;;){if((n<0?r.to<t:r.from>t)&&!r.type.isError)return n<0?Math.max(0,Math.min(r.to-1,t-25)):Math.min(e.length,Math.max(r.from+1,t+25));if(n<0?r.prevSibling():r.nextSibling())break;if(!r.parent())return n<0?0:e.length}}var XK=class{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?YK(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?YK(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let n=this.trees[t],r=this.index[t];if(r==n.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let i=n.children[r],a=this.start[t]+n.positions[r];if(a>e)return this.nextStart=a,null;if(i instanceof dK){if(a==e){if(a<this.safeFrom)return null;let e=a+i.length;if(e<=this.safeTo){let t=i.prop(rK.lookAhead);if(!t||e+t<this.fragment.to)return i}}this.index[t]++,a+i.length>=Math.max(this.safeFrom,e)&&(this.trees.push(i),this.start.push(a),this.index.push(0))}else this.index[t]++,this.nextStart=a+i.length}}},ZK=class{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(e=>new zK)}getActions(e){let t=0,n=null,{parser:r}=e.p,{tokenizers:i}=r,a=r.stateSlot(e.state,3),o=e.curContext?e.curContext.hash:0,s=0;for(let r=0;r<i.length;r++){if(!(1<<r&a))continue;let c=i[r],l=this.tokens[r];if((!n||c.fallback)&&((c.contextual||l.start!=e.pos||l.mask!=a||l.context!=o)&&(this.updateCachedToken(l,c,e),l.mask=a,l.context=o),l.lookAhead>l.end+25&&(s=Math.max(l.lookAhead,s)),l.value!=0)){let r=t;if(l.extended>-1&&(t=this.addActions(e,l.extended,l.end,t)),t=this.addActions(e,l.value,l.end,t),!c.extend&&(n=l,t>r))break}}for(;this.actions.length>t;)this.actions.pop();return s&&e.setLookAhead(s),!n&&e.pos==this.stream.end&&(n=new zK,n.value=e.p.parser.eofTerm,n.start=n.end=e.pos,t=this.addActions(e,n.value,n.end,t)),this.mainToken=n,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new zK,{pos:n,p:r}=e;return t.start=n,t.end=Math.min(n+1,r.stream.end),t.value=n==r.stream.end?r.parser.eofTerm:0,t}updateCachedToken(e,t,n){let r=this.stream.clipPos(n.pos);if(t.token(this.stream.reset(r,e),n),e.value>-1){let{parser:t}=n.p;for(let r=0;r<t.specialized.length;r++)if(t.specialized[r]==e.value){let i=t.specializers[r](this.stream.read(e.start,e.end),n);if(i>=0&&n.p.parser.dialect.allows(i>>1)){i&1?e.extended=i>>1:e.value=i>>1;break}}}else e.value=0,e.end=this.stream.clipPos(r+1)}putAction(e,t,n,r){for(let t=0;t<r;t+=3)if(this.actions[t]==e)return r;return this.actions[r++]=e,this.actions[r++]=t,this.actions[r++]=n,r}addActions(e,t,n,r){let{state:i}=e,{parser:a}=e.p,{data:o}=a;for(let e=0;e<2;e++)for(let s=a.stateSlot(i,e?2:1);;s+=3){if(o[s]==65535){if(o[s+1]==1)s=nq(o,s+2);else{r==0&&o[s+1]==2&&(r=this.putAction(nq(o,s+2),t,n,r));break}}o[s]==t&&(r=this.putAction(nq(o,s+1),t,n,r))}return r}},QK=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new VK(t,r),this.tokens=new ZK(e,this.stream),this.topTerm=e.top[1];let{from:i}=r[0];this.stacks=[PK.start(this,e.top[0],i)],this.fragments=n.length&&this.stream.end-i>e.bufferLength*4?new XK(n,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,n=this.stacks=[],r,i;if(this.bigReductionCount>300&&e.length==1){let[t]=e;for(;t.forceReduce()&&t.stack.length&&t.stack[t.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let a=0;a<e.length;a++){let o=e[a];for(;;){if(this.tokens.mainToken=null,o.pos>t)n.push(o);else if(this.advanceStack(o,n,e))continue;else{r||(r=[],i=[]),r.push(o);let e=this.tokens.getMainToken(o);i.push(e.value,e.end)}break}}if(!n.length){let e=r&&rq(r);if(e)return qK&&console.log(`Finish with `+this.stackID(e)),this.stackToTree(e);if(this.parser.strict)throw qK&&r&&console.log(`Stuck with token `+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):`none`)),SyntaxError(`No parse at `+t);this.recovering||=5}if(this.recovering&&r){let e=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,i,n);if(e)return qK&&console.log(`Force-finish `+this.stackID(e)),this.stackToTree(e.forceAll())}if(this.recovering){let e=this.recovering==1?1:this.recovering*3;if(n.length>e)for(n.sort((e,t)=>t.score-e.score);n.length>e;)n.pop();n.some(e=>e.reducePos>t)&&this.recovering--}else if(n.length>1){outer:for(let e=0;e<n.length-1;e++){let t=n[e];for(let r=e+1;r<n.length;r++){let i=n[r];if(t.sameState(i)||t.buffer.length>500&&i.buffer.length>500){if((t.score-i.score||t.buffer.length-i.buffer.length)>0)n.splice(r--,1);else{n.splice(e--,1);continue outer}}}}n.length>12&&(n.sort((e,t)=>t.score-e.score),n.splice(12,n.length-12))}this.minStackPos=n[0].pos;for(let e=1;e<n.length;e++)n[e].pos<this.minStackPos&&(this.minStackPos=n[e].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw RangeError(`Can't move stoppedAt forward`);this.stoppedAt=e}advanceStack(e,t,n){let r=e.pos,{parser:i}=this,a=qK?this.stackID(e)+` -> `:``;if(this.stoppedAt!=null&&r>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let t=e.curContext&&e.curContext.tracker.strict,n=t?e.curContext.hash:0;for(let o=this.fragments.nodeAt(r);o;){let r=this.parser.nodeSet.types[o.type.id]==o.type?i.getGoto(e.state,o.type.id):-1;if(r>-1&&o.length&&(!t||(o.prop(rK.contextHash)||0)==n))return e.useNode(o,r),qK&&console.log(a+this.stackID(e)+` (via reuse of ${i.getName(o.type.id)})`),!0;if(!(o instanceof dK)||o.children.length==0||o.positions[0]>0)break;let s=o.children[0];if(s instanceof dK&&o.positions[0]==0)o=s;else break}}let o=i.stateSlot(e.state,4);if(o>0)return e.reduce(o),qK&&console.log(a+this.stackID(e)+` (via always-reduce ${i.getName(o&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let s=this.tokens.getActions(e);for(let o=0;o<s.length;){let c=s[o++],l=s[o++],u=s[o++],d=o==s.length||!n,f=d?e:e.split(),p=this.tokens.mainToken;if(f.apply(c,l,p?p.start:f.pos,u),qK&&console.log(a+this.stackID(f)+` (via ${c&65536?`reduce of ${i.getName(c&65535)}`:`shift`} for ${i.getName(l)} @ ${r}${f==e?``:`, split`})`),d)return!0;f.pos>r?t.push(f):n.push(f)}return!1}advanceFully(e,t){let n=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>n)return $K(e,t),!0}}runRecovery(e,t,n){let r=null,i=!1;for(let a=0;a<e.length;a++){let o=e[a],s=t[a<<1],c=t[(a<<1)+1],l=qK?this.stackID(o)+` -> `:``;if(o.deadEnd&&(i||(i=!0,o.restart(),qK&&console.log(l+this.stackID(o)+` (restarted)`),this.advanceFully(o,n))))continue;let u=o.split(),d=l;for(let e=0;e<10&&u.forceReduce()&&(qK&&console.log(d+this.stackID(u)+` (via force-reduce)`),!this.advanceFully(u,n));e++)qK&&(d=this.stackID(u)+` -> `);for(let e of o.recoverByInsert(s))qK&&console.log(l+this.stackID(e)+` (via recover-insert)`),this.advanceFully(e,n);this.stream.end>o.pos?(c==o.pos&&(c++,s=0),o.recoverByDelete(s,c),qK&&console.log(l+this.stackID(o)+` (via recover-delete ${this.parser.getName(s)})`),$K(o,n)):(!r||r.score<u.score)&&(r=u)}return r}stackToTree(e){return e.close(),dK.build({buffer:LK.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(JK||=new WeakMap).get(e);return t||JK.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}};function $K(e,t){for(let n=0;n<t.length;n++){let r=t[n];if(r.pos==e.pos&&r.sameState(e)){t[n].score<e.score&&(t[n]=e);return}}t.push(e)}var eq=class{constructor(e,t,n){this.source=e,this.flags=t,this.disabled=n}allows(e){return!this.disabled||this.disabled[e]==0}},tq=class e extends MK{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(` `);this.minRepeatTerm=t.length;for(let n=0;n<e.repeatNodeCount;n++)t.push(``);let n=Object.keys(e.topRules).map(t=>e.topRules[t][1]),r=[];for(let e=0;e<t.length;e++)r.push([]);function i(e,t,n){r[e].push([t,t.deserialize(String(n))])}if(e.nodeProps)for(let t of e.nodeProps){let e=t[0];typeof e==`string`&&(e=rK[e]);for(let n=1;n<t.length;){let r=t[n++];if(r>=0)i(r,e,t[n++]);else{let a=t[n+-r];for(let o=-r;o>0;o--)i(t[n++],e,a);n++}}}this.nodeSet=new sK(t.map((t,i)=>oK.define({name:i>=this.minRepeatTerm?void 0:t,id:i,props:r[i],top:n.indexOf(i)>-1,error:i==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(i)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=eK;let a=RK(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let e=0;e<this.specializerSpecs.length;e++)this.specialized[e]=this.specializerSpecs[e].term;this.specializers=this.specializerSpecs.map(iq),this.states=RK(e.states,Uint32Array),this.data=RK(e.stateData),this.goto=RK(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(e=>typeof e==`number`?new HK(a,e):e),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,n){let r=new QK(this,e,t,n);for(let i of this.wrappers)r=i(r,e,t,n);return r}getGoto(e,t,n=!1){let r=this.goto;if(t>=r[0])return-1;for(let i=r[t+1];;){let t=r[i++],a=t&1,o=r[i++];if(a&&n)return o;for(let n=i+(t>>1);i<n;i++)if(r[i]==e)return o;if(a)return-1}}hasAction(e,t){let n=this.data;for(let r=0;r<2;r++)for(let i=this.stateSlot(e,r?2:1),a;;i+=3){if((a=n[i])==65535){if(n[i+1]==1)a=n[i=nq(n,i+2)];else if(n[i+1]==2)return nq(n,i+2);else break}if(a==t||a==0)return nq(n,i+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,e=>e==t||null)}allActions(e,t){let n=this.stateSlot(e,4),r=n?t(n):void 0;for(let n=this.stateSlot(e,1);r==null;n+=3){if(this.data[n]==65535){if(this.data[n+1]==1)n=nq(this.data,n+2);else break}r=t(nq(this.data,n+1))}return r}nextStates(e){let t=[];for(let n=this.stateSlot(e,1);;n+=3){if(this.data[n]==65535){if(this.data[n+1]==1)n=nq(this.data,n+2);else break}if(!(this.data[n+2]&1)){let e=this.data[n+1];t.some((t,n)=>n&1&&t==e)||t.push(this.data[n],e)}}return t}configure(t){let n=Object.assign(Object.create(e.prototype),this);if(t.props&&(n.nodeSet=this.nodeSet.extend(...t.props)),t.top){let e=this.topRules[t.top];if(!e)throw RangeError(`Invalid top rule name ${t.top}`);n.top=e}return t.tokenizers&&(n.tokenizers=this.tokenizers.map(e=>{let n=t.tokenizers.find(t=>t.from==e);return n?n.to:e})),t.specializers&&(n.specializers=this.specializers.slice(),n.specializerSpecs=this.specializerSpecs.map((e,r)=>{let i=t.specializers.find(t=>t.from==e.external);if(!i)return e;let a=Object.assign(Object.assign({},e),{external:i.to});return n.specializers[r]=iq(a),a})),t.contextTracker&&(n.context=t.contextTracker),t.dialect&&(n.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(n.strict=t.strict),t.wrap&&(n.wrappers=n.wrappers.concat(t.wrap)),t.bufferLength!=null&&(n.bufferLength=t.bufferLength),n}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),n=t.map(()=>!1);if(e)for(let r of e.split(` `)){let e=t.indexOf(r);e>=0&&(n[e]=!0)}let r=null;for(let e=0;e<t.length;e++)if(!n[e])for(let n=this.dialects[t[e]],i;(i=this.data[n++])!=65535;)(r||=new Uint8Array(this.maxTerm+1))[i]=1;return new eq(e,n,r)}static deserialize(t){return new e(t)}};function nq(e,t){return e[t]|e[t+1]<<16}function rq(e){let t=null;for(let n of e){let e=n.p.stoppedAt;(n.pos==n.p.stream.end||e!=null&&n.pos>e)&&n.p.parser.stateFlag(n.state,2)&&(!t||t.score<n.score)&&(t=n)}return t}function iq(e){if(e.external){let t=+!!e.extend;return(n,r)=>e.external(n,r)<<1|t}return e.get}var aq=0,oq=class e{constructor(e,t,n,r){this.name=e,this.set=t,this.base=n,this.modified=r,this.id=aq++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(t,n){let r=typeof t==`string`?t:`?`;if(t instanceof e&&(n=t),n?.base)throw Error(`Can not derive from a modified tag`);let i=new e(r,[],null,[]);if(i.set.push(i),n)for(let e of n.set)i.set.push(e);return i}static defineModifier(e){let t=new cq(e);return e=>e.modified.indexOf(t)>-1?e:cq.get(e.base||e,e.modified.concat(t).sort((e,t)=>e.id-t.id))}},sq=0,cq=class e{constructor(e){this.name=e,this.instances=[],this.id=sq++}static get(t,n){if(!n.length)return t;let r=n[0].instances.find(e=>e.base==t&&lq(n,e.modified));if(r)return r;let i=[],a=new oq(t.name,i,t,n);for(let e of n)e.instances.push(a);let o=uq(n);for(let n of t.set)if(!n.modified.length)for(let t of o)i.push(e.get(n,t));return a}};function lq(e,t){return e.length==t.length&&e.every((e,n)=>e==t[n])}function uq(e){let t=[[]];for(let n=0;n<e.length;n++)for(let r=0,i=t.length;r<i;r++)t.push(t[r].concat(e[n]));return t.sort((e,t)=>t.length-e.length)}function dq(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let e of n.split(` `))if(e){let n=[],i=2,a=e;for(let t=0;;){if(a==`...`&&t>0&&t+3==e.length){i=1;break}let r=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!r)throw RangeError(`Invalid path: `+e);if(n.push(r[0]==`*`?``:r[0][0]==`"`?JSON.parse(r[0]):r[0]),t+=r[0].length,t==e.length)break;let o=e[t++];if(t==e.length&&o==`!`){i=0;break}if(o!=`/`)throw RangeError(`Invalid path: `+e);a=e.slice(t)}let o=n.length-1,s=n[o];if(!s)throw RangeError(`Invalid path: `+e);t[s]=new pq(r,i,o>0?n.slice(0,o):null).sort(t[s])}}return fq.add(t)}var fq=new rK({combine(e,t){let n,r,i;for(;e||t;){if(!e||t&&e.depth<=t.depth?(i=t,t=t.next):(i=e,e=e.next),n&&n.mode==i.mode&&!i.context&&!n.context)continue;let a=new pq(i.tags,i.mode,i.context);n?n.next=a:r=a,n=a}return r}}),pq=class{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};pq.empty=new pq([],2,null);function mq(e,t){let n=Object.create(null);for(let t of e)if(!Array.isArray(t.tag))n[t.tag.id]=t.class;else for(let e of t.tag)n[e.id]=t.class;let{scope:r,all:i=null}=t||{};return{style:e=>{let t=i;for(let r of e)for(let e of r.set){let r=n[e.id];if(r){t=t?t+` `+r:r;break}}return t},scope:r}}function hq(e,t){let n=null;for(let r of e){let e=r.style(t);e&&(n=n?n+` `+e:e)}return n}function gq(e,t,n,r=0,i=e.length){let a=new _q(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,i,``,a.highlighters),a.flush(i)}var _q=class{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=``}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,i){let{type:a,from:o,to:s}=e;if(o>=n||s<=t)return;a.isTop&&(i=this.highlighters.filter(e=>!e.scope||e.scope(a)));let c=r,l=vq(e)||pq.empty,u=hq(i,l.tags);if(u&&(c&&(c+=` `),c+=u,l.mode==1&&(r+=(r?` `:``)+u)),this.startSpan(Math.max(t,o),c),l.opaque)return;let d=e.tree&&e.tree.prop(rK.mounted);if(d&&d.overlay){let a=e.node.enter(d.overlay[0].from+o,1),l=this.highlighters.filter(e=>!e.scope||e.scope(d.tree.type)),u=e.firstChild();for(let f=0,p=o;;f++){let m=f<d.overlay.length?d.overlay[f]:null,h=m?m.from+o:s,g=Math.max(t,p),_=Math.min(n,h);if(g<_&&u)for(;e.from<_&&(this.highlightRange(e,g,_,r,i),this.startSpan(Math.min(_,e.to),c),!(e.to>=h||!e.nextSibling())););if(!m||h>n)break;p=m.to+o,p>t&&(this.highlightRange(a.cursor(),Math.max(t,m.from+o),Math.min(n,p),``,l),this.startSpan(Math.min(n,p),c))}u&&e.parent()}else if(e.firstChild()){d&&(r=``);do if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,r,i),this.startSpan(Math.min(n,e.to),c)}while(e.nextSibling());e.parent()}}};function vq(e){let t=e.type.prop(fq);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}var q=oq.define,yq=q(),bq=q(),xq=q(bq),Sq=q(bq),Cq=q(),wq=q(Cq),Tq=q(Cq),Eq=q(),Dq=q(Eq),Oq=q(),kq=q(),Aq=q(),jq=q(Aq),Mq=q(),J={comment:yq,lineComment:q(yq),blockComment:q(yq),docComment:q(yq),name:bq,variableName:q(bq),typeName:xq,tagName:q(xq),propertyName:Sq,attributeName:q(Sq),className:q(bq),labelName:q(bq),namespace:q(bq),macroName:q(bq),literal:Cq,string:wq,docString:q(wq),character:q(wq),attributeValue:q(wq),number:Tq,integer:q(Tq),float:q(Tq),bool:q(Cq),regexp:q(Cq),escape:q(Cq),color:q(Cq),url:q(Cq),keyword:Oq,self:q(Oq),null:q(Oq),atom:q(Oq),unit:q(Oq),modifier:q(Oq),operatorKeyword:q(Oq),controlKeyword:q(Oq),definitionKeyword:q(Oq),moduleKeyword:q(Oq),operator:kq,derefOperator:q(kq),arithmeticOperator:q(kq),logicOperator:q(kq),bitwiseOperator:q(kq),compareOperator:q(kq),updateOperator:q(kq),definitionOperator:q(kq),typeOperator:q(kq),controlOperator:q(kq),punctuation:Aq,separator:q(Aq),bracket:jq,angleBracket:q(jq),squareBracket:q(jq),paren:q(jq),brace:q(jq),content:Eq,heading:Dq,heading1:q(Dq),heading2:q(Dq),heading3:q(Dq),heading4:q(Dq),heading5:q(Dq),heading6:q(Dq),contentSeparator:q(Eq),list:q(Eq),quote:q(Eq),emphasis:q(Eq),strong:q(Eq),link:q(Eq),monospace:q(Eq),strikethrough:q(Eq),inserted:q(),deleted:q(),changed:q(),invalid:q(),meta:Mq,documentMeta:q(Mq),annotation:q(Mq),processingInstruction:q(Mq),definition:oq.defineModifier(`definition`),constant:oq.defineModifier(`constant`),function:oq.defineModifier(`function`),standard:oq.defineModifier(`standard`),local:oq.defineModifier(`local`),special:oq.defineModifier(`special`)};for(let e in J){let t=J[e];t instanceof oq&&(t.name=e)}mq([{tag:J.link,class:`tok-link`},{tag:J.heading,class:`tok-heading`},{tag:J.emphasis,class:`tok-emphasis`},{tag:J.strong,class:`tok-strong`},{tag:J.keyword,class:`tok-keyword`},{tag:J.atom,class:`tok-atom`},{tag:J.bool,class:`tok-bool`},{tag:J.url,class:`tok-url`},{tag:J.labelName,class:`tok-labelName`},{tag:J.inserted,class:`tok-inserted`},{tag:J.deleted,class:`tok-deleted`},{tag:J.literal,class:`tok-literal`},{tag:J.string,class:`tok-string`},{tag:J.number,class:`tok-number`},{tag:[J.regexp,J.escape,J.special(J.string)],class:`tok-string2`},{tag:J.variableName,class:`tok-variableName`},{tag:J.local(J.variableName),class:`tok-variableName tok-local`},{tag:J.definition(J.variableName),class:`tok-variableName tok-definition`},{tag:J.special(J.variableName),class:`tok-variableName2`},{tag:J.definition(J.propertyName),class:`tok-propertyName tok-definition`},{tag:J.typeName,class:`tok-typeName`},{tag:J.namespace,class:`tok-namespace`},{tag:J.className,class:`tok-className`},{tag:J.macroName,class:`tok-macroName`},{tag:J.propertyName,class:`tok-propertyName`},{tag:J.operator,class:`tok-operator`},{tag:J.comment,class:`tok-comment`},{tag:J.meta,class:`tok-meta`},{tag:J.invalid,class:`tok-invalid`},{tag:J.punctuation,class:`tok-punctuation`}]);var Nq=dq({String:J.string,Number:J.number,"True False":J.bool,PropertyName:J.propertyName,Null:J.null,", :":J.separator,"[ ]":J.squareBracket,"{ }":J.brace}),Pq=tq.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:`#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O`,goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:`⚠ JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array`,maxTerm:25,nodeProps:[[`isolate`,-2,6,11,``],[`openedBy`,7,`{`,14,`[`],[`closedBy`,8,`}`,15,`]`]],propSources:[Nq],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0}),Fq=[],Iq=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?Iq:Fq).push(n+=e[t])})();function Lq(e){if(e<768)return!1;for(let t=0,n=Fq.length;;){let r=t+n>>1;if(e<Fq[r])n=r;else if(e>=Iq[r])t=r+1;else return!0;if(t==n)return!1}}function Rq(e){return e>=127462&&e<=127487}var zq=8205;function Bq(e,t,n=!0,r=!0){return(n?Vq:Hq)(e,t,r)}function Vq(e,t,n){if(t==e.length)return t;t&&Wq(e.charCodeAt(t))&&Gq(e.charCodeAt(t-1))&&t--;let r=Uq(e,t);for(t+=Kq(r);t<e.length;){let i=Uq(e,t);if(r==zq||i==zq||n&&Lq(i))t+=Kq(i),r=i;else if(Rq(i)){let n=0,r=t-2;for(;r>=0&&Rq(Uq(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function Hq(e,t,n){for(;t>1;){let r=Vq(e,t-2,n);if(r<t)return r;t--}return 0}function Uq(e,t){let n=e.charCodeAt(t);if(!Gq(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return Wq(r)?(n-55296<<10)+(r-56320)+65536:n}function Wq(e){return e>=56320&&e<57344}function Gq(e){return e>=55296&&e<56320}function Kq(e){return e<65536?1:2}var qq=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=rJ(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Yq.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=rJ(this,e,t);let n=[];return this.decompose(e,t,n,0),Yq.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new $q(this),i=new $q(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new $q(this,e)}iterRange(e,t=this.length){return new eJ(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new tJ(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new Jq(t):Yq.from(Jq.split(t,[]))}},Jq=class e extends qq{constructor(e,t=Xq(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new nJ(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(Qq(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=Zq(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=rJ(this,t,n);let i=Zq(this.text,Zq(r.text,Qq(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):Yq.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
|
|
18
|
+
`)&&eW(t)!==void 0;return e?.kind===`section`&&e.line!==void 0?`Reads line ${String(e.line)} of what is between “${e.heading}” and ${e.until===void 0?`the end`:`“${e.until}”`}`:e?.kind===`section`&&e.matchName!==void 0?`Reads the ${e.matchName} in what is below “${e.heading}”, wherever it sits`:e?.kind===`section`?e.until===void 0?`Reads everything below “${e.heading}”`:`Reads what is between “${e.heading}” and “${e.until}”`:n?`Reads the value after its label`:e?.kind===`after`?e.lines>1?`Reads the ${String(e.lines)} lines after “${e.previous}”`:`Reads the line after “${e.previous}”`:`Reads a fixed position on the page: it breaks when the layout moves`}function zW(e){let t=e.currentTarget.getBoundingClientRect(),n=Number(e.currentTarget.getAttribute(`width`)),r=t.width>0&&n>0?t.width/n:1;return{x:(e.clientX-t.left)/r,y:(e.clientY-t.top)/r}}function BW(e){return`staged:${String(e.x)}:${String(e.y)}`}function VW(e,t){return{x:e.x*SW,y:(t-e.y-e.height)*SW,width:Math.max(e.width,1)*SW,height:e.height*SW*TW}}function HW(e,t){let[n,r]=[Math.min(e.x1,e.x2),Math.max(e.x1,e.x2)],[i,a]=[Math.min(e.y1,e.y2),Math.max(e.y1,e.y2)];return{x:n*SW,y:(t-a)*SW,width:(r-n)*SW,height:(a-i)*SW}}function UW(e,t,n,r,i){return{x1:t/SW,y1:e.height-n/SW,x2:r/SW,y2:e.height-i/SW}}function WW(e,t){let n;for(let r of e.rows)for(let i of r.cells){let r=VW(i,e.height),a=Math.max(r.x-t.x,0,t.x-(r.x+r.width)),o=Math.max(r.y-t.y,0,t.y-(r.y+r.height)),s=Math.hypot(a,o);s<=EW&&(n===void 0||s<n.distance)&&(n={cell:i,distance:s})}return n?.cell}function GW({label:e,tip:t,active:n,onClick:r}){return(0,F.jsx)(V,{as:`button`,title:t,fontSize:`sm`,fontWeight:n?`semibold`:`normal`,color:n?`colorPalette.fg`:`fg`,colorPalette:`brand`,cursor:`pointer`,onClick:r,children:e})}function KW({pages:e,value:t,onChange:n}){let r=a_({items:Array.from({length:e},(e,t)=>({label:`Page ${String(t+1)}`,value:String(t)}))});return(0,F.jsxs)(Hw,{collection:r,size:`sm`,width:`140px`,value:[String(t)],onValueChange:e=>{n(Number(e.value[0]))},children:[(0,F.jsx)(Yw,{}),(0,F.jsx)(Jw,{children:(0,F.jsx)(Uw,{children:(0,F.jsx)(Kw,{})})}),(0,F.jsx)(Ww,{children:(0,F.jsx)(Gw,{children:r.items.map(e=>(0,F.jsx)(qw,{item:e,children:e.label},e.value))})})]})}function qW({row:e,colour:t,highlighted:n,scale:r,pageHeight:i,cursor:a,onClick:o}){return(0,F.jsxs)(`g`,{onClick:o,style:{cursor:a},children:[n&&e.cells.length>0&&(0,F.jsx)(`rect`,{x:Math.min(...e.cells.map(e=>e.x))*r,y:(i-e.top)*r,width:(Math.max(...e.cells.map(e=>e.x+e.width))-Math.min(...e.cells.map(e=>e.x)))*r,height:(e.top-e.bottom)*r,fill:AW}),e.cells.map(e=>(0,F.jsx)(`rect`,{x:e.x*r,y:(i-e.y-e.height)*r,width:Math.max(e.width,1)*r,height:e.height*r*TW,fill:`transparent`,stroke:t,strokeWidth:1.5},`${String(e.x)}:${String(e.y)}`))]})}function JW({band:e,scale:t,pageHeight:n,onClick:r}){return(0,F.jsx)(`rect`,{x:e.start*t,y:0,width:Math.max(e.end-e.start,1)*t,height:n*t,fill:`rgba(46, 134, 171, 0.08)`,stroke:`#2e86ab`,strokeDasharray:`4 2`,onClick:r,style:{cursor:`pointer`},children:(0,F.jsx)(`title`,{children:e.name})})}async function YW(e,t,n,r,i){let a=await bW(()=>import(`./pdf-DlUV3lLg.js`),[]),o=await bW(()=>import(`./pdf.worker.min-D7i8o3wR.js`),[]);a.GlobalWorkerOptions.workerSrc=o.default;let s=a.getDocument({url:t}),c=await s.promise;try{let t=await c.getPage(n);if(i.aborted)return;let a=t.getViewport({scale:r});e.width=Math.ceil(a.width),e.height=Math.ceil(a.height);let o=e.getContext(`2d`);if(o===null)return;let s=t.render({canvas:e,canvasContext:o,viewport:a});i.addEventListener(`abort`,()=>{s.cancel()}),await s.promise}finally{await s.destroy()}}function XW(e,t){return{kind:`card`,path:t,stepType:`goto`,sentence:[{kind:`word`,text:`Go to`},{kind:`code`,text:e}],custom:!1,step:{type:`goto`,url:e}}}function ZW(e,t){return[{type:`goto`,url:e},...t]}function QW(e,t,n,r){return{...n,steps:ZW(e,t),keep:[`cookies`],saveTo:r}}function $W(e){let t=e.start;if(!Array.isArray(t))return;let n=t[0];if(typeof n!=`object`||!n)return;let r=n.url;return typeof r==`string`?r:void 0}function eG(e,t){let n=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`)),r=n===-1?`.`:e.slice(0,n),i=n===-1||e[n]===void 0?`/`:e[n];return`${r}${i}storage${i}${t}-session.json`}var tG={id:`by id`,"data-attr":`by test attribute`,class:`by class`,structure:`by place in the page tree`,position:`by position`};function nG(e){return tG[e]}function rG({recipeId:e,stepPath:t,heading:n,hint:r,groups:i,preview:a,collect:o,onAdd:s,onCancel:c,adding:l=!1}){return(0,F.jsxs)(I,{"data-testid":`selector-options`,borderWidth:`1px`,borderColor:`colorPalette.muted`,colorPalette:`brand`,bg:`bg.subtle`,rounded:`md`,mx:3,my:2,p:3,maxH:`45%`,overflowY:`auto`,flexShrink:0,children:[(0,F.jsxs)(W,{justify:`space-between`,align:`start`,gap:3,children:[(0,F.jsxs)(I,{minW:0,children:[(0,F.jsx)(V,{fontSize:`sm`,fontWeight:`semibold`,children:n}),a!==void 0&&a!==``&&(0,F.jsx)(V,{fontSize:`xs`,color:`fg.muted`,truncate:!0,title:a,children:`“${a}”`}),r!==void 0&&(0,F.jsx)(V,{fontSize:`xs`,color:`fg.muted`,children:r})]}),(0,F.jsxs)(W,{flexShrink:0,children:[(0,F.jsx)(UC,{size:`xs`,colorPalette:`brand`,onClick:s,loading:l,children:`Add to recipe`}),(0,F.jsx)(UC,{size:`xs`,variant:`ghost`,onClick:c,"aria-label":`Cancel this pick`,children:`Cancel`})]})]}),(0,F.jsxs)(rw,{gap:3,mt:2,children:[i.map(n=>(0,F.jsx)(aG,{recipeId:e,stepPath:t,group:n},n.title)),o!==void 0&&(0,F.jsx)(iG,{collect:o})]})]})}function iG({collect:e}){return(0,F.jsxs)(rw,{gap:1,role:`radiogroup`,"aria-label":`What to collect`,children:[(0,F.jsx)(V,{fontSize:`xs`,fontWeight:`medium`,color:`fg.muted`,children:`This matches ${String(e.matches)} elements on the page. Collect:`}),(0,F.jsxs)(I,{as:`label`,display:`flex`,alignItems:`center`,gap:2,px:2,py:1,rounded:`sm`,cursor:`pointer`,bg:e.many?void 0:`colorPalette.subtle`,children:[(0,F.jsx)(`input`,{type:`radio`,name:`collect-how-many`,checked:!e.many,onChange:()=>{e.onChange(!1)}}),(0,F.jsx)(V,{fontSize:`xs`,children:`Only the first one`})]}),(0,F.jsxs)(I,{as:`label`,display:`flex`,alignItems:`center`,gap:2,px:2,py:1,rounded:`sm`,cursor:`pointer`,bg:e.many?`colorPalette.subtle`:void 0,children:[(0,F.jsx)(`input`,{type:`radio`,name:`collect-how-many`,checked:e.many,onChange:()=>{e.onChange(!0)}}),(0,F.jsx)(V,{fontSize:`xs`,children:`All ${String(e.matches)}, as a list (an array of values)`})]})]})}function aG({recipeId:e,stepPath:t,group:n}){let r=n.options.some(e=>e.selector===n.selected);return(0,F.jsxs)(rw,{gap:1,role:`radiogroup`,"aria-label":n.title,children:[(0,F.jsx)(V,{fontSize:`xs`,fontWeight:`medium`,color:`fg.muted`,children:n.title}),n.generatedId!==void 0&&(0,F.jsx)(V,{fontSize:`xs`,color:`orange.fg`,children:`This element has the id “${n.generatedId}”, which looks generated, so it may change on the next visit and no option below uses it.`}),n.options.map((e,t)=>(0,F.jsxs)(I,{as:`label`,display:`flex`,alignItems:`center`,gap:2,px:2,py:1,rounded:`sm`,cursor:`pointer`,bg:e.selector===n.selected?`colorPalette.subtle`:void 0,_hover:{bg:`bg.emphasized`},children:[(0,F.jsx)(`input`,{type:`radio`,name:n.title,checked:e.selector===n.selected,onChange:()=>{n.onSelect(e.selector)}}),(0,F.jsx)(V,{as:`code`,fontSize:`xs`,fontFamily:`mono`,truncate:!0,flex:`1`,minW:0,title:e.selector,children:e.selector}),(0,F.jsx)(V,{fontSize:`2xs`,color:`fg.muted`,flexShrink:0,children:nG(e.tier)}),(0,F.jsx)(LC,{size:`xs`,flexShrink:0,colorPalette:e.matches===1?`green`:`gray`,children:`${String(e.matches)} match${e.matches===1?``:`es`}`}),t===0&&(0,F.jsx)(LC,{size:`xs`,colorPalette:`brand`,flexShrink:0,children:`suggested`})]},e.selector)),(0,F.jsx)(oG,{recipeId:e,stepPath:t,selected:r?``:n.selected,onUse:n.onSelect})]})}function oG({recipeId:e,stepPath:t,selected:n,onUse:r}){let[i,a]=(0,P.useState)(n),o=qte();function s(){let n=i.trim();n!==``&&(r(n),o.mutate({recipeId:e,path:t,selector:n}))}return(0,F.jsxs)(W,{gap:2,px:2,children:[(0,F.jsx)(Dw,{size:`xs`,fontFamily:`mono`,value:i,placeholder:`Or type your own selector, e.g. .price > span`,"aria-label":`Your own selector`,onChange:e=>{a(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&s()}}),(0,F.jsx)(UC,{size:`xs`,variant:`outline`,onClick:s,loading:o.isPending,children:`Use`}),o.data!==void 0&&(0,F.jsx)(LC,{size:`xs`,colorPalette:o.data.snapshotMatches>0?`green`:`red`,children:`${String(o.data.snapshotMatches)} match${o.data.snapshotMatches===1?``:`es`}`})]})}function sG(e,t,n){let r=[`[data-oc-node] { cursor: ${e?`crosshair`:`inherit`}; }`,`[data-oc-node]:hover { outline: 2px solid #3182ce !important; outline-offset: -2px; }`];return n!==void 0&&n!==``&&r.push(`${n} { outline: 2px solid #dd6b20 !important; outline-offset: -2px; background: rgba(221,107,32,0.08) !important; }`),t?r.push(`[data-oc-overlay] { display: revert !important; opacity: 0.5 !important; outline: 1px dashed #ed8936 !important; }`):r.push(`[data-oc-overlay] { display: none !important; }`,`html:has([data-oc-overlay]), body:has([data-oc-overlay]) { overflow: auto !important; position: static !important; }`),t&&r.push(`[data-oc-hidden] { display: revert !important; visibility: visible !important; opacity: 0.5 !important; outline: 1px dashed #ed8936 !important; }`),r.join(`
|
|
19
|
+
`)}var cG=1e3,lG=`data-oc-node`,uG=`opencraw-picker-style`;function dG({html:e,pickMode:t,showHidden:n,hoveredSelector:r,onHoverNode:i,onPickNode:a}){let o=(0,P.useRef)(null),s=(0,P.useRef)(null),[c,l]=(0,P.useState)({width:0,height:0}),u=(0,P.useRef)({onHoverNode:i,onPickNode:a});u.current={onHoverNode:i,onPickNode:a},(0,P.useEffect)(()=>{let e=o.current;if(e===null)return;let t,n=e=>{u.current.onHoverNode(pG(e.target))},r=()=>{u.current.onHoverNode(void 0)},i=e=>{fG(e.target)!==void 0&&e.preventDefault();let t=pG(e.target);t!==void 0&&(e.preventDefault(),e.stopPropagation(),u.current.onPickNode(t))},a=e=>{e.preventDefault()},s=()=>{let o=e.contentDocument;o!==null&&(o.addEventListener(`mouseover`,n),o.addEventListener(`mouseout`,r),o.addEventListener(`click`,i,{capture:!0}),o.addEventListener(`contextmenu`,a),t=()=>{o.removeEventListener(`contextmenu`,a),o.removeEventListener(`mouseover`,n),o.removeEventListener(`mouseout`,r),o.removeEventListener(`click`,i,{capture:!0})})};return e.addEventListener(`load`,s),()=>{e.removeEventListener(`load`,s),t?.()}},[e]),(0,P.useEffect)(()=>{let e=s.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{l({width:e.clientWidth,height:e.clientHeight})});return t.observe(e),()=>{t.disconnect()}},[]),(0,P.useEffect)(()=>{let e=o.current?.contentDocument;if(e==null)return;let i=e.getElementById(uG);i===null&&(i=e.createElement(`style`),i.id=uG,e.head?.append(i)),i.textContent=sG(t,n,r)});let d=c.width>0,f=d?Math.max(c.width,cG):0,p=d?c.width/f:1,m=d&&p<1?{width:`${String(f)}px`,height:`${String(c.height/p)}px`,transform:`scale(${String(p)})`,transformOrigin:`top left`}:{width:`100%`,height:`100%`};return(0,F.jsx)(`div`,{ref:s,style:{width:`100%`,height:`100%`,overflow:`hidden`},children:(0,F.jsx)(`iframe`,{ref:o,title:`Snapshot`,sandbox:`allow-same-origin`,srcDoc:e,style:{...m,border:`none`,background:`white`}})})}function fG(e){return(e?.nodeType===Node.ELEMENT_NODE?e.closest(`a[href], area[href]`):null)??void 0}function pG(e){return(e?.nodeType===Node.ELEMENT_NODE?e.closest(`[${CSS.escape(lG)}]`):null)?.getAttribute(lG)??void 0}var mG=[],hG={object:`purple.fg`,array:`purple.fg`,element:`purple.fg`,string:`green.fg`,number:`orange.fg`,boolean:`blue.fg`,null:`fg.muted`},gG=(0,P.memo)(SG),_G=6;function vG(e){let t=new Set,n=(e,r)=>{if(e.children.length===0)return;let i=/^\[?(\d+)\]?$/.exec(e.label)?.[1];if(i!==void 0&&Number(i)>0||r>=_G){t.add(e.id);return}for(let t of e.children)n(t,r+1)};return n(e,0),t}function yG(e,t){let n=[],r=[{node:e,depth:0}];for(let e=r.pop();e!==void 0;e=r.pop())if(n.push(e),!(e.node.children.length===0||t.has(e.node.id)))for(let t=e.node.children.length-1;t>=0;--t)r.push({node:e.node.children[t],depth:e.depth+1});return n}var bG=20,xG=20;function SG({tree:e,onPick:t,steps:n=mG,hoveredStepId:r,onHoverStepId:i}){let[a,o]=(0,P.useState)(()=>vG(e.root)),s=(0,P.useRef)(null),c=yG(e.root,a),l=BO({count:c.length,getScrollElement:()=>s.current,estimateSize:()=>bG,overscan:xG});function u(e){o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return(0,F.jsxs)(I,{ref:s,h:`full`,overflow:`auto`,fontFamily:`mono`,fontSize:`xs`,py:2,children:[e.namespaces!==void 0&&Object.keys(e.namespaces).length>0&&(0,F.jsxs)(W,{px:2,pb:2,gap:2,flexWrap:`wrap`,children:[(0,F.jsx)(V,{color:`fg.muted`,children:`Namespaces:`}),Object.entries(e.namespaces).map(([e,t])=>(0,F.jsx)(LC,{size:`xs`,colorPalette:`gray`,children:`${e}: ${t}`},e))]}),(0,F.jsx)(I,{position:`relative`,style:{height:`${String(l.getTotalSize())}px`},children:l.getVirtualItems().map(e=>{let o=c[e.index];return(0,F.jsx)(I,{position:`absolute`,top:0,left:0,w:`full`,style:{transform:`translateY(${String(e.start)}px)`,height:`${String(bG)}px`},children:(0,F.jsx)(CG,{node:o.node,depth:o.depth,collapsed:a,onToggle:u,onPick:t,steps:n,hoveredStepId:r,onHoverStepId:i})},o.node.id)})})]})}function CG({node:e,depth:t,collapsed:n,onToggle:r,onPick:i,steps:a,hoveredStepId:o,onHoverStepId:s}){let c=e.children.length>0,l=n.has(e.id),u=e.valueType!==`object`&&e.valueType!==`array`&&e.valueType!==`element`,d=LH(e,a),f=o!==void 0&&d.includes(o);return(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)(W,{"data-testid":`tree-node`,"data-highlighted":f,"data-step-ids":d.length===0?void 0:d.join(` `),gap:1,pl:`${t*14+4}px`,pr:2,minH:`20px`,cursor:`pointer`,bg:f?`orange.subtle`:void 0,_hover:{bg:f?`orange.subtle`:`bg.emphasized`},onClick:()=>{i(e,`value`)},onMouseEnter:s===void 0?void 0:()=>{s(d[0])},onMouseLeave:s===void 0?void 0:()=>{s(void 0)},children:[c?(0,F.jsx)(V,{as:`button`,w:`12px`,flexShrink:0,color:`fg.muted`,onClick:t=>{t.stopPropagation(),r(e.id)},children:l?`▸`:`▾`}):(0,F.jsx)(I,{w:`12px`,flexShrink:0}),(0,F.jsx)(V,{as:`span`,color:hG[e.valueType],fontWeight:`medium`,children:e.label}),u&&e.preview!==void 0&&(0,F.jsx)(V,{as:`span`,color:`fg.muted`,truncate:!0,children:e.preview}),d.map(e=>(0,F.jsx)(LC,{size:`xs`,colorPalette:`orange`,variant:f?`solid`:`subtle`,title:`Already in the recipe: the step reading this`,flexShrink:0,children:e},e)),e.listPath!==void 0&&(0,F.jsx)(LC,{as:`button`,size:`xs`,colorPalette:`brand`,onClick:t=>{t.stopPropagation(),i(e,`list`)},title:`Collect this for every one of the ${String(e.listCount??0)} items of the list`,children:`[*] ×${String(e.listCount??0)}`}),u&&e.jsonpath!==void 0&&(0,F.jsx)(V,{as:`button`,fontSize:`2xs`,color:`fg.muted`,_hover:{color:`fg`,textDecoration:`underline`},onClick:t=>{t.stopPropagation(),i(e,`next`)},title:`Use this value to reach the next page of results (for data that comes in pages)`,children:`next →`})]})})}function wG(e){return(e.textContent??``).replace(/\s+/g,` `).trim()}function TG(e){let t=e?.closest(`[data-oc-node]`),n=t instanceof HTMLElement?t.dataset.ocNode:void 0;return t==null||n===void 0?{reason:`that element is not part of the page snapshot`}:{nodeId:n,text:wG(t).slice(0,160)}}function EG(e,t){let n=t.replace(/\s+/g,` `).trim().toLowerCase(),r,i;for(let t of e.body.querySelectorAll(`[data-oc-node]`)){let e=wG(t),a=e.toLowerCase();a===n&&(r===void 0||e.length<r.length)?r={element:t,length:e.length}:a.includes(n)&&(i===void 0||e.length<i.length)&&(i={element:t,length:e.length})}return r?.element??i?.element??null}function DG(e,t){let n=new DOMParser().parseFromString(e,`text/html`);if(t.selector!==void 0)try{let e=n.querySelector(t.selector);return e===null?{reason:`nothing on the page matches ${t.selector}`}:TG(e)}catch{return{reason:`${t.selector} is not a valid CSS selector`}}if(t.text===void 0)return{reason:`say what to pick: a CSS selector or the text it shows`};let r=EG(n,t.text);return r===null?{reason:`no element on the page shows "${t.text}"`}:TG(r)}function OG(e,t){return{pick:e,fieldSelector:e.field.selector,...e.kind===`list`&&{itemSelector:e.item.selector},...t!==void 0&&{text:t}}}function kG(e,t,n){return t?.find(t=>t.selector===e)?.matches??n}function AG(e,t){return{...e,selector:t,matches:kG(t,e.alternatives,e.matches)}}function jG(e){let{pick:t}=e,n=AG(t.field,e.fieldSelector);if(t.kind!==`list`)return{...t,field:n};let r=e.itemSelector??t.item.selector;return{...t,field:n,item:{...t.item,selector:r,matches:kG(r,t.item.alternatives,t.item.matches)}}}function MG(e){if(e.pick.kind===`list`)return;let t=AG(e.pick.field,e.fieldSelector).matches;return t>1?t:void 0}function NG(e){return e.many===!0&&MG(e)!==void 0}function PG(e,t){return e!==void 0&&e.length>0?e:[{selector:t.selector,tier:t.tier,matches:t.matches}]}function FG(e){let{pick:t}=e,n={title:t.kind===`list`?`Value in each item`:`How to find it`,options:PG(t.field.alternatives,t.field),selected:e.fieldSelector,target:`field`,...t.field.generatedId!==void 0&&{generatedId:t.field.generatedId}};return t.kind===`list`?[{title:`Each item of the list`,options:PG(t.item.alternatives,t.item),selected:e.itemSelector??t.item.selector,target:`item`},n]:[n]}function IG(e){return e.pick.kind===`list`?`Collect this for every one of the ${String(e.pick.item.matches)} items`:e.pick.kind===`item-field`?`Collect this from each item of the list`:`Collect this value`}function LG(e){if(e.pick.kind===`field`)return`Click a similar item as well to collect the whole list. Pick the way to find it that will keep working.`;if(e.pick.kind===`list`)return`Pick the ways to find the items and the value that will keep working.`}var RG=100,zG=`img, picture, video, canvas, svg, iframe, object, embed, input, select, textarea, table`,BG=`h1, h2, h3, h4, h5, h6, li, a[href]`;function VG(e){let t=new DOMParser().parseFromString(e,`text/html`).body;for(let e of t.querySelectorAll(`script, style, noscript, template`))e.remove();return(t.textContent??``).trim().length>=RG||t.querySelector(`${zG}, ${BG}`)!==null}function HG({zoom:e,zoomIn:t,zoomOut:n,reset:r}){return(0,F.jsxs)(W,{gap:0,role:`group`,"aria-label":`Zoom`,flexShrink:0,children:[(0,F.jsx)(UC,{size:`2xs`,variant:`outline`,"aria-label":`Zoom out`,title:`Zoom out (ctrl + wheel)`,onClick:n,children:`−`}),(0,F.jsx)(UC,{size:`2xs`,variant:`outline`,"aria-label":`Reset zoom`,title:`Back to 100%`,minW:`3.5em`,onClick:r,children:`${String(Math.round(e*100))}%`}),(0,F.jsx)(UC,{size:`2xs`,variant:`outline`,"aria-label":`Zoom in`,title:`Zoom in (ctrl + wheel)`,onClick:t,children:`+`})]})}var UG=[.5,.67,.8,1,1.25,1.5,2,3];function WG(e,t){let n=UG.findIndex(t=>t>=e),r=n===-1?UG.length-1:n;return UG[Math.min(Math.max(r+t,0),UG.length-1)]??1}function GG(e){let[t,n]=(0,P.useState)(1),r=(0,P.useCallback)(()=>{n(e=>WG(e,1))},[]),i=(0,P.useCallback)(()=>{n(e=>WG(e,-1))},[]),a=(0,P.useCallback)(()=>{n(1)},[]);return(0,P.useEffect)(()=>{let t=e.current;if(t===null)return;let n=e=>{e.ctrlKey&&(e.preventDefault(),e.deltaY<0?r():i())};return t.addEventListener(`wheel`,n,{passive:!1}),()=>{t.removeEventListener(`wheel`,n)}},[e,r,i]),{zoom:t,zoomIn:r,zoomOut:i,reset:a}}function KG(e,t){let n=OD(e,t)?.step.selector;return typeof n==`string`?n:void 0}function qG(e,t,n){if(e!==void 0&&t!==void 0)for(let r of AD(e)){let e=r.step.selector,i=r.step.id;if(typeof e==`string`&&typeof i==`string`&&$O(t,e).has(n))return i}}var JG=`start`,YG=new Set([`json`,`yaml`,`jsonl`,`xml`,`youtube`]),XG=new Set([`csv`,`xlsx`]),ZG=new Set([`pptx`]);function QG({recipe:e,onSaveOutline:t,onSaveRecipe:n}){let r=e?.id,i=Kte(r,r===void 0?void 0:JG),a=oO(),[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(`tree`),u=BD(),d=i.data?.format,f=d!==void 0&&YG.has(d),p=d===`pdf`,m=d!==void 0&&XG.has(d),h=d!==void 0&&ZG.has(d),g=!f&&!p&&!m&&!h,_=i.data?.html,v=(0,P.useMemo)(()=>_===void 0||VG(_),[_]),y=Zte(r,r===void 0?void 0:JG,f),b=Qte(r,r===void 0?void 0:JG,p),[x,S]=(0,P.useState)(void 0),C=lO(r,r===void 0?void 0:JG,m,x),w=dO(r,r===void 0?void 0:JG,h),T=G(e=>e.pickTarget),E=G(e=>e.showHidden),D=G(e=>e.hoveredStepId),O=G(e=>e.startPicking),k=G(e=>e.stopPicking),A=G(e=>e.registerPick),ee=G(e=>e.setShowHidden),te=G(e=>e.setHoveredNodeId),ne=G(e=>e.setHoveredStepId),re=(0,P.useMemo)(()=>KG(e?.outline,D),[e?.outline,D]),ie=(0,P.useMemo)(()=>IH(e?.outline),[e?.outline]),ae=(0,P.useRef)(Ne);ae.current=Ne;let oe=(0,P.useCallback)((e,t)=>{ae.current(e,t)},[]),se=t=>{te(t),ne(t===void 0?void 0:qG(e?.outline,i.data?.html,t))},ce=GD(e=>e.recipeId),j=GD(e=>e.active),le=GD(e=>e.cards.length),ue=GD(e=>e.stoppedSteps),de=GD(e=>e.error),fe=GD(e=>e.dismissStopped),pe=pO(),me=mO(),he=ce===r&&j,ge=ce===r?ue:void 0,[_e,ve]=(0,P.useState)(void 0),M=e=>{ve(e===void 0?void 0:{text:e,ok:!0})},N=e=>{ve(e===void 0?void 0:{text:e,ok:!1})},ye=(0,P.useRef)(void 0),[be,xe]=(0,P.useState)(void 0),Se=(0,P.useRef)(null),Ce=GG(Se),we=(0,P.useRef)(void 0),Te=T!==void 0&&T.recipeId===r,Ee=ZD(e=>e.pick),De=ZD(e=>e.finishPick),Oe=(0,P.useRef)(void 0);(0,P.useEffect)(()=>{we.current=void 0,S(void 0),xe(void 0)},[r]);async function ke(t){if(r===void 0)return;Te||(ye.current=void 0,O(r,JG));let n=A(t);if(n.kind===`first`){let n=e?.outline===void 0?void 0:hD(e.outline.steps),i=await a.mutateAsync({recipeId:r,path:JG,nodeIds:[t],...n!==void 0&&{within:n}});if(i.kind!==`field`&&i.kind!==`item-field`){N(i.kind===`unsupported`?i.reason:void 0);return}let o=OG(i,Ae(t));return xe(o),o}let i=await a.mutateAsync({recipeId:r,path:JG,nodeIds:[n.firstNodeId,t]});if(i.kind!==`list`){N(i.kind===`unsupported`?i.reason:void 0);return}xe(e=>OG(i,e?.text))}function Ae(e){let t=i.data?.html;if(t===void 0)return;let n=new DOMParser().parseFromString(t,`text/html`).querySelector(`[data-oc-node="${CSS.escape(e)}"]`)?.textContent?.replace(/\s+/g,` `).trim();return n===void 0||n===``?void 0:n.slice(0,160)}async function je(e=be){if(r===void 0||e===void 0)return;let t=jG(e),n=NG(e);if(xe(void 0),k(),t.kind===`item-field`){await Re(e=>{let r=Ite(e,t.field,n);return r===void 0?e:(M(`Added to the list: ${t.field.selector}`),r)});return}if(t.kind===`field`){await Re(e=>(M(`Read card: ${t.field.selector} (${t.field.matches} match${t.field.matches===1?``:`es`})`),vD(e,void 0,[dD(t.field,`steps.${e.length}`,void 0,n)])));return}await Re(e=>{let n=_D(e);return M(`List: ${t.item.selector} (${t.item.matches} items) → ${t.field.selector}`),vD(e,void 0,Nte(t,`steps.${n}`))})}function Me(){xe(void 0),k()}(0,P.useEffect)(()=>{let e=Ee,t=i.data?.html;if(!g||t===void 0||e===void 0||e.recipeId!==r||Oe.current===e.requestId)return;if(Te||be!==void 0){Me();return}Oe.current=e.requestId;let n=async(t,n,r)=>{De(e.requestId);try{await u.reportUiOutcome(e.requestId,t,n,r)}catch{}};(async()=>{let r=DG(t,e);if(`reason`in r){await n(!1,`Could not pick: ${r.reason}.`);return}let i=await ke(r.nodeId);if(i===void 0){await n(!1,`Studio could not turn that element into a selector.`,{text:r.text});return}let{field:a}=jG(i),o={text:r.text,selector:a.selector,matches:a.matches,alternatives:(a.alternatives??[]).map(e=>({selector:e.selector,matches:e.matches}))};if(e.add===!0){await je(i),await n(!0,`Added to the recipe: ${a.selector}`,o);return}await n(!0,`Staged: the person can choose a selector and press Add to recipe.`,o)})()});async function Ne(e,t){if(r!==void 0)try{if(t===`next`){await Re(t=>{let n=Mte(e,`steps.${t.length}`);return M(`Paginate: next from ${e.jsonpath}`),vD(t,void 0,[n])});return}await Re(n=>{if(t===`list`){let t=Fte(n,e);if(t!==void 0)return M(`Added to the list: ${String(e.listPath)}`),t;let r=Pte(e,`steps.${_D(n)}`);if(r!==void 0)return M(`List: ${String(e.listPath)} (${String(e.listCount??0)} items)`),vD(n,void 0,r)}let r=jte(e,`steps.${n.length}`,{generalize:t===`list`,namespaces:y.data?.namespaces});return M(`Read card: ${r.step.selector}${t===`list`?` (${String(e.listCount??0)} items)`:``}`),vD(n,void 0,[r])})}catch(e){N(e instanceof Error?e.message:String(e))}}async function Pe(e){await Re(t=>{let n=we.current,r=n??_D(t);return we.current=r,M(`table: ${String(e.step.selector)}`),vD(t,n,[{...e,path:`steps.${r}`}])})}async function Fe(e){await Re(t=>(M(`${String(e.step.kind)}: ${String(e.step.id)} ← ${String(e.step.selector)}`),vD(t,void 0,[{...e,path:`steps.${t.length}`}])))}async function Ie(e){await Re(t=>(M(`jsonpath: ${String(e.step.selector)}`),vD(t,void 0,[{...e,path:`steps.${t.length}`}])))}let Le=(0,P.useRef)(void 0);async function Re(n){if(t===void 0||e?.outline===void 0)return;let r=Le.current,i=n(r!==void 0&&r.file===e.file&&r.basedOn===e.outline?r.steps:e.outline.steps);Le.current={basedOn:e.outline,file:e.file,steps:i},await t(e.file,{...e.outline,steps:i})}function ze(){if(r===void 0||e?.outline===void 0)return;let t=$W(e.outline.recipe);if(t===void 0){N(`this recipe has no start point to record from`);return}pe.mutate({recipeId:r,startUrl:t})}async function Be(){if(ge===void 0||e?.outline===void 0)return;let n=GD.getState().startUrl;if(n===void 0)return;let i=e.outline.recipe.session,a=$G(i)?i:{},o=a.bootstrap,s=$G(o)?o:void 0,c=eG(e.file,r??`recipe`),l={...a,bootstrap:QW(n,ge,s,c)};await t?.(e.file,{...e.outline,recipe:{...e.outline.recipe,session:l}}),M(`Made the login: session.bootstrap, ${ge.length} step${ge.length===1?``:`s`}`),fe()}async function Ve(){if(ge===void 0||e?.outline===void 0)return;let t=GD.getState().startUrl;if(t===void 0)return;let n=GD.getState().cards;await Re(e=>vD(e,void 0,[XW(t,`steps.${e.length}`),...n.map(e=>e.node)])),M(`Kept as steps: ${ge.length} step${ge.length===1?``:`s`}`),fe()}if(r===void 0)return(0,F.jsx)(I,{p:4,color:`fg.muted`,children:(0,F.jsx)(V,{children:`Pick a recipe to see its snapshot here.`})});function He(){if(Te){k();return}ye.current=void 0,O(r,JG)}return(0,F.jsxs)(I,{h:`full`,display:`flex`,flexDirection:`column`,children:[(0,F.jsxs)(W,{px:3,py:2,borderBottomWidth:`1px`,gap:3,flexShrink:0,minH:`38px`,children:[!f&&!p&&!m&&!h&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(V,{as:`button`,fontSize:`sm`,fontWeight:Te?`semibold`:`normal`,whiteSpace:`nowrap`,color:Te?`colorPalette.fg`:`fg`,colorPalette:`brand`,cursor:`pointer`,title:`Pick data from the page: click here, then click the text you want to collect (click two similar things to collect a whole list)`,onClick:He,children:Te?`Cancel pick`:`Read`}),(0,F.jsxs)(oT,{checked:E,onCheckedChange:e=>{ee(e.checked)},size:`sm`,title:`Also show the parts of the page that are normally out of sight (menus, pop-ups, tabs that are not open)`,children:[(0,F.jsx)(uT,{}),(0,F.jsx)(lT,{}),(0,F.jsx)(sT,{fontSize:`sm`,whiteSpace:`nowrap`,children:`Show hidden`})]}),(0,F.jsx)(V,{as:`button`,fontSize:`sm`,fontWeight:o?`semibold`:`normal`,color:o?`colorPalette.fg`:`fg`,colorPalette:`purple`,cursor:`pointer`,title:`See how the page is built, and the data it loads: for things that are hard to click`,onClick:()=>{s(e=>!e)},children:o?`Hide inspector`:`Inspect`}),(0,F.jsx)(V,{as:`button`,fontSize:`sm`,fontWeight:he?`semibold`:`normal`,color:he?`red.fg`:`fg`,colorPalette:`red`,cursor:`pointer`,title:`Open a real browser window and record what you click and type (to log in, open a menu or fill a form), as steps`,onClick:()=>{he?me.mutate():ze()},children:he?`Stop recording`:`Record`})]}),f&&(d===`json`||d===`yaml`)&&(0,F.jsx)(KV,{value:c,onChange:l}),f&&(0,F.jsx)(V,{fontSize:`sm`,color:`fg.muted`,children:`Click a value to collect it. Click [*] beside a field to collect it for every item of a list.`}),(i.isFetching||f&&y.isFetching||p&&b.isFetching||m&&C.isFetching||h&&w.isFetching)&&(0,F.jsx)(zC,{size:`xs`}),_e!==void 0&&(0,F.jsx)(LC,{size:`sm`,colorPalette:_e.ok?`green`:`orange`,children:_e.text}),(0,F.jsx)(I,{ml:`auto`,children:(0,F.jsx)(HG,{...Ce})})]}),he&&(0,F.jsxs)(W,{px:3,py:2,bg:`red.subtle`,color:`red.fg`,fontSize:`sm`,gap:3,flexShrink:0,"data-testid":`recording-banner`,children:[(0,F.jsx)(I,{w:`8px`,h:`8px`,borderRadius:`full`,bg:`red.solid`,flexShrink:0}),(0,F.jsx)(V,{children:`Recording — a browser window opened for you to drive; interact with it, not with the snapshot below.`}),(0,F.jsxs)(LC,{size:`sm`,colorPalette:`red`,children:[le,` step`,le===1?``:`s`]})]}),de!==void 0&&ce===r&&(0,F.jsx)(I,{px:3,py:1,bg:`red.subtle`,color:`red.fg`,fontSize:`sm`,flexShrink:0,children:de}),ge!==void 0&&(0,F.jsxs)(W,{px:3,py:2,borderBottomWidth:`1px`,gap:3,flexShrink:0,"data-testid":`recording-stopped-bar`,children:[(0,F.jsxs)(V,{fontSize:`sm`,children:[`Recording stopped: `,ge.length,` step`,ge.length===1?``:`s`,` recorded.`]}),(0,F.jsx)(UC,{size:`xs`,colorPalette:`brand`,onClick:()=>{Be()},disabled:ge.length===0,children:`Make this the login`}),(0,F.jsx)(UC,{size:`xs`,variant:`outline`,onClick:()=>{Ve()},disabled:ge.length===0,children:`Keep as steps`}),(0,F.jsx)(UC,{size:`xs`,variant:`ghost`,onClick:fe,children:`Discard`})]}),i.data?.notice!==void 0&&(0,F.jsx)(GV,{text:i.data.notice}),be!==void 0&&r!==void 0&&!f&&!p&&!m&&!h&&(0,F.jsx)(rG,{recipeId:r,stepPath:JG,heading:IG(be),hint:LG(be),preview:be.text,groups:FG(be).map(e=>({title:e.title,options:e.options,selected:e.selected,onSelect:t=>{xe(n=>n===void 0?n:e.target===`item`?{...n,itemSelector:t}:{...n,fieldSelector:t})},...e.generatedId!==void 0&&{generatedId:e.generatedId}})),collect:MG(be)===void 0?void 0:{matches:MG(be),many:NG(be),onChange:e=>{xe(t=>t===void 0?t:{...t,many:e})}},onAdd:()=>{je()},onCancel:Me}),g&&i.data!==void 0&&i.data.notice===void 0&&!v&&(0,F.jsx)(WV,{}),(0,F.jsxs)(I,{ref:Se,flex:`1`,minH:`0`,overflow:`auto`,style:p?void 0:{zoom:Ce.zoom},onContextMenu:e=>{e.preventDefault()},children:[f&&c===`text`&&i.data!==void 0&&(0,F.jsx)(dG,{html:i.data.html,pickMode:!1,showHidden:!1,onHoverNode:()=>{},onPickNode:()=>{}}),f&&c===`tree`&&y.data!==void 0&&(0,F.jsx)(gG,{tree:y.data,onPick:oe,steps:ie,hoveredStepId:D,onHoverStepId:ne}),f&&y.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:y.error.message})}),p&&b.data!==void 0&&(0,F.jsx)(NW,{recipeId:r,stepPath:JG,view:b.data,zoom:Ce.zoom,bytesUrl:u.pdfBytesUrl(r,JG,i.data?.baseUrl),onTablePick:e=>{Pe(e)},onRegionPick:e=>{Fe(e)},steps:ie,hoveredStepId:D,onHoverStepId:ne},u.pdfBytesUrl(r,JG,i.data?.baseUrl)),p&&b.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:b.error.message})}),m&&C.data!==void 0&&(0,F.jsx)(AU,{recipeId:r,stepPath:JG,view:C.data,onTablePick:e=>{Pe(e)},onCellPick:e=>{Fe(e)},steps:ie,hoveredStepId:D,onHoverStepId:ne,csvOverride:x,onCsvOverrideChange:S}),m&&C.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:C.error.message})}),h&&w.data!==void 0&&(0,F.jsx)($H,{recipeId:r,stepPath:JG,view:w.data,onTablePick:e=>{Pe(e)},onChartPick:e=>{Ie(e)},onRegionPick:e=>{Fe(e)},steps:ie,hoveredStepId:D,onHoverStepId:ne}),h&&w.isError&&(0,F.jsx)(I,{p:4,color:`fg.error`,children:(0,F.jsx)(V,{children:w.error.message})}),!f&&!p&&!m&&!h&&i.data!==void 0&&!o&&(0,F.jsx)(dG,{html:i.data.html,pickMode:Te,showHidden:E,hoveredSelector:re,onHoverNode:se,onPickNode:e=>{ke(e)}}),!f&&!p&&!m&&!h&&i.data!==void 0&&o&&(0,F.jsxs)(Qw,{panels:[{id:`snapshot`,minSize:15},{id:`inspect`,minSize:20}],h:`full`,children:[(0,F.jsx)($w,{id:`snapshot`,overflow:`hidden`,children:(0,F.jsx)(dG,{html:i.data.html,pickMode:Te,showHidden:E,hoveredSelector:re,onHoverNode:se,onPickNode:e=>{ke(e)}})}),(0,F.jsx)(nT,{id:`snapshot:inspect`}),(0,F.jsx)($w,{id:`inspect`,overflow:`hidden`,children:(0,F.jsx)(uk,{recipeId:r,recipe:e,snapshot:i.data,onSaveOutline:t,onSaveRecipe:n})})]}),i.isError&&(0,F.jsxs)(I,{p:4,color:`fg.error`,role:`alert`,children:[(0,F.jsx)(V,{fontWeight:`semibold`,children:`Could not take a snapshot of this recipe's page.`}),(0,F.jsx)(V,{children:FD(i.error.message)})]}),!i.isFetching&&!i.isError&&i.data===void 0&&(0,F.jsx)(I,{p:4,color:`fg.muted`,children:(0,F.jsx)(V,{children:`Run a sample, or open a recipe, to see its snapshot here.`})})]})]})}function $G(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var eK=1024,tK=0,nK=class{constructor(e,t){this.from=e,this.to=t}},rK=class{constructor(e={}){this.id=tK++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw Error(`This node type doesn't define a deserialize function`)}),this.combine=e.combine||null}add(e){if(this.perNode)throw RangeError(`Can't add per-node props to node types`);return typeof e!=`function`&&(e=oK.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};rK.closedBy=new rK({deserialize:e=>e.split(` `)}),rK.openedBy=new rK({deserialize:e=>e.split(` `)}),rK.group=new rK({deserialize:e=>e.split(` `)}),rK.isolate=new rK({deserialize:e=>{if(e&&e!=`rtl`&&e!=`ltr`&&e!=`auto`)throw RangeError(`Invalid value for isolate: `+e);return e||`auto`}}),rK.contextHash=new rK({perNode:!0}),rK.lookAhead=new rK({perNode:!0}),rK.mounted=new rK({perNode:!0});var iK=class{constructor(e,t,n,r=!1){this.tree=e,this.overlay=t,this.parser=n,this.bracketed=r}static get(e){return e&&e.props&&e.props[rK.mounted.id]}},aK=Object.create(null),oK=class e{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(t){let n=t.props&&t.props.length?Object.create(null):aK,r=+!!t.top|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new e(t.name||``,n,t.id,r);if(t.props){for(let e of t.props)if(Array.isArray(e)||(e=e(i)),e){if(e[0].perNode)throw RangeError(`Can't store a per-node prop on a node type`);n[e[0].id]=e[1]}}return i}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e==`string`){if(this.name==e)return!0;let t=this.prop(rK.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(` `))t[r]=e[n];return e=>{for(let n=e.prop(rK.group),r=-1;r<(n?n.length:0);r++){let i=t[r<0?e.name:n[r]];if(i)return i}}}};oK.none=new oK(``,Object.create(null),0,8);var sK=class e{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw RangeError(`Node type ids should correspond to array positions when creating a node set`)}extend(...t){let n=[];for(let e of this.types){let r=null;for(let n of t){let t=n(e);if(t){r||=Object.assign({},e.props);let n=t[1],i=t[0];i.combine&&i.id in r&&(n=i.combine(r[i.id],n)),r[i.id]=n}}n.push(r?new oK(e.name,r,e.id,e.flags):e)}return new e(n)}},cK=new WeakMap,lK=new WeakMap,uK;(function(e){e[e.ExcludeBuffers=1]=`ExcludeBuffers`,e[e.IncludeAnonymous=2]=`IncludeAnonymous`,e[e.IgnoreMounts=4]=`IgnoreMounts`,e[e.IgnoreOverlays=8]=`IgnoreOverlays`,e[e.EnterBracketed=16]=`EnterBracketed`})(uK||={});var dK=class e{constructor(e,t,n,r,i){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)this.props[typeof e==`number`?e:e.id]=t}}toString(){let e=iK.get(this);if(e&&!e.overlay)return e.tree.toString();let t=``;for(let e of this.children){let n=e.toString();n&&(t&&(t+=`,`),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?`(`+t+`)`:``):t}cursor(e=0){return new TK(this.topNode,e)}cursorAt(e,t=0,n=0){let r=new TK(cK.get(this)||this.topNode);return r.moveTo(e,t),cK.set(this,r._tree),r}get topNode(){return new _K(this,0,0,null)}resolve(e,t=0){let n=hK(cK.get(this)||this.topNode,e,t,!1);return cK.set(this,n),n}resolveInner(e,t=0){let n=hK(lK.get(this)||this.topNode,e,t,!0);return lK.set(this,n),n}resolveStack(e,t=0){return wK(this,e,t)}iterate(e){let{enter:t,leave:n,from:r=0,to:i=this.length}=e,a=e.mode||0,o=(a&uK.IncludeAnonymous)>0;for(let e=this.cursor(a|uK.IncludeAnonymous);;){let a=!1;if(e.from<=i&&e.to>=r&&(!o&&e.type.isAnonymous||t(e)!==!1)){if(e.firstChild())continue;a=!0}for(;a&&n&&(o||!e.type.isAnonymous)&&n(e),!e.nextSibling();){if(!e.parent())return;a=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(t={}){return this.children.length<=8?this:AK(oK.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new e(this.type,t,n,r,this.propValues),t.makeTree||((t,n,r)=>new e(oK.none,t,n,r)))}static build(e){return DK(e)}};dK.empty=new dK(oK.none,[],[],0);var fK=class e{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new e(this.buffer,this.index)}},pK=class e{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return oK.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(`,`)}childString(e){let t=this.buffer[e],n=this.buffer[e+3],r=this.set.types[t],i=r.name;if(/\W/.test(i)&&!r.isError&&(i=JSON.stringify(i)),e+=4,n==e)return i;let a=[];for(;e<n;)a.push(this.childString(e)),e=this.buffer[e+3];return i+`(`+a.join(`,`)+`)`}findChild(e,t,n,r,i){let{buffer:a}=this,o=-1;for(let s=e;s!=t&&!(mK(i,r,a[s+1],a[s+2])&&(o=s,n>0));s=a[s+3]);return o}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let e=t,s=0;e<n;){a[s++]=i[e++],a[s++]=i[e++]-r;let n=a[s++]=i[e++]-r;a[s++]=i[e++]-t,o=Math.max(o,n)}return new e(a,o,this.set)}};function mK(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function hK(e,t,n,r){for(;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let t=!r&&e instanceof _K&&e.index<0?null:e.parent;if(!t)return e;e=t}let i=r?0:uK.IgnoreOverlays;if(r)for(let r=e,a=r.parent;a;r=a,a=r.parent)r instanceof _K&&r.index<0&&a.enter(t,n,i)?.from!=r.from&&(e=a);for(;;){let r=e.enter(t,n,i);if(!r)return e;e=r}}var gK=class{cursor(e=0){return new TK(this,e)}getChild(e,t=null,n=null){let r=vK(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return vK(this,e,t,n)}resolve(e,t=0){return hK(this,e,t,!1)}resolveInner(e,t=0){return hK(this,e,t,!0)}matchContext(e){return yK(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),n=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(n=t,t=e.prevSibling):t=e}return n}get node(){return this}get next(){return this.parent}},_K=class e extends gK{constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,i,a=0){for(let o=this;;){for(let{children:s,positions:c}=o._tree,l=n>0?s.length:-1;t!=l;t+=n){let l=s[t],u=c[t]+o.from,d;if(a&uK.EnterBracketed&&l instanceof dK&&(d=iK.get(l))&&!d.overlay&&d.bracketed&&r>=u&&r<=u+l.length||mK(i,r,u,u+l.length)){if(l instanceof pK){if(a&uK.ExcludeBuffers)continue;let e=l.findChild(0,l.buffer.length,n,r-u,i);if(e>-1)return new xK(new bK(o,l,t,u),null,e)}else if(a&uK.IncludeAnonymous||!l.type.isAnonymous||EK(l)){let s;if(!(a&uK.IgnoreMounts)&&(s=iK.get(l))&&!s.overlay)return new e(s.tree,u,t,o);let c=new e(l,u,t,o);return a&uK.IncludeAnonymous||!c.type.isAnonymous?c:c.nextChild(n<0?l.children.length-1:0,n,r,i,a)}}}if(a&uK.IncludeAnonymous||!o.type.isAnonymous||(t=o.index>=0?o.index+n:n<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(t,n,r=0){let i;if(!(r&uK.IgnoreOverlays)&&(i=iK.get(this._tree))&&i.overlay){let a=t-this.from,o=r&uK.EnterBracketed&&i.bracketed;for(let{from:t,to:r}of i.overlay)if((n>0||o?t<=a:t<a)&&(n<0||o?r>=a:r>a))return new e(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function vK(e,t,n,r){let i=e.cursor(),a=[];if(!i.firstChild())return a;if(n!=null){for(let e=!1;!e;)if(e=i.type.is(n),!i.nextSibling())return a}for(;;){if(r!=null&&i.type.is(r))return a;if(i.type.is(t)&&a.push(i.node),!i.nextSibling())return r==null?a:[]}}function yK(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}var bK=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},xK=class e extends gK{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new e(this.context,this,a)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(t,n,r=0){if(r&uK.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new e(this.context,this,a)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new e(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new e(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let a=n.buffer[this.index+1];e.push(n.slice(r,i,a)),t.push(0)}return new dK(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function SK(e){if(!e.length)return null;let t=0,n=e[0];for(let r=1;r<e.length;r++){let i=e[r];(i.from>n.from||i.to<n.to)&&(n=i,t=r)}let r=n instanceof _K&&n.index<0?null:n.parent,i=e.slice();return r?i[t]=r:i.splice(t,1),new CK(i,n)}var CK=class{constructor(e,t){this.heads=e,this.node=t}get next(){return SK(this.heads)}};function wK(e,t,n){let r=e.resolveInner(t,n),i=null;for(let e=r instanceof _K?r:r.context.parent;e;e=e.parent)if(e.index<0){let a=e.parent;(i||=[r]).push(a.resolve(t,n)),e=a}else{let a=iK.get(e.tree);if(a&&a.overlay&&a.overlay[0].from<=t&&a.overlay[a.overlay.length-1].to>=t){let o=new _K(a.tree,a.overlay[0].from+e.from,-1,e);(i||=[r]).push(hK(o,t,n,!1))}}return i?SK(i):r}var TK=class{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~uK.EnterBracketed,e instanceof _K)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof _K?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&uK.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&uK.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&uK.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let e=n<0?0:this.stack[n]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(e)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(r.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let r=t+e,i=e<0?-1:n._tree.children.length;r!=i;r+=e){let e=n._tree.children[r];if(this.mode&uK.IncludeAnonymous||e instanceof pK||!e.type.isAnonymous||EK(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)scan:for(let r=this.index,i=this.stack.length;i>=0;){for(let a=e;a;a=a._parent)if(a.index==r){if(r==this.index)return a;t=a,n=i+1;break scan}r=this.stack[--i]}for(let e=n;e<this.stack.length;e++)t=new xK(this.buffer,t,this.stack[e]);return this.bufferNode=new xK(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!n)return;if(this.nextSibling())break;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return yK(this.node.parent,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,i=this.stack.length-1;r>=0;i--){if(i<0)return yK(this._tree,e,r);let a=n[t.buffer[this.stack[i]]];if(!a.isAnonymous){if(e[r]&&e[r]!=a.name)return!1;r--}}return!0}};function EK(e){return e.children.some(e=>e instanceof pK||!e.type.isAnonymous||EK(e))}function DK(e){let{buffer:t,nodeSet:n,maxBufferLength:r=eK,reused:i=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(t)?new fK(t,t.length):t,s=n.types,c=0,l=0;function u(e,t,_,v,y,b){let{id:x,start:S,end:C,size:w}=o,T=l,E=c;if(w<0){if(o.next(),w==-1){let t=i[x];_.push(t),v.push(S-e);return}if(w==-3){c=x;return}if(w==-4){l=x;return}throw RangeError(`Unrecognized record size: ${w}`)}let D=s[x],O,k,A=S-e;if(C-S<=r&&(k=h(o.pos-t,y))){let t=new Uint16Array(k.size-k.skip),r=o.pos-k.size,i=t.length;for(;o.pos>r;)i=g(k.start,t,i);O=new pK(t,C-k.start,n),A=k.start-e}else{let e=o.pos-w;o.next();let t=[],n=[],i=x>=a?x:-1,s=0,c=C;for(;o.pos>e;)i>=0&&o.id==i&&o.size>=0?(o.end<=c-r&&(p(t,n,S,s,o.end,c,i,T,E),s=t.length,c=o.end),o.next()):b>2500?d(S,e,t,n):u(S,e,t,n,i,b+1);if(i>=0&&s>0&&s<t.length&&p(t,n,S,s,S,c,i,T,E),t.reverse(),n.reverse(),i>-1&&s>0){let e=f(D,E);O=AK(D,t,n,0,t.length,0,C-S,e,e)}else O=m(D,t,n,C-S,T-C,E)}_.push(O),v.push(A)}function d(e,t,i,a){let s=[],c=0,l=-1;for(;o.pos>t;){let{id:e,start:t,end:n,size:i}=o;if(i>4)o.next();else if(l>-1&&t<l)break;else l<0&&(l=n-r),s.push(e,t,n),c++,o.next()}if(c){let t=new Uint16Array(c*4),r=s[s.length-2];for(let e=s.length-3,n=0;e>=0;e-=3)t[n++]=s[e],t[n++]=s[e+1]-r,t[n++]=s[e+2]-r,t[n++]=n;i.push(new pK(t,s[2]-r,n)),a.push(r-e)}}function f(e,t){return(n,r,i)=>{let a=0,o=n.length-1,s,c;if(o>=0&&(s=n[o])instanceof dK){if(!o&&s.type==e&&s.length==i)return s;(c=s.prop(rK.lookAhead))&&(a=r[o]+s.length+c)}return m(e,n,r,i,a,t)}}function p(e,t,r,i,a,o,s,c,l){let u=[],d=[];for(;e.length>i;)u.push(e.pop()),d.push(t.pop()+r-a);e.push(m(n.types[s],u,d,o-a,c-o,l)),t.push(a-r)}function m(e,t,n,r,i,a,o){if(a){let e=[rK.contextHash,a];o=o?[e].concat(o):[e]}if(i>25){let e=[rK.lookAhead,i];o=o?[e].concat(o):[e]}return new dK(e,t,n,r,o)}function h(e,t){let n=o.fork(),i=0,s=0,c=0,l=n.end-r,u={size:0,start:0,skip:0};scan:for(let r=n.pos-e;n.pos>r;){let e=n.size;if(n.id==t&&e>=0){u.size=i,u.start=s,u.skip=c,c+=4,i+=4,n.next();continue}let o=n.pos-e;if(e<0||o<r||n.start<l)break;let d=n.id>=a?4:0,f=n.start;for(n.next();n.pos>o;){if(n.size<0){if(n.size==-3||n.size==-4)d+=4;else break scan}else n.id>=a&&(d+=4);n.next()}s=f,i+=e,c+=d}return(t<0||i==e)&&(u.size=i,u.start=s,u.skip=c),u.size>4?u:void 0}function g(e,t,n){let{id:r,start:i,end:s,size:u}=o;if(o.next(),u>=0&&r<a){let a=n;if(u>4){let r=o.pos-(u-4);for(;o.pos>r;)n=g(e,t,n)}t[--n]=a,t[--n]=s-e,t[--n]=i-e,t[--n]=r}else u==-3?c=r:u==-4&&(l=r);return n}let _=[],v=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,_,v,-1,0);let y=e.length??(_.length?v[0]+_[0].length:0);return new dK(s[e.topID],_.reverse(),v.reverse(),y)}var OK=new WeakMap;function kK(e,t){if(!e.isAnonymous||t instanceof pK||t.type!=e)return 1;let n=OK.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof dK)){n=1;break}n+=kK(e,r)}OK.set(t,n)}return n}function AK(e,t,n,r,i,a,o,s,c){let l=0;for(let n=r;n<i;n++)l+=kK(e,t[n]);let u=Math.ceil(l*1.5/8),d=[],f=[];function p(t,n,r,i,o){for(let s=r;s<i;){let r=s,l=n[s],m=kK(e,t[s]);for(s++;s<i;s++){let n=kK(e,t[s]);if(m+n>=u)break;m+=n}if(s==r+1){if(m>u){let e=t[r];p(e.children,e.positions,0,e.children.length,n[r]+o);continue}d.push(t[r])}else{let i=n[s-1]+t[s-1].length-l;d.push(AK(e,t,n,r,s,l,i,null,c))}f.push(l+o-a)}}return p(t,n,r,i,0),(s||c)(d,f,o)}var jK=class e{constructor(e,t,n,r,i=!1,a=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=!!i|(a?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let i=[new e(0,t.length,t,0,!1,r)];for(let e of n)e.to>t.length&&i.push(e);return i}static applyChanges(t,n,r=128){if(!n.length)return t;let i=[],a=1,o=t.length?t[0]:null;for(let s=0,c=0,l=0;;s++){let u=s<n.length?n[s]:null,d=u?u.fromA:1e9;if(d-c>=r)for(;o&&o.from<d;){let n=o;if(c>=n.from||d<=n.to||l){let t=Math.max(n.from,c)-l,r=Math.min(n.to,d)-l;n=t>=r?null:new e(t,r,n.tree,n.offset+l,s>0,!!u)}if(n&&i.push(n),o.to>d)break;o=a<t.length?t[a++]:null}if(!u)break;c=u.toA,l=u.toA-u.toB}return i}},MK=class{startParse(e,t,n){return typeof e==`string`&&(e=new NK(e)),n=n?n.length?n.map(e=>new nK(e.from,e.to)):[new nK(0,0)]:[new nK(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let e=r.advance();if(e)return e}}},NK=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};new rK({perNode:!0});var PK=class e{constructor(e,t,n,r,i,a,o,s,c,l=0,u){this.p=e,this.stack=t,this.state=n,this.reducePos=r,this.pos=i,this.score=a,this.buffer=o,this.bufferBase=s,this.curContext=c,this.lookAhead=l,this.parent=u}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?`!`+this.score:``}`}static start(t,n,r=0){let i=t.parser.context;return new e(t,[],n,r,r,0,[],0,i?new FK(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){let t=e>>19,n=e&65535,{parser:r}=this.p,i=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),a=r.dynamicPrecedence(n);if(a&&(this.score+=a),t==0){n<r.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,i?8:4,!0),this.reduceContext(n,this.reducePos);return}let o=this.stack.length-(t-1)*3-(e&262144?6:0),s=o?this.stack[o-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&s==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let c=this.reducePos-s;c>=2e3&&!this.p.parser.nodeSet.types[n]?.isAnonymous&&(s==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=s,this.p.lastBigReductionSize=c));let l=o?this.stack[o-1]:0,u=this.bufferBase+this.buffer.length-l;if(n<r.minRepeatTerm||e&131072){let e=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,s,e,u+4,!0)}if(e&262144)this.state=this.stack[o];else{let e=this.stack[o-3];this.state=r.getGoto(e,n,!0)}for(;this.stack.length>o;)this.stack.pop();this.reduceContext(n,s)}storeNode(e,t,n,r=4,i=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let e=this.buffer.length;if(e>0&&this.buffer[e-4]==0&&this.buffer[e-1]>-1){if(t==n)return;if(this.buffer[e-2]>=t){this.buffer[e-2]=n;return}}}if(!i||this.pos==n)this.buffer.push(e,t,n,r);else{let i=this.buffer.length;if(i>0&&(this.buffer[i-4]!=0||this.buffer[i-1]<0)){let e=!1;for(let t=i;t>0&&this.buffer[t-2]>n;t-=4)if(this.buffer[t-1]>=0){e=!0;break}if(e)for(;i>0&&this.buffer[i-2]>n;)this.buffer[i]=this.buffer[i-4],this.buffer[i+1]=this.buffer[i-3],this.buffer[i+2]=this.buffer[i-2],this.buffer[i+3]=this.buffer[i-1],i-=4,r>4&&(r-=4)}this.buffer[i]=e,this.buffer[i+1]=t,this.buffer[i+2]=n,this.buffer[i+3]=r}}shift(e,t,n,r){if(e&131072)this.pushState(e&65535,this.pos);else if(e&262144)this.pos=r,this.shiftContext(t,n),t<=this.p.parser.maxNode&&this.buffer.push(t,n,r,4);else{let i=e,{parser:a}=this.p;this.pos=r;let o=a.stateFlag(i,1);!o&&(r>n||t<=a.maxNode)&&(this.reducePos=r),this.pushState(i,o?n:Math.min(n,this.reducePos)),this.shiftContext(t,n),t<=a.maxNode&&this.buffer.push(t,n,r,4)}}apply(e,t,n,r){e&65536?this.reduce(e):this.shift(e,t,n,r)}useNode(e,t){let n=this.p.reused.length-1;(n<0||this.p.reused[n]!=e)&&(this.p.reused.push(e),n++);let r=this.pos;this.reducePos=this.pos=r+e.length,this.pushState(t,r),this.buffer.push(n,r,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let t=this,n=t.buffer.length;for(n&&t.buffer[n-4]==0&&(n-=4);n>0&&t.buffer[n-2]>t.reducePos;)n-=4;let r=t.buffer.slice(n),i=t.bufferBase+n;for(;t&&i==t.bufferBase;)t=t.parent;return new e(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,r,i,this.curContext,this.lookAhead,t)}recoverByDelete(e,t){let n=e<=this.p.parser.maxNode;n&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,n?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new IK(this);;){let n=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(n==0)return!1;if(!(n&65536))return!0;t.reduce(n)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let n=[];for(let r=0,i;r<t.length;r+=2)(i=t[r+1])!=this.state&&this.p.parser.hasAction(i,e)&&n.push(t[r],i);if(this.stack.length<120)for(let e=0;n.length<8&&e<t.length;e+=2){let r=t[e+1];n.some((e,t)=>t&1&&e==r)||n.push(t[e],r)}t=n}let n=[];for(let e=0;e<t.length&&n.length<4;e+=2){let r=t[e+1];if(r==this.state)continue;let i=this.split();i.pushState(r,this.pos),i.storeNode(0,i.pos,i.pos,4,!0),i.shiftContext(t[e],this.pos),i.reducePos=this.pos,i.score-=200,n.push(i)}return n}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if(!(t&65536))return!1;if(!e.validAction(this.state,t)){let n=t>>19,r=t&65535,i=this.stack.length-n*3;if(i<0||e.getGoto(this.stack[i],r,!1)<0){let e=this.findForcedReduction();if(e==null)return!1;t=e}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],n=(r,i)=>{if(!t.includes(r))return t.push(r),e.allActions(r,t=>{if(!(t&393216)){if(t&65536){let n=(t>>19)-i;if(n>1){let r=t&65535,i=this.stack.length-n*3;if(i>=0&&e.getGoto(this.stack[i],r,!1)>=0)return n<<19|65536|r}}else{let e=n(t,i+1);if(e!=null)return e}}})};return n(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new FK(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},FK=class{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}},IK=class{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,n=e>>19;n==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(n-1)*3;let r=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=r}},LK=class e{constructor(e,t,n){this.stack=e,this.pos=t,this.index=n,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(t,n=t.bufferBase+t.buffer.length){return new e(t,n,n-t.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new e(this.stack,this.pos,this.index)}};function RK(e,t=Uint16Array){if(typeof e!=`string`)return e;let n=null;for(let r=0,i=0;r<e.length;){let a=0;for(;;){let t=e.charCodeAt(r++),n=!1;if(t==126){a=65535;break}t>=92&&t--,t>=34&&t--;let i=t-32;if(i>=46&&(i-=46,n=!0),a+=i,n)break;a*=46}n?n[i++]=a:n=new t(a)}return n}var zK=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},BK=new zK,VK=class{constructor(e,t){this.input=e,this.ranges=t,this.chunk=``,this.chunkOff=0,this.chunk2=``,this.chunk2Pos=0,this.next=-1,this.token=BK,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let n=this.range,r=this.rangeIndex,i=this.pos+e;for(;i<n.from;){if(!r)return null;let e=this.ranges[--r];i-=n.from-e.to,n=e}for(;t<0?i>n.to:i>=n.to;){if(r==this.ranges.length-1)return null;let e=this.ranges[++r];i+=e.from-n.to,n=e}return i}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,n,r;if(t>=0&&t<this.chunk.length)n=this.pos+e,r=this.chunk.charCodeAt(t);else{let t=this.resolveOffset(e,1);if(t==null)return-1;if(n=t,n>=this.chunk2Pos&&n<this.chunk2Pos+this.chunk2.length)r=this.chunk2.charCodeAt(n-this.chunk2Pos);else{let e=this.rangeIndex,t=this.range;for(;t.to<=n;)t=this.ranges[++e];this.chunk2=this.input.chunk(this.chunk2Pos=n),n+this.chunk2.length>t.to&&(this.chunk2=this.chunk2.slice(0,t.to-n)),r=this.chunk2.charCodeAt(0)}}return n>=this.token.lookAhead&&(this.token.lookAhead=n+1),r}acceptToken(e,t=0){let n=t?this.resolveOffset(t,-1):this.pos;if(n==null||n<this.token.start)throw RangeError(`Token end out of bounds`);this.token.value=e,this.token.end=n}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.next=this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?-1:this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk=``,this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=BK,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk=``,this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let n=``;for(let r of this.ranges){if(r.from>=t)break;r.to>e&&(n+=this.input.read(Math.max(r.from,e),Math.min(r.to,t)))}return n}},HK=class{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:n}=t.p;WK(this.data,e,t,this.id,n.data,n.tokenPrecTable)}};HK.prototype.contextual=HK.prototype.fallback=HK.prototype.extend=!1;var UK=class{constructor(e,t,n){this.precTable=t,this.elseToken=n,this.data=typeof e==`string`?RK(e):e}token(e,t){let n=e.pos,r=0;for(;;){let n=e.next<0,i=e.resolveOffset(1,1);if(WK(this.data,e,t,0,this.data,this.precTable),e.token.value>-1)break;if(this.elseToken==null)return;if(n||r++,i==null)break;e.reset(i,e.token)}r&&(e.reset(n,e.token),e.acceptToken(this.elseToken,r))}};UK.prototype.contextual=HK.prototype.fallback=HK.prototype.extend=!1;function WK(e,t,n,r,i,a){let o=0,s=1<<r,{dialect:c}=n.p.parser;scan:for(;(s&e[o])!=0;){let n=e[o+1];for(let r=o+3;r<n;r+=2)if((e[r+1]&s)>0){let n=e[r];if(c.allows(n)&&(t.token.value==-1||t.token.value==n||KK(n,t.token.value,i,a))){t.acceptToken(n);break}}let r=t.next,l=0,u=e[o+2];if(t.next<0&&u>l&&e[n+u*3-3]==65535){o=e[n+u*3-1];continue scan}for(;l<u;){let i=l+u>>1,a=n+i+(i<<1),s=e[a],c=e[a+1]||65536;if(r<s)u=i;else if(r>=c)l=i+1;else{o=e[a+2],t.advance();continue scan}}break}}function GK(e,t,n){for(let r=t,i;(i=e[r])!=65535;r++)if(i==n)return r-t;return-1}function KK(e,t,n,r){let i=GK(n,r,t);return i<0||GK(n,r,e)<i}var qK=typeof process<`u`&&/\bparse\b/.test({}.LOG),JK=null;function YK(e,t,n){let r=e.cursor(uK.IncludeAnonymous);for(r.moveTo(t);;)if(!(n<0?r.childBefore(t):r.childAfter(t)))for(;;){if((n<0?r.to<t:r.from>t)&&!r.type.isError)return n<0?Math.max(0,Math.min(r.to-1,t-25)):Math.min(e.length,Math.max(r.from+1,t+25));if(n<0?r.prevSibling():r.nextSibling())break;if(!r.parent())return n<0?0:e.length}}var XK=class{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?YK(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?YK(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let n=this.trees[t],r=this.index[t];if(r==n.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let i=n.children[r],a=this.start[t]+n.positions[r];if(a>e)return this.nextStart=a,null;if(i instanceof dK){if(a==e){if(a<this.safeFrom)return null;let e=a+i.length;if(e<=this.safeTo){let t=i.prop(rK.lookAhead);if(!t||e+t<this.fragment.to)return i}}this.index[t]++,a+i.length>=Math.max(this.safeFrom,e)&&(this.trees.push(i),this.start.push(a),this.index.push(0))}else this.index[t]++,this.nextStart=a+i.length}}},ZK=class{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(e=>new zK)}getActions(e){let t=0,n=null,{parser:r}=e.p,{tokenizers:i}=r,a=r.stateSlot(e.state,3),o=e.curContext?e.curContext.hash:0,s=0;for(let r=0;r<i.length;r++){if(!(1<<r&a))continue;let c=i[r],l=this.tokens[r];if((!n||c.fallback)&&((c.contextual||l.start!=e.pos||l.mask!=a||l.context!=o)&&(this.updateCachedToken(l,c,e),l.mask=a,l.context=o),l.lookAhead>l.end+25&&(s=Math.max(l.lookAhead,s)),l.value!=0)){let r=t;if(l.extended>-1&&(t=this.addActions(e,l.extended,l.end,t)),t=this.addActions(e,l.value,l.end,t),!c.extend&&(n=l,t>r))break}}for(;this.actions.length>t;)this.actions.pop();return s&&e.setLookAhead(s),!n&&e.pos==this.stream.end&&(n=new zK,n.value=e.p.parser.eofTerm,n.start=n.end=e.pos,t=this.addActions(e,n.value,n.end,t)),this.mainToken=n,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new zK,{pos:n,p:r}=e;return t.start=n,t.end=Math.min(n+1,r.stream.end),t.value=n==r.stream.end?r.parser.eofTerm:0,t}updateCachedToken(e,t,n){let r=this.stream.clipPos(n.pos);if(t.token(this.stream.reset(r,e),n),e.value>-1){let{parser:t}=n.p;for(let r=0;r<t.specialized.length;r++)if(t.specialized[r]==e.value){let i=t.specializers[r](this.stream.read(e.start,e.end),n);if(i>=0&&n.p.parser.dialect.allows(i>>1)){i&1?e.extended=i>>1:e.value=i>>1;break}}}else e.value=0,e.end=this.stream.clipPos(r+1)}putAction(e,t,n,r){for(let t=0;t<r;t+=3)if(this.actions[t]==e)return r;return this.actions[r++]=e,this.actions[r++]=t,this.actions[r++]=n,r}addActions(e,t,n,r){let{state:i}=e,{parser:a}=e.p,{data:o}=a;for(let e=0;e<2;e++)for(let s=a.stateSlot(i,e?2:1);;s+=3){if(o[s]==65535){if(o[s+1]==1)s=nq(o,s+2);else{r==0&&o[s+1]==2&&(r=this.putAction(nq(o,s+2),t,n,r));break}}o[s]==t&&(r=this.putAction(nq(o,s+1),t,n,r))}return r}},QK=class{constructor(e,t,n,r){this.parser=e,this.input=t,this.ranges=r,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new VK(t,r),this.tokens=new ZK(e,this.stream),this.topTerm=e.top[1];let{from:i}=r[0];this.stacks=[PK.start(this,e.top[0],i)],this.fragments=n.length&&this.stream.end-i>e.bufferLength*4?new XK(n,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,n=this.stacks=[],r,i;if(this.bigReductionCount>300&&e.length==1){let[t]=e;for(;t.forceReduce()&&t.stack.length&&t.stack[t.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let a=0;a<e.length;a++){let o=e[a];for(;;){if(this.tokens.mainToken=null,o.pos>t)n.push(o);else if(this.advanceStack(o,n,e))continue;else{r||(r=[],i=[]),r.push(o);let e=this.tokens.getMainToken(o);i.push(e.value,e.end)}break}}if(!n.length){let e=r&&rq(r);if(e)return qK&&console.log(`Finish with `+this.stackID(e)),this.stackToTree(e);if(this.parser.strict)throw qK&&r&&console.log(`Stuck with token `+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):`none`)),SyntaxError(`No parse at `+t);this.recovering||=5}if(this.recovering&&r){let e=this.stoppedAt!=null&&r[0].pos>this.stoppedAt?r[0]:this.runRecovery(r,i,n);if(e)return qK&&console.log(`Force-finish `+this.stackID(e)),this.stackToTree(e.forceAll())}if(this.recovering){let e=this.recovering==1?1:this.recovering*3;if(n.length>e)for(n.sort((e,t)=>t.score-e.score);n.length>e;)n.pop();n.some(e=>e.reducePos>t)&&this.recovering--}else if(n.length>1){outer:for(let e=0;e<n.length-1;e++){let t=n[e];for(let r=e+1;r<n.length;r++){let i=n[r];if(t.sameState(i)||t.buffer.length>500&&i.buffer.length>500){if((t.score-i.score||t.buffer.length-i.buffer.length)>0)n.splice(r--,1);else{n.splice(e--,1);continue outer}}}}n.length>12&&(n.sort((e,t)=>t.score-e.score),n.splice(12,n.length-12))}this.minStackPos=n[0].pos;for(let e=1;e<n.length;e++)n[e].pos<this.minStackPos&&(this.minStackPos=n[e].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw RangeError(`Can't move stoppedAt forward`);this.stoppedAt=e}advanceStack(e,t,n){let r=e.pos,{parser:i}=this,a=qK?this.stackID(e)+` -> `:``;if(this.stoppedAt!=null&&r>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let t=e.curContext&&e.curContext.tracker.strict,n=t?e.curContext.hash:0;for(let o=this.fragments.nodeAt(r);o;){let r=this.parser.nodeSet.types[o.type.id]==o.type?i.getGoto(e.state,o.type.id):-1;if(r>-1&&o.length&&(!t||(o.prop(rK.contextHash)||0)==n))return e.useNode(o,r),qK&&console.log(a+this.stackID(e)+` (via reuse of ${i.getName(o.type.id)})`),!0;if(!(o instanceof dK)||o.children.length==0||o.positions[0]>0)break;let s=o.children[0];if(s instanceof dK&&o.positions[0]==0)o=s;else break}}let o=i.stateSlot(e.state,4);if(o>0)return e.reduce(o),qK&&console.log(a+this.stackID(e)+` (via always-reduce ${i.getName(o&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let s=this.tokens.getActions(e);for(let o=0;o<s.length;){let c=s[o++],l=s[o++],u=s[o++],d=o==s.length||!n,f=d?e:e.split(),p=this.tokens.mainToken;if(f.apply(c,l,p?p.start:f.pos,u),qK&&console.log(a+this.stackID(f)+` (via ${c&65536?`reduce of ${i.getName(c&65535)}`:`shift`} for ${i.getName(l)} @ ${r}${f==e?``:`, split`})`),d)return!0;f.pos>r?t.push(f):n.push(f)}return!1}advanceFully(e,t){let n=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>n)return $K(e,t),!0}}runRecovery(e,t,n){let r=null,i=!1;for(let a=0;a<e.length;a++){let o=e[a],s=t[a<<1],c=t[(a<<1)+1],l=qK?this.stackID(o)+` -> `:``;if(o.deadEnd&&(i||(i=!0,o.restart(),qK&&console.log(l+this.stackID(o)+` (restarted)`),this.advanceFully(o,n))))continue;let u=o.split(),d=l;for(let e=0;e<10&&u.forceReduce()&&(qK&&console.log(d+this.stackID(u)+` (via force-reduce)`),!this.advanceFully(u,n));e++)qK&&(d=this.stackID(u)+` -> `);for(let e of o.recoverByInsert(s))qK&&console.log(l+this.stackID(e)+` (via recover-insert)`),this.advanceFully(e,n);this.stream.end>o.pos?(c==o.pos&&(c++,s=0),o.recoverByDelete(s,c),qK&&console.log(l+this.stackID(o)+` (via recover-delete ${this.parser.getName(s)})`),$K(o,n)):(!r||r.score<u.score)&&(r=u)}return r}stackToTree(e){return e.close(),dK.build({buffer:LK.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(JK||=new WeakMap).get(e);return t||JK.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}};function $K(e,t){for(let n=0;n<t.length;n++){let r=t[n];if(r.pos==e.pos&&r.sameState(e)){t[n].score<e.score&&(t[n]=e);return}}t.push(e)}var eq=class{constructor(e,t,n){this.source=e,this.flags=t,this.disabled=n}allows(e){return!this.disabled||this.disabled[e]==0}},tq=class e extends MK{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(` `);this.minRepeatTerm=t.length;for(let n=0;n<e.repeatNodeCount;n++)t.push(``);let n=Object.keys(e.topRules).map(t=>e.topRules[t][1]),r=[];for(let e=0;e<t.length;e++)r.push([]);function i(e,t,n){r[e].push([t,t.deserialize(String(n))])}if(e.nodeProps)for(let t of e.nodeProps){let e=t[0];typeof e==`string`&&(e=rK[e]);for(let n=1;n<t.length;){let r=t[n++];if(r>=0)i(r,e,t[n++]);else{let a=t[n+-r];for(let o=-r;o>0;o--)i(t[n++],e,a);n++}}}this.nodeSet=new sK(t.map((t,i)=>oK.define({name:i>=this.minRepeatTerm?void 0:t,id:i,props:r[i],top:n.indexOf(i)>-1,error:i==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(i)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=eK;let a=RK(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let e=0;e<this.specializerSpecs.length;e++)this.specialized[e]=this.specializerSpecs[e].term;this.specializers=this.specializerSpecs.map(iq),this.states=RK(e.states,Uint32Array),this.data=RK(e.stateData),this.goto=RK(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(e=>typeof e==`number`?new HK(a,e):e),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,n){let r=new QK(this,e,t,n);for(let i of this.wrappers)r=i(r,e,t,n);return r}getGoto(e,t,n=!1){let r=this.goto;if(t>=r[0])return-1;for(let i=r[t+1];;){let t=r[i++],a=t&1,o=r[i++];if(a&&n)return o;for(let n=i+(t>>1);i<n;i++)if(r[i]==e)return o;if(a)return-1}}hasAction(e,t){let n=this.data;for(let r=0;r<2;r++)for(let i=this.stateSlot(e,r?2:1),a;;i+=3){if((a=n[i])==65535){if(n[i+1]==1)a=n[i=nq(n,i+2)];else if(n[i+1]==2)return nq(n,i+2);else break}if(a==t||a==0)return nq(n,i+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,e=>e==t||null)}allActions(e,t){let n=this.stateSlot(e,4),r=n?t(n):void 0;for(let n=this.stateSlot(e,1);r==null;n+=3){if(this.data[n]==65535){if(this.data[n+1]==1)n=nq(this.data,n+2);else break}r=t(nq(this.data,n+1))}return r}nextStates(e){let t=[];for(let n=this.stateSlot(e,1);;n+=3){if(this.data[n]==65535){if(this.data[n+1]==1)n=nq(this.data,n+2);else break}if(!(this.data[n+2]&1)){let e=this.data[n+1];t.some((t,n)=>n&1&&t==e)||t.push(this.data[n],e)}}return t}configure(t){let n=Object.assign(Object.create(e.prototype),this);if(t.props&&(n.nodeSet=this.nodeSet.extend(...t.props)),t.top){let e=this.topRules[t.top];if(!e)throw RangeError(`Invalid top rule name ${t.top}`);n.top=e}return t.tokenizers&&(n.tokenizers=this.tokenizers.map(e=>{let n=t.tokenizers.find(t=>t.from==e);return n?n.to:e})),t.specializers&&(n.specializers=this.specializers.slice(),n.specializerSpecs=this.specializerSpecs.map((e,r)=>{let i=t.specializers.find(t=>t.from==e.external);if(!i)return e;let a=Object.assign(Object.assign({},e),{external:i.to});return n.specializers[r]=iq(a),a})),t.contextTracker&&(n.context=t.contextTracker),t.dialect&&(n.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(n.strict=t.strict),t.wrap&&(n.wrappers=n.wrappers.concat(t.wrap)),t.bufferLength!=null&&(n.bufferLength=t.bufferLength),n}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),n=t.map(()=>!1);if(e)for(let r of e.split(` `)){let e=t.indexOf(r);e>=0&&(n[e]=!0)}let r=null;for(let e=0;e<t.length;e++)if(!n[e])for(let n=this.dialects[t[e]],i;(i=this.data[n++])!=65535;)(r||=new Uint8Array(this.maxTerm+1))[i]=1;return new eq(e,n,r)}static deserialize(t){return new e(t)}};function nq(e,t){return e[t]|e[t+1]<<16}function rq(e){let t=null;for(let n of e){let e=n.p.stoppedAt;(n.pos==n.p.stream.end||e!=null&&n.pos>e)&&n.p.parser.stateFlag(n.state,2)&&(!t||t.score<n.score)&&(t=n)}return t}function iq(e){if(e.external){let t=+!!e.extend;return(n,r)=>e.external(n,r)<<1|t}return e.get}var aq=0,oq=class e{constructor(e,t,n,r){this.name=e,this.set=t,this.base=n,this.modified=r,this.id=aq++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(t,n){let r=typeof t==`string`?t:`?`;if(t instanceof e&&(n=t),n?.base)throw Error(`Can not derive from a modified tag`);let i=new e(r,[],null,[]);if(i.set.push(i),n)for(let e of n.set)i.set.push(e);return i}static defineModifier(e){let t=new cq(e);return e=>e.modified.indexOf(t)>-1?e:cq.get(e.base||e,e.modified.concat(t).sort((e,t)=>e.id-t.id))}},sq=0,cq=class e{constructor(e){this.name=e,this.instances=[],this.id=sq++}static get(t,n){if(!n.length)return t;let r=n[0].instances.find(e=>e.base==t&&lq(n,e.modified));if(r)return r;let i=[],a=new oq(t.name,i,t,n);for(let e of n)e.instances.push(a);let o=uq(n);for(let n of t.set)if(!n.modified.length)for(let t of o)i.push(e.get(n,t));return a}};function lq(e,t){return e.length==t.length&&e.every((e,n)=>e==t[n])}function uq(e){let t=[[]];for(let n=0;n<e.length;n++)for(let r=0,i=t.length;r<i;r++)t.push(t[r].concat(e[n]));return t.sort((e,t)=>t.length-e.length)}function dq(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let e of n.split(` `))if(e){let n=[],i=2,a=e;for(let t=0;;){if(a==`...`&&t>0&&t+3==e.length){i=1;break}let r=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!r)throw RangeError(`Invalid path: `+e);if(n.push(r[0]==`*`?``:r[0][0]==`"`?JSON.parse(r[0]):r[0]),t+=r[0].length,t==e.length)break;let o=e[t++];if(t==e.length&&o==`!`){i=0;break}if(o!=`/`)throw RangeError(`Invalid path: `+e);a=e.slice(t)}let o=n.length-1,s=n[o];if(!s)throw RangeError(`Invalid path: `+e);t[s]=new pq(r,i,o>0?n.slice(0,o):null).sort(t[s])}}return fq.add(t)}var fq=new rK({combine(e,t){let n,r,i;for(;e||t;){if(!e||t&&e.depth<=t.depth?(i=t,t=t.next):(i=e,e=e.next),n&&n.mode==i.mode&&!i.context&&!n.context)continue;let a=new pq(i.tags,i.mode,i.context);n?n.next=a:r=a,n=a}return r}}),pq=class{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};pq.empty=new pq([],2,null);function mq(e,t){let n=Object.create(null);for(let t of e)if(!Array.isArray(t.tag))n[t.tag.id]=t.class;else for(let e of t.tag)n[e.id]=t.class;let{scope:r,all:i=null}=t||{};return{style:e=>{let t=i;for(let r of e)for(let e of r.set){let r=n[e.id];if(r){t=t?t+` `+r:r;break}}return t},scope:r}}function hq(e,t){let n=null;for(let r of e){let e=r.style(t);e&&(n=n?n+` `+e:e)}return n}function gq(e,t,n,r=0,i=e.length){let a=new _q(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,i,``,a.highlighters),a.flush(i)}var _q=class{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=``}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,i){let{type:a,from:o,to:s}=e;if(o>=n||s<=t)return;a.isTop&&(i=this.highlighters.filter(e=>!e.scope||e.scope(a)));let c=r,l=vq(e)||pq.empty,u=hq(i,l.tags);if(u&&(c&&(c+=` `),c+=u,l.mode==1&&(r+=(r?` `:``)+u)),this.startSpan(Math.max(t,o),c),l.opaque)return;let d=e.tree&&e.tree.prop(rK.mounted);if(d&&d.overlay){let a=e.node.enter(d.overlay[0].from+o,1),l=this.highlighters.filter(e=>!e.scope||e.scope(d.tree.type)),u=e.firstChild();for(let f=0,p=o;;f++){let m=f<d.overlay.length?d.overlay[f]:null,h=m?m.from+o:s,g=Math.max(t,p),_=Math.min(n,h);if(g<_&&u)for(;e.from<_&&(this.highlightRange(e,g,_,r,i),this.startSpan(Math.min(_,e.to),c),!(e.to>=h||!e.nextSibling())););if(!m||h>n)break;p=m.to+o,p>t&&(this.highlightRange(a.cursor(),Math.max(t,m.from+o),Math.min(n,p),``,l),this.startSpan(Math.min(n,p),c))}u&&e.parent()}else if(e.firstChild()){d&&(r=``);do if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,r,i),this.startSpan(Math.min(n,e.to),c)}while(e.nextSibling());e.parent()}}};function vq(e){let t=e.type.prop(fq);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}var q=oq.define,yq=q(),bq=q(),xq=q(bq),Sq=q(bq),Cq=q(),wq=q(Cq),Tq=q(Cq),Eq=q(),Dq=q(Eq),Oq=q(),kq=q(),Aq=q(),jq=q(Aq),Mq=q(),J={comment:yq,lineComment:q(yq),blockComment:q(yq),docComment:q(yq),name:bq,variableName:q(bq),typeName:xq,tagName:q(xq),propertyName:Sq,attributeName:q(Sq),className:q(bq),labelName:q(bq),namespace:q(bq),macroName:q(bq),literal:Cq,string:wq,docString:q(wq),character:q(wq),attributeValue:q(wq),number:Tq,integer:q(Tq),float:q(Tq),bool:q(Cq),regexp:q(Cq),escape:q(Cq),color:q(Cq),url:q(Cq),keyword:Oq,self:q(Oq),null:q(Oq),atom:q(Oq),unit:q(Oq),modifier:q(Oq),operatorKeyword:q(Oq),controlKeyword:q(Oq),definitionKeyword:q(Oq),moduleKeyword:q(Oq),operator:kq,derefOperator:q(kq),arithmeticOperator:q(kq),logicOperator:q(kq),bitwiseOperator:q(kq),compareOperator:q(kq),updateOperator:q(kq),definitionOperator:q(kq),typeOperator:q(kq),controlOperator:q(kq),punctuation:Aq,separator:q(Aq),bracket:jq,angleBracket:q(jq),squareBracket:q(jq),paren:q(jq),brace:q(jq),content:Eq,heading:Dq,heading1:q(Dq),heading2:q(Dq),heading3:q(Dq),heading4:q(Dq),heading5:q(Dq),heading6:q(Dq),contentSeparator:q(Eq),list:q(Eq),quote:q(Eq),emphasis:q(Eq),strong:q(Eq),link:q(Eq),monospace:q(Eq),strikethrough:q(Eq),inserted:q(),deleted:q(),changed:q(),invalid:q(),meta:Mq,documentMeta:q(Mq),annotation:q(Mq),processingInstruction:q(Mq),definition:oq.defineModifier(`definition`),constant:oq.defineModifier(`constant`),function:oq.defineModifier(`function`),standard:oq.defineModifier(`standard`),local:oq.defineModifier(`local`),special:oq.defineModifier(`special`)};for(let e in J){let t=J[e];t instanceof oq&&(t.name=e)}mq([{tag:J.link,class:`tok-link`},{tag:J.heading,class:`tok-heading`},{tag:J.emphasis,class:`tok-emphasis`},{tag:J.strong,class:`tok-strong`},{tag:J.keyword,class:`tok-keyword`},{tag:J.atom,class:`tok-atom`},{tag:J.bool,class:`tok-bool`},{tag:J.url,class:`tok-url`},{tag:J.labelName,class:`tok-labelName`},{tag:J.inserted,class:`tok-inserted`},{tag:J.deleted,class:`tok-deleted`},{tag:J.literal,class:`tok-literal`},{tag:J.string,class:`tok-string`},{tag:J.number,class:`tok-number`},{tag:[J.regexp,J.escape,J.special(J.string)],class:`tok-string2`},{tag:J.variableName,class:`tok-variableName`},{tag:J.local(J.variableName),class:`tok-variableName tok-local`},{tag:J.definition(J.variableName),class:`tok-variableName tok-definition`},{tag:J.special(J.variableName),class:`tok-variableName2`},{tag:J.definition(J.propertyName),class:`tok-propertyName tok-definition`},{tag:J.typeName,class:`tok-typeName`},{tag:J.namespace,class:`tok-namespace`},{tag:J.className,class:`tok-className`},{tag:J.macroName,class:`tok-macroName`},{tag:J.propertyName,class:`tok-propertyName`},{tag:J.operator,class:`tok-operator`},{tag:J.comment,class:`tok-comment`},{tag:J.meta,class:`tok-meta`},{tag:J.invalid,class:`tok-invalid`},{tag:J.punctuation,class:`tok-punctuation`}]);var Nq=dq({String:J.string,Number:J.number,"True False":J.bool,PropertyName:J.propertyName,Null:J.null,", :":J.separator,"[ ]":J.squareBracket,"{ }":J.brace}),Pq=tq.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:`#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O`,goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:`⚠ JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array`,maxTerm:25,nodeProps:[[`isolate`,-2,6,11,``],[`openedBy`,7,`{`,14,`[`],[`closedBy`,8,`}`,15,`]`]],propSources:[Nq],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0}),Fq=[],Iq=[];(()=>{let e=`lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?Iq:Fq).push(n+=e[t])})();function Lq(e){if(e<768)return!1;for(let t=0,n=Fq.length;;){let r=t+n>>1;if(e<Fq[r])n=r;else if(e>=Iq[r])t=r+1;else return!0;if(t==n)return!1}}function Rq(e){return e>=127462&&e<=127487}var zq=8205;function Bq(e,t,n=!0,r=!0){return(n?Vq:Hq)(e,t,r)}function Vq(e,t,n){if(t==e.length)return t;t&&Wq(e.charCodeAt(t))&&Gq(e.charCodeAt(t-1))&&t--;let r=Uq(e,t);for(t+=Kq(r);t<e.length;){let i=Uq(e,t);if(r==zq||i==zq||n&&Lq(i))t+=Kq(i),r=i;else if(Rq(i)){let n=0,r=t-2;for(;r>=0&&Rq(Uq(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function Hq(e,t,n){for(;t>1;){let r=Vq(e,t-2,n);if(r<t)return r;t--}return 0}function Uq(e,t){let n=e.charCodeAt(t);if(!Gq(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return Wq(r)?(n-55296<<10)+(r-56320)+65536:n}function Wq(e){return e>=56320&&e<57344}function Gq(e){return e>=55296&&e<56320}function Kq(e){return e<65536?1:2}var qq=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=rJ(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),Yq.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=rJ(this,e,t);let n=[];return this.decompose(e,t,n,0),Yq.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new $q(this),i=new $q(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new $q(this,e)}iterRange(e,t=this.length){return new eJ(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new tJ(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new Jq(t):Yq.from(Jq.split(t,[]))}},Jq=class e extends qq{constructor(e,t=Xq(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new nJ(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(Qq(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=Zq(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=rJ(this,t,n);let i=Zq(this.text,Zq(r.text,Qq(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):Yq.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
|
|
20
20
|
`){[e,t]=rJ(this,e,t);let r=``;for(let i=0,a=0;i<=t&&a<this.text.length;a++){let o=this.text[a],s=i+o.length;i>e&&a&&(r+=n),e<s&&t>i&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}},Yq=class e extends qq{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(e<=s&&t>=a){let i=r&(a<=e|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=rJ(this,t,n),r.lines<this.lines)for(let i=0,a=0;i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(t>=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines<l>>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=`
|
|
21
21
|
`){[e,t]=rJ(this,e,t);let r=``;for(let i=0,a=0;i<this.children.length&&a<=t;i++){let o=this.children[i],s=a+o.length;a>e&&i&&(r+=n),e<s&&t>a&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new Jq(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof Jq&&c&&(n=u[u.length-1])instanceof Jq&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new Jq(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}};qq.empty=new Jq([``],0);function Xq(e){let t=-1;for(let n of e)t+=n.length+1;return t}function Zq(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a<e.length&&i<=r;a++){let s=e[a],c=i+s.length;c>=n&&(c>r&&(s=s.slice(0,r-i)),i<n&&(s=s.slice(n-i)),o?(t[t.length-1]+=s,o=!1):t.push(s)),i=c+1}return t}function Qq(e,t,n){return Zq(e,[``],t,n)}var $q=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof Jq?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof Jq?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
22
22
|
`,this;e--}else if(r instanceof Jq){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof Jq?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},eJ=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new $q(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},tJ=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(qq.prototype[Symbol.iterator]=function(){return this.iter()},$q.prototype[Symbol.iterator]=eJ.prototype[Symbol.iterator]=tJ.prototype[Symbol.iterator]=function(){return this});var nJ=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function rJ(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function iJ(e,t,n=!0,r=!0){return Bq(e,t,n,r)}function aJ(e){return e>=56320&&e<57344}function oJ(e){return e>=55296&&e<56320}function sJ(e,t){let n=e.charCodeAt(t);if(!oJ(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return aJ(r)?(n-55296<<10)+(r-56320)+65536:n}function cJ(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}function lJ(e){return e<65536?1:2}var uJ=/\r\n?|\n/,dJ=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(dJ||={}),fJ=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){gJ(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:vJ(this,e)}mapDesc(e,t=!1){return e.empty?this:_J(this,e,t)}mapPos(e,t=-1,n=dJ.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=dJ.Simple&&c>=e&&(n==dJ.TrackDel&&r<e&&c>e||n==dJ.TrackBefore&&r<e||n==dJ.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},pJ=class e extends fJ{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return gJ(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return _J(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(qq.empty);r.push(a?t.slice(i,i+a):qq.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:vJ(this,e,!0)}map(e,t=!1){return e.empty?this:_J(this,e,t,!0)}iterChanges(e,t=!1){gJ(this,e,t)}get desc(){return fJ.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new yJ(this);done:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break done;let e=Math.min(a.len,s-o);mJ(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;mJ(n,e,t),t>0&&hJ(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break done;let e=Math.min(a.len,c-o);mJ(n,e,-1),mJ(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:fJ.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&mJ(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?qq.of(l.split(r||uJ)):l:qq.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&mJ(i,e-o,-1),mJ(i,s-e,d),hJ(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(qq.empty);r[e]=qq.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function mJ(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function hJ(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(qq.empty);e.push(n)}}function gJ(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=qq.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function _J(e,t,n,r=!1){let i=[],a=r?[]:null,o=new yJ(e),s=new yJ(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);mJ(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(mJ(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(mJ(i,0,o.ins),a&&hJ(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;mJ(i,t,e<o.i?o.ins:0),a&&e<o.i&&hJ(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?pJ.createSet(i,a):fJ.create(i);else throw Error(`Mismatched change set lengths`)}function vJ(e,t,n=!1){let r=[],i=n?[]:null,a=new yJ(e),o=new yJ(t);for(let e=!1;;)if(a.done&&o.done)return i?pJ.createSet(r,i):fJ.create(r);else if(a.ins==0)mJ(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)mJ(r,0,o.ins,e),i&&hJ(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;mJ(r,t,n,e),i&&n&&hJ(i,r,o.text)}else o.ins==-1?(mJ(r,a.off?0:a.len,t,e),i&&hJ(i,r,a.textBit(t))):(mJ(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&hJ(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var yJ=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?qq.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?qq.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},bJ=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return Y.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return Y.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return Y.range(e.anchor,e.head)}static create(t,n,r,i){return new e(t,n,r,i)}},Y=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>bJ.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return bJ.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,i){let a=r==null?7:Math.min(6,r);return!i&&e!=t&&(i=t<e?1:-1),i&&(a|=i<0?8:16),t<e?bJ.create(t,e,a|32,n):bJ.create(e,t,a,n)}static undirectionalRange(e,t){return bJ.create(e,t,64,void 0)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function xJ(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}var SJ=0,X=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=SJ++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:CJ),!!t.static,t.enables)}of(e){return new wJ([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new wJ(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new wJ(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function CJ(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var wJ=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=SJ++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||EJ(e,c)){let r=t(e);if(a?!TJ(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=zJ(o,c);if(this.dependencies.every(t=>t instanceof X?o.facet(t)===e.facet(t):t instanceof kJ?o.field(t,!1)==e.field(t,!1):!0)||(a?TJ(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}get extension(){return this}};function TJ(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function EJ(e,t){let n=!1;for(let r of t)RJ(e,r)&1&&(n=!0);return n}function DJ(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=zJ(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)RJ(e,t);return e.values[o]=s(e),1},update(e,n){if(!EJ(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=EJ(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&CJ(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}var OJ=X.define({static:!0}),kJ=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(SJ++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(OJ).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(OJ),i=n.facet(OJ),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,OJ.of({field:this,create:e})]}get extension(){return this}},AJ={lowest:4,low:3,default:2,high:1,highest:0};function jJ(e){return t=>new NJ(t,e)}var MJ={highest:jJ(AJ.highest),high:jJ(AJ.high),default:jJ(AJ.default),low:jJ(AJ.low),lowest:jJ(AJ.lowest)},NJ=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},PJ=class e{of(e){return new FJ(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},FJ=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},IJ=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of LJ(t,n,o))e instanceof kJ?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0)){if(s[n.id]=c.length<<1|1,CJ(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>DJ(e,n,t))}}let d=l.map(e=>e(s));return new e(t,o,d,s,c,a)}};function LJ(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof FJ&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof FJ){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof NJ)a(e.inner,e.prec);else if(e instanceof kJ)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof wJ)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,AJ.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}).`);if(t==e)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,AJ.default),r.reduce((e,t)=>e.concat(t))}function RJ(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function zJ(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}var BJ=X.define(),VJ=X.define({combine:e=>e.some(e=>e),static:!0}),HJ=X.define({combine:e=>e.length?e[0]:void 0,static:!0}),UJ=X.define(),WJ=X.define(),GJ=X.define(),KJ=X.define({combine:e=>e.length?e[0]:!1}),qJ=class{constructor(e,t){this.type=e,this.value=t}static define(){return new JJ}},JJ=class{of(e){return new qJ(this,e)}},YJ=class{constructor(e){this.map=e}of(e){return new XJ(this,e)}},XJ=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new YJ(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};XJ.reconfigure=XJ.define(),XJ.appendConfig=XJ.define();var ZJ=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&xJ(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};ZJ.time=qJ.define(),ZJ.userEvent=qJ.define(),ZJ.addToHistory=qJ.define(),ZJ.remote=qJ.define();function QJ(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function $J(e,t,n){let r,i,a;return n?(r=t.changes,i=pJ.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:XJ.mapEffects(e.effects,r).concat(XJ.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function eY(e,t,n){let r=t.selection,i=aY(t.annotations);return t.userEvent&&(i=i.concat(ZJ.userEvent.of(t.userEvent))),{changes:t.changes instanceof pJ?t.changes:pJ.of(t.changes||[],n,e.facet(HJ)),selection:r&&(r instanceof Y?r:Y.single(r.anchor,r.head)),effects:aY(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function tY(e,t,n){let r=eY(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=$J(r,eY(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=ZJ.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return rY(n?nY(i):i)}function nY(e){let t=e.startState,n=!0;for(let r of t.facet(UJ)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:QJ(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=pJ.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=ZJ.create(t,r,e.selection&&e.selection.map(i),XJ.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(WJ);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof ZJ?i:Array.isArray(i)&&i.length==1&&i[0]instanceof ZJ?i[0]:tY(t,aY(i),!1)}return e}function rY(e){let t=e.startState,n=t.facet(GJ),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=$J(r,eY(t,a,e.changes.newLength),!0))}return r==e?e:ZJ.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}var iY=[];function aY(e){return e==null?iY:Array.isArray(e)?e:[e]}var oY=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})(oY||={}),sY=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,cY;try{cY=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function lY(e){if(cY)return cY.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>``&&(n.toUpperCase()!=n.toLowerCase()||sY.test(n)))return!0}return!1}function uY(e){return t=>{if(!/\S/.test(t))return oY.Space;if(lY(t))return oY.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return oY.Word;return oY.Other}}var dY=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)RJ(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`);return}return RJ(this,n),zJ(this,n)}update(...e){return tY(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(PJ.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(XJ.reconfigure)?(n=null,r=e.value):e.is(XJ.appendConfig)&&(n=null,r=aY(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=IJ.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(VJ)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:Y.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=aY(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=XJ.mapEffects(a,c).concat(XJ.mapEffects(aY(o.effects),l))}return{changes:r,selection:Y.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof pJ?t:pJ.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return qq.of(t.split(this.facet(e.lineSeparator)||uJ))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(RJ(this,t),zJ(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof kJ&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:Y.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=IJ.resolve(t.extensions||[],new Map),r=t.doc instanceof qq?t.doc:qq.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||uJ)),i=t.selection?t.selection instanceof Y?t.selection:Y.single(t.selection.anchor,t.selection.head):Y.single(0);return xJ(i,r.length),n.staticFacet(VJ)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`
|