@playpilot/tpi 5.10.0 → 5.10.1

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.
@@ -9,6 +9,6 @@ var ja=Object.defineProperty;var Di=e=>{throw TypeError(e)};var La=(e,t,n)=>t in
9
9
 
10
10
  `)}function Ec(e,t={aiInjections:[],manualInjections:[]}){Pi(),Nc();const n=Dc(t);if(!n)return[];const i=Oe(e.map(u=>u.innerText).join(" ")),r=Oc(n),a=r.filter(u=>i.includes(Oe(u.sentence))),l={};let s=-1;for(const u of a){s++;const d=e.findIndex(j=>Oe(j.innerText).includes(Oe(u.sentence))),v=e[d];if(!v)continue;const f=tr(u.title,v,["A"]);if(!(f!=null&&f.nodeValue)||nr(f)){const j=tr(u.title,v);if(j&&nr(j)){l[u.key]="Given text is already inside of a link.";continue}}const{injectionElement:p,linkElement:m}=Tc(u),{phrase_before:_,phrase_after:k}=u;let w=-1,g=!1;if(pc(v.innerHTML,u.title)===1&&(w=v.innerHTML.indexOf(u.title)),w===-1&&(_||k)){const j=[_,u.title,k].filter(Boolean).join(" ");if(w=v.innerHTML.indexOf(j),w===-1){const b=kc(v.innerHTML,u.title,_||"",k||"");if(b){const{leadingSpaces:C,trailingSpaces:I}=wc(b.match);m.innerHTML=b.match.trim();const E=b.index+C,T=b.index+b.match.length-I;v.innerHTML=gc(v.innerHTML,p.outerHTML,E,T),w=b.index,g=!0}}}if(w===-1&&(f!=null&&f.nodeValue)){const j=v.innerHTML.indexOf(f.nodeValue),b=v.innerHTML.indexOf(u.sentence),C=fc(a.slice(0,s+1),u,["title","sentence"])-1,I=bc(f.nodeValue,v,C);w=Math.max(j,I,b,0)}w!==-1&&(g||Ic(v.innerHTML,u.title,v,p,w)||(l[u.key]="Injection would have lead to broken HTML."))}Pc(r),Ac();const c=Rc(n);return c.length&&jc(e,c),n.filter(u=>u.title_details).map((u,d)=>{const v=u.duplicate??(!u.manual&&qc(u,d,n)),f=document.querySelector(`[${gt}="${u.key}"]`),p=qn(u)&&!u.inactive&&!u.after_article&&!f,m=!!e.find(k=>Oe(k.innerText).includes(Oe(u.sentence))),_=p?l[u.key]||(m?"The link failed to inject for unknown reasons.":"Given sentence was not found in the article."):"";return{...u,inactive:u.inactive??!1,duplicate:v,failed:p,failed_message:_}})}function Tc(e){const t=document.createElement("span");t.dataset.playpilotInjectionKey=e.key;const n=document.createElement("a");return n.innerText=e.title,n.href=e.playpilot_url,n.target="_blank",n.rel="noopener nofollow noreferrer",t.insertAdjacentElement("beforeend",n),{injectionElement:t,linkElement:n}}function Ic(e,t,n,i,r){const a=document.createElement("div");a.innerHTML=e;const l=Array.from(a.querySelectorAll("a")).filter(c=>c.innerText).length;return a.innerHTML=hc(e,t,i.outerHTML,r),Array.from(a.querySelectorAll("a")).filter(c=>c.innerText).length!=l+1?!1:(n.innerHTML=a.innerHTML,!0)}function Ac(){const e=Array.from(document.querySelectorAll(`${Dt} a`)),t=["--playpilot-injection-text-color","--playpilot-injection-text-color-hover","--playpilot-injection-font-weight","--playpilot-injection-font-weight-headings","--playpilot-injection-text-decoration","--playpilot-injection-text-decoration-hover","--playpilot-injection-background-color","--playpilot-injection-background-color-hover"];e.forEach(n=>{t.forEach(i=>{getComputedStyle(n).getPropertyValue(i)&&(n.dataset.usedCssVariables=`${n.dataset.usedCssVariables||""} ${i}`)})})}function Pc(e){window.addEventListener("click",n=>{if(va(n))return;let i=n.target;if(!i||(i.hasAttribute(gt)||(i=i.closest(Dt)),!i))return;const r=i.getAttribute(gt);if(!r)return;const a=e.find(l=>r===l.key);a&&(n.preventDefault(),Sc(()=>{An(!1),ha(n,a)},!Si.current&&window.innerWidth>=pi&&!window.matchMedia("(pointer: coarse)").matches))}),window.addEventListener("mousemove",n=>{if(!mt)return;const i=n.target;i.hasAttribute("data-playpilot-title-popover")||i.closest("[data-playpilot-title-popover]")||i.hasAttribute(gt)||i.closest(Dt)||An()}),Array.from(document.querySelectorAll(Dt)).forEach(n=>{const i=n.dataset.playpilotInjectionKey,r=e.find(a=>i===a.key);r&&(n.addEventListener("mouseenter",a=>{mt||Cc(a,r)}),n.addEventListener("mouseleave",()=>In=null))})}function ha(e,t){va(e)||Zt||(e.preventDefault(),Zt=dn(Zs,{target:wa(),props:{title:t.title_details,onclose:ga}}))}function ga(e=!0){Zt&&(Rn(Zt,{outro:e}),Zt=null)}function Cc(e,t){if(window.matchMedia("(pointer: coarse)").matches)return;mt&&An();const n=e.currentTarget;In=n,setTimeout(()=>{In===n&&(mt=dn(ec,{target:wa(),props:{event:e,title:t.title_details}}))},100)}function An(e=!0){if(!mt){document.querySelectorAll("[data-playpilot-title-popover]").forEach(t=>t.remove());return}Rn(mt,{outro:e}),In=null,mt=null}function jc(e,t){var l,s;if(Yt||!t.length)return;const n=document.createElement("div"),i=(l=window.PlayPilotLinkInjections)==null?void 0:l.after_article_selector,r=(i?document.querySelector(i):null)||e[e.length-1],a=((s=window.PlayPilotLinkInjections)==null?void 0:s.after_article_insert_position)||"afterend";n.dataset.playpilotAfterArticlePlaylinks="true",r.insertAdjacentElement(a,n),Yt=dn(dc,{target:n,props:{linkInjections:t,onclickmodal:(c,u)=>ha(c,u)}})}function Lc(){var e;Yt&&(Rn(Yt),(e=document.querySelector("[data-playpilot-after-article-playlinks]"))==null||e.remove(),Yt=null)}function Pi(){document.querySelectorAll(Dt).forEach(t=>Mc(t.getAttribute(gt)||"")),Lc(),ga(!1),An(!1)}function Mc(e){var i;const t=document.querySelector(`[${gt}="${e}"]`);if(!t)return;const n=(i=t.querySelector("a"))==null?void 0:i.innerHTML;t.outerHTML=n||""}function Nc(){document.querySelectorAll('a[href*="playpilot.com"]').forEach(t=>{t.closest(Dt)||/\/movie|show\//.test(t.href)&&(t.outerHTML=t.innerHTML)})}function Dc({aiInjections:e,manualInjections:t}){return[...t.map(n=>({...n,manual:!0})),...e]}function ma(e){return{aiInjections:e.filter(t=>!t.manual),manualInjections:e.filter(t=>t.manual)}}function pa(e){return!e.inactive&&!e.removed&&!e.duplicate&&!!e.title_details&&qn(e)}function qn(e){return e.in_text||e.in_text===void 0?!0:!!e.after_article}function Oc(e){return ya(e).filter(t=>t.in_text!==!1&&pa(t))}function Rc(e){return ya(e).filter(t=>t.after_article===!0&&pa(t))}function ya(e){return e.filter(t=>t.removed||t.inactive?!1:t.manual&&!t.removed&&!t.inactive?!0:!e.some(n=>n.manual&&(n.removed||n.inactive)&&ka(n,t)))}function qc(e,t,n){return n.some((i,r)=>t!==r&&i.manual&&ka(i,e))}function ka(e,t){return e.title===t.title&&Oe(e.sentence)===Oe(t.sentence)}function wa(){return document.querySelector("[data-playpilot-link-injections]")||document.body}function Ci(){const e=Rt();return{content_heading:Hc(e),content_modified_time:Bc(e),content_published_time:Fc(e)}}function Hc(e){const t=e.querySelector("h1")||document.querySelector("h1");return(t==null?void 0:t.innerText.trim())||null}function Bc(e){const t=document.querySelector('meta[property*="modified_time"]')||document.querySelector('meta[name*="modified_time"]')||e.querySelector('[itemprop="dateModified"]')||document.querySelector('[itemprop="dateModified"]')||null,n=(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?ji(n):null}function Fc(e){const t=document.querySelector('meta[property*="published_time"]')||document.querySelector('meta[name*="published_time"]')||e.querySelector('[itemprop="datePublished"]')||document.querySelector('[itemprop="datePublished"]')||e.querySelector("time")||document.querySelector("time")||e.querySelector("[datetime]")||document.querySelector("[datetime]")||null,n=(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?ji(n):null}function ji(e){try{return new Date(e).toISOString()}catch{return null}}let Un=null;async function vn(e,{url:t=yi(),hash:n=Ml(e||""),params:i={}}={}){const r=new Headers({"Content-Type":"application/json"}),a=_n(),l=ia()?await na():!1,s=aa();if(!a)throw new Error("No token was provided");i.metadata=Ci(),i.run_ai&&(i.hash=n,i.page_text=e);const c=await fetch(fn+`/external-pages/?api-token=${a}&include_title_details=true${l?"&editorial_mode_enabled=true":""}&language=${s}`,{headers:r,method:"POST",body:JSON.stringify({url:t,...i})});if(!c.ok)throw c;const u=await c.json();return window.PlayPilotLinkInjections.last_successful_fetch=u,u}async function ar(e,{requireCompletedResult:t=!1,runAiWhenRelevant:n=!1,pollInterval:i=3e3,maxTries:r=600,onpoll:a=()=>null}={}){let l=0;Un&&clearTimeout(Un);const s=async(c,u)=>{let d;try{if(d=await vn(e),n&&(d=await Vc(e,d)),t&&d.ai_enabled&&d.ai_running)throw new Error;d.manual_injections=or(d.manual_injections||[]),d.ai_injections=or(d.ai_injections||[]),c(d);return}catch{if(l++,l>=r){r>1&&console.error("Max poll limit exceeded. Please return later."),c();return}d&&a(d),Un=setTimeout(()=>s(c),i)}};return new Promise(s)}async function Vc(e,t){if(!e||!t.ai_enabled||t.ai_running)return t;const n=Ci().content_modified_time,i=t.content_modified_time?ji(t.content_modified_time):null,r=n&&i===n;return t.ai_last_run&&r?t:await vn(e,{params:{run_ai:!0}})}async function zc(e,t){var l;const n=(l=window.PlayPilotLinkInjections)==null?void 0:l.selector,r=e.filter(s=>s.manual).map(s=>({sid:s.sid,title:s.title,sentence:s.sentence,phrase_before:s.phrase_before,phrase_after:s.phrase_after,playpilot_url:s.playpilot_url,after_article:!!s.after_article,after_article_style:s.after_article_style||null,in_text:s.in_text??!0,inactive:!!s.inactive,removed:!!s.removed}));if(!await vn(t,{params:{private_token:wi(),manual_injections:r,content_text_selector:n}}))throw new Error("saveLinkInjections response was faulty");return e}async function Uc(){const e=new Headers({"Content-Type":"application/json"}),t=_n();if(!t)throw new Error("No token was provided");const n=await fetch(fn+`/domains/config?api-token=${t}`,{headers:e});if(!n.ok)throw n;try{return await n.json()||null}catch{return null}}function or(e){return e.map(t=>({...t,key:ba(t.sid)}))}function ba(e){return e+"-"+ra()}function _n(){var e;return(e=window.PlayPilotLinkInjections)==null?void 0:e.token}function Wc(){const e=navigator.userAgent.toLowerCase();return/bot|crawl|spider|google|baidu|bing|msn|teoma|slurp|yandex|facebookexternalhit|facebot/i.test(e)}var Kc=Ve('<svg width="8" height="4" viewBox="0 0 8 4" fill="none" class="svelte-by11ix"><path d="M1 0.5L4 3.5L7 0.5" stroke="currentColor" stroke-width="0.9975" stroke-linecap="round" stroke-linejoin="round"></path></svg>');function Yc(e,t){const n=H(t,"expanded",3,!1);var i=Kc();D(()=>ie(i,"expanded",n())),y(e,i)}var Zc=Ve('<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none"><circle cx="12" cy="17" r="1" fill="var(--playpilot-warning)"></circle><path d="M12 10L12 14" stroke="var(--playpilot-warning)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M3.44722 18.1056L10.2111 4.57771C10.9482 3.10361 13.0518 3.10362 13.7889 4.57771L20.5528 18.1056C21.2177 19.4354 20.2507 21 18.7639 21H5.23607C3.7493 21 2.78231 19.4354 3.44722 18.1056Z" stroke="var(--playpilot-warning)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>');function Gc(e){var t=Zc();y(e,t)}function Xc(e,t,n){t(!t()),n()(t())}var Jc=P('<button class="switch svelte-91s87b"><div class="label svelte-91s87b"><!></div> <div class="track svelte-91s87b"><div class="knob svelte-91s87b"></div></div></button>');function ti(e,t){le(t,!0);let n=H(t,"active",15),i=H(t,"fullwidth",3,!1),r=H(t,"label",3,""),a=H(t,"onclick",3,()=>null);var l=Jc();l.__click=[Xc,n,a];var s=x(l),c=x(s);qe(c,()=>t.children),D(()=>{re(l,"aria-label",`Toggle ${r()??""} ${(n()?"off":"on")??""}`),ie(l,"active",n()),ie(l,"fullwidth",i())}),y(e,l),se()}ve(["click"]);var Qc=P('<input type="text" autocomplete="off" class="svelte-1vrer3i">');function Li(e,t){let n=H(t,"value",15),i=H(t,"label",3,""),r=H(t,"name",3,""),a=H(t,"readonly",3,!1),l=H(t,"oninput",3,()=>null);var s=Qc();s.__input=function(...c){var u;(u=l())==null||u.apply(this,c)},D(()=>{re(s,"name",r()),re(s,"aria-label",i()),re(s,"placeholder",i()),s.readOnly=a()}),ul(s,n),y(e,s)}ve(["input"]);var $c=Ve('<path d="M13.5833 13.6667L4.41667 13.6667M5.5 1.5H12.5C13.9001 1.5 14.6002 1.5 15.135 1.77248C15.6054 2.01217 15.9878 2.39462 16.2275 2.86502C16.5 3.3998 16.5 4.09987 16.5 5.5V12.5C16.5 13.9001 16.5 14.6002 16.2275 15.135C15.9878 15.6054 15.6054 15.9878 15.135 16.2275C14.6002 16.5 13.9001 16.5 12.5 16.5H5.5C4.09987 16.5 3.3998 16.5 2.86502 16.2275C2.39462 15.9878 2.01217 15.6054 1.77248 15.135C1.5 14.6002 1.5 13.9001 1.5 12.5V5.5C1.5 4.09987 1.5 3.3998 1.77248 2.86502C2.01217 2.39462 2.39462 2.01217 2.86502 1.77248C3.3998 1.5 4.09987 1.5 5.5 1.5Z" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"></path>'),eu=Ve('<path d="M13.5833 8.58342H4.41667M5.5 1.50009H12.5C13.9001 1.50009 14.6002 1.50009 15.135 1.77258C15.6054 2.01226 15.9878 2.39471 16.2275 2.86512C16.5 3.39989 16.5 4.09996 16.5 5.50009V12.5001C16.5 13.9002 16.5 14.6003 16.2275 15.1351C15.9878 15.6055 15.6054 15.9879 15.135 16.2276C14.6002 16.5001 13.9001 16.5001 12.5 16.5001H5.5C4.09987 16.5001 3.3998 16.5001 2.86502 16.2276C2.39462 15.9879 2.01217 15.6055 1.77248 15.1351C1.5 14.6003 1.5 13.9002 1.5 12.5001V5.50009C1.5 4.09996 1.5 3.39989 1.77248 2.86512C2.01217 2.39471 2.39462 2.01226 2.86502 1.77258C3.3998 1.50009 4.09987 1.50009 5.5 1.50009Z" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"></path>'),tu=Ve('<svg width="18" height="18" viewBox="0 0 18 18" fill="none"><!></svg>');function lr(e,t){const n=H(t,"align",3,"bottom");var i=tu(),r=x(i);{var a=s=>{var c=$c();y(s,c)},l=s=>{var c=me(),u=X(c);{var d=v=>{var f=eu();y(v,f)};N(u,v=>{n()==="center"&&v(d)},!0)}y(s,c)};N(r,s=>{n()==="bottom"?s(a):s(l,!1)})}y(e,i)}var nu=P("<div><!></div>");function St(e,t){le(t,!0);const n=H(t,"type",3,"error"),i=H(t,"fixed",3,!1);var r=nu(),a=x(r);qe(a,()=>t.children),D(()=>{rl(r,`alert ${n()??""} svelte-df5n87`),ie(r,"fixed",i())}),y(e,r),se()}var iu=P("<!> In-text Playlink",1),ru=P("<!> Bottom Playlink",1),au=P('<div class="alert svelte-1shw34x"><!></div>'),ou=(e,t)=>t().after_article_style="playlinks",lu=(e,t)=>t().after_article_style="modal_button",su=P('<div><div class="label svelte-1shw34x">Bottom playlinks style</div> <div class="group svelte-1shw34x" role="listbox" tabindex="0" aria-label="Playlink type"><button role="option" id="playlinks-in-text" class="svelte-1shw34x">Playlinks sentence</button> <button role="option" id="playlinks-after-article" class="svelte-1shw34x">Modal button</button> <div class="active-marker svelte-1shw34x"></div></div></div>'),cu=P('<div class="switches svelte-1shw34x"><!> <!></div> <!> <!>',1);function uu(e,t){le(t,!0);const n=H(t,"linkInjection",7),i=O(()=>n().after_article_style==="modal_button");var r=cu(),a=X(r),l=x(a),s=O(()=>n().in_text??!0);ti(l,{fullwidth:!0,get active(){return o(s)},onclick:m=>{n().in_text=m,n().manual=!0},label:"In-text Playlink",children:(m,_)=>{var k=iu(),w=X(k);lr(w,{align:"center"}),y(m,k)},$$slots:{default:!0}});var c=A(l,2),u=O(()=>n().after_article??!1);ti(c,{fullwidth:!0,get active(){return o(u)},onclick:m=>{n().after_article=m,n().manual=!0},label:"Bottom Playlink",children:(m,_)=>{var k=ru(),w=X(k);lr(w,{align:"bottom"}),y(m,k)},$$slots:{default:!0}});var d=A(a,2);{var v=m=>{var _=au(),k=x(_);St(k,{type:"warning",children:(w,g)=>{var S=Ie("At least one layout option must be selected for the playlink to be visible.");y(w,S)},$$slots:{default:!0}}),ge(3,_,()=>$t,()=>({duration:200})),y(m,_)};N(d,m=>{qn(n())||m(v)})}var f=A(d,2);{var p=m=>{var _=su(),k=A(x(_),2),w=x(k);w.__click=[ou,n];var g=A(w,2);g.__click=[lu,n];var S=A(g,2);D(()=>{re(k,"aria-activedescendant",`playlinks-${(o(i)?"after-article":"in-text")??""}`),re(w,"aria-selected",!o(i)||null),ie(w,"active",!o(i)),re(g,"aria-selected",o(i)||null),ie(g,"active",o(i)),ie(S,"right",o(i))}),ge(3,_,()=>$t,()=>({duration:100})),y(m,_)};N(f,m=>{n().after_article&&m(p)})}y(e,r),se()}ve(["click"]);var du=Ve('<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M9.99984 10.8333C10.4601 10.8333 10.8332 10.4602 10.8332 10C10.8332 9.53977 10.4601 9.16668 9.99984 9.16668C9.5396 9.16668 9.1665 9.53977 9.1665 10C9.1665 10.4602 9.5396 10.8333 9.99984 10.8333Z" stroke="currentColor" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"></path><path d="M9.99984 5.00001C10.4601 5.00001 10.8332 4.62691 10.8332 4.16668C10.8332 3.70644 10.4601 3.33334 9.99984 3.33334C9.5396 3.33334 9.1665 3.70644 9.1665 4.16668C9.1665 4.62691 9.5396 5.00001 9.99984 5.00001Z" stroke="currentColor" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"></path><path d="M9.99984 16.6667C10.4601 16.6667 10.8332 16.2936 10.8332 15.8333C10.8332 15.3731 10.4601 15 9.99984 15C9.5396 15 9.1665 15.3731 9.1665 15.8333C9.1665 16.2936 9.5396 16.6667 9.99984 16.6667Z" stroke="currentColor" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"></path></svg>');function fu(e){var t=du();y(e,t)}var vu=(e,t)=>M(t,!o(t)),_u=P('<div class="content svelte-zpsd2z"><!></div>'),hu=P('<div class="context-menu svelte-zpsd2z"><button class="svelte-zpsd2z"><!></button> <!></div>');function gu(e,t){le(t,!0);let n=V(!1),i=V(null);function r(d){var f;const v=d.target;v===o(i)||(f=o(i))!=null&&f.contains(v)||M(n,!1)}var a=hu();ue("click",ye,r);var l=x(a);l.__click=[vu,n];var s=x(l);fu(s),At(l,d=>M(i,d),()=>o(i));var c=A(l,2);{var u=d=>{var v=_u(),f=x(v);qe(f,()=>t.children),ge(1,v,()=>Mt,()=>({duration:150,y:5})),y(d,v)};N(c,d=>{o(n)&&d(u)})}D(()=>{re(l,"aria-label",t.ariaLabel),re(l,"aria-expanded",o(n))}),y(e,a),se()}ve(["click"]);function mu(e,t,n,i){var r,a;o(t)&&(he(fe.ManualReport,n.linkInjection.title_details,{report_reason:o(t),sid:n.linkInjection.sid,title:n.linkInjection.title,sentence:n.linkInjection.sentence,failed:(r=n.linkInjection.failed)==null?void 0:r.toString(),failed_message:n.linkInjection.failed_message,manual:(a=n.linkInjection.manual)==null?void 0:a.toString()}),M(i,!0),setTimeout(n.onclose,3e3))}var pu=(e,t,n)=>M(t,J(n())),yu=P('<option class="svelte-o5qkco"> </option>'),ku=P('<div class="sent svelte-o5qkco">Report has been sent, thank you! Closing window...</div>'),wu=P('<button class="submit svelte-o5qkco">Send report</button>'),bu=P('<div class="form svelte-o5qkco"><div class="heading svelte-o5qkco">Report issue</div> <div class="info svelte-o5qkco"><div><strong class="svelte-o5qkco">Title</strong> </div> <div><strong class="svelte-o5qkco">Sentence</strong> </div></div> <label for="reason">What would you like to report?</label> <select id="reason" name="reason" class="svelte-o5qkco"><option class="svelte-o5qkco">Select an issue...</option><!></select> <div><!></div></div>');function xu(e,t){le(t,!0);const n=[{value:"failed_injection",label:"The link failed to appear on the page."},{value:"layout_issue",label:"The link is breaking the layout or formatting of my page."},{value:"wrong_content",label:"The link points to the wrong movie or show."},{value:"inappropriate_title",label:"The link points to an inappropriate movie or show."},{value:"broken_link",label:"The link is broken or leads to an error page."},{value:"other",label:"My issue is not listed, but please have a look regardless."}];let i=V(""),r=V(!1);sa(e,{get onclose(){return t.onclose},children:(a,l)=>{var s=bu(),c=x(s);It(c,(b,C)=>Ae==null?void 0:Ae(b,C),()=>2);var u=A(c,2),d=x(u),v=A(x(d)),f=A(d,2),p=A(x(f));D(()=>Y(p,`:
11
11
  ${fa(t.linkInjection.sentence,t.linkInjection.title,100)??""}`));var m=A(u,4),_=x(m);_.value=((_.__value="")==null,"");var k=A(_);We(k,17,()=>n,et,(b,C)=>{let I=()=>o(C).value,E=()=>o(C).label;var T=yu(),R={};T.__click=[pu,i,I];var U=x(T);D(()=>{R!==(R=I())&&(T.value=(T.__value=I())==null?"":I()),Y(U,E())}),y(b,T)});var w=A(m,2),g=x(w);{var S=b=>{var C=ku();ge(1,C,()=>xt,()=>({duration:200})),y(b,C)},j=b=>{var C=wu();C.__click=[mu,i,t,r],D(()=>C.disabled=!o(i)),y(b,C)};N(g,b=>{o(r)?b(S):b(j,!1)})}D(()=>Y(v,`: ${t.linkInjection.title??""}`)),fl(m,()=>o(i),b=>M(i,b)),y(a,s)},$$slots:{default:!0}}),se()}ve(["click"]);function Su(e,t,n){requestAnimationFrame(()=>t());const i=e.target;if(["BUTTON","INPUT"].includes(i.nodeName)||i.closest("button")||i.closest("input"))return;const r=n()[0];r&&r.scrollIntoView({behavior:"smooth"})}function Eu(e,t){const n=dn(xu,{target:document.body,props:{linkInjection:t(),onclose:()=>Rn(n)}})}var Tu=(e,t)=>M(t,!o(t)),Iu=P('<button class="expand-sentence svelte-lo6h85"> </button>'),Au=P('<button class="context-menu-action svelte-lo6h85">Remove</button> <button class="context-menu-action svelte-lo6h85">Report issue</button>',1),Pu=(e,t)=>M(t,!o(t)),Cu=P('<div class="warning svelte-lo6h85" aria-label="Invalid playlink settings"><!></div>'),ju=P('<div class="actions svelte-lo6h85"><button class="expand svelte-lo6h85" aria-label="Expand"><!></button> <!> <!></div>'),Lu=P('<div class="expanded svelte-lo6h85"><div class="label svelte-lo6h85">Link URL</div> <!> <div class="label offset svelte-lo6h85">Layout options</div> <div class="type-select svelte-lo6h85"><!></div></div>'),Mu=P('<div class="item svelte-lo6h85"><div class="header svelte-lo6h85"><img class="poster svelte-lo6h85" alt="" width="32" height="48"> <div class="info svelte-lo6h85"><div class="title svelte-lo6h85"> </div> <div class="sentence svelte-lo6h85"><!> <!></div></div> <div class="context-menu svelte-lo6h85"><!></div></div> <div class="content svelte-lo6h85"><!> <!></div></div>');function Nu(e,t){le(t,!0);const n=H(t,"linkInjection",15),i=H(t,"onremove",3,()=>null),r=H(t,"onhighlight",3,()=>null),a=O(()=>n()||{}),l=O(()=>o(a).key),s=O(()=>o(a).sentence),c=O(()=>o(a).title_details),u=O(()=>o(a).failed),d=O(()=>o(a).failed_message),v=O(()=>o(a).inactive),f=O(()=>o(c)),p=O(()=>fa(n().sentence,n().title,60));let m=V(!1),_=V(!1),k=V(!1),w=V(null);Ye(()=>{o(u)&&he(fe.InjectionFailed,o(f),{phrase:n().title,sentence:o(s)})});function g(te=!0){j().forEach(ce=>{ce.classList.toggle("playpilot-injection-highlight",te)})}function S(te){let ne=te.target,ce=ne==null?void 0:ne.dataset.playpilotInjectionKey;ne&&!ce&&(ne=ne.closest(`[data-playpilot-injection-key="${o(l)}"]`),ce=ne==null?void 0:ne.dataset.playpilotInjectionKey),M(k,ce===o(l)),o(w)&&o(k)&&r()(o(w))}function j(){const te=Array.from(document.querySelectorAll(`[data-playpilot-injection-key="${o(l)}"]`));return te.length?te:Ai(Rt()).filter(ne=>Oe(ne.innerText).includes(Oe(n().sentence)))||[]}var b=Mu();ue("mouseover",ye,S),b.__click=[Su,g,j];var C=x(b),I=x(C);D(()=>re(I,"src",en(o(f).standing_poster)));var E=A(I,2),T=x(E),R=x(T),U=A(T,2),W=x(U);Qo(W,()=>(o(_)?o(s):o(p)).replace(n().title,`<em>${n().title}</em>`));var F=A(W,2);{var G=te=>{var ne=Iu();ne.__click=[Tu,_];var ce=x(ne);D(()=>Y(ce,o(_)?"Less":"More")),y(te,ne)};N(F,te=>{o(p).length<o(s).length&&te(G)})}var L=A(E,2),q=x(L);gu(q,{ariaLabel:"More options",children:(te,ne)=>{var ce=Au(),Se=X(ce);Se.__click=function(...dt){var Z;(Z=i())==null||Z.apply(this,dt)};var it=A(Se,2);it.__click=[Eu,n],y(te,ce)},$$slots:{default:!0}});var B=A(C,2),z=x(B);{var K=te=>{St(te,{children:(ne,ce)=>{var Se=Ie();D(()=>Y(Se,o(d))),y(ne,Se)},$$slots:{default:!0}})},ee=te=>{var ne=ju(),ce=x(ne);ce.__click=[Pu,m];var Se=x(ce);Yc(Se,{get expanded(){return o(m)}});var it=A(ce,2);{var dt=pe=>{var Pe=Cu(),Ne=x(Pe);Gc(Ne),ge(3,Pe,()=>xt,()=>({duration:100})),y(pe,Pe)};N(it,pe=>{qn(n())||pe(dt)})}var Z=A(it,2),Q=O(()=>o(v)?"Inactive":"Visible"),ke=O(()=>!n().inactive);ti(Z,{get label(){return o(Q)},get active(){return o(ke)},onclick:pe=>{n(n().inactive=!pe,!0),n(n().manual=!0,!0)},children:(pe,Pe)=>{var Ne=Ie();D(()=>Y(Ne,o(v)?"Inactive":"Visible")),y(pe,Ne)},$$slots:{default:!0}}),D(()=>re(ce,"aria-expanded",o(m))),y(te,ne)};N(z,te=>{o(u)?te(K):te(ee,!1)})}var de=A(z,2);{var _e=te=>{var ne=Lu(),ce=A(x(ne),2);Li(ce,{oninput:()=>n(n().manual=!0,!0),label:"Playlink URL",get value(){return n().playpilot_url},set value(dt){n(n().playpilot_url=dt,!0)}});var Se=A(ce,4),it=x(Se);uu(it,{get linkInjection(){return n()}}),ge(3,ne,()=>$t,()=>({duration:100})),y(te,ne)};N(de,te=>{o(m)&&te(_e)})}At(b,te=>M(w,te),()=>o(w)),D(()=>{ie(b,"highlighted",o(k)),ie(b,"inactive",o(v)),Y(R,o(f).title)}),ue("mouseenter",b,()=>g(!0)),ue("mouseleave",b,()=>g(!1)),ue("error",I,({target:te})=>te.src=$r),ge(6,b,()=>$t,()=>({duration:200})),y(e,b),se()}ve(["click"]);var Du=P('<button class="drag-handle svelte-19mcc5g" aria-label="Move editor"></button>');function Ou(e,t){le(t,!0);let n=H(t,"element",7),i=H(t,"position",23,()=>({x:0,y:0})),r=H(t,"limit",19,()=>({x:0,y:0})),a=H(t,"onchange",3,()=>null),l=!1,s={x:0,y:0},c=i();Ye(()=>{u(i().x,i().y)});function u(_,k){const w=window.innerWidth,g=window.innerHeight,S=n().clientWidth,j=n().clientHeight;_=Math.min(Math.max(_,r().x),w-S-r().x),k=Math.min(Math.max(k,r().y),g-j-r().y),n().style.right=_+"px",n().style.bottom=Math.max(k,r().y)+"px",i({x:_,y:k}),a()(i())}function d(_){var k,w;return{x:_.pageX||((k=_.touches)==null?void 0:k[0].pageX)||0,y:_.pageY||((w=_.touches)==null?void 0:w[0].pageY)||0}}function v(_){l=!0,s=d(_),c=i()}function f(_){if(!l)return;const k=d(_),w=k.x-s.x,g=k.y-s.y,S=c.x-w,j=c.y-g;u(S,j)}function p(){l&&(l=!1)}var m=Du();ue("mousemove",ye,f),ue("touchmove",ye,f,void 0,!0),ue("mouseup",ye,p),ue("touchend",ye,p),ue("resize",ye,()=>u(i().x,i().y)),m.__mousedown=v,m.__touchstart=v,y(e,m),se()}ve(["mousedown","touchstart"]);var Ru=P('<button class="resize-handle svelte-sxkuxk" aria-label="Move editor"></button>');function qu(e,t){le(t,!0);let n=H(t,"element",7),i=H(t,"height",7,200),r=H(t,"onchange",3,()=>null);const a=16;let l=!1,s=0,c=i();Ye(()=>{i()&&u(i())});function u(_){const k=window.getComputedStyle(n()).minHeight||"0",w=Math.max(parseInt(k),Math.min(_,p()));n().style.height=`${w}px`,i(w),r()(w)}function d(_){var k,w;l=!0,s=_.pageY||((w=(k=_.touches)==null?void 0:k[0])==null?void 0:w.pageY)||0,c=n().clientHeight}function v(_){var S,j;if(!l)return;const k=_.pageY||((j=(S=_.touches)==null?void 0:S[0])==null?void 0:j.pageY)||0,w=s-k,g=c+w;u(g)}function f(){l=!1}function p(){const _=window.innerHeight-n().getBoundingClientRect().bottom;return Math.max(window.innerHeight-a*2-_,0)}var m=Ru();ue("mousemove",ye,v),ue("touchmove",ye,v,void 0,!0),ue("mouseup",ye,f),ue("touchend",ye,f),ue("resize",ye,()=>{i()&&u(i())}),m.__mousedown=d,m.__touchstart=d,y(e,m),se()}ve(["mousedown","touchstart"]);var Hu=Ve('<svg width="4" height="8" viewBox="0 0 4 8" fill="none"><path d="M3.5 7L0.5 4L3.5 1" stroke="currentcolor" stroke-width="0.9975" stroke-linecap="round" stroke-linejoin="round"></path></svg>');function Bu(e){var t=Hu();y(e,t)}async function Fu(e){const t=new Headers({"Content-Type":"application/json"}),n=_n();if(!n)throw new Error("No token was provided");const i=await fetch(fn+`/search/titles/?api-token=${n}&query=${e}`,{headers:t});if(!i.ok)throw i;return await i.json()}var Vu=Ve('<svg viewBox="0 -960 960 960" width="18" height="18"><path fill="currentColor" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h560v-280h80v280q0 33-23.5 56.5T760-120H200Zm188-212-56-56 372-372H560v-80h280v280h-80v-144L388-332Z"></path></svg>');function zu(e){var t=Vu();y(e,t)}var Uu=P("<div> </div>"),Wu=e=>e.stopImmediatePropagation(),Ku=P('<button class="item svelte-rjq94e"><img class="poster svelte-rjq94e" alt="" width="28" height="42"> <div class="content"><div class="name svelte-rjq94e"> </div> <div class="meta svelte-rjq94e"><div class="imdb svelte-rjq94e"><!> </div> <div> </div> <div> </div> <!></div></div> <a target="_blank" class="open-in-new-tab svelte-rjq94e"><!></a></button>');function sr(e,t){le(t,!0);const n=H(t,"hoverable",3,!0),i=H(t,"onclick",3,()=>null);var r=Ku();r.__click=function(...b){var C;(C=i())==null||C.apply(this,b)};var a=x(r);D(()=>re(a,"src",en(t.title.standing_poster)));var l=A(a,2),s=x(l),c=x(s),u=A(s,2),d=x(u),v=x(d);ca(v);var f=A(v),p=A(d,2),m=x(p),_=A(p,2),k=x(_),w=A(_,2);{var g=b=>{var C=Uu(),I=x(C);D(()=>Y(I,`${t.title.length??""} min`)),y(b,C)};N(w,b=>{t.title.length&&b(g)})}var S=A(l,2);S.__click=[Wu];var j=x(S);zu(j),D(()=>{ie(r,"hoverable",n()),Y(c,t.title.title),Y(f,` ${t.title.imdb_score??""}`),Y(m,t.title.year),Y(k,t.title.type),re(S,"href",`${Qr}/${t.title.type??""}/${t.title.slug??""}`)}),ue("error",a,({target:b})=>b.src=$r),y(e,r),se()}ve(["click"]);var Yu=P('<em class="empty svelte-1olb8n0">No results found</em>'),Zu=P('<div class="results svelte-1olb8n0" data-testid="search-results"></div>'),Gu=P('<div class="selected svelte-1olb8n0"><!></div>'),Xu=P('<div class="search svelte-1olb8n0"><!> <!> <!></div>');function Ju(e,t){le(t,!0);let n=H(t,"onselect",3,()=>null),i=H(t,"query",15),r=V(J([])),a=V(null),l=V(!1);yt(()=>{i()&&s(i())});async function s(_){M(l,!0);try{M(r,J(await Fu(_)))}finally{M(l,!1)}}function c(_){i(_.title),M(a,J(_)),n()(_)}var u=Xu(),d=x(u);Li(d,{oninput:()=>M(a,null),name:"search",label:"Search...",get value(){return i()},set value(_){i(_)}});var v=A(d,2);{var f=_=>{var k=Zu();We(k,21,()=>o(r),w=>w.sid,(w,g)=>{sr(w,{get title(){return o(g)},onclick:()=>c(o(g))})},w=>{var g=me(),S=X(g);{var j=b=>{var C=Yu();y(b,C)};N(S,b=>{o(l)||b(j)})}y(w,g)}),y(_,k)};N(v,_=>{i()&&!o(a)&&_(f)})}var p=A(v,2);{var m=_=>{var k=Gu(),w=x(k);sr(w,{get title(){return o(a)},hoverable:!1}),y(_,k)};N(p,_=>{o(a)&&_(m)})}y(e,u),se()}function Qu(e,t=e.anchorNode){if(!e.anchorNode||!t)return{start:-1,end:-1};const n=e.toString().trim(),i=e.toString().search(/\S/);if(e.anchorNode===t&&t.nodeType===Node.TEXT_NODE){const u=Math.min(e.anchorOffset,e.focusOffset)+i;return{start:u,end:u+n.length}}const r=e.getRangeAt(0),a=r.cloneRange();a.selectNodeContents(t),a.setEnd(r.startContainer,r.startOffset);const s=a.toString().length+i,c=s+n.length;return{start:s,end:c}}function $u(e,t,n,i,r,a,l,s){if(!o(t)||!o(n))return;const c=o(n).type==="movie"?"movie":"show",u=Qr+`/${c}/${o(n).slug}`,d={sid:o(n).sid,title:o(t),sentence:o(i),phrase_before:o(r),phrase_after:o(a),playpilot_url:u,key:ba(o(n).sid),title_details:o(n),manual:!0};l.onsave(d),s()()}var ed=P('<div class="error svelte-1i8p6op"><!></div>'),td=P('<label for="text" class="svelte-1i8p6op">Paired title</label> <!>',1),nd=P('<section class="layout svelte-1i8p6op"><div class="header svelte-1i8p6op"><!> <div class="heading svelte-1i8p6op">Add Playlink manually</div></div> <p class="svelte-1i8p6op">Highlight the text section in your post that you want to turn into a Playlink.</p> <label for="text" class="svelte-1i8p6op">Selected text</label> <!> <!> <!> <button class="save svelte-1i8p6op">Add playlink</button></section>');function id(e,t){le(t,!0);const n=H(t,"pageText",3,""),i=H(t,"onclose",3,()=>null);let r=V(""),a=V(""),l=V(null),s=V(""),c=V(""),u=V(""),d=V("");Ye(v);function v(){const T=window.getSelection();if(!(T!=null&&T.anchorNode)||T.anchorNode.parentElement&&!Rt().contains(T.anchorNode.parentElement))return;const R=T.toString().trim();if(!R)return;M(u,""),M(r,J(R));const U=T.getRangeAt(0).cloneContents();if(Array.from(U.childNodes).filter(K=>{var ee;return(ee=K.textContent)==null?void 0:ee.trim()}).find(K=>{var ee;return K.nodeName==="A"||((ee=K.querySelector)==null?void 0:ee.call(K,"a"))})){M(u,"Selection is or contains a link. Injections can not be created around already existing links.");return}M(d,J(o(r)));const{node:F,sentence:G}=f(T,R);if(!F)return;M(a,J(G));const{start:L,end:q}=Qu(T,F);(K=>(M(c,J(K.before)),M(s,J(K.after))))(mc(F,L,q)),G.includes(o(c))||M(c,""),G.includes(o(s))||M(s,"");const B=T.getRangeAt(0).commonAncestorContainer.textContent,z=Oe(n());(!B||!z.includes(Oe(B)))&&M(u,"Selection was not inside of given content")}function f(T,R){const U=T.getRangeAt(0),W=Rt();let F=U.startContainer;for(;(F.textContent||"").length<=R.length*3&&F.parentNode&&F.parentNode.textContent!==W.textContent;)F=F.parentNode;if(!F||!F.textContent)return{node:null,sentence:""};const G=F.textContent,L=p(F,U.startContainer,U.startOffset),q=p(F,U.endContainer,U.endOffset),B=G.slice(0,L).lastIndexOf("."),z=G.slice(q).match(/[.!?]/),K=z?q+z.index:G.length,ee=B===-1?0:B+1,de=K,_e=G.slice(ee,de+1).trim();return{node:F,sentence:_e}}function p(T,R,U){let W=0;const F=T,G=L=>{var q;if(L===R)return W+=U,!0;L.nodeType===Node.TEXT_NODE&&(W+=((q=L.textContent)==null?void 0:q.length)||0);for(let B=L.firstChild;B;B=B.nextSibling)if(G(B))return!0;return!1};return G(F),W}function m(T){var R,U;M(l,J(T)),(U=(R=window.getSelection())==null?void 0:R.removeAllRanges)==null||U.call(R)}var _=nd();ue("mouseup",ye,v);var k=x(_),w=x(k);xi(w,{get onclick(){return i()},size:"24px",children:(T,R)=>{Bu(T)},$$slots:{default:!0}});var g=A(w,2);It(g,(T,R)=>Ae==null?void 0:Ae(T,R),()=>2);var S=A(k,6);Li(S,{get value(){return o(r)},label:"Select text on the page",name:"selected-text",readonly:!0});var j=A(S,2);{var b=T=>{var R=ed(),U=x(R);St(U,{children:(W,F)=>{var G=Ie();D(()=>Y(G,o(u))),y(W,G)},$$slots:{default:!0}}),y(T,R)};N(j,T=>{o(u)&&T(b)})}var C=A(j,2);{var I=T=>{var R=td(),U=A(X(R),2);Kr(U,()=>o(a)+o(r),W=>{Ju(W,{onselect:m,get query(){return o(d)},set query(F){M(d,J(F))}})}),y(T,R)};N(C,T=>{o(u)||T(I)})}var E=A(C,2);E.__click=[$u,r,l,a,c,s,t,i],D(()=>E.disabled=!o(r)||!o(l)),y(e,_),se()}ve(["click"]);const ni="PlayPilotEditorialSessionId",xa=5e3,rd=xa*2;async function ad(e){const{ai_enabled:t,injections_enabled:n,ai_last_run:i,session_id:r,session_last_ping:a}=await vn(e),l=Ea(r||null,a||null),s={ai_enabled:t,ai_last_run:i,injections_enabled:n,session_id:r,session_last_ping:a};return l?await Sa(e):s}async function Sa(e){const t=Ta(),n=new Date(Date.now()).toISOString(),i={session_id:t,session_last_ping:n.toString()},{ai_enabled:r,injections_enabled:a,ai_last_run:l}=await vn(e,{params:i});return{ai_enabled:r,ai_last_run:l,injections_enabled:a,...i}}function Ea(e,t){if(!e||!t)return!0;const n=Date.now(),i=new Date(t),r=Ta();return n-i.getTime()>rd?!0:r===e}function Ta(){return sessionStorage.getItem(ni)||od()}function od(){const e=sessionStorage.getItem(ni)||ra();return sessionStorage.setItem(ni,e),e}function ld(e,t,n){Sa(t()),n()()}var sd=P('<p class="svelte-2m2urs"><strong>Someone else is currently editing this document.</strong> Wait for them to exit the page or take over edit permissions, preventing them from making more changes.</p> <button class="button svelte-2m2urs">Take over editing</button>',1),cd=P('<div class="alert svelte-2m2urs"><!></div>');function ud(e,t){le(t,!0);const n=H(t,"pageText",3,""),i=H(t,"onpoll",3,()=>null),r=H(t,"onallow",3,()=>null),a=H(t,"ondisallow",3,()=>null),l=H(t,"ontakeover",3,()=>null);let s=null,c=V(!0);Ye(()=>(u(),()=>{s&&clearInterval(s)}));function u(){d(),s=setInterval(d,xa)}async function d(){const m=await ad(n());m&&(M(c,J(Ea(m.session_id||null,m.session_last_ping||null))),o(c)?r()():a()(),i()({injectionsEnabled:!!m.injections_enabled,aiEnabled:!!m.ai_enabled}))}var v=me(),f=X(v);{var p=m=>{var _=cd(),k=x(_);St(k,{type:"warning",children:(w,g)=>{var S=sd(),j=A(X(S),2);j.__click=[ld,n,l],y(w,S)},$$slots:{default:!0}}),y(m,_)};N(f,m=>{o(c)||m(p)})}y(e,v),se()}ve(["click"]);var dd=Ve('<svg width="24px" height="24px" viewBox="0 0 64 64" stroke-width="3" stroke="currentColor" fill="none"><circle cx="34.52" cy="11.43" r="5.82"></circle><circle cx="53.63" cy="31.6" r="5.82"></circle><circle cx="34.52" cy="50.57" r="5.82"></circle><circle cx="15.16" cy="42.03" r="5.82"></circle><circle cx="15.16" cy="19.27" r="5.82"></circle><circle cx="34.51" cy="29.27" r="4.7"></circle><line x1="20.17" y1="16.3" x2="28.9" y2="12.93"></line><line x1="38.6" y1="15.59" x2="49.48" y2="27.52"></line><line x1="50.07" y1="36.2" x2="38.67" y2="46.49"></line><line x1="18.36" y1="24.13" x2="30.91" y2="46.01"></line><line x1="20.31" y1="44.74" x2="28.7" y2="48.63"></line><line x1="17.34" y1="36.63" x2="31.37" y2="16.32"></line><line x1="20.52" y1="21.55" x2="30.34" y2="27.1"></line><line x1="39.22" y1="29.8" x2="47.81" y2="30.45"></line><line x1="34.51" y1="33.98" x2="34.52" y2="44.74"></line></svg>');function fd(e){var t=dd();y(e,t)}var vd=P('<strong class="svelte-1kpafo0">AI processing is disabled.</strong> Enable AI from the <a href="https://partner.playpilot.net" class="svelte-1kpafo0">Partner Portal</a>',1),_d=P('<span class="svelte-1kpafo0">.</span>'),hd=P(`<strong class="svelte-1kpafo0">AI links are currently processing.</strong> This can take several minutes. We'll insert all found injections once ready. <div class="message svelte-1kpafo0"> <span class="ellipses svelte-1kpafo0"></span></div> <div class="loading-bar svelte-1kpafo0"><div class="loading-bar-progress svelte-1kpafo0"><div class="loading-bar-fill svelte-1kpafo0" data-testid="loading-bar"></div></div> <div class="loading-bar-label svelte-1kpafo0"> </div></div>`,1),gd=(e,t)=>M(t,!0),md=P('<p class="svelte-1kpafo0"><strong class="svelte-1kpafo0">AI has finished processing.</strong> <br class="svelte-1kpafo0"> <!></p> <button class="dismiss svelte-1kpafo0">Dismiss</button>',1),pd=P('<div class="animator svelte-1kpafo0" data-test-id="animator"></div>'),yd=P('<div class="ai-indicator svelte-1kpafo0" data-testid="ai-indicator"><div class="content svelte-1kpafo0"><div class="icon svelte-1kpafo0"><!></div> <div class="svelte-1kpafo0"><!></div></div> <div class="border svelte-1kpafo0"><!></div></div>');function kd(e,t){const n=H(t,"aiRunning",3,!1),i=H(t,"aiEnabled",3,!1),r=H(t,"message",3,""),a=H(t,"percentage",3,0),l=H(t,"aiInjectionsCount",3,0),s=l();let c=V(!1);var u=me(),d=X(u);{var v=f=>{var p=yd(),m=x(p),_=x(m),k=x(_);fd(k);var w=A(_,2),g=x(w);{var S=E=>{var T=vd();y(E,T)},j=E=>{var T=me(),R=X(T);{var U=F=>{var G=hd(),L=A(X(G),2),q=x(L),B=A(q);We(B,20,()=>({length:3}),et,(ne,ce)=>{var Se=_d();y(ne,Se)});var z=A(L,2),K=x(z),ee=x(K);const de=O(()=>`${Math.max(a(),3)??""}%`);D(()=>bt(ee,"width",o(de)));var _e=A(K,2),te=x(_e);D(()=>Y(te,`${Math.floor(a())??""}%`)),D(()=>Y(q,`${r()??""} `)),y(F,G)},W=F=>{var G=md(),L=X(G),q=A(x(L),4);{var B=ee=>{var de=Ie("No new injections where found.");y(ee,de)},z=ee=>{var de=Ie();D(()=>Y(de,`${l()??""} Injections where found and added to the page.`)),y(ee,de)};N(q,ee=>{s===l()?ee(B):ee(z,!1)})}var K=A(L,2);K.__click=[gd,c],y(F,G)};N(R,F=>{n()?F(U):F(W,!1)},!0)}y(E,T)};N(g,E=>{i()?E(j,!1):E(S)})}var b=A(m,2),C=x(b);{var I=E=>{var T=pd();y(E,T)};N(C,E=>{n()&&E(I)})}D(()=>ie(p,"running",n())),y(f,p)};N(d,f=>{o(c)||f(v)})}y(e,u)}ve(["click"]);async function wd(e,t,n,i,r,a,l){try{M(t,!0),M(n,!1),i(await zc(i(),r())),M(a,J(o(l)))}catch{M(n,!0)}finally{M(t,!1)}}var bd=P('<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:400,600,700">'),xd=P('<div class="handles svelte-11aj6xq"><div class="handle svelte-11aj6xq"><!></div> <div class="handle svelte-11aj6xq"><!></div></div>'),Sd=P('<div class="loading svelte-11aj6xq">Loading...</div>'),Ed=P('<div class="bubble svelte-11aj6xq"> </div> <!>',1),Td=P(`<strong>Playlinks are currently not published.</strong> Visitors to this page will not see any of the injected links.
12
- Publish playlinks from the <a href="https://partner.playpilot.net">Partner Portal.</a>`,1),Id=P('<div class="alert svelte-11aj6xq"><!></div>'),Ad=P('<div class="error svelte-11aj6xq"><!></div>'),Pd=P('<div class="empty svelte-11aj6xq">No links available. Add links manually by clicking the + button and select text to add a link to.</div>'),Cd=P('<button class="save svelte-11aj6xq"> </button>'),jd=P('<!> <!> <div class="items svelte-11aj6xq"></div> <!>',1),Ld=P("<!> <!> <!>",1),Md=P('<div class="panel playpilot-styled-scrollbar svelte-11aj6xq"><!></div>'),Nd=P('<section class="editor playpilot-styled-scrollbar svelte-11aj6xq"><!> <header class="header svelte-11aj6xq"><div class="heading svelte-11aj6xq">Playlinks</div> <!></header> <!> <!></section>');function Dd(e,t){le(t,!0);let n=H(t,"linkInjections",15),i=H(t,"pageText",3,""),r=H(t,"loading",3,!1),a=H(t,"injectionsEnabled",7,!1),l=H(t,"aiStatus",23,()=>({})),s=H(t,"onreinitialize",3,()=>null);const c="editor-position",u="editor-height",d=JSON.parse(localStorage.getItem(c)||'{ "x": 0, "y": 0 }'),v=parseInt(localStorage.getItem(u)||"0");let f=V(null),p=V(!1),m=V(!1),_=V(!1),k=V(!0),w=V(0),g=V("");const S=O(()=>wn(l().aiEnabled,!1)),j=O(()=>wn(l().aiRunning,!1)),b=O(()=>JSON.stringify(n())),C=O(()=>!o(j)&&o(k)),I=O(()=>o(g)&&o(g)!==o(b)),E=O(()=>n().filter(Z=>Z.title_details&&!Z.removed&&!Z.duplicate&&(Z.manual||!Z.manual&&!Z.failed))),T=O(()=>U(o(E))),R=O(()=>!r()&&Fe(()=>l().aiRunning));yt(()=>{r()||Fe(()=>{requestAnimationFrame(()=>M(g,J(o(b)))),q()})});function U(Z){return Z.sort((Q,ke)=>Q.failed!==ke.failed?Q.failed?1:-1:Q.title_details.title.localeCompare(ke.title_details.title))}function W(Z,Q){localStorage.setItem(Z,Q)}function F(Z){const Q=n().findIndex(ke=>ke.key===Z);n(n()[Q].manual=!0,!0),n(n()[Q].removed=!0,!0),n([...n()])}function G(Z){if(!o(f))return;const Q=Z.offsetTop,ke=Q+Z.offsetHeight,pe=o(f).scrollTop,Pe=pe+o(f).clientHeight;Q>=pe&&ke<=Pe||o(f).scrollTo({top:Q-o(f).clientHeight/2,behavior:"smooth"})}function L(Z){const Q=Z.target;M(w,J(Q.scrollTop))}function q(){const Z={total:n().length,failed_automatic:n().filter(Q=>Q.failed&&!Q.manual).length,failed_manual:n().filter(Q=>Q.failed&&Q.manual).length,final_injected:o(E).length};he(fe.TotalInjectionsCount,null,Z)}var B=Nd();Ko(Z=>{var Q=bd();y(Z,Q)});var z=x(B);{var K=Z=>{var Q=xd(),ke=x(Q),pe=x(ke);qu(pe,{get element(){return o(f)},height:v,onchange:Qe=>W(u,JSON.stringify(Qe))});var Pe=A(ke,2),Ne=x(Pe);Ou(Ne,{get element(){return o(f)},position:d,limit:{x:16,y:16},onchange:Qe=>W(c,JSON.stringify(Qe))}),y(Z,Q)};N(z,Z=>{o(f)&&!r()&&Z(K)})}var ee=A(z,2),de=x(ee);It(de,Z=>Ae==null?void 0:Ae(Z));var _e=A(de,2);{var te=Z=>{var Q=Sd();y(Z,Q)},ne=Z=>{var Q=me(),ke=X(Q);{var pe=Pe=>{var Ne=Ed(),Qe=X(Ne),De=x(Qe),hn=A(Qe,2);xi(hn,{onclick:()=>M(p,!0),size:"24px","aria-label":"Add manual injection",children:(gn,Mi)=>{var mn=Ie("+");y(gn,mn)},$$slots:{default:!0}}),D(()=>{re(Qe,"aria-label",`${o(E).length??""} found playlinks`),Y(De,o(E).length)}),y(Pe,Ne)};N(ke,Pe=>{o(C)&&Pe(pe)},!0)}y(Z,Q)};N(_e,Z=>{r()?Z(te):Z(ne,!1)})}var ce=A(ee,2);{var Se=Z=>{var Q=Ld(),ke=X(Q);ud(ke,{get pageText(){return i()},onallow:()=>M(k,!0),ondisallow:()=>M(k,!1),get ontakeover(){return s()},onpoll:De=>{a(De.injectionsEnabled),l({...l(),aiEnabled:De.aiEnabled})}});var pe=A(ke,2);{var Pe=De=>{kd(De,kl(l,{get aiInjectionsCount(){return ma(n()).aiInjections.length}}))};N(pe,De=>{o(k)&&(o(R)||!o(S))&&De(Pe)})}var Ne=A(pe,2);{var Qe=De=>{var hn=jd(),gn=X(hn);{var Mi=we=>{var be=Id(),rt=x(be);St(rt,{type:"warning",children:(ft,Ca)=>{var Hn=Td();y(ft,Hn)},$$slots:{default:!0}}),y(we,be)};N(gn,we=>{a()||we(Mi)})}var mn=A(gn,2);{var Ia=we=>{var be=Ad(),rt=x(be);St(rt,{children:(ft,Ca)=>{var Hn=Ie("Something went wrong, check your links below.");y(ft,Hn)},$$slots:{default:!0}}),ge(7,be,()=>$t,()=>({duration:150})),y(we,be)};N(mn,we=>{o(_)&&we(Ia)})}var Ni=A(mn,2);We(Ni,21,()=>o(T),we=>we.key,(we,be)=>{const rt=O(()=>n().findIndex(ft=>ft.key===o(be).key));Nu(we,{onremove:()=>F(o(be).key),onhighlight:G,get linkInjection(){return n()[o(rt)]},set linkInjection(ft){n(n()[o(rt)]=ft,!0)}})},we=>{var be=Pd();y(we,be)});var Aa=A(Ni,2);{var Pa=we=>{var be=Cd();be.__click=[wd,m,_,n,i,g,b];var rt=x(be);D(()=>{be.disabled=o(m),Y(rt,o(m)?"Saving...":"Save links")}),ge(1,be,()=>xt,()=>({duration:100})),y(we,be)};N(Aa,we=>{o(I)&&n().length&&o(k)&&we(Pa)})}y(De,hn)};N(Ne,De=>{o(C)&&De(Qe)})}y(Z,Q)};N(ce,Z=>{r()||Z(Se)})}var it=A(ce,2);{var dt=Z=>{var Q=Md(),ke=x(Q);id(ke,{get pageText(){return i()},onclose:()=>M(p,!1),onsave:pe=>n().push(pe)}),D(()=>bt(Q,"top",`${o(w)??""}px`)),ge(3,Q,()=>Mt,()=>({x:Math.min(window.innerWidth,320),duration:200,opacity:1})),y(Z,Q)};N(it,Z=>{o(p)&&Z(dt)})}At(B,Z=>M(f,Z),()=>o(f)),D(()=>{ie(B,"panel-open",o(p)),ie(B,"loading",r())}),ue("scroll",B,L),y(e,B),se()}ve(["click"]);var Od=Ve('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 57.48 62.96"><defs><style>.playpilot-logo{fill:url(#playpilot-linear-gradient);}</style><linearGradient id="playpilot-linear-gradient" x1="-90.03" y1="-40.23" x2="-34.8" y2="-101.48" gradientTransform="translate(74.02 108.65)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#de00b9"></stop><stop offset="0.99" stop-color="#ff557b"></stop></linearGradient></defs><path class="playpilot-logo" d="M57.48,31.48C57.48,22.17,20.85,2.19,9.2.18,7.42-.12,3.78-.37,1.36,2.25-4.32,8.39,9.62,21.5,9.62,31.48S-4.32,54.57,1.36,60.72c2.42,2.61,6.06,2.37,7.84,2.06C20.85,60.78,57.48,40.79,57.48,31.48Z"></path></svg>');function Rd(e){var t=Od();y(e,t)}var qd=P('<div class="trigger svelte-qee95d"><button type="button" class="button svelte-qee95d" title="Show PlayPilot TPI editor"><!></button> <button type="button" class="button close svelte-qee95d" title="Close PlayPilot TPI"><!></button></div>');function Hd(e,t){var n=qd(),i=x(n);i.__click=function(...s){var c;(c=t.onclick)==null||c.apply(this,s)};var r=x(i);Rd(r);var a=A(i,2);a.__click=function(...s){var c;(c=t.onclose)==null||c.apply(this,s)};var l=x(a);oa(l),y(e,n)}ve(["click"]);var Bd=P('<img alt="" class="svelte-j7f9xl">');function Fd(e,t){var n=me(),i=X(n);We(i,17,()=>t.pixels,et,(r,a)=>{var l=Bd();D(()=>re(l,"src",o(a))),y(r,l)}),y(e,n)}var Vd=P('<div class="item svelte-1n0r9h1"><span class="label"> </span>: <span class="data svelte-1n0r9h1"> </span></div>'),zd=P('<details><summary class="svelte-1n0r9h1"> </summary> <!></details>'),Ud=P('<div class="debugger svelte-1n0r9h1"><strong>TPI Debugger</strong> <hr class="svelte-1n0r9h1"> <!></div>');function Wd(e,t){le(t,!0);const n=["tpidebug","debugtpi"],i=[];let r=V(J(s())),a=V(!1),l=null;bl(()=>{l&&clearInterval(l)});function s(){var _,k,w,g,S,j;const f=window.PlayPilotLinkInjections,p=((_=f.evaluated_link_injections)==null?void 0:_.filter(b=>!b.failed))||[],m=((k=f.evaluated_link_injections)==null?void 0:k.filter(b=>b.failed))||[];return{Config:[{label:"Domain",data:f.domain_sid},{label:"Organization",data:f.organization_sid},{label:"HTML selector",data:f.selector}],[`Succesful injections (${p.length})`]:p.map(b=>({label:b.title,data:b.sentence})),[`Failed injections (${m.length})`]:m.map(b=>({label:b.title,data:b.failed_message})),[`Fetched ads (${((w=f.ads)==null?void 0:w.length)||0})`]:(g=f.ads)==null?void 0:g.map(b=>({label:b.campaign_name,data:b})),[`Tracking events (${((S=f.tracked_events)==null?void 0:S.length)||0})`]:(j=f.tracked_events)==null?void 0:j.map(b=>({label:b.event,data:b.payload}))}}function c(f){const p=f.key;i.push(p),M(a,J(n.some(m=>i.slice(i.length-m.length,i.length).join("")===m))),l=setInterval(()=>M(r,J(s())),200)}var u=me();ue("keydown",ye,c);var d=X(u);{var v=f=>{var p=Ud(),m=A(x(p),4);We(m,17,()=>Object.entries(o(r)),et,(_,k)=>{let w=()=>o(k)[0],g=()=>o(k)[1];var S=zd(),j=x(S),b=x(j),C=A(j,2);{var I=T=>{var R=me(),U=X(R);{var W=F=>{var G=me(),L=X(G);We(L,17,g,et,(B,z)=>{let K=()=>o(z).label,ee=()=>o(z).data;var de=Vd(),_e=x(de),te=x(_e),ne=A(_e,2),ce=x(ne);D(()=>Y(ce,JSON.stringify(ee()))),D(()=>Y(te,K())),y(B,de)}),y(F,G)};N(U,F=>{Array.isArray(g())&&F(W)})}y(T,R)},E=T=>{var R=Ie("No data");y(T,R)};N(C,T=>{var R;(R=g())!=null&&R.length?T(I):T(E,!1)})}D(()=>Y(b,w())),y(_,S)}),y(f,p)};N(d,f=>{o(a)&&f(v)})}y(e,u),se()}var Kd=P('<div class="playpilot-link-injections svelte-13rmd3g" data-playpilot-link-injections=""><!> <!></div> <!> <!>',1);function Yd(e,t){le(t,!0);let n=V(null),i=V(J([])),r=V(null),a=V(J(ia())),l=V(!!wi()),s=V(!1),c=V(!0),u=V(!0),d=V(J([]));const v=O(()=>o(r)||{}),f=O(()=>wn(o(v).ai_injections,()=>[],!0)),p=O(()=>wn(o(v).manual_injections,()=>[],!0)),m=O(()=>_a(o(i)));yt(()=>{o(a)&&!o(c)&&k()}),Ye(()=>{if(!Wc())return(async()=>(await _(),he(fe.ArticlePageView),(o(f).length||o(p).length)&&(window.PlayPilotLinkInjections.ads=await ws())))(),()=>Pi()});async function _(){M(c,!0),o(a)&&M(s,J(await na()));try{const L=await Uc(),q=yi();if(M(u,!!(L!=null&&L.exclude_urls_pattern&&q.match(new RegExp(L.exclude_urls_pattern)))),o(u))return;L!=null&&L.custom_style&&b(L.custom_style||""),S((L==null?void 0:L.html_selector)||"",(L==null?void 0:L.exclude_elements_selector)||"")}catch(L){he(fe.FetchingConfigFailed),console.error("TPI Config failed to fetch",L);return}try{if(M(r,J(await ar(o(m),{maxTries:1,runAiWhenRelevant:!0}))),M(c,!1),!o(r))return;if(Al({organizationSid:o(r).organization_sid,domainSid:o(r).domain_sid}),!o(r).ai_running||!o(r).ai_enabled){g({aiInjections:o(f),manualInjections:o(p)});return}if(!o(a))return;M(r,J(await ar(o(m),{requireCompletedResult:!0,onpoll:L=>M(r,J(L))}))),g({aiInjections:o(f),manualInjections:o(p)})}catch(L){console.error(L),he(fe.InjectionError,null,{message:L.message})}}function k(){g(ma(o(d)))}function w(){M(a,!1),requestAnimationFrame(()=>{M(a,!0),_()})}function g(L={aiInjections:o(f),manualInjections:o(p)}){const q=Ec(o(i),L);JSON.stringify(q)!==JSON.stringify(o(d))&&(M(d,J(q)),window.PlayPilotLinkInjections.evaluated_link_injections=q);const B=q.filter(z=>!z.failed);B.length&&(o(a)||he(fe.ArticleInjected,null,{manual:B.filter(z=>z.manual).length,ai:B.filter(z=>!z.manual).length}))}function S(L,q){L&&(window.PlayPilotLinkInjections.selector=L),M(n,J(Rt())),M(i,J(Ai(o(n),q)))}function j(){M(a,!0),jl(),_()}function b(L){const q="playpilot-custom-style",B=document.getElementById(q),z=B||document.createElement("style");z.textContent=`[data-playpilot-link-injections] { ${L} }`,z.id=q,B||document.body.appendChild(z)}var C=Kd(),I=X(C),E=x(I);{var T=L=>{Hd(L,{onclick:j,onclose:()=>{M(l,!1),Cl()}})};N(E,L=>{!o(u)&&o(l)&&!o(a)&&L(T)})}var R=A(E,2);{var U=L=>{var q=me(),B=X(q);wl(B,{onerror:K=>he(fe.EditorError,null,{message:K.message}),failed:K=>{St(K,{fixed:!0,children:(ee,de)=>{var _e=Ie("An error has occured in the PlayPilot Linkinjections editor view. We've been notified and will investigate!");y(ee,_e)},$$slots:{default:!0}})}},K=>{var ee=O(()=>{var _e;return(_e=o(r))==null?void 0:_e.injections_enabled}),de=O(()=>{var _e,te,ne,ce,Se;return{aiEnabled:(_e=o(r))==null?void 0:_e.ai_enabled,aiRunning:((te=o(r))==null?void 0:te.ai_running)&&((ne=o(r))==null?void 0:ne.ai_enabled),message:(ce=o(r))==null?void 0:ce.ai_progress_message,percentage:(Se=o(r))==null?void 0:Se.ai_progress_percentage}});Dd(K,{get pageText(){return o(m)},get loading(){return o(c)},onreinitialize:w,get injectionsEnabled(){return o(ee)},get aiStatus(){return o(de)},get linkInjections(){return o(d)},set linkInjections(_e){M(d,J(_e))}})}),y(L,q)};N(R,L=>{!o(u)&&o(a)&&o(s)&&L(U)})}var W=A(I,2);Wd(W,{});var F=A(W,2);{var G=L=>{Fd(L,{get pixels(){return o(r).pixels}})};N(F,L=>{var q,B;(B=(q=o(r))==null?void 0:q.pixels)!=null&&B.length&&L(G)})}y(e,C),se()}window.PlayPilotLinkInjections={token:"",editorial_token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,organization_sid:null,domain_sid:null,last_successful_fetch:null,tracked_events:[],split_test_identifiers:{},evaluated_link_injections:[],ads:[],app:null,initialize(e={token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,organization_sid:null,domain_sid:null,editorial_token:""}){if(!e.token){console.error("An API token is required.");return}this.token=e.token,this.editorial_token=e.editorial_token,this.selector=e.selector,this.after_article_selector=e.after_article_selector,this.after_article_insert_position=e.after_article_insert_position,this.language=e.language,this.organization_sid=e.organization_sid,this.domain_sid=e.domain_sid,this.app&&this.destroy();const t=document.createElement("div");t.id="playpilot-link-injection",document.body.insertAdjacentElement("beforeend",t),this.app=dn(Yd,{target:t})},destroy(){if(!this.app)return;this.app=null;const e=document.getElementById("playpilot-link-injection");e&&e.remove(),Pi()},debug(){const e=Rt(),t=Ai(e);console.groupCollapsed("Config"),console.table(Object.entries(this)),console.groupEnd(),console.groupCollapsed("Elements"),console.log("Parent element",e),console.log("Valid elements",t),console.groupEnd(),console.groupCollapsed("Last fetch"),console.log(this.last_successful_fetch),console.groupEnd(),console.groupCollapsed("Meta"),console.log(Ci()),console.groupEnd(),console.groupCollapsed("Page text"),console.log(_a(t)),console.groupEnd(),console.groupCollapsed("Evaluated injections"),console.log(this.evaluated_link_injections),console.groupEnd(),console.groupCollapsed("Tracked events"),console.log(this.tracked_events),console.groupEnd(),console.groupCollapsed("Split tests"),console.log(this.split_test_identifiers),console.groupEnd()},mockAd(e={}){const t={campaign_format:"card",campaign_type:"image",campaign_name:"some_campaign",content:{header:"Some content header",header_logo:"https://picsum.photos/seed/picsum/40/40",header_logo_uuid:"",subheader:"Some content subheader",image:"https://picsum.photos/seed/picsum/640/360",image_uuid:"",video:null,format:null},cta:{header:"Some cta header",subheader:"Some cta subheader",url:"https://google.com/",image:null,image_uuid:null},disclaimer:"Some disclaimer"};this.ads=[{...t,...e}]}};
12
+ Publish playlinks from the <a href="https://partner.playpilot.net">Partner Portal.</a>`,1),Id=P('<div class="alert svelte-11aj6xq"><!></div>'),Ad=P('<div class="error svelte-11aj6xq"><!></div>'),Pd=P('<div class="empty svelte-11aj6xq">No links available. Add links manually by clicking the + button and select text to add a link to.</div>'),Cd=P('<button class="save svelte-11aj6xq"> </button>'),jd=P('<!> <!> <div class="items svelte-11aj6xq"></div> <!>',1),Ld=P("<!> <!> <!>",1),Md=P('<div class="panel playpilot-styled-scrollbar svelte-11aj6xq"><!></div>'),Nd=P('<section class="editor playpilot-styled-scrollbar svelte-11aj6xq"><!> <header class="header svelte-11aj6xq"><div class="heading svelte-11aj6xq">Playlinks</div> <!></header> <!> <!></section>');function Dd(e,t){le(t,!0);let n=H(t,"linkInjections",15),i=H(t,"pageText",3,""),r=H(t,"loading",3,!1),a=H(t,"injectionsEnabled",7,!1),l=H(t,"aiStatus",23,()=>({})),s=H(t,"onreinitialize",3,()=>null);const c="editor-position",u="editor-height",d=JSON.parse(localStorage.getItem(c)||'{ "x": 0, "y": 0 }'),v=parseInt(localStorage.getItem(u)||"0");let f=V(null),p=V(!1),m=V(!1),_=V(!1),k=V(!0),w=V(0),g=V("");const S=O(()=>wn(l().aiEnabled,!1)),j=O(()=>wn(l().aiRunning,!1)),b=O(()=>JSON.stringify(n())),C=O(()=>!o(j)&&o(k)),I=O(()=>o(g)&&o(g)!==o(b)),E=O(()=>n().filter(Z=>Z.title_details&&!Z.removed&&!Z.duplicate&&(Z.manual||!Z.manual&&!Z.failed))),T=O(()=>U(o(E))),R=O(()=>!r()&&Fe(()=>l().aiRunning));yt(()=>{r()||Fe(()=>{requestAnimationFrame(()=>M(g,J(o(b)))),q()})});function U(Z){return Z.sort((Q,ke)=>Q.failed!==ke.failed?Q.failed?1:-1:Q.title_details.title.localeCompare(ke.title_details.title))}function W(Z,Q){localStorage.setItem(Z,Q)}function F(Z){const Q=n().findIndex(ke=>ke.key===Z);n(n()[Q].manual=!0,!0),n(n()[Q].removed=!0,!0),n([...n()])}function G(Z){if(!o(f))return;const Q=Z.offsetTop,ke=Q+Z.offsetHeight,pe=o(f).scrollTop,Pe=pe+o(f).clientHeight;Q>=pe&&ke<=Pe||o(f).scrollTo({top:Q-o(f).clientHeight/2,behavior:"smooth"})}function L(Z){const Q=Z.target;M(w,J(Q.scrollTop))}function q(){const Z={total:n().length,failed_automatic:n().filter(Q=>Q.failed&&!Q.manual).length,failed_manual:n().filter(Q=>Q.failed&&Q.manual).length,final_injected:o(E).length};he(fe.TotalInjectionsCount,null,Z)}var B=Nd();Ko(Z=>{var Q=bd();y(Z,Q)});var z=x(B);{var K=Z=>{var Q=xd(),ke=x(Q),pe=x(ke);qu(pe,{get element(){return o(f)},height:v,onchange:Qe=>W(u,JSON.stringify(Qe))});var Pe=A(ke,2),Ne=x(Pe);Ou(Ne,{get element(){return o(f)},position:d,limit:{x:16,y:16},onchange:Qe=>W(c,JSON.stringify(Qe))}),y(Z,Q)};N(z,Z=>{o(f)&&!r()&&Z(K)})}var ee=A(z,2),de=x(ee);It(de,Z=>Ae==null?void 0:Ae(Z));var _e=A(de,2);{var te=Z=>{var Q=Sd();y(Z,Q)},ne=Z=>{var Q=me(),ke=X(Q);{var pe=Pe=>{var Ne=Ed(),Qe=X(Ne),De=x(Qe),hn=A(Qe,2);xi(hn,{onclick:()=>M(p,!0),size:"24px","aria-label":"Add manual injection",children:(gn,Mi)=>{var mn=Ie("+");y(gn,mn)},$$slots:{default:!0}}),D(()=>{re(Qe,"aria-label",`${o(E).length??""} found playlinks`),Y(De,o(E).length)}),y(Pe,Ne)};N(ke,Pe=>{o(C)&&Pe(pe)},!0)}y(Z,Q)};N(_e,Z=>{r()?Z(te):Z(ne,!1)})}var ce=A(ee,2);{var Se=Z=>{var Q=Ld(),ke=X(Q);ud(ke,{get pageText(){return i()},onallow:()=>M(k,!0),ondisallow:()=>M(k,!1),get ontakeover(){return s()},onpoll:De=>{a(De.injectionsEnabled),l({...l(),aiEnabled:De.aiEnabled})}});var pe=A(ke,2);{var Pe=De=>{kd(De,kl(l,{get aiInjectionsCount(){return ma(n()).aiInjections.length}}))};N(pe,De=>{o(k)&&(o(R)||!o(S))&&De(Pe)})}var Ne=A(pe,2);{var Qe=De=>{var hn=jd(),gn=X(hn);{var Mi=we=>{var be=Id(),rt=x(be);St(rt,{type:"warning",children:(ft,Ca)=>{var Hn=Td();y(ft,Hn)},$$slots:{default:!0}}),y(we,be)};N(gn,we=>{a()||we(Mi)})}var mn=A(gn,2);{var Ia=we=>{var be=Ad(),rt=x(be);St(rt,{children:(ft,Ca)=>{var Hn=Ie("Something went wrong, check your links below.");y(ft,Hn)},$$slots:{default:!0}}),ge(7,be,()=>$t,()=>({duration:150})),y(we,be)};N(mn,we=>{o(_)&&we(Ia)})}var Ni=A(mn,2);We(Ni,21,()=>o(T),we=>we.key,(we,be)=>{const rt=O(()=>n().findIndex(ft=>ft.key===o(be).key));Nu(we,{onremove:()=>F(o(be).key),onhighlight:G,get linkInjection(){return n()[o(rt)]},set linkInjection(ft){n(n()[o(rt)]=ft,!0)}})},we=>{var be=Pd();y(we,be)});var Aa=A(Ni,2);{var Pa=we=>{var be=Cd();be.__click=[wd,m,_,n,i,g,b];var rt=x(be);D(()=>{be.disabled=o(m),Y(rt,o(m)?"Saving...":"Save links")}),ge(1,be,()=>xt,()=>({duration:100})),y(we,be)};N(Aa,we=>{o(I)&&n().length&&o(k)&&we(Pa)})}y(De,hn)};N(Ne,De=>{o(C)&&De(Qe)})}y(Z,Q)};N(ce,Z=>{r()||Z(Se)})}var it=A(ce,2);{var dt=Z=>{var Q=Md(),ke=x(Q);id(ke,{get pageText(){return i()},onclose:()=>M(p,!1),onsave:pe=>n().push(pe)}),D(()=>bt(Q,"top",`${o(w)??""}px`)),ge(3,Q,()=>Mt,()=>({x:Math.min(window.innerWidth,320),duration:200,opacity:1})),y(Z,Q)};N(it,Z=>{o(p)&&Z(dt)})}At(B,Z=>M(f,Z),()=>o(f)),D(()=>{ie(B,"panel-open",o(p)),ie(B,"loading",r())}),ue("scroll",B,L),y(e,B),se()}ve(["click"]);var Od=Ve('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 57.48 62.96"><defs><style>.playpilot-logo{fill:url(#playpilot-linear-gradient);}</style><linearGradient id="playpilot-linear-gradient" x1="-90.03" y1="-40.23" x2="-34.8" y2="-101.48" gradientTransform="translate(74.02 108.65)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#de00b9"></stop><stop offset="0.99" stop-color="#ff557b"></stop></linearGradient></defs><path class="playpilot-logo" d="M57.48,31.48C57.48,22.17,20.85,2.19,9.2.18,7.42-.12,3.78-.37,1.36,2.25-4.32,8.39,9.62,21.5,9.62,31.48S-4.32,54.57,1.36,60.72c2.42,2.61,6.06,2.37,7.84,2.06C20.85,60.78,57.48,40.79,57.48,31.48Z"></path></svg>');function Rd(e){var t=Od();y(e,t)}var qd=P('<div class="trigger svelte-qee95d"><button type="button" class="button svelte-qee95d" title="Show PlayPilot TPI editor"><!></button> <button type="button" class="button close svelte-qee95d" title="Close PlayPilot TPI"><!></button></div>');function Hd(e,t){var n=qd(),i=x(n);i.__click=function(...s){var c;(c=t.onclick)==null||c.apply(this,s)};var r=x(i);Rd(r);var a=A(i,2);a.__click=function(...s){var c;(c=t.onclose)==null||c.apply(this,s)};var l=x(a);oa(l),y(e,n)}ve(["click"]);var Bd=P('<img alt="" class="svelte-j7f9xl">');function Fd(e,t){var n=me(),i=X(n);We(i,17,()=>t.pixels,et,(r,a)=>{var l=Bd();D(()=>re(l,"src",o(a))),y(r,l)}),y(e,n)}var Vd=P('<div class="item svelte-1n0r9h1"><span class="label"> </span>: <span class="data svelte-1n0r9h1"> </span></div>'),zd=P('<details><summary class="svelte-1n0r9h1"> </summary> <!></details>'),Ud=P('<div class="debugger svelte-1n0r9h1"><strong>TPI Debugger</strong> <hr class="svelte-1n0r9h1"> <!></div>');function Wd(e,t){le(t,!0);const n=["tpidebug","debugtpi"],i=[];let r=V(J(s())),a=V(!1),l=null;bl(()=>{l&&clearInterval(l)});function s(){var _,k,w,g,S,j;const f=window.PlayPilotLinkInjections,p=((_=f.evaluated_link_injections)==null?void 0:_.filter(b=>!b.failed))||[],m=((k=f.evaluated_link_injections)==null?void 0:k.filter(b=>b.failed))||[];return{Config:[{label:"Domain",data:f.domain_sid},{label:"Organization",data:f.organization_sid},{label:"HTML selector",data:f.selector}],[`Succesful injections (${p.length})`]:p.map(b=>({label:b.title,data:b.sentence})),[`Failed injections (${m.length})`]:m.map(b=>({label:b.title,data:b.failed_message})),[`Fetched ads (${((w=f.ads)==null?void 0:w.length)||0})`]:(g=f.ads)==null?void 0:g.map(b=>({label:b.campaign_name,data:b})),[`Tracking events (${((S=f.tracked_events)==null?void 0:S.length)||0})`]:(j=f.tracked_events)==null?void 0:j.map(b=>({label:b.event,data:b.payload}))}}function c(f){if(o(a))return;const p=f.key;i.push(p),M(a,J(n.some(m=>i.slice(i.length-m.length,i.length).join("")===m))),l=setInterval(()=>M(r,J(s())),200)}var u=me();ue("keydown",ye,c);var d=X(u);{var v=f=>{var p=Ud(),m=A(x(p),4);We(m,17,()=>Object.entries(o(r)),et,(_,k)=>{let w=()=>o(k)[0],g=()=>o(k)[1];var S=zd(),j=x(S),b=x(j),C=A(j,2);{var I=T=>{var R=me(),U=X(R);{var W=F=>{var G=me(),L=X(G);We(L,17,g,et,(B,z)=>{let K=()=>o(z).label,ee=()=>o(z).data;var de=Vd(),_e=x(de),te=x(_e),ne=A(_e,2),ce=x(ne);D(()=>Y(ce,JSON.stringify(ee()))),D(()=>Y(te,K())),y(B,de)}),y(F,G)};N(U,F=>{Array.isArray(g())&&F(W)})}y(T,R)},E=T=>{var R=Ie("No data");y(T,R)};N(C,T=>{var R;(R=g())!=null&&R.length?T(I):T(E,!1)})}D(()=>Y(b,w())),y(_,S)}),y(f,p)};N(d,f=>{o(a)&&f(v)})}y(e,u),se()}var Kd=P('<div class="playpilot-link-injections svelte-13rmd3g" data-playpilot-link-injections=""><!> <!></div> <!> <!>',1);function Yd(e,t){le(t,!0);let n=V(null),i=V(J([])),r=V(null),a=V(J(ia())),l=V(!!wi()),s=V(!1),c=V(!0),u=V(!0),d=V(J([]));const v=O(()=>o(r)||{}),f=O(()=>wn(o(v).ai_injections,()=>[],!0)),p=O(()=>wn(o(v).manual_injections,()=>[],!0)),m=O(()=>_a(o(i)));yt(()=>{o(a)&&!o(c)&&k()}),Ye(()=>{if(!Wc())return(async()=>(await _(),he(fe.ArticlePageView),(o(f).length||o(p).length)&&(window.PlayPilotLinkInjections.ads=await ws())))(),()=>Pi()});async function _(){M(c,!0),o(a)&&M(s,J(await na()));try{const L=await Uc(),q=yi();if(M(u,!!(L!=null&&L.exclude_urls_pattern&&q.match(new RegExp(L.exclude_urls_pattern)))),o(u))return;L!=null&&L.custom_style&&b(L.custom_style||""),S((L==null?void 0:L.html_selector)||"",(L==null?void 0:L.exclude_elements_selector)||"")}catch(L){he(fe.FetchingConfigFailed),console.error("TPI Config failed to fetch",L);return}try{if(M(r,J(await ar(o(m),{maxTries:1,runAiWhenRelevant:!0}))),M(c,!1),!o(r))return;if(Al({organizationSid:o(r).organization_sid,domainSid:o(r).domain_sid}),!o(r).ai_running||!o(r).ai_enabled){g({aiInjections:o(f),manualInjections:o(p)});return}if(!o(a))return;M(r,J(await ar(o(m),{requireCompletedResult:!0,onpoll:L=>M(r,J(L))}))),g({aiInjections:o(f),manualInjections:o(p)})}catch(L){console.error(L),he(fe.InjectionError,null,{message:L.message})}}function k(){g(ma(o(d)))}function w(){M(a,!1),requestAnimationFrame(()=>{M(a,!0),_()})}function g(L={aiInjections:o(f),manualInjections:o(p)}){const q=Ec(o(i),L);JSON.stringify(q)!==JSON.stringify(o(d))&&(M(d,J(q)),window.PlayPilotLinkInjections.evaluated_link_injections=q);const B=q.filter(z=>!z.failed);B.length&&(o(a)||he(fe.ArticleInjected,null,{manual:B.filter(z=>z.manual).length,ai:B.filter(z=>!z.manual).length}))}function S(L,q){L&&(window.PlayPilotLinkInjections.selector=L),M(n,J(Rt())),M(i,J(Ai(o(n),q)))}function j(){M(a,!0),jl(),_()}function b(L){const q="playpilot-custom-style",B=document.getElementById(q),z=B||document.createElement("style");z.textContent=`[data-playpilot-link-injections] { ${L} }`,z.id=q,B||document.body.appendChild(z)}var C=Kd(),I=X(C),E=x(I);{var T=L=>{Hd(L,{onclick:j,onclose:()=>{M(l,!1),Cl()}})};N(E,L=>{!o(u)&&o(l)&&!o(a)&&L(T)})}var R=A(E,2);{var U=L=>{var q=me(),B=X(q);wl(B,{onerror:K=>he(fe.EditorError,null,{message:K.message}),failed:K=>{St(K,{fixed:!0,children:(ee,de)=>{var _e=Ie("An error has occured in the PlayPilot Linkinjections editor view. We've been notified and will investigate!");y(ee,_e)},$$slots:{default:!0}})}},K=>{var ee=O(()=>{var _e;return(_e=o(r))==null?void 0:_e.injections_enabled}),de=O(()=>{var _e,te,ne,ce,Se;return{aiEnabled:(_e=o(r))==null?void 0:_e.ai_enabled,aiRunning:((te=o(r))==null?void 0:te.ai_running)&&((ne=o(r))==null?void 0:ne.ai_enabled),message:(ce=o(r))==null?void 0:ce.ai_progress_message,percentage:(Se=o(r))==null?void 0:Se.ai_progress_percentage}});Dd(K,{get pageText(){return o(m)},get loading(){return o(c)},onreinitialize:w,get injectionsEnabled(){return o(ee)},get aiStatus(){return o(de)},get linkInjections(){return o(d)},set linkInjections(_e){M(d,J(_e))}})}),y(L,q)};N(R,L=>{!o(u)&&o(a)&&o(s)&&L(U)})}var W=A(I,2);Wd(W,{});var F=A(W,2);{var G=L=>{Fd(L,{get pixels(){return o(r).pixels}})};N(F,L=>{var q,B;(B=(q=o(r))==null?void 0:q.pixels)!=null&&B.length&&L(G)})}y(e,C),se()}window.PlayPilotLinkInjections={token:"",editorial_token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,organization_sid:null,domain_sid:null,last_successful_fetch:null,tracked_events:[],split_test_identifiers:{},evaluated_link_injections:[],ads:[],app:null,initialize(e={token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,organization_sid:null,domain_sid:null,editorial_token:""}){if(!e.token){console.error("An API token is required.");return}this.token=e.token,this.editorial_token=e.editorial_token,this.selector=e.selector,this.after_article_selector=e.after_article_selector,this.after_article_insert_position=e.after_article_insert_position,this.language=e.language,this.organization_sid=e.organization_sid,this.domain_sid=e.domain_sid,this.app&&this.destroy();const t=document.createElement("div");t.id="playpilot-link-injection",document.body.insertAdjacentElement("beforeend",t),this.app=dn(Yd,{target:t})},destroy(){if(!this.app)return;this.app=null;const e=document.getElementById("playpilot-link-injection");e&&e.remove(),Pi()},debug(){const e=Rt(),t=Ai(e);console.groupCollapsed("Config"),console.table(Object.entries(this)),console.groupEnd(),console.groupCollapsed("Elements"),console.log("Parent element",e),console.log("Valid elements",t),console.groupEnd(),console.groupCollapsed("Last fetch"),console.log(this.last_successful_fetch),console.groupEnd(),console.groupCollapsed("Meta"),console.log(Ci()),console.groupEnd(),console.groupCollapsed("Page text"),console.log(_a(t)),console.groupEnd(),console.groupCollapsed("Evaluated injections"),console.log(this.evaluated_link_injections),console.groupEnd(),console.groupCollapsed("Tracked events"),console.log(this.tracked_events),console.groupEnd(),console.groupCollapsed("Split tests"),console.log(this.split_test_identifiers),console.groupEnd()},mockAd(e={}){const t={campaign_format:"card",campaign_type:"image",campaign_name:"some_campaign",content:{header:"Some content header",header_logo:"https://picsum.photos/seed/picsum/40/40",header_logo_uuid:"",subheader:"Some content subheader",image:"https://picsum.photos/seed/picsum/640/360",image_uuid:"",video:null,format:null},cta:{header:"Some cta header",subheader:"Some cta subheader",url:"https://google.com/",image:null,image_uuid:null},disclaimer:"Some disclaimer"};this.ads=[{...t,...e}]}};
13
13
 
14
14
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "5.10.0",
3
+ "version": "5.10.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -33,6 +33,8 @@
33
33
 
34
34
  // Keep track of all last inputs. If the last inputs match the "secret" key we show the debugger and start setting data
35
35
  function onkeydown(event: KeyboardEvent): void {
36
+ if (shown) return
37
+
36
38
  const key = event.key
37
39
 
38
40
  lastInputs.push(key)
@@ -51,4 +51,15 @@ describe('Debugger.svelte', () => {
51
51
 
52
52
  expect(getByText('TPI Debugger')).toBeTruthy()
53
53
  })
54
+
55
+ it('Should continue to show debugger after entering correct input and then pressing more keys', async () => {
56
+ const { getByText } = render(Debugger)
57
+
58
+ const keys = ['t', 'p', 'i', 'd', 'e', 'b', 'u', 'g', '1', '2']
59
+ for (const key of keys) {
60
+ await fireEvent.keyDown(window, { key })
61
+ }
62
+
63
+ expect(getByText('TPI Debugger')).toBeTruthy()
64
+ })
54
65
  })