import{getAstNodeByPointer as x,getLineColLocation as P}from"@redocly/openapi-core";import*as c from"yaml-ast-parser";import{combineUrls as A}from"@redocly/theme/core/utils";const K=(e,n,t,o)=>{const r=[];return e.forEach(s=>{const i=L(s,n,t);i.length===0&&r.push(o),r.push(...i)}),Array.from(new Set(r)).map(s=>A(o,s))},L=(e,n,t)=>{const o=E(e,n,3),r=f(o,n,s=>{const i=s.split("/");return i[1]==="paths"?i.slice(0,4).join("/"):null});return v(r,t)},k=(e,n)=>{const t=e.split("/"),o=t.length;for(let r=1;r<o;r++){const s=t.join("/"),i=[...n.matchAll(new RegExp(`[^a-zA-Z0-9]${s}[^a-zA-Z0-9]`,"g"))].filter(u=>u.index!==void 0).map(u=>u.index);if(i.length>0)return{pointer:s,indexes:i};t.pop()}return null},f=(e,n,t,o=new Set,r=[])=>{const s=[],i=n.getAst(c.safeLoad),u=t(e);if(u){s.push({pointer:u,trace:[e,...r]});const a=x(i,u,!1),l=u.split("/");a&&a.parent&&a.parent.key.value==="parameters"&&l[1]==="paths"&&m(a.parent.parent).forEach(d=>{if(d.key.value!=="parameters"){const y=`${l.slice(0,3).join("/")}/${d.key.value}`;s.push(...f(y,n,t,o,r))}})}r=[e,...r];const p=k(e,n.body);return p&&!o.has(p.pointer)&&(o.add(p.pointer),p.indexes.forEach(a=>{const l=g(a,n);s.push(...f(l,n,t,o,r))})),s},v=(e,n)=>e.map(t=>n[t.pointer]).filter(t=>typeof t<"u"),B=(e,n)=>{const t=n.body.split(`
`);let o=0;for(let s=0;s<e-1;s++)t[s][0]==="\r"&&o++,o+=t[s].length+1;let r=0;for(;t[e-1][r]===" "||t[e-1][r]==="	"||t[e-1][r]==="-";)o++,r++;return o},E=(e,n,t)=>{const o=B(e,n);return g(o,n,t)},g=(e,n,t)=>{const o=n.getAst(c.safeLoad),{nodePath:r}=h(o,e,t??0);return"#/"+r.join("/")},h=(e,n,t,o=[])=>{if(t&&o.length===t)return{node:e,nodePath:o};const r=m(e),s=r.findIndex(i=>{if(i.startPosition<=n&&i.endPosition>=n)return!0});if(s!==-1){const i=r[s],u=N(o,e,i,s);return h(i,n,t,u)}return{node:e,nodePath:o}};function m(e){switch(e?.kind){case c.Kind.MAPPING:return[e.key,e.value];case c.Kind.MAP:return e.mappings;case c.Kind.SEQ:return e?.items;default:return[]}}function N(e,n,t,o){return n?.kind===c.Kind.SEQ?[...e,o]:t?.kind===c.Kind.MAPPING&&t?.key?.value&&typeof t.key.value=="string"?[...e,t.key.value.replace(/\//g,"~1")]:e}function R(e,n){const t=P({pointer:e,source:n}),o={lineNumber:t.start.line,column:t.start.col},r=t.end?{lineNumber:t.end.line,column:t.end.col}:void 0;return{start:o,end:r}}export{h as getAstNodeByStartPosition,m as getChildNodes,E as getPointerByLine,g as getPointerByStartPosition,R as getPointerPosition,f as getPointerUsed,L as getRoutesByLine,K as getRoutesByLines,v as getRoutesWhereUsed,B as getStartPositionByLine};
