@paperclipai/ui 2026.831.0-canary.7 → 2026.831.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/assets/{CompanyExport-rggjsxpt.js → CompanyExport-BkapGNc4.js} +3 -3
  2. package/dist/assets/{dist-BSP7JRAi.js → dist-BFE4nrdb.js} +1 -1
  3. package/dist/assets/{dist-DJ-O_mNc.js → dist-BIB8B5Yt.js} +1 -1
  4. package/dist/assets/{dist-D1h1dj9A.js → dist-BT_-J9vH.js} +1 -1
  5. package/dist/assets/{dist-BlUGIfXE.js → dist-BY8Ovukd.js} +1 -1
  6. package/dist/assets/{dist-Btu1Ytww.js → dist-Bj22b5x0.js} +1 -1
  7. package/dist/assets/{dist-BVvgyrhi.js → dist-C8A1Q1Q2.js} +1 -1
  8. package/dist/assets/{dist-CRjLhJg_.js → dist-CIaSSm62.js} +1 -1
  9. package/dist/assets/{dist-CWbEFtIx.js → dist-COkHxnM-.js} +1 -1
  10. package/dist/assets/{dist-CHAynoU8.js → dist-ClHUjRaR.js} +1 -1
  11. package/dist/assets/{dist-DmlICbph.js → dist-D36tWFvq.js} +1 -1
  12. package/dist/assets/{dist-Y2f7F2Hn.js → dist-D8x7mYVS.js} +1 -1
  13. package/dist/assets/{dist-a67CW5um.js → dist-DammdbHg.js} +1 -1
  14. package/dist/assets/{dist-CH7XGxhA.js → dist-De1dLVWv.js} +1 -1
  15. package/dist/assets/{dist-CdPQIHAj.js → dist-DfhA_362.js} +1 -1
  16. package/dist/assets/{dist-dRLfP20f.js → dist-R-JSNxQc.js} +1 -1
  17. package/dist/assets/{dist-BLOaXvcV.js → dist-aV8W0Cid.js} +1 -1
  18. package/dist/assets/{dist-CKZSvEju.js → dist-d3LFhBWV.js} +1 -1
  19. package/dist/assets/{dist-omVp0oO-.js → dist-ephSgHpc.js} +1 -1
  20. package/dist/assets/{dist-CSqAz06-.js → dist-jE0s8Epb.js} +1 -1
  21. package/dist/assets/{dist-BF8lOG-c.js → dist-u9Xf4fZO.js} +1 -1
  22. package/dist/assets/{dist-BY6UgYBA.js → dist-v4lY6ztx.js} +1 -1
  23. package/dist/assets/{dist-DU4AOzSl.js → dist-ypw5cJye.js} +1 -1
  24. package/dist/assets/{dist-Dz2r9OEF.js → dist-yqWtMRTU.js} +1 -1
  25. package/dist/assets/index-BU41-p9M.css +1 -0
  26. package/dist/assets/{index-Cj4ZrUu7.js → index-DXc1QDcn.js} +203 -242
  27. package/dist/assets/mention-chips-CbXq5njg.js +143 -0
  28. package/dist/index.html +3 -3
  29. package/package.json +1 -1
  30. package/dist/assets/index-CN96dwmy.css +0 -1
  31. package/dist/assets/mention-chips-DtaQg8CU.js +0 -144
  32. package/dist/brands/apps/airtable.svg +0 -1
  33. package/dist/brands/apps/anthropic-dark.svg +0 -1
  34. package/dist/brands/apps/anthropic.svg +0 -1
  35. package/dist/brands/apps/api-key-generic.svg +0 -1
  36. package/dist/brands/apps/asana.svg +0 -1
  37. package/dist/brands/apps/beehiiv.png +0 -0
  38. package/dist/brands/apps/bitly.svg +0 -1
  39. package/dist/brands/apps/box.svg +0 -1
  40. package/dist/brands/apps/brex-dark.svg +0 -1
  41. package/dist/brands/apps/brex.svg +0 -1
  42. package/dist/brands/apps/candid.png +0 -0
  43. package/dist/brands/apps/clickhouse.svg +0 -1
  44. package/dist/brands/apps/cloudflare.svg +0 -1
  45. package/dist/brands/apps/cloudinary-dark.svg +0 -1
  46. package/dist/brands/apps/cloudinary.svg +0 -1
  47. package/dist/brands/apps/coda.svg +0 -1
  48. package/dist/brands/apps/composio-dark.svg +0 -11
  49. package/dist/brands/apps/composio.svg +0 -16
  50. package/dist/brands/apps/context7-dark.svg +0 -8
  51. package/dist/brands/apps/context7.svg +0 -8
  52. package/dist/brands/apps/egnyte.svg +0 -1
  53. package/dist/brands/apps/embat.svg +0 -1
  54. package/dist/brands/apps/github-dark.svg +0 -1
  55. package/dist/brands/apps/github.svg +0 -1
  56. package/dist/brands/apps/gmail.svg +0 -1
  57. package/dist/brands/apps/google-calendar.svg +0 -1
  58. package/dist/brands/apps/google-chat.svg +0 -1
  59. package/dist/brands/apps/google-docs.svg +0 -1
  60. package/dist/brands/apps/google-drive.svg +0 -1
  61. package/dist/brands/apps/google-people.svg +0 -1
  62. package/dist/brands/apps/google-sheets.svg +0 -1
  63. package/dist/brands/apps/google-slides.svg +0 -1
  64. package/dist/brands/apps/google-workspace-search.svg +0 -1
  65. package/dist/brands/apps/hugging-face.svg +0 -1
  66. package/dist/brands/apps/jira-dark.svg +0 -1
  67. package/dist/brands/apps/jira.svg +0 -1
  68. package/dist/brands/apps/kernel.svg +0 -3
  69. package/dist/brands/apps/linear.svg +0 -1
  70. package/dist/brands/apps/local-falcon.png +0 -0
  71. package/dist/brands/apps/make-dark.svg +0 -1
  72. package/dist/brands/apps/make.svg +0 -1
  73. package/dist/brands/apps/manifest.json +0 -598
  74. package/dist/brands/apps/manufact.svg +0 -26
  75. package/dist/brands/apps/mem0.svg +0 -1
  76. package/dist/brands/apps/miro-dark.svg +0 -1
  77. package/dist/brands/apps/miro.svg +0 -1
  78. package/dist/brands/apps/mixpanel.svg +0 -1
  79. package/dist/brands/apps/netlify.svg +0 -1
  80. package/dist/brands/apps/notion-dark.svg +0 -1
  81. package/dist/brands/apps/notion.svg +0 -1
  82. package/dist/brands/apps/oauth-generic.svg +0 -1
  83. package/dist/brands/apps/oreilly.svg +0 -1
  84. package/dist/brands/apps/pagerduty.svg +0 -1
  85. package/dist/brands/apps/planetscale-dark.svg +0 -1
  86. package/dist/brands/apps/planetscale.svg +0 -1
  87. package/dist/brands/apps/posthog-dark.svg +0 -1
  88. package/dist/brands/apps/posthog.svg +0 -1
  89. package/dist/brands/apps/postman.svg +0 -1
  90. package/dist/brands/apps/razorpay-dark.svg +0 -1
  91. package/dist/brands/apps/razorpay.svg +0 -1
  92. package/dist/brands/apps/resend-dark.svg +0 -1
  93. package/dist/brands/apps/resend.svg +0 -1
  94. package/dist/brands/apps/sanity-dark.svg +0 -1
  95. package/dist/brands/apps/sanity.svg +0 -1
  96. package/dist/brands/apps/sentry-dark.svg +0 -1
  97. package/dist/brands/apps/sentry.svg +0 -1
  98. package/dist/brands/apps/shopify.svg +0 -5
  99. package/dist/brands/apps/similarweb-dark.svg +0 -1
  100. package/dist/brands/apps/similarweb.svg +0 -1
  101. package/dist/brands/apps/slack.png +0 -0
  102. package/dist/brands/apps/stripe.svg +0 -1
  103. package/dist/brands/apps/supabase.svg +0 -1
  104. package/dist/brands/apps/ticket-tailor-dark.svg +0 -1
  105. package/dist/brands/apps/ticket-tailor.svg +0 -1
  106. package/dist/brands/apps/ticktick.svg +0 -1
  107. package/dist/brands/apps/todoist.svg +0 -1
  108. package/dist/brands/apps/vercel-dark.svg +0 -1
  109. package/dist/brands/apps/vercel.svg +0 -1
  110. package/dist/brands/apps/webflow.svg +0 -1
  111. package/dist/brands/apps/wix.svg +0 -1
  112. package/dist/brands/apps/xero.svg +0 -1
  113. package/dist/brands/apps/zapier.svg +0 -1
@@ -1,4 +1,4 @@
1
- import{o as be}from"./rolldown-runtime-CPfWejcf.js";import{$n as Be,Ar as ze,Ki as ue,Mn as se,Oa as De,Vi as ee,et as _e,ir as Ue,lr as We,lt as qe,oa as Ke,pt as B,qi as Z,rr as G}from"./mention-chips-DtaQg8CU.js";import{_t as pe,a as Ye,bt as Ze,c as fe,ct as Ge,d as Xe,dt as He,f as Ve,ft as Je,gt as Qe,h as he,ht as et,i as tt,l as st,lt as nt,m as rt,mt as X,n as ot,o as at,p as z,pt as it,r as ct,s as lt,t as we,u as dt,ut,vt as pt,yt as ft}from"./index-Cj4ZrUu7.js";var h=be(De(),1),ht=["agents","projects","skills","routines","tasks","attachments"],mt={agents:"Agents",projects:"Projects",skills:"Skills",routines:"Routines",tasks:"Tasks",attachments:"Attachments"};function gt(){return{agents:!0,projects:!0,skills:!0,routines:!0,tasks:!0,attachments:!0}}function je(e){return e.tasks||e.routines}function ye(e){const o=new Set;for(const a of e){if(!a.recurring)continue;const n=a.path.trim();if(!n)continue;o.add(n);const r=n.lastIndexOf("/");r>=0&&o.add(`${n.slice(0,r+1)}`)}return o}function xt(e,o){for(const a of o)if(e===a||e.startsWith(a))return!0;return!1}function bt(e){const o=new Set,a=new Set;for(const n of e)for(const r of n.attachments??[]){const c=r.sha256.trim().toLowerCase();c&&(n.recurring?o:a).add(c)}return{recurring:o,oneOff:a}}var wt=new Set(["agents","projects","skills","routines","tasks"]);function jt(e){const o=new Map;for(const a of e){const n=a.sha256.trim().toLowerCase();if(!n)continue;const r=o.get(n)??new Set,c=a.ownedBy&&a.ownedBy.length>0?a.ownedBy:["always"];for(const u of c)r.add(u);o.set(n,r)}return o}function yt(e,o){for(const a of e)if(!wt.has(a)||o[a])return!0;return!1}function ve(e,o){return e.startsWith("agents/")?"agents":e.startsWith("projects/")?"projects":e.startsWith("skills/")?"skills":e.startsWith("tasks/")?xt(e,o)?"routines":"tasks":e.startsWith("blobs/")?"attachments":null}function vt(e,o){const a=ye(o),n={agents:0,projects:0,skills:0,routines:0,tasks:0,attachments:0};for(const r of e){const c=ve(r,a);c&&(n[c]+=1)}return n}function kt(e){const{filePaths:o,issues:a,categories:n}=e,r=ye(a),c=bt(a),u=jt(e.embeddedAssets??[]),p=n.attachments&&je(n),m=new Set;for(const l of o){const x=ve(l,r);if(x===null){m.add(l);continue}if(x==="attachments"){const i=l.slice(6).trim().toLowerCase(),g=u.get(i);if(g&&yt(g,n)){m.add(l);continue}if(!p)continue;const w=c.recurring.has(i),j=c.oneOff.has(i);!w&&!j?g||m.add(l):(j&&n.tasks||w&&n.routines)&&m.add(l);continue}n[x]&&m.add(l)}return m}function ke(e,o){if(!o.has(e))return o.add(e),e;let a=2;for(;;){const n=`${e}-${a}`;if(!o.has(n))return o.add(n),n;a+=1}}function St(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=ze(r.name)??"agent";a.set(r.id,ke(c,o))}return a}function Ct(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=We(r.name,r.name);a.set(r.id,ke(c,o))}return a}function Et(e){const o=St(e.agents),a=Ct(e.projects),n={agents:e.orderedAgents.map(r=>o.get(r.id)).filter(r=>!!r),projects:e.orderedProjects.map(r=>a.get(r.id)).filter(r=>!!r)};return n.agents.length>0||n.projects.length>0?n:void 0}var t=be(Ke(),1);function Se(e){const o=new Set,a=new Set,n=new Set;for(const r of e){const c=r.match(/^agents\/([^/]+)\//);c&&o.add(c[1]);const u=r.match(/^projects\/([^/]+)\//);u&&a.add(u[1]);const p=r.match(/^tasks\/([^/]+)\//);p&&n.add(p[1])}return{agents:o,projects:a,tasks:n,routines:new Set(n)}}function Nt(e,o){const a=Se(o),n=e.split(`
1
+ import{o as be}from"./rolldown-runtime-CPfWejcf.js";import{$n as Be,Di as ee,Dr as ze,Ki as De,Mi as ue,Mn as se,Ni as Z,et as _e,ir as Ue,lr as We,lt as qe,ma as Ke,pt as B,rr as G}from"./mention-chips-CbXq5njg.js";import{_t as pe,a as Ye,bt as Ze,c as fe,ct as Ge,d as Xe,dt as He,f as Ve,ft as Je,gt as Qe,h as he,ht as et,i as tt,l as st,lt as nt,m as rt,mt as X,n as ot,o as at,p as z,pt as it,r as ct,s as lt,t as we,u as dt,ut,vt as pt,yt as ft}from"./index-DXc1QDcn.js";var h=be(Ke(),1),ht=["agents","projects","skills","routines","tasks","attachments"],mt={agents:"Agents",projects:"Projects",skills:"Skills",routines:"Routines",tasks:"Tasks",attachments:"Attachments"};function gt(){return{agents:!0,projects:!0,skills:!0,routines:!0,tasks:!0,attachments:!0}}function je(e){return e.tasks||e.routines}function ye(e){const o=new Set;for(const a of e){if(!a.recurring)continue;const n=a.path.trim();if(!n)continue;o.add(n);const r=n.lastIndexOf("/");r>=0&&o.add(`${n.slice(0,r+1)}`)}return o}function xt(e,o){for(const a of o)if(e===a||e.startsWith(a))return!0;return!1}function bt(e){const o=new Set,a=new Set;for(const n of e)for(const r of n.attachments??[]){const c=r.sha256.trim().toLowerCase();c&&(n.recurring?o:a).add(c)}return{recurring:o,oneOff:a}}var wt=new Set(["agents","projects","skills","routines","tasks"]);function jt(e){const o=new Map;for(const a of e){const n=a.sha256.trim().toLowerCase();if(!n)continue;const r=o.get(n)??new Set,c=a.ownedBy&&a.ownedBy.length>0?a.ownedBy:["always"];for(const u of c)r.add(u);o.set(n,r)}return o}function yt(e,o){for(const a of e)if(!wt.has(a)||o[a])return!0;return!1}function ve(e,o){return e.startsWith("agents/")?"agents":e.startsWith("projects/")?"projects":e.startsWith("skills/")?"skills":e.startsWith("tasks/")?xt(e,o)?"routines":"tasks":e.startsWith("blobs/")?"attachments":null}function vt(e,o){const a=ye(o),n={agents:0,projects:0,skills:0,routines:0,tasks:0,attachments:0};for(const r of e){const c=ve(r,a);c&&(n[c]+=1)}return n}function kt(e){const{filePaths:o,issues:a,categories:n}=e,r=ye(a),c=bt(a),u=jt(e.embeddedAssets??[]),p=n.attachments&&je(n),m=new Set;for(const l of o){const x=ve(l,r);if(x===null){m.add(l);continue}if(x==="attachments"){const i=l.slice(6).trim().toLowerCase(),g=u.get(i);if(g&&yt(g,n)){m.add(l);continue}if(!p)continue;const w=c.recurring.has(i),j=c.oneOff.has(i);!w&&!j?g||m.add(l):(j&&n.tasks||w&&n.routines)&&m.add(l);continue}n[x]&&m.add(l)}return m}function ke(e,o){if(!o.has(e))return o.add(e),e;let a=2;for(;;){const n=`${e}-${a}`;if(!o.has(n))return o.add(n),n;a+=1}}function St(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=ze(r.name)??"agent";a.set(r.id,ke(c,o))}return a}function Ct(e){const o=new Set,a=new Map,n=[...e].sort((r,c)=>r.name.localeCompare(c.name));for(const r of n){const c=We(r.name,r.name);a.set(r.id,ke(c,o))}return a}function Et(e){const o=St(e.agents),a=Ct(e.projects),n={agents:e.orderedAgents.map(r=>o.get(r.id)).filter(r=>!!r),projects:e.orderedProjects.map(r=>a.get(r.id)).filter(r=>!!r)};return n.agents.length>0||n.projects.length>0?n:void 0}var t=be(De(),1);function Se(e){const o=new Set,a=new Set,n=new Set;for(const r of e){const c=r.match(/^agents\/([^/]+)\//);c&&o.add(c[1]);const u=r.match(/^projects\/([^/]+)\//);u&&a.add(u[1]);const p=r.match(/^tasks\/([^/]+)\//);p&&n.add(p[1])}return{agents:o,projects:a,tasks:n,routines:new Set(n)}}function Nt(e,o){const a=Se(o),n=e.split(`
2
2
  `),r=[],c=new Set(["agents","projects","tasks","routines"]),u=new Set(["agents","projects"]);let p=null,m=null,l=!0,x=null,i=null,g=[],w=null,j=[];function R(){i!==null&&g.length>0&&(j.push(i),j.push(...g)),i=null,g=[]}function E(){R(),w!==null&&j.length>0&&(r.push(w),r.push(...j)),w=null,j=[]}for(const b of n){const _=b.match(/^([a-zA-Z_][\w-]*):\s*(.*)$/);if(_&&!b.startsWith(" ")){E(),m=null,l=!0;const C=_[0].split(":")[0];if(c.has(C)){p=C,w=b;continue}else if(C==="sidebar"){p=C,x=null,w=b;continue}else{p=null,r.push(b);continue}}if(p==="sidebar"){const C=b.match(/^ ([\w-]+):\s*$/);if(C&&!b.startsWith(" ")){R();const N=C[1];x=N&&u.has(N)?N:null,i=x?b:null;continue}const T=b.match(/^ - ["']?([^"'\n]+)["']?\s*$/);if(T&&x){const N=T[1],U=a[x];N&&U.has(N)&&g.push(b);continue}if(x){g.push(b);continue}}if(p&&c.has(p)){const C=b.match(/^ ([\w][\w-]*):\s*(.*)$/);if(C&&!b.startsWith(" ")){const T=C[1];m=T,l=a[p].has(T),l&&j.push(b);continue}if(m!==null){l&&j.push(b);continue}j.push(b);continue}r.push(b)}E();let S=r.join(`
3
- `);const D=S.match(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*$/m);return D&&!o.has(D[1])&&(S=S.replace(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*\n?/m,"")),S}function Ce(e,o){if(!o)return e;const a=o.toLowerCase();return e.map(n=>{if(n.kind==="file")return n.name.toLowerCase().includes(a)||n.path.toLowerCase().includes(a)?n:null;const r=Ce(n.children,o);return r.length>0?{...n,children:r}:null}).filter(n=>n!==null)}function At(e,o){const a=new Set,n=o.toLowerCase();function r(c,u){if(c.kind==="file"){if(c.name.toLowerCase().includes(n)||c.path.toLowerCase().includes(n))for(const p of u)a.add(p)}else for(const p of c.children)r(p,[...u,c.path])}for(const c of e)r(c,[]);return a}var me=10;function Pt(e,o,a,n){let r=0,c=0;return{nodes:e.map(u=>{if(u.kind==="dir"&&u.name==="tasks"){r=u.children.length;const p=[],m=[],l=a.toLowerCase();for(const g of u.children){const w=st([g],"file"),j=n!==null&&w.has(n),R=a&&(g.name.toLowerCase().includes(l)||g.path.toLowerCase().includes(l)||[...w].some(E=>E.toLowerCase().includes(l)));j||R?p.push(g):m.push(g)}const x=Math.max(0,o-p.length),i=[...p,...m.slice(0,x)];return c=i.length,{...u,children:i}}return u}),totalTaskChildren:r,visibleTaskChildren:c}}function Ee(e,o,a){const n={};for(const r of Object.keys(e))o.has(r)&&(n[r]=a[r]??e[r]);return n}function Rt(e,o,a){const n=Ee(e.files,o,a),r=tt(n,e.rootPath),c=new ArrayBuffer(r.byteLength);new Uint8Array(c).set(r);const u=new Blob([c],{type:"application/zip"}),p=URL.createObjectURL(u),m=document.createElement("a");m.href=p,m.download=`${e.rootPath}.zip`,document.body.appendChild(m),m.click(),m.remove(),window.setTimeout(()=>URL.revokeObjectURL(p),1e3)}function Tt({data:e,onSkillClick:o}){return(0,t.jsx)("div",{className:"rounded-md border border-border bg-accent/20 px-4 py-3 mb-4",children:(0,t.jsx)("dl",{className:"grid grid-cols-(--gtc-5) gap-x-4 gap-y-1.5 text-sm",children:Object.entries(e).map(([a,n])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-muted-foreground whitespace-nowrap py-0.5",children:at[a]??a}),(0,t.jsx)("dd",{className:"py-0.5",children:Array.isArray(n)?(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:n.map(r=>(0,t.jsx)("button",{type:"button",className:se("inline-flex items-center rounded-md border border-border bg-background px-2 py-0.5 text-xs",a==="skills"&&o&&"cursor-pointer hover:bg-accent/50 hover:border-foreground/30 transition-colors"),onClick:()=>a==="skills"&&o?.(r),children:r},r))}):(0,t.jsx)("span",{children:n})})]},a))})})}var Ot={ceo:"CEO",cto:"CTO",cmo:"CMO",cfo:"CFO",coo:"COO",vp:"VP",manager:"Manager",engineer:"Engineer",agent:"Agent"};function Lt(e,o,a,n){const r=Se(o),c=e.agents.filter(i=>r.agents.has(i.slug)),u=e.projects.filter(i=>r.projects.has(i.slug)),p=e.issues.filter(i=>r.tasks.has(i.slug)),m=e.skills.filter(i=>[...o].some(g=>g.startsWith(`skills/${i.key}/`)||g.startsWith("skills/")&&g.includes(`/${i.slug}/`))),l=[];l.push(`# ${a}`),l.push(""),n&&(l.push(`> ${n}`),l.push("")),c.length>0&&(l.push("![Org Chart](images/org-chart.png)"),l.push("")),l.push("## What's Inside"),l.push(""),l.push("This is an [Agent Company](https://paperclip.ing) package."),l.push("");const x=[];if(c.length>0&&x.push(["Agents",c.length]),u.length>0&&x.push(["Projects",u.length]),m.length>0&&x.push(["Skills",m.length]),p.length>0&&x.push(["Tasks",p.length]),x.length>0){l.push("| Content | Count |"),l.push("|---------|-------|");for(const[i,g]of x)l.push(`| ${i} | ${g} |`);l.push("")}if(c.length>0){l.push("### Agents"),l.push(""),l.push("| Agent | Role | Reports To |"),l.push("|-------|------|------------|");for(const i of c){const g=Ot[i.role]??i.role,w=i.reportsToSlug??"—";l.push(`| ${i.name} | ${g} | ${w} |`)}l.push("")}if(u.length>0){l.push("### Projects"),l.push("");for(const i of u){const g=i.description?` — ${i.description}`:"";l.push(`- **${i.name}**${g}`)}l.push("")}return l.push("## Getting Started"),l.push(""),l.push("```bash"),l.push("npx paperclipai company import this-github-url-or-folder"),l.push("```"),l.push(""),l.push("See [Paperclip](https://paperclip.ing) for more information."),l.push(""),l.push("---"),l.push(`Exported from [Paperclip](https://paperclip.ing) on ${new Date().toISOString().split("T")[0]}`),l.push(""),l.join(`
4
- `)}function Mt(e){const{src:o,selectedFile:a,allFiles:n,orgChartPreviewUrl:r}=e;if(/^(?:https?:|data:)/i.test(o))return null;if(o.replace(/^\.\//,"")==="images/org-chart.png"&&r)return r;const c=(a.includes("/")?a.slice(0,a.lastIndexOf("/")+1):"")+o,u=n[c]??n[o];return u?we(c in n?c:o,u):null}function Ft({selectedFile:e,content:o,allFiles:a,orgChartPreviewUrl:n,onSkillClick:r}){if(!e||o===null)return(0,t.jsx)(z,{icon:B,message:"Select a file to preview its contents."});const c=ot(o),u=e.endsWith(".md")&&c!==null,p=u&&c?Xe(c):null,m=ct(e,o)?we(e,o):null,l=u?x=>Mt({src:x,selectedFile:e,allFiles:a,orgChartPreviewUrl:n}):void 0;return(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"border-b border-border px-5 py-3",children:(0,t.jsx)("div",{className:"truncate font-mono text-sm",children:e})}),(0,t.jsx)("div",{className:"min-h-(--sz-560px) px-5 py-5",children:p?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Tt,{data:p.data,onSkillClick:r}),p.body.trim()&&(0,t.jsx)(he,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:p.body})]}):u?(0,t.jsx)(he,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:c??""}):m?(0,t.jsx)("div",{className:"flex min-h-(--sz-520px) items-center justify-center rounded-lg border border-border bg-accent/10 p-6",children:(0,t.jsx)("img",{src:m,alt:e,className:"max-h-(--sz-480px) max-w-full object-contain"})}):c!==null?(0,t.jsx)("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words border-0 bg-transparent p-0 font-mono text-sm text-foreground",children:(0,t.jsx)("code",{children:c})}):(0,t.jsx)("div",{className:"rounded-lg border border-border bg-accent/10 px-4 py-3 text-sm text-muted-foreground",children:"Binary asset preview is not available for this file type."})})]})}function ge(e){const o="/company/export/files/",a=Qe(e),n=a.indexOf(o);return n===-1?null:decodeURIComponent(a.slice(n+22))||null}function xe(e){const o=e.split("/").slice(0,-1),a=[];let n="";for(const r of o)n=n?`${n}/${r}`:r,a.push(n);return a}function It(e){return(e instanceof DOMException||e instanceof Error)&&e.name==="AbortError"}function te(e){return e instanceof Error?e.message:"Failed to load export data."}function Dt(){const{selectedCompanyId:e,selectedCompany:o}=Be(),{setBreadcrumbs:a}=Ge(),{pushToast:n}=it(),r=et(),c=Ze(),u=(0,h.useRef)(ge(c.pathname)),{data:p}=Z({queryKey:G.auth.session,queryFn:()=>Ue.getSession()}),{data:m=[]}=Z({queryKey:G.agents.list(e),queryFn:()=>Je.list(e),enabled:!!e}),{data:l=[]}=Z({queryKey:G.projects.list(e),queryFn:()=>ut.list(e),enabled:!!e}),{data:x}=Z({queryKey:G.companies.exportFidelity(e),queryFn:()=>ee.exportFidelity(e),enabled:!!e}),[i,g]=(0,h.useState)(null),[w,j]=(0,h.useState)(null),[R,E]=(0,h.useState)(new Set),[S,D]=(0,h.useState)(()=>({...gt(),tasks:!1,routines:!1,attachments:!1})),[b,_]=(0,h.useState)(""),[C,T]=(0,h.useState)(me),[N,U]=(0,h.useState)(!1),W=(0,h.useRef)(null),F=(0,h.useRef)(null),L=(0,h.useRef)(0),ne=(0,h.useRef)(null),re=p?.user?.id??p?.session?.userId??null,H=(0,h.useMemo)(()=>m.filter(s=>s.status!=="terminated"),[m]),V=(0,h.useMemo)(()=>l,[l]),{orderedAgents:oe}=He({agents:H,companyId:e,userId:re}),{orderedProjects:ae}=nt({projects:V,companyId:e,userId:re}),ie=(0,h.useMemo)(()=>Et({agents:H,orderedAgents:oe,projects:V,orderedProjects:ae}),[oe,ae,H,V]),J=S.tasks||S.routines,Q=(0,h.useCallback)((s,d=!1)=>{j(s),s?r(`/company/export/files/${encodeURI(s)}`,{replace:d}):r("/company/export",{replace:d})},[r]);(0,h.useEffect)(()=>{if(!i)return;const s=ge(c.pathname);s&&s in i.files&&s!==w?(j(s),E(d=>{const f=new Set(d);for(const y of xe(s))f.add(y);return f})):!s&&w&&j(null)},[c.pathname,i]),(0,h.useEffect)(()=>{a([{label:o?.name??"Organization",href:"/dashboard"},{label:"Settings",href:"/company/settings"},{label:"Export"}])},[o?.name,a]);const A=ue({mutationFn:({includeIssues:s,includeSkills:d,signal:f})=>ee.exportPreview(e,{include:{company:!0,agents:!0,projects:!0,issues:s,skills:d},sidebarOrder:ie},{signal:f}),onSuccess:(s,d)=>{if(d.requestId!==L.current)return;g(s);const f=fe(s.files),y=new Set;for(const v of f)v.kind==="dir"&&v.name!=="tasks"&&y.add(v.path);const k=u.current;if(k&&k in s.files){j(k);const v=xe(k);E(new Set([...y,...v]))}else{const v="README.md"in s.files?"README.md":Object.keys(s.files)[0];v&&Q(v,!0),E(y)}},onError:(s,d)=>{d.requestId!==L.current||It(s)||n({tone:"error",title:"Export failed",body:te(s)})}});function M(){if(!e)return;F.current?.abort();const s=new AbortController,d=L.current+1;L.current=d,F.current=s,U(!1),A.mutate({includeIssues:J,includeSkills:S.skills,requestId:d,signal:s.signal})}const q=ue({mutationFn:()=>ee.exportBundle(e,{include:{company:!0,agents:!0,projects:!0,issues:J,skills:S.skills},selectedFiles:Array.from(P).sort(),sidebarOrder:ie}),onSuccess:s=>{const d=new Set(Object.keys(s.files));Rt(s,d,s.files),n({tone:"success",title:"Export downloaded",body:`${d.size} file${d.size===1?"":"s"} exported as ${s.rootPath}.zip`})},onError:s=>{n({tone:"error",title:"Export failed",body:s instanceof Error?s.message:"Failed to build export package."})}});(0,h.useEffect)(()=>{e&&(ne.current!==e&&(ne.current=e,g(null),j(null)),M())},[e,J,S.skills]),(0,h.useEffect)(()=>()=>{L.current+=1,F.current?.abort()},[]);const O=(0,h.useMemo)(()=>i?fe(i.files):[],[i]),P=(0,h.useMemo)(()=>i?kt({filePaths:Object.keys(i.files),issues:i.manifest.issues,categories:S,embeddedAssets:i.manifest.embeddedAssets??[]}):new Set,[i,S]),Ne=(0,h.useMemo)(()=>i?vt(Object.keys(i.files),i.manifest.issues):null,[i]),{displayTree:Ae,totalTaskChildren:ce,visibleTaskChildren:le}=(0,h.useMemo)(()=>{let s=O;b&&(s=Ce(s,b));const d=Pt(s,C,b,w);return{displayTree:d.nodes,totalTaskChildren:d.totalTaskChildren,visibleTaskChildren:d.visibleTaskChildren}},[O,b,C,w]),Pe=(0,h.useMemo)(()=>{const s={};function d(f){if(f.kind==="file"){const k=P.has(f.path);return k||(s[f.path]="muted"),k}let y=!1;for(const k of f.children)d(k)&&(y=!0);return y||(s[f.path]="muted"),y}for(const f of O)d(f);return s},[O,P]),K=(0,h.useMemo)(()=>{if(!i)return{};const s={...i.files},d=i.paperclipExtensionPath;if(d&&typeof i.files[d]=="string"&&(s[d]=Nt(i.files[d],P)),typeof i.files["README.md"]=="string"){const f=i.manifest.company?.name??o?.name??"Company",y=i.manifest.company?.description??null;s["README.md"]=Lt(i.manifest,P,f,y)}return s},[i,P,o?.name]),Re=(0,h.useMemo)(()=>i?Ye(Ee(i.files,P,K),i.rootPath):0,[i,P,K]),de=(0,h.useMemo)(()=>dt(O),[O]),I=P.size,$=(0,h.useMemo)(()=>i?i.warnings.filter(s=>!/terminated agent/i.test(s)):[],[i]);function Te(s){E(d=>{const f=new Set(d);return f.has(s)?f.delete(s):f.add(s),f})}function Oe(s){D(d=>({...d,[s]:!d[s]}))}function Le(s){const d=b.length>0,f=s.length>0;if(f&&!d&&(W.current=new Set(R)),_(s),f){const y=At(O,s);E(k=>{const v=new Set(k);for(const Y of y)v.add(Y);return v})}else d&&W.current&&(E(W.current),W.current=null)}function Me(s){if(!i)return;const d=i.manifest.skills.find(f=>f.key===s||f.slug===s)?.path??`skills/${s}/SKILL.md`;d in i.files&&(Q(d),E(f=>{const y=new Set(f);y.add("skills");const k=d.split("/").slice(0,-1);let v="";for(const Y of k)v=v?`${v}/${Y}`:Y,y.add(v);return y}))}function Fe(){!i||P.size===0||q.isPending||q.mutate()}function Ie(){L.current+=1,F.current?.abort(),F.current=null,A.reset(),U(!0)}if(!e)return(0,t.jsx)(z,{icon:B,message:"Select an organization to export."});if(A.isPending&&!i)return(0,t.jsx)(Ve,{variant:"detail"});if(N&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview cancelled",message:"The preview request was cancelled. Your export settings are unchanged.",action:"Retry preview",onAction:M,hideActionIcon:!0});if(A.isError&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview failed",message:te(A.error),description:"Retry the preview. You do not need to reload this page.",action:"Retry preview",onAction:M,hideActionIcon:!0});if(!i)return(0,t.jsx)(z,{icon:B,title:"Export preview unavailable",message:"No export preview is loaded.",action:"Load preview",onAction:M,hideActionIcon:!0});const $e=w?K[w]??null:null;return(0,t.jsxs)("div",{className:"max-w-6xl",children:[(0,t.jsx)("div",{className:"sticky top-0 z-10 border-b border-border bg-background px-5 py-3",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-4 text-sm",children:[(0,t.jsxs)("span",{className:"font-medium",children:[o?.name??"Organization"," export"]}),(0,t.jsxs)("span",{className:"text-muted-foreground",children:["Exporting ",I.toLocaleString()," of ",de.toLocaleString()," file",de===1?"":"s",I>0&&` (~${rt(Re)})`]}),$.length>0&&(0,t.jsxs)("span",{className:"text-amber-500",children:[$.length," warning",$.length===1?"":"s"]})]}),(0,t.jsxs)(X,{size:"sm",onClick:Fe,disabled:I===0||q.isPending||A.isPending||A.isError||N,children:[(0,t.jsx)(ft,{className:"mr-1.5 h-3.5 w-3.5"}),q.isPending?"Building export...":`Export ${I.toLocaleString()} file${I===1?"":"s"}`]})]})}),$.length>0&&(0,t.jsx)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:$.map(s=>(0,t.jsx)("div",{className:"text-xs text-amber-500",children:s},s))}),x&&x.warnings.length>0&&(0,t.jsxs)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:[(0,t.jsx)("h3",{className:"mb-1.5 text-xs font-medium",children:"Not included in this export"}),x.warnings.map(s=>(0,t.jsx)("div",{className:se("text-xs",s.severity==="blocker"?"font-medium text-destructive":"text-amber-500"),children:s.message},s.code))]}),(0,t.jsxs)("div",{className:"grid gap-4 xl:h-(--sz-calc-30) xl:grid-cols-(--gtc-25) xl:gap-0",children:[(0,t.jsxs)("aside",{className:"flex max-h-(--sz-24rem) flex-col overflow-hidden border-b border-border xl:max-h-none xl:border-b-0 xl:border-r",children:[(0,t.jsx)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Package files"})}),(0,t.jsxs)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:[(0,t.jsx)("h3",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"What to include"}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1.5",role:"group","aria-label":"What to include",children:ht.map(s=>{const d=s==="attachments"&&!je(S),f=S[s]&&!d,y=Ne?.[s]??0,k=i.manifest.includes.issues||s!=="tasks"&&s!=="routines"&&s!=="attachments";return(0,t.jsxs)("label",{className:se("flex items-center gap-2 text-sm",d?"cursor-not-allowed opacity-50":"cursor-pointer"),title:d?"Attachments travel with tasks and routines; re-enable one of them to include attachments.":void 0,children:[(0,t.jsx)("input",{type:"checkbox",checked:f,disabled:d,onChange:()=>Oe(s),className:"accent-foreground","data-export-category":s}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:mt[s]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:k?y.toLocaleString():"—"})]},s)})}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Task and routine history is opt-in because it can be large."})]}),(0,t.jsx)("div",{className:"border-b border-border px-3 py-2 shrink-0",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-border px-2 py-1",children:[(0,t.jsx)(qe,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)("input",{type:"text",value:b,onChange:s=>Le(s.target.value),placeholder:"Search files...",className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground","data-page-search-target":"true"})]})}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,t.jsx)(lt,{nodes:Ae,selectedFile:w,expandedDirs:R,onToggleDir:Te,onSelectFile:Q,fileTones:Pe,showCheckboxes:!1,wrapLabels:!1}),ce>le&&!b&&(0,t.jsx)("div",{className:"px-4 py-2",children:(0,t.jsxs)("button",{type:"button",onClick:()=>T(s=>s+me),className:"w-full rounded-md border border-border px-3 py-1.5 text-xs text-muted-foreground hover:bg-accent/30 hover:text-foreground transition-colors",children:["Show more tasks (",le," of ",ce,")"]})})]})]}),(0,t.jsxs)("div",{className:"relative min-w-0 overflow-y-auto xl:pl-6",children:[(0,t.jsx)(Ft,{selectedFile:w,content:$e,allFiles:K,orgChartPreviewUrl:`/api/companies/${encodeURIComponent(e)}/org.svg`,onSkillClick:Me}),A.isPending?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"status","aria-live":"polite","aria-busy":"true","data-export-preview-state":"loading",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsx)(pt,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Updating export preview…"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large task histories can take a minute. You can untick Tasks or cancel this update."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:Ie,children:[(0,t.jsx)(_e,{}),"Cancel update"]})]})}):N?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center","data-export-preview-state":"cancelled",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Preview update cancelled"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"The previous preview remains available. Retry when you are ready."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:M,children:[(0,t.jsx)(pe,{}),"Retry preview"]})]})}):A.isError?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"alert","data-export-preview-state":"error",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium text-destructive",children:"Export preview failed"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:te(A.error)})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:M,children:[(0,t.jsx)(pe,{}),"Retry preview"]})]})}):null]})]})]})}export{Dt as CompanyExport};
3
+ `);const D=S.match(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*$/m);return D&&!o.has(D[1])&&(S=S.replace(/^\s{2}logoPath:\s*["']?([^"'\n]+)["']?\s*\n?/m,"")),S}function Ce(e,o){if(!o)return e;const a=o.toLowerCase();return e.map(n=>{if(n.kind==="file")return n.name.toLowerCase().includes(a)||n.path.toLowerCase().includes(a)?n:null;const r=Ce(n.children,o);return r.length>0?{...n,children:r}:null}).filter(n=>n!==null)}function At(e,o){const a=new Set,n=o.toLowerCase();function r(c,u){if(c.kind==="file"){if(c.name.toLowerCase().includes(n)||c.path.toLowerCase().includes(n))for(const p of u)a.add(p)}else for(const p of c.children)r(p,[...u,c.path])}for(const c of e)r(c,[]);return a}var me=10;function Pt(e,o,a,n){let r=0,c=0;return{nodes:e.map(u=>{if(u.kind==="dir"&&u.name==="tasks"){r=u.children.length;const p=[],m=[],l=a.toLowerCase();for(const g of u.children){const w=st([g],"file"),j=n!==null&&w.has(n),R=a&&(g.name.toLowerCase().includes(l)||g.path.toLowerCase().includes(l)||[...w].some(E=>E.toLowerCase().includes(l)));j||R?p.push(g):m.push(g)}const x=Math.max(0,o-p.length),i=[...p,...m.slice(0,x)];return c=i.length,{...u,children:i}}return u}),totalTaskChildren:r,visibleTaskChildren:c}}function Ee(e,o,a){const n={};for(const r of Object.keys(e))o.has(r)&&(n[r]=a[r]??e[r]);return n}function Rt(e,o,a){const n=Ee(e.files,o,a),r=tt(n,e.rootPath),c=new ArrayBuffer(r.byteLength);new Uint8Array(c).set(r);const u=new Blob([c],{type:"application/zip"}),p=URL.createObjectURL(u),m=document.createElement("a");m.href=p,m.download=`${e.rootPath}.zip`,document.body.appendChild(m),m.click(),m.remove(),window.setTimeout(()=>URL.revokeObjectURL(p),1e3)}function Tt({data:e,onSkillClick:o}){return(0,t.jsx)("div",{className:"rounded-md border border-border bg-accent/20 px-4 py-3 mb-4",children:(0,t.jsx)("dl",{className:"grid grid-cols-(--gtc-5) gap-x-4 gap-y-1.5 text-sm",children:Object.entries(e).map(([a,n])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-muted-foreground whitespace-nowrap py-0.5",children:at[a]??a}),(0,t.jsx)("dd",{className:"py-0.5",children:Array.isArray(n)?(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:n.map(r=>(0,t.jsx)("button",{type:"button",className:se("inline-flex items-center rounded-md border border-border bg-background px-2 py-0.5 text-xs",a==="skills"&&o&&"cursor-pointer hover:bg-accent/50 hover:border-foreground/30 transition-colors"),onClick:()=>a==="skills"&&o?.(r),children:r},r))}):(0,t.jsx)("span",{children:n})})]},a))})})}var Mt={ceo:"CEO",cto:"CTO",cmo:"CMO",cfo:"CFO",coo:"COO",vp:"VP",manager:"Manager",engineer:"Engineer",agent:"Agent"};function Lt(e,o,a,n){const r=Se(o),c=e.agents.filter(i=>r.agents.has(i.slug)),u=e.projects.filter(i=>r.projects.has(i.slug)),p=e.issues.filter(i=>r.tasks.has(i.slug)),m=e.skills.filter(i=>[...o].some(g=>g.startsWith(`skills/${i.key}/`)||g.startsWith("skills/")&&g.includes(`/${i.slug}/`))),l=[];l.push(`# ${a}`),l.push(""),n&&(l.push(`> ${n}`),l.push("")),c.length>0&&(l.push("![Org Chart](images/org-chart.png)"),l.push("")),l.push("## What's Inside"),l.push(""),l.push("This is an [Agent Company](https://paperclip.ing) package."),l.push("");const x=[];if(c.length>0&&x.push(["Agents",c.length]),u.length>0&&x.push(["Projects",u.length]),m.length>0&&x.push(["Skills",m.length]),p.length>0&&x.push(["Tasks",p.length]),x.length>0){l.push("| Content | Count |"),l.push("|---------|-------|");for(const[i,g]of x)l.push(`| ${i} | ${g} |`);l.push("")}if(c.length>0){l.push("### Agents"),l.push(""),l.push("| Agent | Role | Reports To |"),l.push("|-------|------|------------|");for(const i of c){const g=Mt[i.role]??i.role,w=i.reportsToSlug??"—";l.push(`| ${i.name} | ${g} | ${w} |`)}l.push("")}if(u.length>0){l.push("### Projects"),l.push("");for(const i of u){const g=i.description?` — ${i.description}`:"";l.push(`- **${i.name}**${g}`)}l.push("")}return l.push("## Getting Started"),l.push(""),l.push("```bash"),l.push("npx paperclipai company import this-github-url-or-folder"),l.push("```"),l.push(""),l.push("See [Paperclip](https://paperclip.ing) for more information."),l.push(""),l.push("---"),l.push(`Exported from [Paperclip](https://paperclip.ing) on ${new Date().toISOString().split("T")[0]}`),l.push(""),l.join(`
4
+ `)}function Ot(e){const{src:o,selectedFile:a,allFiles:n,orgChartPreviewUrl:r}=e;if(/^(?:https?:|data:)/i.test(o))return null;if(o.replace(/^\.\//,"")==="images/org-chart.png"&&r)return r;const c=(a.includes("/")?a.slice(0,a.lastIndexOf("/")+1):"")+o,u=n[c]??n[o];return u?we(c in n?c:o,u):null}function Ft({selectedFile:e,content:o,allFiles:a,orgChartPreviewUrl:n,onSkillClick:r}){if(!e||o===null)return(0,t.jsx)(z,{icon:B,message:"Select a file to preview its contents."});const c=ot(o),u=e.endsWith(".md")&&c!==null,p=u&&c?Xe(c):null,m=ct(e,o)?we(e,o):null,l=u?x=>Ot({src:x,selectedFile:e,allFiles:a,orgChartPreviewUrl:n}):void 0;return(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"border-b border-border px-5 py-3",children:(0,t.jsx)("div",{className:"truncate font-mono text-sm",children:e})}),(0,t.jsx)("div",{className:"min-h-(--sz-560px) px-5 py-5",children:p?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Tt,{data:p.data,onSkillClick:r}),p.body.trim()&&(0,t.jsx)(he,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:p.body})]}):u?(0,t.jsx)(he,{resolveImageSrc:l,softBreaks:!1,linkIssueReferences:!1,children:c??""}):m?(0,t.jsx)("div",{className:"flex min-h-(--sz-520px) items-center justify-center rounded-lg border border-border bg-accent/10 p-6",children:(0,t.jsx)("img",{src:m,alt:e,className:"max-h-(--sz-480px) max-w-full object-contain"})}):c!==null?(0,t.jsx)("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words border-0 bg-transparent p-0 font-mono text-sm text-foreground",children:(0,t.jsx)("code",{children:c})}):(0,t.jsx)("div",{className:"rounded-lg border border-border bg-accent/10 px-4 py-3 text-sm text-muted-foreground",children:"Binary asset preview is not available for this file type."})})]})}function ge(e){const o="/company/export/files/",a=Qe(e),n=a.indexOf(o);return n===-1?null:decodeURIComponent(a.slice(n+22))||null}function xe(e){const o=e.split("/").slice(0,-1),a=[];let n="";for(const r of o)n=n?`${n}/${r}`:r,a.push(n);return a}function It(e){return(e instanceof DOMException||e instanceof Error)&&e.name==="AbortError"}function te(e){return e instanceof Error?e.message:"Failed to load export data."}function Dt(){const{selectedCompanyId:e,selectedCompany:o}=Be(),{setBreadcrumbs:a}=Ge(),{pushToast:n}=it(),r=et(),c=Ze(),u=(0,h.useRef)(ge(c.pathname)),{data:p}=Z({queryKey:G.auth.session,queryFn:()=>Ue.getSession()}),{data:m=[]}=Z({queryKey:G.agents.list(e),queryFn:()=>Je.list(e),enabled:!!e}),{data:l=[]}=Z({queryKey:G.projects.list(e),queryFn:()=>ut.list(e),enabled:!!e}),{data:x}=Z({queryKey:G.companies.exportFidelity(e),queryFn:()=>ee.exportFidelity(e),enabled:!!e}),[i,g]=(0,h.useState)(null),[w,j]=(0,h.useState)(null),[R,E]=(0,h.useState)(new Set),[S,D]=(0,h.useState)(()=>({...gt(),tasks:!1,routines:!1,attachments:!1})),[b,_]=(0,h.useState)(""),[C,T]=(0,h.useState)(me),[N,U]=(0,h.useState)(!1),W=(0,h.useRef)(null),F=(0,h.useRef)(null),L=(0,h.useRef)(0),ne=(0,h.useRef)(null),re=p?.user?.id??p?.session?.userId??null,H=(0,h.useMemo)(()=>m.filter(s=>s.status!=="terminated"),[m]),V=(0,h.useMemo)(()=>l,[l]),{orderedAgents:oe}=He({agents:H,companyId:e,userId:re}),{orderedProjects:ae}=nt({projects:V,companyId:e,userId:re}),ie=(0,h.useMemo)(()=>Et({agents:H,orderedAgents:oe,projects:V,orderedProjects:ae}),[oe,ae,H,V]),J=S.tasks||S.routines,Q=(0,h.useCallback)((s,d=!1)=>{j(s),s?r(`/company/export/files/${encodeURI(s)}`,{replace:d}):r("/company/export",{replace:d})},[r]);(0,h.useEffect)(()=>{if(!i)return;const s=ge(c.pathname);s&&s in i.files&&s!==w?(j(s),E(d=>{const f=new Set(d);for(const y of xe(s))f.add(y);return f})):!s&&w&&j(null)},[c.pathname,i]),(0,h.useEffect)(()=>{a([{label:o?.name??"Organization",href:"/dashboard"},{label:"Settings",href:"/company/settings"},{label:"Export"}])},[o?.name,a]);const A=ue({mutationFn:({includeIssues:s,includeSkills:d,signal:f})=>ee.exportPreview(e,{include:{company:!0,agents:!0,projects:!0,issues:s,skills:d},sidebarOrder:ie},{signal:f}),onSuccess:(s,d)=>{if(d.requestId!==L.current)return;g(s);const f=fe(s.files),y=new Set;for(const v of f)v.kind==="dir"&&v.name!=="tasks"&&y.add(v.path);const k=u.current;if(k&&k in s.files){j(k);const v=xe(k);E(new Set([...y,...v]))}else{const v="README.md"in s.files?"README.md":Object.keys(s.files)[0];v&&Q(v,!0),E(y)}},onError:(s,d)=>{d.requestId!==L.current||It(s)||n({tone:"error",title:"Export failed",body:te(s)})}});function O(){if(!e)return;F.current?.abort();const s=new AbortController,d=L.current+1;L.current=d,F.current=s,U(!1),A.mutate({includeIssues:J,includeSkills:S.skills,requestId:d,signal:s.signal})}const q=ue({mutationFn:()=>ee.exportBundle(e,{include:{company:!0,agents:!0,projects:!0,issues:J,skills:S.skills},selectedFiles:Array.from(P).sort(),sidebarOrder:ie}),onSuccess:s=>{const d=new Set(Object.keys(s.files));Rt(s,d,s.files),n({tone:"success",title:"Export downloaded",body:`${d.size} file${d.size===1?"":"s"} exported as ${s.rootPath}.zip`})},onError:s=>{n({tone:"error",title:"Export failed",body:s instanceof Error?s.message:"Failed to build export package."})}});(0,h.useEffect)(()=>{e&&(ne.current!==e&&(ne.current=e,g(null),j(null)),O())},[e,J,S.skills]),(0,h.useEffect)(()=>()=>{L.current+=1,F.current?.abort()},[]);const M=(0,h.useMemo)(()=>i?fe(i.files):[],[i]),P=(0,h.useMemo)(()=>i?kt({filePaths:Object.keys(i.files),issues:i.manifest.issues,categories:S,embeddedAssets:i.manifest.embeddedAssets??[]}):new Set,[i,S]),Ne=(0,h.useMemo)(()=>i?vt(Object.keys(i.files),i.manifest.issues):null,[i]),{displayTree:Ae,totalTaskChildren:ce,visibleTaskChildren:le}=(0,h.useMemo)(()=>{let s=M;b&&(s=Ce(s,b));const d=Pt(s,C,b,w);return{displayTree:d.nodes,totalTaskChildren:d.totalTaskChildren,visibleTaskChildren:d.visibleTaskChildren}},[M,b,C,w]),Pe=(0,h.useMemo)(()=>{const s={};function d(f){if(f.kind==="file"){const k=P.has(f.path);return k||(s[f.path]="muted"),k}let y=!1;for(const k of f.children)d(k)&&(y=!0);return y||(s[f.path]="muted"),y}for(const f of M)d(f);return s},[M,P]),K=(0,h.useMemo)(()=>{if(!i)return{};const s={...i.files},d=i.paperclipExtensionPath;if(d&&typeof i.files[d]=="string"&&(s[d]=Nt(i.files[d],P)),typeof i.files["README.md"]=="string"){const f=i.manifest.company?.name??o?.name??"Company",y=i.manifest.company?.description??null;s["README.md"]=Lt(i.manifest,P,f,y)}return s},[i,P,o?.name]),Re=(0,h.useMemo)(()=>i?Ye(Ee(i.files,P,K),i.rootPath):0,[i,P,K]),de=(0,h.useMemo)(()=>dt(M),[M]),I=P.size,$=(0,h.useMemo)(()=>i?i.warnings.filter(s=>!/terminated agent/i.test(s)):[],[i]);function Te(s){E(d=>{const f=new Set(d);return f.has(s)?f.delete(s):f.add(s),f})}function Me(s){D(d=>({...d,[s]:!d[s]}))}function Le(s){const d=b.length>0,f=s.length>0;if(f&&!d&&(W.current=new Set(R)),_(s),f){const y=At(M,s);E(k=>{const v=new Set(k);for(const Y of y)v.add(Y);return v})}else d&&W.current&&(E(W.current),W.current=null)}function Oe(s){if(!i)return;const d=i.manifest.skills.find(f=>f.key===s||f.slug===s)?.path??`skills/${s}/SKILL.md`;d in i.files&&(Q(d),E(f=>{const y=new Set(f);y.add("skills");const k=d.split("/").slice(0,-1);let v="";for(const Y of k)v=v?`${v}/${Y}`:Y,y.add(v);return y}))}function Fe(){!i||P.size===0||q.isPending||q.mutate()}function Ie(){L.current+=1,F.current?.abort(),F.current=null,A.reset(),U(!0)}if(!e)return(0,t.jsx)(z,{icon:B,message:"Select an organization to export."});if(A.isPending&&!i)return(0,t.jsx)(Ve,{variant:"detail"});if(N&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview cancelled",message:"The preview request was cancelled. Your export settings are unchanged.",action:"Retry preview",onAction:O,hideActionIcon:!0});if(A.isError&&!i)return(0,t.jsx)(z,{icon:B,title:"Export preview failed",message:te(A.error),description:"Retry the preview. You do not need to reload this page.",action:"Retry preview",onAction:O,hideActionIcon:!0});if(!i)return(0,t.jsx)(z,{icon:B,title:"Export preview unavailable",message:"No export preview is loaded.",action:"Load preview",onAction:O,hideActionIcon:!0});const $e=w?K[w]??null:null;return(0,t.jsxs)("div",{className:"max-w-6xl",children:[(0,t.jsx)("div",{className:"sticky top-0 z-10 border-b border-border bg-background px-5 py-3",children:(0,t.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-4 text-sm",children:[(0,t.jsxs)("span",{className:"font-medium",children:[o?.name??"Organization"," export"]}),(0,t.jsxs)("span",{className:"text-muted-foreground",children:["Exporting ",I.toLocaleString()," of ",de.toLocaleString()," file",de===1?"":"s",I>0&&` (~${rt(Re)})`]}),$.length>0&&(0,t.jsxs)("span",{className:"text-amber-500",children:[$.length," warning",$.length===1?"":"s"]})]}),(0,t.jsxs)(X,{size:"sm",onClick:Fe,disabled:I===0||q.isPending||A.isPending||A.isError||N,children:[(0,t.jsx)(ft,{className:"mr-1.5 h-3.5 w-3.5"}),q.isPending?"Building export...":`Export ${I.toLocaleString()} file${I===1?"":"s"}`]})]})}),$.length>0&&(0,t.jsx)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:$.map(s=>(0,t.jsx)("div",{className:"text-xs text-amber-500",children:s},s))}),x&&x.warnings.length>0&&(0,t.jsxs)("div",{className:"mx-5 mt-3 rounded-md border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:[(0,t.jsx)("h3",{className:"mb-1.5 text-xs font-medium",children:"Not included in this export"}),x.warnings.map(s=>(0,t.jsx)("div",{className:se("text-xs",s.severity==="blocker"?"font-medium text-destructive":"text-amber-500"),children:s.message},s.code))]}),(0,t.jsxs)("div",{className:"grid gap-4 xl:h-(--sz-calc-30) xl:grid-cols-(--gtc-25) xl:gap-0",children:[(0,t.jsxs)("aside",{className:"flex max-h-(--sz-24rem) flex-col overflow-hidden border-b border-border xl:max-h-none xl:border-b-0 xl:border-r",children:[(0,t.jsx)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:(0,t.jsx)("h2",{className:"text-base font-semibold",children:"Package files"})}),(0,t.jsxs)("div",{className:"border-b border-border px-4 py-3 shrink-0",children:[(0,t.jsx)("h3",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"What to include"}),(0,t.jsx)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1.5",role:"group","aria-label":"What to include",children:ht.map(s=>{const d=s==="attachments"&&!je(S),f=S[s]&&!d,y=Ne?.[s]??0,k=i.manifest.includes.issues||s!=="tasks"&&s!=="routines"&&s!=="attachments";return(0,t.jsxs)("label",{className:se("flex items-center gap-2 text-sm",d?"cursor-not-allowed opacity-50":"cursor-pointer"),title:d?"Attachments travel with tasks and routines; re-enable one of them to include attachments.":void 0,children:[(0,t.jsx)("input",{type:"checkbox",checked:f,disabled:d,onChange:()=>Me(s),className:"accent-foreground","data-export-category":s}),(0,t.jsx)("span",{className:"min-w-0 truncate",children:mt[s]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:k?y.toLocaleString():"—"})]},s)})}),(0,t.jsx)("p",{className:"mt-2 text-xs text-muted-foreground",children:"Task and routine history is opt-in because it can be large."})]}),(0,t.jsx)("div",{className:"border-b border-border px-3 py-2 shrink-0",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-border px-2 py-1",children:[(0,t.jsx)(qe,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)("input",{type:"text",value:b,onChange:s=>Le(s.target.value),placeholder:"Search files...",className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground","data-page-search-target":"true"})]})}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,t.jsx)(lt,{nodes:Ae,selectedFile:w,expandedDirs:R,onToggleDir:Te,onSelectFile:Q,fileTones:Pe,showCheckboxes:!1,wrapLabels:!1}),ce>le&&!b&&(0,t.jsx)("div",{className:"px-4 py-2",children:(0,t.jsxs)("button",{type:"button",onClick:()=>T(s=>s+me),className:"w-full rounded-md border border-border px-3 py-1.5 text-xs text-muted-foreground hover:bg-accent/30 hover:text-foreground transition-colors",children:["Show more tasks (",le," of ",ce,")"]})})]})]}),(0,t.jsxs)("div",{className:"relative min-w-0 overflow-y-auto xl:pl-6",children:[(0,t.jsx)(Ft,{selectedFile:w,content:$e,allFiles:K,orgChartPreviewUrl:`/api/companies/${encodeURIComponent(e)}/org.svg`,onSkillClick:Oe}),A.isPending?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"status","aria-live":"polite","aria-busy":"true","data-export-preview-state":"loading",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsx)(pt,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Updating export preview…"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large task histories can take a minute. You can untick Tasks or cancel this update."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:Ie,children:[(0,t.jsx)(_e,{}),"Cancel update"]})]})}):N?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center","data-export-preview-state":"cancelled",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Preview update cancelled"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:"The previous preview remains available. Retry when you are ready."})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:O,children:[(0,t.jsx)(pe,{}),"Retry preview"]})]})}):A.isError?(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex min-h-(--sz-520px) items-center justify-center bg-background/90 px-6 text-center",role:"alert","data-export-preview-state":"error",children:(0,t.jsxs)("div",{className:"flex max-w-md flex-col items-center gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium text-destructive",children:"Export preview failed"}),(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground",children:te(A.error)})]}),(0,t.jsxs)(X,{type:"button",variant:"outline",size:"sm",onClick:O,children:[(0,t.jsx)(pe,{}),"Retry preview"]})]})}):null]})]})]})}export{Dt as CompanyExport};
@@ -1 +1 @@
1
- import{$ as L,at as M,et as $,nt as E,ot as b,rt as j,tt as w}from"./index-Cj4ZrUu7.js";var G=class A{constructor(t,e,i,n,r,h,o,a,f,l=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=n,this.pos=r,this.score=h,this.buffer=o,this.bufferBase=a,this.curContext=f,this.lookAhead=l,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let n=t.parser.context;return new A(t,[],e,i,i,0,[],0,n?new y(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,n=t&65535,{parser:r}=this.p,h=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),o=r.dynamicPrecedence(n);if(o&&(this.score+=o),i==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,h?8:4,!0),this.reduceContext(n,this.reducePos);return}let a=this.stack.length-(i-1)*3-(t&262144?6:0),f=a?this.stack[a-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&f==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let l=this.reducePos-f;l>=2e3&&!(!((e=this.p.parser.nodeSet.types[n])===null||e===void 0)&&e.isAnonymous)&&(f==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=l):this.p.lastBigReductionSize<l&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=f,this.p.lastBigReductionSize=l));let c=a?this.stack[a-1]:0,u=this.bufferBase+this.buffer.length-c;if(n<r.minRepeatTerm||t&131072){let p=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,f,p,u+4,!0)}if(t&262144)this.state=this.stack[a];else{let p=this.stack[a-3];this.state=r.getGoto(p,n,!0)}for(;this.stack.length>a;)this.stack.pop();this.reduceContext(n,f)}storeNode(t,e,i,n=4,r=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let h=this.buffer.length;if(h>0&&this.buffer[h-4]==0&&this.buffer[h-1]>-1){if(e==i)return;if(this.buffer[h-2]>=e){this.buffer[h-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(t,e,i,n);else{let h=this.buffer.length;if(h>0&&(this.buffer[h-4]!=0||this.buffer[h-1]<0)){let o=!1;for(let a=h;a>0&&this.buffer[a-2]>i;a-=4)if(this.buffer[a-1]>=0){o=!0;break}if(o)for(;h>0&&this.buffer[h-2]>i;)this.buffer[h]=this.buffer[h-4],this.buffer[h+1]=this.buffer[h-3],this.buffer[h+2]=this.buffer[h-2],this.buffer[h+3]=this.buffer[h-1],h-=4,n>4&&(n-=4)}this.buffer[h]=t,this.buffer[h+1]=e,this.buffer[h+2]=i,this.buffer[h+3]=n}}shift(t,e,i,n){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let r=t,{parser:h}=this.p;this.pos=n;let o=h.stateFlag(r,1);!o&&(n>i||e<=h.maxNode)&&(this.reducePos=n),this.pushState(r,o?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=h.maxNode&&this.buffer.push(e,i,n,4)}else this.pos=n,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,n,4)}apply(t,e,i,n){t&65536?this.reduce(t):this.shift(t,e,i,n)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let n=this.pos;this.reducePos=this.pos=n+t.length,this.pushState(e,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),n=t.bufferBase+e;for(;t&&n==t.bufferBase;)t=t.parent;return new A(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new U(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let n=[];for(let r=0,h;r<e.length;r+=2)(h=e[r+1])!=this.state&&this.p.parser.hasAction(h,t)&&n.push(e[r],h);if(this.stack.length<120)for(let r=0;n.length<8&&r<e.length;r+=2){let h=e[r+1];n.some((o,a)=>a&1&&o==h)||n.push(e[r],h)}e=n}let i=[];for(let n=0;n<e.length&&i.length<4;n+=2){let r=e[n+1];if(r==this.state)continue;let h=this.split();h.pushState(r,this.pos),h.storeNode(0,h.pos,h.pos,4,!0),h.shiftContext(e[n],this.pos),h.reducePos=this.pos,h.score-=200,i.push(h)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,n=e&65535,r=this.stack.length-i*3;if(r<0||t.getGoto(this.stack[r],n,!1)<0){let h=this.findForcedReduction();if(h==null)return!1;e=h}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(n,r)=>{if(!e.includes(n))return e.push(n),t.allActions(n,h=>{if(!(h&393216))if(h&65536){let o=(h>>19)-r;if(o>1){let a=h&65535,f=this.stack.length-o*3;if(f>=0&&t.getGoto(this.stack[f],a,!1)>=0)return o<<19|65536|a}}else{let o=i(h,r+1);if(o!=null)return o}})};return i(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:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new y(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},y=class{constructor(s,t){this.tracker=s,this.context=t,this.hash=s.strict?s.hash(t):0}},U=class{constructor(s){this.start=s,this.state=s.state,this.stack=s.stack,this.base=this.stack.length}reduce(s){let t=s&65535,e=s>>19;e==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(e-1)*3;let i=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=i}},H=class T{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new T(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.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 T(this.stack,this.pos,this.index)}};function x(s,t=Uint16Array){if(typeof s!="string")return s;let e=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let h=s.charCodeAt(i++),o=!1;if(h==126){r=65535;break}h>=92&&h--,h>=34&&h--;let a=h-32;if(a>=46&&(a-=46,o=!0),r+=a,o)break;r*=46}e?e[n++]=r:e=new t(r)}return e}var S=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},R=new S,W=class{constructor(s,t){this.input=s,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=R,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(s,t){let e=this.range,i=this.rangeIndex,n=this.pos+s;for(;n<e.from;){if(!i)return null;let r=this.ranges[--i];n-=e.from-r.to,e=r}for(;t<0?n>e.to:n>=e.to;){if(i==this.ranges.length-1)return null;let r=this.ranges[++i];n+=r.from-e.to,e=r}return n}clipPos(s){if(s>=this.range.from&&s<this.range.to)return s;for(let t of this.ranges)if(t.to>s)return Math.max(s,t.from);return this.end}peek(s){let t=this.chunkOff+s,e,i;if(t>=0&&t<this.chunk.length)e=this.pos+s,i=this.chunk.charCodeAt(t);else{let n=this.resolveOffset(s,1);if(n==null)return-1;if(e=n,e>=this.chunk2Pos&&e<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(e-this.chunk2Pos);else{let r=this.rangeIndex,h=this.range;for(;h.to<=e;)h=this.ranges[++r];this.chunk2=this.input.chunk(this.chunk2Pos=e),e+this.chunk2.length>h.to&&(this.chunk2=this.chunk2.slice(0,h.to-e)),i=this.chunk2.charCodeAt(0)}}return e>=this.token.lookAhead&&(this.token.lookAhead=e+1),i}acceptToken(s,t=0){let e=t?this.resolveOffset(t,-1):this.pos;if(e==null||e<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=s,this.token.end=e}acceptTokenTo(s,t){this.token.value=s,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:s,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=s,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let s=this.input.chunk(this.pos),t=this.pos+s.length;this.chunk=t>this.range.to?s.slice(0,this.range.to-this.pos):s,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(s=1){for(this.chunkOff+=s;this.pos+s>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();s-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=s,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(s,t){if(t?(this.token=t,t.start=s,t.lookAhead=s+1,t.value=t.extended=-1):this.token=R,this.pos!=s){if(this.pos=s,s==this.end)return this.setDone(),this;for(;s<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;s>=this.range.to;)this.range=this.ranges[++this.rangeIndex];s>=this.chunkPos&&s<this.chunkPos+this.chunk.length?this.chunkOff=s-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(s,t){if(s>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(s-this.chunkPos,t-this.chunkPos);if(s>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(s-this.chunk2Pos,t-this.chunk2Pos);if(s>=this.range.from&&t<=this.range.to)return this.input.read(s,t);let e="";for(let i of this.ranges){if(i.from>=t)break;i.to>s&&(e+=this.input.read(Math.max(i.from,s),Math.min(i.to,t)))}return e}},m=class{constructor(s,t){this.data=s,this.id=t}token(s,t){let{parser:e}=t.p;D(this.data,s,t,this.id,e.data,e.tokenPrecTable)}};m.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;var q=class{constructor(s,t,e){this.precTable=t,this.elseToken=e,this.data=typeof s=="string"?x(s):s}token(s,t){let e=s.pos,i=0;for(;;){let n=s.next<0,r=s.resolveOffset(1,1);if(D(this.data,s,t,0,this.data,this.precTable),s.token.value>-1)break;if(this.elseToken==null)return;if(n||i++,r==null)break;s.reset(r,s.token)}i&&(s.reset(e,s.token),s.acceptToken(this.elseToken,i))}};q.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;var _=class{constructor(s,t={}){this.token=s,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}};function D(s,t,e,i,n,r){let h=0,o=1<<i,{dialect:a}=e.p.parser;t:for(;(o&s[h])!=0;){let f=s[h+1];for(let p=h+3;p<f;p+=2)if((s[p+1]&o)>0){let k=s[p];if(a.allows(k)&&(t.token.value==-1||t.token.value==k||J(k,t.token.value,n,r))){t.acceptToken(k);break}}let l=t.next,c=0,u=s[h+2];if(t.next<0&&u>c&&s[f+u*3-3]==65535){h=s[f+u*3-1];continue t}for(;c<u;){let p=c+u>>1,k=f+p+(p<<1),F=s[k],O=s[k+1]||65536;if(l<F)u=p;else if(l>=O)c=p+1;else{h=s[k+2],t.advance();continue t}}break}}function N(s,t,e){for(let i=t,n;(n=s[i])!=65535;i++)if(n==e)return i-t;return-1}function J(s,t,e,i){let n=N(e,i,t);return n<0||N(e,i,s)<n}var d=typeof process<"u"&&/\bparse\b/.test({}.LOG),v=null;function z(s,t,e){let i=s.cursor($.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(s.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:s.length}}var K=class{constructor(s,t){this.fragments=s,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 s=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(s){for(this.safeFrom=s.openStart?z(s.tree,s.from+s.offset,1)-s.offset:s.from,this.safeTo=s.openEnd?z(s.tree,s.to+s.offset,-1)-s.offset:s.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(s.tree),this.start.push(-s.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(s){if(s<this.nextStart)return null;for(;this.fragment&&this.safeTo<=s;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let e=this.trees[t],i=this.index[t];if(i==e.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=e.children[i],r=this.start[t]+e.positions[i];if(r>s)return this.nextStart=r,null;if(n instanceof b){if(r==s){if(r<this.safeFrom)return null;let h=r+n.length;if(h<=this.safeTo){let o=n.prop(w.lookAhead);if(!o||h+o<this.fragment.to)return n}}this.index[t]++,r+n.length>=Math.max(this.safeFrom,s)&&(this.trees.push(n),this.start.push(r),this.index.push(0))}else this.index[t]++,this.nextStart=r+n.length}}},Q=class{constructor(s,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=s.tokenizers.map(e=>new S)}getActions(s){let t=0,e=null,{parser:i}=s.p,{tokenizers:n}=i,r=i.stateSlot(s.state,3),h=s.curContext?s.curContext.hash:0,o=0;for(let a=0;a<n.length;a++){if((1<<a&r)==0)continue;let f=n[a],l=this.tokens[a];if(!(e&&!f.fallback)&&((f.contextual||l.start!=s.pos||l.mask!=r||l.context!=h)&&(this.updateCachedToken(l,f,s),l.mask=r,l.context=h),l.lookAhead>l.end+25&&(o=Math.max(l.lookAhead,o)),l.value!=0)){let c=t;if(l.extended>-1&&(t=this.addActions(s,l.extended,l.end,t)),t=this.addActions(s,l.value,l.end,t),!f.extend&&(e=l,t>c))break}}for(;this.actions.length>t;)this.actions.pop();return o&&s.setLookAhead(o),!e&&s.pos==this.stream.end&&(e=new S,e.value=s.p.parser.eofTerm,e.start=e.end=s.pos,t=this.addActions(s,e.value,e.end,t)),this.mainToken=e,this.actions}getMainToken(s){if(this.mainToken)return this.mainToken;let t=new S,{pos:e,p:i}=s;return t.start=e,t.end=Math.min(e+1,i.stream.end),t.value=e==i.stream.end?i.parser.eofTerm:0,t}updateCachedToken(s,t,e){let i=this.stream.clipPos(e.pos);if(t.token(this.stream.reset(i,s),e),s.value>-1){let{parser:n}=e.p;for(let r=0;r<n.specialized.length;r++)if(n.specialized[r]==s.value){let h=n.specializers[r](this.stream.read(s.start,s.end),e);if(h>=0&&e.p.parser.dialect.allows(h>>1)){(h&1)==0?s.value=h>>1:s.extended=h>>1;break}}}else s.value=0,s.end=this.stream.clipPos(i+1)}putAction(s,t,e,i){for(let n=0;n<i;n+=3)if(this.actions[n]==s)return i;return this.actions[i++]=s,this.actions[i++]=t,this.actions[i++]=e,i}addActions(s,t,e,i){let{state:n}=s,{parser:r}=s.p,{data:h}=r;for(let o=0;o<2;o++)for(let a=r.stateSlot(n,o?2:1);;a+=3){if(h[a]==65535)if(h[a+1]==1)a=g(h,a+2);else{i==0&&h[a+1]==2&&(i=this.putAction(g(h,a+2),t,e,i));break}h[a]==t&&(i=this.putAction(g(h,a+1),t,e,i))}return i}},V=class{constructor(s,t,e,i){this.parser=s,this.input=t,this.ranges=i,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 W(t,i),this.tokens=new Q(s,this.stream),this.topTerm=s.top[1];let{from:n}=i[0];this.stacks=[G.start(this,s.top[0],n)],this.fragments=e.length&&this.stream.end-n>s.bufferLength*4?new K(e,s.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let s=this.stacks,t=this.minStackPos,e=this.stacks=[],i,n;if(this.bigReductionCount>300&&s.length==1){let[r]=s;for(;r.forceReduce()&&r.stack.length&&r.stack[r.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;r<s.length;r++){let h=s[r];for(;;){if(this.tokens.mainToken=null,h.pos>t)e.push(h);else{if(this.advanceStack(h,e,s))continue;{i||(i=[],n=[]),i.push(h);let o=this.tokens.getMainToken(h);n.push(o.value,o.end)}}break}}if(!e.length){let r=i&&Y(i);if(r)return this.stackToTree(r);if(this.parser.strict)throw new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&i){let r=this.stoppedAt!=null&&i[0].pos>this.stoppedAt?i[0]:this.runRecovery(i,n,e);if(r)return this.stackToTree(r.forceAll())}if(this.recovering){let r=this.recovering==1?1:this.recovering*3;if(e.length>r)for(e.sort((h,o)=>o.score-h.score);e.length>r;)e.pop();e.some(h=>h.reducePos>t)&&this.recovering--}else if(e.length>1){t:for(let r=0;r<e.length-1;r++){let h=e[r];for(let o=r+1;o<e.length;o++){let a=e[o];if(h.sameState(a)||h.buffer.length>500&&a.buffer.length>500)if((h.score-a.score||h.buffer.length-a.buffer.length)>0)e.splice(o--,1);else{e.splice(r--,1);continue t}}}e.length>12&&(e.sort((r,h)=>h.score-r.score),e.splice(12,e.length-12))}this.minStackPos=e[0].pos;for(let r=1;r<e.length;r++)e[r].pos<this.minStackPos&&(this.minStackPos=e[r].pos);return null}stopAt(s){if(this.stoppedAt!=null&&this.stoppedAt<s)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=s}advanceStack(s,t,e){let i=s.pos,{parser:n}=this,r=d?this.stackID(s)+" -> ":"";if(this.stoppedAt!=null&&i>this.stoppedAt)return s.forceReduce()?s:null;if(this.fragments){let a=s.curContext&&s.curContext.tracker.strict,f=a?s.curContext.hash:0;for(let l=this.fragments.nodeAt(i);l;){let c=this.parser.nodeSet.types[l.type.id]==l.type?n.getGoto(s.state,l.type.id):-1;if(c>-1&&l.length&&(!a||(l.prop(w.contextHash)||0)==f))return s.useNode(l,c),!0;if(!(l instanceof b)||l.children.length==0||l.positions[0]>0)break;let u=l.children[0];if(u instanceof b&&l.positions[0]==0)l=u;else break}}let h=n.stateSlot(s.state,4);if(h>0)return s.reduce(h),!0;if(s.stack.length>=8400)for(;s.stack.length>6e3&&s.forceReduce(););let o=this.tokens.getActions(s);for(let a=0;a<o.length;){let f=o[a++],l=o[a++],c=o[a++],u=a==o.length||!e,p=u?s:s.split(),k=this.tokens.mainToken;if(p.apply(f,l,k?k.start:p.pos,c),u)return!0;p.pos>i?t.push(p):e.push(p)}return!1}advanceFully(s,t){let e=s.pos;for(;;){if(!this.advanceStack(s,null,null))return!1;if(s.pos>e)return I(s,t),!0}}runRecovery(s,t,e){let i=null,n=!1;for(let r=0;r<s.length;r++){let h=s[r],o=t[r<<1],a=t[(r<<1)+1],f=d?this.stackID(h)+" -> ":"";if(h.deadEnd&&(n||(n=!0,h.restart(),this.advanceFully(h,e))))continue;let l=h.split(),c=f;for(let u=0;u<10&&l.forceReduce()&&!this.advanceFully(l,e);u++)d&&(c=this.stackID(l)+" -> ");for(let u of h.recoverByInsert(o))this.advanceFully(u,e);this.stream.end>h.pos?(a==h.pos&&(a++,o=0),h.recoverByDelete(o,a),I(h,e)):(!i||i.score<l.score)&&(i=l)}return i}stackToTree(s){return s.close(),b.build({buffer:H.create(s),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:s.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(s){let t=(v||(v=new WeakMap)).get(s);return t||v.set(s,t=String.fromCodePoint(this.nextStackID++)),t+s}};function I(s,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==s.pos&&i.sameState(s)){t[e].score<s.score&&(t[e]=s);return}}t.push(s)}var X=class{constructor(s,t,e){this.source=s,this.flags=t,this.disabled=e}allows(s){return!this.disabled||this.disabled[s]==0}},P=s=>s,tt=class{constructor(s){this.start=s.start,this.shift=s.shift||P,this.reduce=s.reduce||P,this.reuse=s.reuse||P,this.hash=s.hash||(()=>0),this.strict=s.strict!==!1}},et=class C extends M{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let o=0;o<t.repeatNodeCount;o++)e.push("");let i=Object.keys(t.topRules).map(o=>t.topRules[o][1]),n=[];for(let o=0;o<e.length;o++)n.push([]);function r(o,a,f){n[o].push([a,a.deserialize(String(f))])}if(t.nodeProps)for(let o of t.nodeProps){let a=o[0];typeof a=="string"&&(a=w[a]);for(let f=1;f<o.length;){let l=o[f++];if(l>=0)r(l,a,o[f++]);else{let c=o[f+-l];for(let u=-l;u>0;u--)r(o[f++],a,c);f++}}}this.nodeSet=new E(e.map((o,a)=>j.define({name:a>=this.minRepeatTerm?void 0:o,id:a,props:n[a],top:i.indexOf(a)>-1,error:a==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(a)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=L;let h=x(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let o=0;o<this.specializerSpecs.length;o++)this.specialized[o]=this.specializerSpecs[o].term;this.specializers=this.specializerSpecs.map(B),this.states=x(t.states,Uint32Array),this.data=x(t.stateData),this.goto=x(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(o=>typeof o=="number"?new m(h,o):o),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let n=new V(this,t,e,i);for(let r of this.wrappers)n=r(n,t,e,i);return n}getGoto(t,e,i=!1){let n=this.goto;if(e>=n[0])return-1;for(let r=n[e+1];;){let h=n[r++],o=h&1,a=n[r++];if(o&&i)return a;for(let f=r+(h>>1);r<f;r++)if(n[r]==t)return a;if(o)return-1}}hasAction(t,e){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(t,n?2:1),h;;r+=3){if((h=i[r])==65535)if(i[r+1]==1)h=i[r=g(i,r+2)];else{if(i[r+1]==2)return g(i,r+2);break}if(h==e||h==0)return g(i,r+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),n=i?e(i):void 0;for(let r=this.stateSlot(t,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=g(this.data,r+2);else break;n=e(g(this.data,r+1))}return n}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=g(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];e.some((r,h)=>h&1&&r==n)||e.push(this.data[i],n)}}return e}configure(t){let e=Object.assign(Object.create(C.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let n=t.tokenizers.find(r=>r.from==i);return n?n.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=t.specializers.find(o=>o.from==i.external);if(!r)return i;let h=Object.assign(Object.assign({},i),{external:r.to});return e.specializers[n]=B(h),h})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let r of t.split(" ")){let h=e.indexOf(r);h>=0&&(i[h]=!0)}let n=null;for(let r=0;r<e.length;r++)if(!i[r])for(let h=this.dialects[e[r]],o;(o=this.data[h++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[o]=1;return new X(t,i,n)}static deserialize(t){return new C(t)}};function g(s,t){return s[t]|s[t+1]<<16}function Y(s){let t=null;for(let e of s){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function B(s){if(s.external){let t=s.extend?1:0;return(e,i)=>s.external(e,i)<<1|t}return s.get}export{q as i,_ as n,et as r,tt as t};
1
+ import{$ as L,at as M,et as $,nt as E,ot as b,rt as j,tt as w}from"./index-DXc1QDcn.js";var G=class A{constructor(t,e,i,n,r,h,o,a,f,l=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=n,this.pos=r,this.score=h,this.buffer=o,this.bufferBase=a,this.curContext=f,this.lookAhead=l,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let n=t.parser.context;return new A(t,[],e,i,i,0,[],0,n?new y(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,n=t&65535,{parser:r}=this.p,h=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),o=r.dynamicPrecedence(n);if(o&&(this.score+=o),i==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,h?8:4,!0),this.reduceContext(n,this.reducePos);return}let a=this.stack.length-(i-1)*3-(t&262144?6:0),f=a?this.stack[a-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&f==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let l=this.reducePos-f;l>=2e3&&!(!((e=this.p.parser.nodeSet.types[n])===null||e===void 0)&&e.isAnonymous)&&(f==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=l):this.p.lastBigReductionSize<l&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=f,this.p.lastBigReductionSize=l));let c=a?this.stack[a-1]:0,u=this.bufferBase+this.buffer.length-c;if(n<r.minRepeatTerm||t&131072){let p=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,f,p,u+4,!0)}if(t&262144)this.state=this.stack[a];else{let p=this.stack[a-3];this.state=r.getGoto(p,n,!0)}for(;this.stack.length>a;)this.stack.pop();this.reduceContext(n,f)}storeNode(t,e,i,n=4,r=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let h=this.buffer.length;if(h>0&&this.buffer[h-4]==0&&this.buffer[h-1]>-1){if(e==i)return;if(this.buffer[h-2]>=e){this.buffer[h-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(t,e,i,n);else{let h=this.buffer.length;if(h>0&&(this.buffer[h-4]!=0||this.buffer[h-1]<0)){let o=!1;for(let a=h;a>0&&this.buffer[a-2]>i;a-=4)if(this.buffer[a-1]>=0){o=!0;break}if(o)for(;h>0&&this.buffer[h-2]>i;)this.buffer[h]=this.buffer[h-4],this.buffer[h+1]=this.buffer[h-3],this.buffer[h+2]=this.buffer[h-2],this.buffer[h+3]=this.buffer[h-1],h-=4,n>4&&(n-=4)}this.buffer[h]=t,this.buffer[h+1]=e,this.buffer[h+2]=i,this.buffer[h+3]=n}}shift(t,e,i,n){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let r=t,{parser:h}=this.p;this.pos=n;let o=h.stateFlag(r,1);!o&&(n>i||e<=h.maxNode)&&(this.reducePos=n),this.pushState(r,o?i:Math.min(i,this.reducePos)),this.shiftContext(e,i),e<=h.maxNode&&this.buffer.push(e,i,n,4)}else this.pos=n,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,n,4)}apply(t,e,i,n){t&65536?this.reduce(t):this.shift(t,e,i,n)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let n=this.pos;this.reducePos=this.pos=n+t.length,this.pushState(e,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(e&&t.buffer[e-4]==0&&(e-=4);e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),n=t.bufferBase+e;for(;t&&n==t.bufferBase;)t=t.parent;return new A(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new U(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let n=[];for(let r=0,h;r<e.length;r+=2)(h=e[r+1])!=this.state&&this.p.parser.hasAction(h,t)&&n.push(e[r],h);if(this.stack.length<120)for(let r=0;n.length<8&&r<e.length;r+=2){let h=e[r+1];n.some((o,a)=>a&1&&o==h)||n.push(e[r],h)}e=n}let i=[];for(let n=0;n<e.length&&i.length<4;n+=2){let r=e[n+1];if(r==this.state)continue;let h=this.split();h.pushState(r,this.pos),h.storeNode(0,h.pos,h.pos,4,!0),h.shiftContext(e[n],this.pos),h.reducePos=this.pos,h.score-=200,i.push(h)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,n=e&65535,r=this.stack.length-i*3;if(r<0||t.getGoto(this.stack[r],n,!1)<0){let h=this.findForcedReduction();if(h==null)return!1;e=h}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(n,r)=>{if(!e.includes(n))return e.push(n),t.allActions(n,h=>{if(!(h&393216))if(h&65536){let o=(h>>19)-r;if(o>1){let a=h&65535,f=this.stack.length-o*3;if(f>=0&&t.getGoto(this.stack[f],a,!1)>=0)return o<<19|65536|a}}else{let o=i(h,r+1);if(o!=null)return o}})};return i(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:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new y(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},y=class{constructor(s,t){this.tracker=s,this.context=t,this.hash=s.strict?s.hash(t):0}},U=class{constructor(s){this.start=s,this.state=s.state,this.stack=s.stack,this.base=this.stack.length}reduce(s){let t=s&65535,e=s>>19;e==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(e-1)*3;let i=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=i}},H=class T{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new T(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.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 T(this.stack,this.pos,this.index)}};function x(s,t=Uint16Array){if(typeof s!="string")return s;let e=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let h=s.charCodeAt(i++),o=!1;if(h==126){r=65535;break}h>=92&&h--,h>=34&&h--;let a=h-32;if(a>=46&&(a-=46,o=!0),r+=a,o)break;r*=46}e?e[n++]=r:e=new t(r)}return e}var S=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},R=new S,W=class{constructor(s,t){this.input=s,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=R,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(s,t){let e=this.range,i=this.rangeIndex,n=this.pos+s;for(;n<e.from;){if(!i)return null;let r=this.ranges[--i];n-=e.from-r.to,e=r}for(;t<0?n>e.to:n>=e.to;){if(i==this.ranges.length-1)return null;let r=this.ranges[++i];n+=r.from-e.to,e=r}return n}clipPos(s){if(s>=this.range.from&&s<this.range.to)return s;for(let t of this.ranges)if(t.to>s)return Math.max(s,t.from);return this.end}peek(s){let t=this.chunkOff+s,e,i;if(t>=0&&t<this.chunk.length)e=this.pos+s,i=this.chunk.charCodeAt(t);else{let n=this.resolveOffset(s,1);if(n==null)return-1;if(e=n,e>=this.chunk2Pos&&e<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(e-this.chunk2Pos);else{let r=this.rangeIndex,h=this.range;for(;h.to<=e;)h=this.ranges[++r];this.chunk2=this.input.chunk(this.chunk2Pos=e),e+this.chunk2.length>h.to&&(this.chunk2=this.chunk2.slice(0,h.to-e)),i=this.chunk2.charCodeAt(0)}}return e>=this.token.lookAhead&&(this.token.lookAhead=e+1),i}acceptToken(s,t=0){let e=t?this.resolveOffset(t,-1):this.pos;if(e==null||e<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=s,this.token.end=e}acceptTokenTo(s,t){this.token.value=s,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:s,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=s,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let s=this.input.chunk(this.pos),t=this.pos+s.length;this.chunk=t>this.range.to?s.slice(0,this.range.to-this.pos):s,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(s=1){for(this.chunkOff+=s;this.pos+s>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();s-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=s,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(s,t){if(t?(this.token=t,t.start=s,t.lookAhead=s+1,t.value=t.extended=-1):this.token=R,this.pos!=s){if(this.pos=s,s==this.end)return this.setDone(),this;for(;s<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;s>=this.range.to;)this.range=this.ranges[++this.rangeIndex];s>=this.chunkPos&&s<this.chunkPos+this.chunk.length?this.chunkOff=s-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(s,t){if(s>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(s-this.chunkPos,t-this.chunkPos);if(s>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(s-this.chunk2Pos,t-this.chunk2Pos);if(s>=this.range.from&&t<=this.range.to)return this.input.read(s,t);let e="";for(let i of this.ranges){if(i.from>=t)break;i.to>s&&(e+=this.input.read(Math.max(i.from,s),Math.min(i.to,t)))}return e}},m=class{constructor(s,t){this.data=s,this.id=t}token(s,t){let{parser:e}=t.p;D(this.data,s,t,this.id,e.data,e.tokenPrecTable)}};m.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;var q=class{constructor(s,t,e){this.precTable=t,this.elseToken=e,this.data=typeof s=="string"?x(s):s}token(s,t){let e=s.pos,i=0;for(;;){let n=s.next<0,r=s.resolveOffset(1,1);if(D(this.data,s,t,0,this.data,this.precTable),s.token.value>-1)break;if(this.elseToken==null)return;if(n||i++,r==null)break;s.reset(r,s.token)}i&&(s.reset(e,s.token),s.acceptToken(this.elseToken,i))}};q.prototype.contextual=m.prototype.fallback=m.prototype.extend=!1;var _=class{constructor(s,t={}){this.token=s,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}};function D(s,t,e,i,n,r){let h=0,o=1<<i,{dialect:a}=e.p.parser;t:for(;(o&s[h])!=0;){let f=s[h+1];for(let p=h+3;p<f;p+=2)if((s[p+1]&o)>0){let k=s[p];if(a.allows(k)&&(t.token.value==-1||t.token.value==k||J(k,t.token.value,n,r))){t.acceptToken(k);break}}let l=t.next,c=0,u=s[h+2];if(t.next<0&&u>c&&s[f+u*3-3]==65535){h=s[f+u*3-1];continue t}for(;c<u;){let p=c+u>>1,k=f+p+(p<<1),F=s[k],O=s[k+1]||65536;if(l<F)u=p;else if(l>=O)c=p+1;else{h=s[k+2],t.advance();continue t}}break}}function N(s,t,e){for(let i=t,n;(n=s[i])!=65535;i++)if(n==e)return i-t;return-1}function J(s,t,e,i){let n=N(e,i,t);return n<0||N(e,i,s)<n}var d=typeof process<"u"&&/\bparse\b/.test({}.LOG),v=null;function z(s,t,e){let i=s.cursor($.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(s.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:s.length}}var K=class{constructor(s,t){this.fragments=s,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 s=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(s){for(this.safeFrom=s.openStart?z(s.tree,s.from+s.offset,1)-s.offset:s.from,this.safeTo=s.openEnd?z(s.tree,s.to+s.offset,-1)-s.offset:s.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(s.tree),this.start.push(-s.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(s){if(s<this.nextStart)return null;for(;this.fragment&&this.safeTo<=s;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let e=this.trees[t],i=this.index[t];if(i==e.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=e.children[i],r=this.start[t]+e.positions[i];if(r>s)return this.nextStart=r,null;if(n instanceof b){if(r==s){if(r<this.safeFrom)return null;let h=r+n.length;if(h<=this.safeTo){let o=n.prop(w.lookAhead);if(!o||h+o<this.fragment.to)return n}}this.index[t]++,r+n.length>=Math.max(this.safeFrom,s)&&(this.trees.push(n),this.start.push(r),this.index.push(0))}else this.index[t]++,this.nextStart=r+n.length}}},Q=class{constructor(s,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=s.tokenizers.map(e=>new S)}getActions(s){let t=0,e=null,{parser:i}=s.p,{tokenizers:n}=i,r=i.stateSlot(s.state,3),h=s.curContext?s.curContext.hash:0,o=0;for(let a=0;a<n.length;a++){if((1<<a&r)==0)continue;let f=n[a],l=this.tokens[a];if(!(e&&!f.fallback)&&((f.contextual||l.start!=s.pos||l.mask!=r||l.context!=h)&&(this.updateCachedToken(l,f,s),l.mask=r,l.context=h),l.lookAhead>l.end+25&&(o=Math.max(l.lookAhead,o)),l.value!=0)){let c=t;if(l.extended>-1&&(t=this.addActions(s,l.extended,l.end,t)),t=this.addActions(s,l.value,l.end,t),!f.extend&&(e=l,t>c))break}}for(;this.actions.length>t;)this.actions.pop();return o&&s.setLookAhead(o),!e&&s.pos==this.stream.end&&(e=new S,e.value=s.p.parser.eofTerm,e.start=e.end=s.pos,t=this.addActions(s,e.value,e.end,t)),this.mainToken=e,this.actions}getMainToken(s){if(this.mainToken)return this.mainToken;let t=new S,{pos:e,p:i}=s;return t.start=e,t.end=Math.min(e+1,i.stream.end),t.value=e==i.stream.end?i.parser.eofTerm:0,t}updateCachedToken(s,t,e){let i=this.stream.clipPos(e.pos);if(t.token(this.stream.reset(i,s),e),s.value>-1){let{parser:n}=e.p;for(let r=0;r<n.specialized.length;r++)if(n.specialized[r]==s.value){let h=n.specializers[r](this.stream.read(s.start,s.end),e);if(h>=0&&e.p.parser.dialect.allows(h>>1)){(h&1)==0?s.value=h>>1:s.extended=h>>1;break}}}else s.value=0,s.end=this.stream.clipPos(i+1)}putAction(s,t,e,i){for(let n=0;n<i;n+=3)if(this.actions[n]==s)return i;return this.actions[i++]=s,this.actions[i++]=t,this.actions[i++]=e,i}addActions(s,t,e,i){let{state:n}=s,{parser:r}=s.p,{data:h}=r;for(let o=0;o<2;o++)for(let a=r.stateSlot(n,o?2:1);;a+=3){if(h[a]==65535)if(h[a+1]==1)a=g(h,a+2);else{i==0&&h[a+1]==2&&(i=this.putAction(g(h,a+2),t,e,i));break}h[a]==t&&(i=this.putAction(g(h,a+1),t,e,i))}return i}},V=class{constructor(s,t,e,i){this.parser=s,this.input=t,this.ranges=i,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 W(t,i),this.tokens=new Q(s,this.stream),this.topTerm=s.top[1];let{from:n}=i[0];this.stacks=[G.start(this,s.top[0],n)],this.fragments=e.length&&this.stream.end-n>s.bufferLength*4?new K(e,s.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let s=this.stacks,t=this.minStackPos,e=this.stacks=[],i,n;if(this.bigReductionCount>300&&s.length==1){let[r]=s;for(;r.forceReduce()&&r.stack.length&&r.stack[r.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;r<s.length;r++){let h=s[r];for(;;){if(this.tokens.mainToken=null,h.pos>t)e.push(h);else{if(this.advanceStack(h,e,s))continue;{i||(i=[],n=[]),i.push(h);let o=this.tokens.getMainToken(h);n.push(o.value,o.end)}}break}}if(!e.length){let r=i&&Y(i);if(r)return this.stackToTree(r);if(this.parser.strict)throw new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&i){let r=this.stoppedAt!=null&&i[0].pos>this.stoppedAt?i[0]:this.runRecovery(i,n,e);if(r)return this.stackToTree(r.forceAll())}if(this.recovering){let r=this.recovering==1?1:this.recovering*3;if(e.length>r)for(e.sort((h,o)=>o.score-h.score);e.length>r;)e.pop();e.some(h=>h.reducePos>t)&&this.recovering--}else if(e.length>1){t:for(let r=0;r<e.length-1;r++){let h=e[r];for(let o=r+1;o<e.length;o++){let a=e[o];if(h.sameState(a)||h.buffer.length>500&&a.buffer.length>500)if((h.score-a.score||h.buffer.length-a.buffer.length)>0)e.splice(o--,1);else{e.splice(r--,1);continue t}}}e.length>12&&(e.sort((r,h)=>h.score-r.score),e.splice(12,e.length-12))}this.minStackPos=e[0].pos;for(let r=1;r<e.length;r++)e[r].pos<this.minStackPos&&(this.minStackPos=e[r].pos);return null}stopAt(s){if(this.stoppedAt!=null&&this.stoppedAt<s)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=s}advanceStack(s,t,e){let i=s.pos,{parser:n}=this,r=d?this.stackID(s)+" -> ":"";if(this.stoppedAt!=null&&i>this.stoppedAt)return s.forceReduce()?s:null;if(this.fragments){let a=s.curContext&&s.curContext.tracker.strict,f=a?s.curContext.hash:0;for(let l=this.fragments.nodeAt(i);l;){let c=this.parser.nodeSet.types[l.type.id]==l.type?n.getGoto(s.state,l.type.id):-1;if(c>-1&&l.length&&(!a||(l.prop(w.contextHash)||0)==f))return s.useNode(l,c),!0;if(!(l instanceof b)||l.children.length==0||l.positions[0]>0)break;let u=l.children[0];if(u instanceof b&&l.positions[0]==0)l=u;else break}}let h=n.stateSlot(s.state,4);if(h>0)return s.reduce(h),!0;if(s.stack.length>=8400)for(;s.stack.length>6e3&&s.forceReduce(););let o=this.tokens.getActions(s);for(let a=0;a<o.length;){let f=o[a++],l=o[a++],c=o[a++],u=a==o.length||!e,p=u?s:s.split(),k=this.tokens.mainToken;if(p.apply(f,l,k?k.start:p.pos,c),u)return!0;p.pos>i?t.push(p):e.push(p)}return!1}advanceFully(s,t){let e=s.pos;for(;;){if(!this.advanceStack(s,null,null))return!1;if(s.pos>e)return I(s,t),!0}}runRecovery(s,t,e){let i=null,n=!1;for(let r=0;r<s.length;r++){let h=s[r],o=t[r<<1],a=t[(r<<1)+1],f=d?this.stackID(h)+" -> ":"";if(h.deadEnd&&(n||(n=!0,h.restart(),this.advanceFully(h,e))))continue;let l=h.split(),c=f;for(let u=0;u<10&&l.forceReduce()&&!this.advanceFully(l,e);u++)d&&(c=this.stackID(l)+" -> ");for(let u of h.recoverByInsert(o))this.advanceFully(u,e);this.stream.end>h.pos?(a==h.pos&&(a++,o=0),h.recoverByDelete(o,a),I(h,e)):(!i||i.score<l.score)&&(i=l)}return i}stackToTree(s){return s.close(),b.build({buffer:H.create(s),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:s.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(s){let t=(v||(v=new WeakMap)).get(s);return t||v.set(s,t=String.fromCodePoint(this.nextStackID++)),t+s}};function I(s,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==s.pos&&i.sameState(s)){t[e].score<s.score&&(t[e]=s);return}}t.push(s)}var X=class{constructor(s,t,e){this.source=s,this.flags=t,this.disabled=e}allows(s){return!this.disabled||this.disabled[s]==0}},P=s=>s,tt=class{constructor(s){this.start=s.start,this.shift=s.shift||P,this.reduce=s.reduce||P,this.reuse=s.reuse||P,this.hash=s.hash||(()=>0),this.strict=s.strict!==!1}},et=class C extends M{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let o=0;o<t.repeatNodeCount;o++)e.push("");let i=Object.keys(t.topRules).map(o=>t.topRules[o][1]),n=[];for(let o=0;o<e.length;o++)n.push([]);function r(o,a,f){n[o].push([a,a.deserialize(String(f))])}if(t.nodeProps)for(let o of t.nodeProps){let a=o[0];typeof a=="string"&&(a=w[a]);for(let f=1;f<o.length;){let l=o[f++];if(l>=0)r(l,a,o[f++]);else{let c=o[f+-l];for(let u=-l;u>0;u--)r(o[f++],a,c);f++}}}this.nodeSet=new E(e.map((o,a)=>j.define({name:a>=this.minRepeatTerm?void 0:o,id:a,props:n[a],top:i.indexOf(a)>-1,error:a==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(a)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=L;let h=x(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let o=0;o<this.specializerSpecs.length;o++)this.specialized[o]=this.specializerSpecs[o].term;this.specializers=this.specializerSpecs.map(B),this.states=x(t.states,Uint32Array),this.data=x(t.stateData),this.goto=x(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(o=>typeof o=="number"?new m(h,o):o),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let n=new V(this,t,e,i);for(let r of this.wrappers)n=r(n,t,e,i);return n}getGoto(t,e,i=!1){let n=this.goto;if(e>=n[0])return-1;for(let r=n[e+1];;){let h=n[r++],o=h&1,a=n[r++];if(o&&i)return a;for(let f=r+(h>>1);r<f;r++)if(n[r]==t)return a;if(o)return-1}}hasAction(t,e){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(t,n?2:1),h;;r+=3){if((h=i[r])==65535)if(i[r+1]==1)h=i[r=g(i,r+2)];else{if(i[r+1]==2)return g(i,r+2);break}if(h==e||h==0)return g(i,r+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),n=i?e(i):void 0;for(let r=this.stateSlot(t,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=g(this.data,r+2);else break;n=e(g(this.data,r+1))}return n}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=g(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];e.some((r,h)=>h&1&&r==n)||e.push(this.data[i],n)}}return e}configure(t){let e=Object.assign(Object.create(C.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let n=t.tokenizers.find(r=>r.from==i);return n?n.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=t.specializers.find(o=>o.from==i.external);if(!r)return i;let h=Object.assign(Object.assign({},i),{external:r.to});return e.specializers[n]=B(h),h})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let r of t.split(" ")){let h=e.indexOf(r);h>=0&&(i[h]=!0)}let n=null;for(let r=0;r<e.length;r++)if(!i[r])for(let h=this.dialects[e[r]],o;(o=this.data[h++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[o]=1;return new X(t,i,n)}static deserialize(t){return new C(t)}};function g(s,t){return s[t]|s[t+1]<<16}function Y(s){let t=null;for(let e of s){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function B(s){if(s.external){let t=s.extend?1:0;return(e,i)=>s.external(e,i)<<1|t}return s.get}export{q as i,_ as n,et as r,tt as t};