import{s as V,n as O,o as K}from"../chunks/scheduler.d6170356.js";import{S as ee,i as te,g as l,s as n,r as k,A as ae,h as i,f as a,c as p,j as X,u as P,x as M,k as F,y as se,a as s,v as E,d as I,t as z,w as B}from"../chunks/index.fcd4cc08.js";import{C as ne}from"../chunks/CodeBlock.db16bf50.js";import{H as pe,E as le}from"../chunks/index.9f2da87a.js";function ie(Q){let o,U,T,$,r,_,c,A="You can use URL query parameters as a data sharing mechanism, for instance to be able to deep-link into an app with a specific state.",v,h,N="On a Space page (<code>https://huggingface.co/spaces/&lt;user&gt;/&lt;app&gt;</code>), the actual application page (<code>https://*.hf.space/</code>) is embedded in an iframe. The query string and the hash attached to the parent page URL are propagated to the embedded app on initial load, so the embedded app can read these values without special consideration.",x,d,Y=`In contrast, updating the query string and the hash of the parent page URL from the embedded app is slightly more complex.
If you want to do this in a Docker or static Space, you need to add the following JS code that sends a message to the parent page that has a <code>queryString</code> and/or <code>hash</code> key.`,C,m,L,u,Z="<strong>This is only for Docker or static Spaces.</strong>",S,f,D="For Streamlit apps, Spaces automatically syncs the URL parameters. Gradio apps can read the query parameters from the Spaces page, but do not sync updated URL parameters with the parent page.",J,g,G="Note that the URL parameters of the parent page are propagated to the embedded app <em>only</em> on the initial load. So <code>location.hash</code> in the embedded app will not change even if the parent URL hash is updated using this method.",j,y,W=`An example of this method can be found in this static Space,
<a href="https://huggingface.co/spaces/whitphx/static-url-param-sync-example" rel="nofollow"><code>whitphx/static-url-param-sync-example</code></a>.`,H,w,q,b,R;return r=new pe({props:{title:"How to handle URL parameters in Spaces",local:"how-to-handle-url-parameters-in-spaces",headingTag:"h1"}}),m=new ne({props:{code:"Y29uc3QlMjBxdWVyeVN0cmluZyUyMCUzRCUyMCUyMi4uLiUyMiUzQiUwQWNvbnN0JTIwaGFzaCUyMCUzRCUyMCUyMi4uLiUyMiUzQiUwQSUwQXdpbmRvdy5wYXJlbnQucG9zdE1lc3NhZ2UoJTdCJTBBJTIwJTIwJTIwJTIwcXVlcnlTdHJpbmclMkMlMEElMjAlMjAlMjAlMjBoYXNoJTJDJTBBJTdEJTJDJTIwJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyMiklM0I=",highlighted:`<span class="hljs-keyword">const</span> queryString = <span class="hljs-string">&quot;...&quot;</span>;
<span class="hljs-keyword">const</span> hash = <span class="hljs-string">&quot;...&quot;</span>;

<span class="hljs-variable language_">window</span>.<span class="hljs-property">parent</span>.<span class="hljs-title function_">postMessage</span>({
    queryString,
    hash,
}, <span class="hljs-string">&quot;https://huggingface.co&quot;</span>);`,wrap:!1}}),w=new le({props:{source:"https://github.com/huggingface/hub-docs/blob/main/docs/hub/spaces-handle-url-parameters.md"}}),{c(){o=l("meta"),U=n(),T=l("p"),$=n(),k(r.$$.fragment),_=n(),c=l("p"),c.textContent=A,v=n(),h=l("p"),h.innerHTML=N,x=n(),d=l("p"),d.innerHTML=Y,C=n(),k(m.$$.fragment),L=n(),u=l("p"),u.innerHTML=Z,S=n(),f=l("p"),f.textContent=D,J=n(),g=l("p"),g.innerHTML=G,j=n(),y=l("p"),y.innerHTML=W,H=n(),k(w.$$.fragment),q=n(),b=l("p"),this.h()},l(e){const t=ae("svelte-u9bgzb",document.head);o=i(t,"META",{name:!0,content:!0}),t.forEach(a),U=p(e),T=i(e,"P",{}),X(T).forEach(a),$=p(e),P(r.$$.fragment,e),_=p(e),c=i(e,"P",{"data-svelte-h":!0}),M(c)!=="svelte-13bdlzr"&&(c.textContent=A),v=p(e),h=i(e,"P",{"data-svelte-h":!0}),M(h)!=="svelte-12t98gf"&&(h.innerHTML=N),x=p(e),d=i(e,"P",{"data-svelte-h":!0}),M(d)!=="svelte-ngy7gm"&&(d.innerHTML=Y),C=p(e),P(m.$$.fragment,e),L=p(e),u=i(e,"P",{"data-svelte-h":!0}),M(u)!=="svelte-1pi7s18"&&(u.innerHTML=Z),S=p(e),f=i(e,"P",{"data-svelte-h":!0}),M(f)!=="svelte-mvq3g"&&(f.textContent=D),J=p(e),g=i(e,"P",{"data-svelte-h":!0}),M(g)!=="svelte-zn49j8"&&(g.innerHTML=G),j=p(e),y=i(e,"P",{"data-svelte-h":!0}),M(y)!=="svelte-1ft72d"&&(y.innerHTML=W),H=p(e),P(w.$$.fragment,e),q=p(e),b=i(e,"P",{}),X(b).forEach(a),this.h()},h(){F(o,"name","hf:doc:metadata"),F(o,"content",oe)},m(e,t){se(document.head,o),s(e,U,t),s(e,T,t),s(e,$,t),E(r,e,t),s(e,_,t),s(e,c,t),s(e,v,t),s(e,h,t),s(e,x,t),s(e,d,t),s(e,C,t),E(m,e,t),s(e,L,t),s(e,u,t),s(e,S,t),s(e,f,t),s(e,J,t),s(e,g,t),s(e,j,t),s(e,y,t),s(e,H,t),E(w,e,t),s(e,q,t),s(e,b,t),R=!0},p:O,i(e){R||(I(r.$$.fragment,e),I(m.$$.fragment,e),I(w.$$.fragment,e),R=!0)},o(e){z(r.$$.fragment,e),z(m.$$.fragment,e),z(w.$$.fragment,e),R=!1},d(e){e&&(a(U),a(T),a($),a(_),a(c),a(v),a(h),a(x),a(d),a(C),a(L),a(u),a(S),a(f),a(J),a(g),a(j),a(y),a(H),a(q),a(b)),a(o),B(r,e),B(m,e),B(w,e)}}}const oe='{"title":"How to handle URL parameters in Spaces","local":"how-to-handle-url-parameters-in-spaces","sections":[],"depth":1}';function re(Q){return K(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ue extends ee{constructor(o){super(),te(this,o,re,ie,V,{})}}export{ue as component};
