1import{i as x,y as H}from"./index-CTbswPI0.js";const L=/_key\s*==\s*['"](.*)['"]/;function K(e){return typeof e=="string"?L.test(e.trim()):typeof e=="object"&&"_key"in e}function N(e){if(!Array.isArray(e))throw new Error("Path is not an array");return e.reduce((t,r,i)=>{const n=typeof r;if(n==="number")return`${t}[${r}]`;if(n==="string")return`${t}${i===0?"":"."}${r}`;if(K(r)&&r._key)return`${t}[_key=="${r._key}"]`;if(Array.isArray(r)){const[s,o]=r;return`${t}[${s}:${o}]`}throw new Error(`Unsupported path segment \`${JSON.stringify(r)}\``)},"")}const S={"\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","'":"\\'","\\":"\\\\"},I={"\\f":"\f","\\n":` 2`,"\\r":"\r","\\t":" ","\\'":"'","\\\\":"\\"};function X(e){return`$${e.map(t=>typeof t=="string"?`['${t.replace(/[\f\n\r\t'\\]/g,r=>S[r])}']`:typeof t=="number"?`[${t}]`:t._key!==""?`[?(@._key=='${t._key.replace(/['\\]/g,r=>S[r])}')]`:`[${t._index}]`).join("")}`}function B(e){return e.map(t=>typeof t=="string"?`['${t.replace(/[\f\n\r\t'\\]/g,r=>S[r])}']`:typeof t=="number"?`[${t}]`:t._key!==""?`[?(@._key=='${t._key.replace(/['\\]/g,r=>S[r])}')]`:`[${t._index}]`)}function j(e){const t=[],r=/\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;let i;for(;(i=r.exec(e))!==null;){if(i[1]!==void 0){const n=i[1].replace(/\\(\\|f|n|r|t|')/g,s=>I[s]);t.push(n);continue}if(i[2]!==void 0){t.push(parseInt(i[2],10));continue}if(i[3]!==void 0){const n=i[3].replace(/\\(\\')/g,s=>I[s]);t.push({_key:n,_index:-1});continue}}return t}function W(e){return e.map(t=>{if(typeof t=="string"||typeof t=="number")return t;if(t._key!=="")return{_key:t._key};if(t._index!==-1)return t._index;throw new Error(`invalid segment:${JSON.stringify(t)}`)})}function T(e){return e.map(t=>{if(typeof t=="string"||typeof t=="number")return t;if(t._index!==-1)return t._index;throw new Error(`invalid segment:${JSON.stringify(t)}`)})}function Q(e,t){if(!(t!=null&&t.mappings))return;const r=X(T(e));if(t.mappings[r]!==void 0)return{mapping:t.mappings[r],matchedPath:r,pathSuffix:""};const i=B(T(e));for(let n=i.length-1;n>=0;n--){const s=`$${i.slice(0,n).join("")}`,o=t.mappings[s];if(o){const u=r.substring(s.length);return{mapping:o,matchedPath:s,pathSuffix:u}}}}function Y(e){return e!==null&&Array.isArray(e)}function $(e,t,r=[]){if(Y(e))return e.map((i,n)=>{if(x(i)){const s=i._key;if(typeof s=="string")return $(i,t,r.concat({_key:s,_index:n}))}return $(i,t,r.concat(n))});if(x(e)){if(e._type==="block"||e._type==="span"){const i={...e};return e._type==="block"?i.children=$(e.children,t,r.concat("children")):e._type==="span"&&(i.text=$(e.text,t,r.concat("text"))),i}return Object.fromEntries(Object.entries(e).map(([i,n])=>[i,$(n,t,r.concat(i))]))}return t(e,r)}function Z(e,t,r){return $(e,(i,n)=>{if(typeof i!="string")return i;const s=Q(n,t);if(!s)return i;const{mapping:o,matchedPath:u}=s;if(o.type!=="value"||o.source.type!=="documentValue")return i;const h=t.documents[o.source.document],f=t.paths[o.source.path],d=j(u),y=j(f).concat(n.slice(d.length));return r({sourcePath:y,sourceDocument:h,resultPath:n,value:i})})}const v="drafts",g="versions",E=".",C=`${v}${E}`,tt=`${g}${E}`;function V(e){return e.startsWith(C)}function R(e){return e.startsWith(tt)}function et(e){return!V(e)&&!R(e)}function nt(e){if(!R(e))return;const[t,r]=e.split(E);return r}function rt(e){return R(e)?e.split(E).slice(2).join(E):V(e)?e.slice(C.length):e}function it(e){const{baseUrl:t,workspace:r="default",tool:i="default",id:n,type:s,path:o,projectId:u,dataset:h}=e;if(!t)throw new Error("baseUrl is required");if(!o)throw new Error("path is required");if(!n)throw new Error("id is required");if(t!=="/"&&t.endsWith("/"))throw new Error("baseUrl must not end with a slash");const f=r==="default"?void 0:r,d=i==="default"?void 0:i,y=rt(n),k=Array.isArray(o)?N(W(o)):o,c=new URLSearchParams({baseUrl:t,id:y,type:s,path:k});if(f&&c.set("workspace",f),d&&c.set("tool",d),u&&c.set("projectId",u),h&&c.set("dataset",h),et(n))c.set("perspective","published");else if(R(n)){const m=nt(n);c.set("perspective",m)}const l=[t==="/"?"":t];f&&l.push(f);const w=["mode=presentation",`id=${y}`,`type=${s}`,`path=${encodeURIComponent(k)}`];return d&&w.push(`tool=${d}`),l.push("intent","edit",`${w.join(";")}?${c}`),l.join("/")}function ot(e){let t=typeof e=="string"?e:e.baseUrl;return t!=="/"&&(t=t.replace(/\/$/,"")),typeof e=="string"?{baseUrl:t}:{...e,baseUrl:t}}const U=({sourcePath:e,resultPath:t,value:r})=>{if(at(r)||ct(r))return!1;const i=e.at(-1);return!(e.at(-2)==="slug"&&i==="current"||typeof i=="string"&&(i.startsWith("_")||i.endsWith("Id"))||e.some(n=>n==="meta"||n==="metadata"||n==="openGraph"||n==="seo")||O(e)||O(t)||typeof i=="string"&&st.has(i))},st=new Set(["color","colour","currency","email","format","gid","hex","href","hsl","hsla","icon","id","index","key","language","layout","link","linkAction","locale","lqip","page","path","ref","rgb","rgba","route","secret","slug","status","tag","template","theme","type","textTheme","unit","url","username","variant","website"]);function at(e){return/^\d{4}-\d{2}-\d{2}/.test(e)?!!Date.parse(e):!1}const pt=new Set(["app:","data:","discord:","file:","ftp:","ftps:","geo:","http:","https:","imap:","javascript:","magnet:","mailto:","maps:","ms-excel:","ms-powerpoint:","ms-word:","slack:","sms:","spotify:","steam:","teams:","tel:","vscode:","zoom:"]);function ct(e){try{const{protocol:t}=new URL(e,e.startsWith("/")?"https://acme.com":void 0);return pt.has(t)||t.startsWith("web+")}catch{return!1}}function O(e){return e.some(t=>typeof t=="string"&&t.match(/type/i)!==null)}const P=20;function ft(e,t,r){var h,f,d,y,k,c,l,w,m;const{filter:i,logger:n,enabled:s}=r;if(!s){const a="config.enabled must be true, don't call this function otherwise";throw(h=n==null?void 0:n.error)==null||h.call(n,`[@sanity/client]: ${a}`,{result:e,resultSourceMap:t,config:r}),new TypeError(a)}
2if(!t)return(f=n==null?void 0:n.error)==null||f.call(n,"[@sanity/client]: Missing Content Source Map from response body",{result:e,resultSourceMap:t,config:r}),e;if(!r.studioUrl){const a="config.studioUrl must be defined";throw(d=n==null?void 0:n.error)==null||d.call(n,`[@sanity/client]: ${a}`,{result:e,resultSourceMap:t,config:r}),new TypeError(a)}const o={encoded:[],skipped:[]},u=Z(e,t,({sourcePath:a,sourceDocument:_,resultPath:b,value:p})=>{if((typeof i=="function"?i({sourcePath:a,resultPath:b,filterDefault:U,sourceDocument:_,value:p}):U({sourcePath:a,resultPath:b,value:p}))===!1)return n&&o.skipped.push({path:D(a),value:`${p.slice(0,P)}${p.length>P?"...":""}`,length:p.length}),p;n&&o.encoded.push({path:D(a),value:`${p.slice(0,P)}${p.length>P?"...":""}`,length:p.length});const{baseUrl:A,workspace:M,tool:q}=ot(typeof r.studioUrl=="function"?r.studioUrl(_):r.studioUrl);if(!A)return p;const{_id:F,_type:J,_projectId:z,_dataset:G}=_;return H(p,{origin:"sanity.io",href:it({baseUrl:A,workspace:M,tool:q,id:F,type:J,path:a,...!r.omitCrossDatasetReferenceData&&{dataset:G,projectId:z}})},!1)});if(n){const a=o.skipped.length,_=o.encoded.length;if((a||_)&&((y=(n==null?void 0:n.groupCollapsed)||n.log)==null||y("[@sanity/client]: Encoding source map into result"),(k=n.log)==null||k.call(n,`[@sanity/client]: Paths encoded: ${o.encoded.length}, skipped: ${o.skipped.length}`)),o.encoded.length>0&&((c=n==null?void 0:n.log)==null||c.call(n,"[@sanity/client]: Table of encoded paths"),(l=(n==null?void 0:n.table)||n.log)==null||l(o.encoded)),o.skipped.length>0){const b=new Set;for(const{path:p}of o.skipped)b.add(p.replace(L,"0").replace(/\[\d+\]/g,"[]"));(w=n==null?void 0:n.log)==null||w.call(n,"[@sanity/client]: List of skipped paths",[...b.values()])}(a||_)&&((m=n==null?void 0:n.groupEnd)==null||m.call(n))}return u}function D(e){return N(W(e))}var ut=Object.freeze({__proto__:null,stegaEncodeSourceMap:ft});export{Z as encodeIntoResult,ft as stegaEncodeSourceMap,ut as stegaEncodeSourceMap$1};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.