1import{i as S}from"./index-BpCiARvf.js";const T=/_key\s*==\s*['"](.*)['"]/;function H(t){return typeof t=="string"?T.test(t.trim()):typeof t=="object"&&"_key"in t}function O(t){if(!Array.isArray(t))throw new Error("Path is not an array");return t.reduce((e,r,o)=>{const n=typeof r;if(n==="number")return`${e}[${r}]`;if(n==="string")return`${e}${o===0?"":"."}${r}`;if(H(r)&&r._key)return`${e}[_key=="${r._key}"]`;if(Array.isArray(r)){const[i,s]=r;return`${e}[${i}:${s}]`}throw new Error(`Unsupported path segment \`${JSON.stringify(r)}\``)},"")}const m={"\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","'":"\\'","\\":"\\\\"},P={"\\f":"\f","\\n":` 2`,"\\r":"\r","\\t":" ","\\'":"'","\\\\":"\\"};function V(t){return`$${t.map(e=>typeof e=="string"?`['${e.replace(/[\f\n\r\t'\\]/g,r=>m[r])}']`:typeof e=="number"?`[${e}]`:e._key!==""?`[?(@._key=='${e._key.replace(/['\\]/g,r=>m[r])}')]`:`[${e._index}]`).join("")}`}function M(t){return t.map(e=>typeof e=="string"?`['${e.replace(/[\f\n\r\t'\\]/g,r=>m[r])}']`:typeof e=="number"?`[${e}]`:e._key!==""?`[?(@._key=='${e._key.replace(/['\\]/g,r=>m[r])}')]`:`[${e._index}]`)}function R(t){const e=[],r=/\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;let o;for(;(o=r.exec(t))!==null;){if(o[1]!==void 0){const n=o[1].replace(/\\(\\|f|n|r|t|')/g,i=>P[i]);e.push(n);continue}if(o[2]!==void 0){e.push(parseInt(o[2],10));continue}if(o[3]!==void 0){const n=o[3].replace(/\\(\\')/g,i=>P[i]);e.push({_key:n,_index:-1});continue}}return e}function U(t){return t.map(e=>{if(typeof e=="string"||typeof e=="number")return e;if(e._key!=="")return{_key:e._key};if(e._index!==-1)return e._index;throw new Error(`invalid segment:${JSON.stringify(e)}`)})}function I(t){return t.map(e=>{if(typeof e=="string"||typeof e=="number")return e;if(e._index!==-1)return e._index;throw new Error(`invalid segment:${JSON.stringify(e)}`)})}function F(t,e){if(!e?.mappings)return;const r=V(I(t));if(e.mappings[r]!==void 0)return{mapping:e.mappings[r],matchedPath:r,pathSuffix:""};const o=M(I(t));for(let n=o.length-1;n>=0;n--){const i=`$${o.slice(0,n).join("")}`,s=e.mappings[i];if(s){const u=r.substring(i.length);return{mapping:s,matchedPath:i,pathSuffix:u}}}}function J(t){return t!==null&&Array.isArray(t)}function l(t,e,r=[]){if(J(t))return t.map((o,n)=>{if(S(o)){const i=o._key;if(typeof i=="string")return l(o,e,r.concat({_key:i,_index:n}))}return l(o,e,r.concat(n))});if(S(t)){if(t._type==="block"||t._type==="span"){const o={...t};return t._type==="block"?o.children=l(t.children,e,r.concat("children")):t._type==="span"&&(o.text=l(t.text,e,r.concat("text"))),o}return Object.fromEntries(Object.entries(t).map(([o,n])=>[o,l(n,e,r.concat(o))]))}return e(t,r)}function q(t,e,r){return l(t,(o,n)=>{if(typeof o!="string")return o;const i=F(n,e);if(!i)return o;const{mapping:s,matchedPath:u}=i;if(s.type!=="value"||s.source.type!=="documentValue")return o;const a=e.documents[s.source.document],p=e.paths[s.source.path],f=R(u),c=R(p).concat(n.slice(f.length));return r({sourcePath:c,sourceDocument:a,resultPath:n,value:o})})}const G="drafts",X="versions",g=".",D=`${G}${g}`,z=`${X}${g}`;function L(t){return t.startsWith(D)}function w(t){return t.startsWith(z)}function K(t){return!L(t)&&!w(t)}function Z(t){if(!w(t))return;const[e,r]=t.split(g);return r}function B(t){return w(t)?t.split(g).slice(2).join(g):L(t)?t.slice(D.length):t}function Y(t){const{baseUrl:e,workspace:r="default",tool:o="default",id:n,type:i,path:s,projectId:u,dataset:a}=t;if(!e)throw new Error("baseUrl is required");if(!s)throw new Error("path is required");if(!n)throw new Error("id is required");if(e!=="/"&&e.endsWith("/"))throw new Error("baseUrl must not end with a slash");const p=r==="default"?void 0:r,f=o==="default"?void 0:o,c=B(n),h=Array.isArray(s)?O(U(s)):s,d=new URLSearchParams({baseUrl:e,id:c,type:i,path:h});if(p&&d.set("workspace",p),f&&d.set("tool",f),u&&d.set("projectId",u),a&&d.set("dataset",a),K(n))d.set("perspective","published");else if(w(n)){const b=Z(n);d.set("perspective",b)}const y=[e==="/"?"":e];p&&y.push(p);const _=["mode=presentation",`id=${c}`,`type=${i}`,`path=${encodeURIComponent(h)}`];return f&&_.push(`tool=${f}`),y.push("intent","edit",`${_.join(";")}?${d}`),y.join("/")}function Q(t){let e=typeof t=="string"?t:t.baseUrl;return e!=="/"&&(e=e.replace(/\/$/,"")),typeof t=="string"?{baseUrl:e}:{...t,baseUrl:e}}const A=({sourcePath:t,resultPath:e,value:r})=>{if(tt(r)||rt(r))return!1;const o=t.at(-1);
2return!(t.at(-2)==="slug"&&o==="current"||typeof o=="string"&&(o.startsWith("_")||o.endsWith("Id"))||t.some(n=>n==="meta"||n==="metadata"||n==="openGraph"||n==="seo")||j(t)||j(e)||typeof o=="string"&&v.has(o))},v=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 tt(t){return/^\d{4}-\d{2}-\d{2}/.test(t)?!!Date.parse(t):!1}const et=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 rt(t){try{const{protocol:e}=new URL(t,t.startsWith("/")?"https://acme.com":void 0);return et.has(e)||e.startsWith("web+")}catch{return!1}}function j(t){return t.some(e=>typeof e=="string"&&e.match(/type/i)!==null)}const E=[8203,8204,8205,65279],$=E.map(t=>String.fromCharCode(t)),C=[8203,8204,8205,8290,8291,8288,65279,8289,119155,119156,119157,119158,119159,119160,119161,119162];Object.fromEntries(E.map((t,e)=>[t,e]));Object.fromEntries(C.map((t,e)=>[t,e.toString(16)]));const nt=String.fromCodePoint(E[0]).repeat(4),ot=[...E,...C];ot.map(t=>`\\u{${t.toString(16)}}`).join("");function it(t){if(t===void 0)return"";const e=typeof t=="string"?t:JSON.stringify(t),r=new TextEncoder().encode(e);let o="";for(let n=0;n<r.length;n++){const i=r[n];o+=$[i>>6&3]+$[i>>4&3]+$[i>>2&3]+$[i&3]}return nt+o}function st(t,e,r="auto"){return r===!0||r==="auto"&&!ct(t)&&!at(t)?`${t}${it(e)}`:t}function at(t){try{return new URL(t,t.startsWith("/")?"https://example.com":void 0),!0}catch{return!1}}function ct(t){return!t||typeof t!="string"?!1:!!Date.parse(t)}const k=20;function pt(t,e,r){const{filter:o,logger:n,enabled:i}=r;if(!i){const a="config.enabled must be true, don't call this function otherwise";throw n?.error?.(`[@sanity/client]: ${a}`,{result:t,resultSourceMap:e,config:r}),new TypeError(a)}if(!e)return n?.error?.("[@sanity/client]: Missing Content Source Map from response body",{result:t,resultSourceMap:e,config:r}),t;if(!r.studioUrl){const a="config.studioUrl must be defined";throw n?.error?.(`[@sanity/client]: ${a}`,{result:t,resultSourceMap:e,config:r}),new TypeError(a)}const s={encoded:[],skipped:[]},u=q(t,e,({sourcePath:a,sourceDocument:p,resultPath:f,value:c})=>{if((typeof o=="function"?o({sourcePath:a,resultPath:f,filterDefault:A,sourceDocument:p,value:c}):A({sourcePath:a,resultPath:f,value:c}))===!1)return n&&s.skipped.push({path:x(a),value:`${c.slice(0,k)}${c.length>k?"...":""}`,length:c.length}),c;n&&s.encoded.push({path:x(a),value:`${c.slice(0,k)}${c.length>k?"...":""}`,length:c.length});const{baseUrl:h,workspace:d,tool:y}=Q(typeof r.studioUrl=="function"?r.studioUrl(p):r.studioUrl);if(!h)return c;const{_id:_,_type:b,_projectId:W,_dataset:N}=p;return st(c,{origin:"sanity.io",href:Y({baseUrl:h,workspace:d,tool:y,id:_,type:b,path:a,...!r.omitCrossDatasetReferenceData&&{dataset:N,projectId:W}})},!0)});if(n){const a=s.skipped.length,p=s.encoded.length;if((a||p)&&((n?.groupCollapsed||n.log)?.("[@sanity/client]: Encoding source map into result"),n.log?.(`[@sanity/client]: Paths encoded: ${s.encoded.length}, skipped: ${s.skipped.length}`)),s.encoded.length>0&&(n?.log?.("[@sanity/client]: Table of encoded paths"),(n?.table||n.log)?.(s.encoded)),s.skipped.length>0){const f=new Set;for(const{path:c}of s.skipped)f.add(c.replace(T,"0").replace(/\[\d+\]/g,"[]"));n?.log?.("[@sanity/client]: List of skipped paths",[...f.values()])}(a||p)&&n?.groupEnd?.()}return u}function x(t){return O(U(t))}var dt=Object.freeze({__proto__:null,stegaEncodeSourceMap:pt});export{q as encodeIntoResult,pt as stegaEncodeSourceMap,dt 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.