@playpilot/tpi 7.1.0 → 8.0.0-beta.explore-home.2

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.
Files changed (32) hide show
  1. package/.env +1 -0
  2. package/dist/editorial.mount.js +9 -9
  3. package/dist/link-injections.js +1 -1
  4. package/dist/mount.js +7 -7
  5. package/events.md +1 -0
  6. package/package.json +1 -1
  7. package/src/lib/api/youtubeAvailability.ts +26 -0
  8. package/src/lib/enums/TrackingEvent.ts +1 -0
  9. package/src/lib/explore.ts +2 -2
  10. package/src/lib/trailer.ts +31 -0
  11. package/src/lib/types/explore.d.ts +5 -0
  12. package/src/routes/components/Button.svelte +2 -1
  13. package/src/routes/components/Explore/ExploreLayout.svelte +102 -0
  14. package/src/routes/components/Explore/ExploreModal.svelte +2 -2
  15. package/src/routes/components/Explore/ExploreRouter.svelte +35 -0
  16. package/src/routes/components/Explore/Routes/ExploreHome.svelte +15 -0
  17. package/src/routes/components/Explore/{Explore.svelte → Routes/ExploreResults.svelte} +46 -115
  18. package/src/routes/components/Rails/TitlesRail.svelte +61 -9
  19. package/src/routes/components/YouTubeEmbed.svelte +35 -0
  20. package/src/routes/components/YouTubeEmbedOverlay.svelte +14 -28
  21. package/src/routes/elements/+page.svelte +12 -2
  22. package/src/routes/explore/+page.svelte +1 -1
  23. package/src/tests/lib/api/youtubeAvailability.test.js +70 -0
  24. package/src/tests/lib/trailer.test.js +57 -1
  25. package/src/tests/routes/components/Explore/ExploreLayout.test.js +52 -0
  26. package/src/tests/routes/components/Explore/ExploreRouter.test.js +20 -0
  27. package/src/tests/routes/components/Explore/Routes/ExploreHome.test.js +18 -0
  28. package/src/tests/routes/components/Explore/{Explore.test.js → Routes/ExploreResults.test.js} +29 -22
  29. package/src/tests/routes/components/Rails/TitlesRail.test.js +51 -0
  30. package/src/tests/routes/components/YouTubeEmbed.test.js +31 -0
  31. package/src/tests/routes/components/YouTubeEmbedOverlay.test.js +1 -8
  32. package/vite.config.js +8 -0
@@ -1,3 +1,3 @@
1
1
  (function(){"use strict";function m(){var e;return(e=window.PlayPilotLinkInjections)==null?void 0:e.token}const q="https://partner-api.playpilot.tech/1.0",h={};async function d(e,{headers:t={},method:n="GET",body:i=null}={}){const o=!_()&&n==="GET";if(o&&e in h)return h[e];const c=n==="GET"?{}:{"Content-Type":"application/json"},l=await fetch(q+e,{method:n,headers:new Headers({...c,...t}),body:i?JSON.stringify(i):null});if(!(l!=null&&l.ok))throw l;const s=await l.text();let r=s;try{s&&(r=JSON.parse(s))}catch{}return o&&(h[e]=r),r}const y="EncryptedToken",k="articleReplacementEditToken",x="playpilot-editorial-mode";async function I({href:e=window.location.href,throwError:t=!1}={}){try{const n=m();if(!n)throw new Error("No token was provided");const i=P(e);if(!i)throw new Error("Could not be authenticated");return await d(`/external-pages/edit-authorization?api-token=${n}`,{method:"POST",body:{private_token:i}}),A(i),!0}catch(n){if(console.error(n),t)throw n}finally{C()}return!1}function P(e=""){var i,o;const t=(i=window==null?void 0:window.PlayPilotLinkInjections)==null?void 0:i.editorial_token;if(t)return t;if(e){const c=new URL(e).searchParams.get(k);if(c)return decodeURI(c)}return((o=("; "+document.cookie).split(`; ${y}=`).pop())==null?void 0:o.split(";")[0])||""}function A(e){const t=new Date;t.setTime(t.getTime()+30*24*60*60*1e3);const i="expires="+t.toUTCString();document.cookie=y+"="+e+";"+i+";path=/"}function _(){var t;const e=(t=window==null?void 0:window.PlayPilotLinkInjections)==null?void 0:t.editorial_token;return new URLSearchParams(window.location.search).get(x)==="true"||!!e}function C(){const e=new URL(window.location.href);e.searchParams.delete(k),window.history.replaceState({},"",e)}async function O(){const e=m();if(!e)throw new Error("No token was provided");try{return await await d(`/domains/config?api-token=${e}`)||null}catch{return null}}function N(e){let t=0;for(let n=0;n<e.length;n++){const i=e.charCodeAt(n);t=t*31+i>>>0}return t.toString(16)}function M(e=5){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(;n.length<e;)n+=t[Math.floor(Math.random()*t.length)];return n}const T=Object.freeze({English:"en-US",Swedish:"sv-SE",Danish:"da-DK"});function R(){var i,o;const e=(i=window.PlayPilotLinkInjections)==null?void 0:i.language,t=Object.values(T);if(e){if(t.includes(e))return e;console.warn(`PlayPilot Link Injections: ${e} is not an accepted language`)}const n=(o=document.querySelector("html"))==null?void 0:o.getAttribute("lang");if(n){if(t.includes(n))return n;const c=t.find(l=>l.toLowerCase().startsWith(n+"-"));if(c)return c}return T.English}function U(e,t=""){const n=[],i=[e];for(;i.length>0;){const o=i.pop();if(n.includes(o)||t&&o.matches(t)||/^(A|BUTTON|SCRIPT|NOSCRIPT|STYLE|IFRAME|FIGCAPTION|TIME|LABEL|BLOCKQUOTE|H1)$/.test(o.tagName)||o.offsetWidth<=1)continue;const c=Array.from(o.childNodes).some(r=>{var u;return r.nodeType===Node.TEXT_NODE&&((u=r.nodeValue)==null?void 0:u.trim())!==""});if(c&&o.tagName==="LI"){const r=o.closest("ul, ol");r&&!n.includes(r)&&n.push(r);continue}const l=o.tagName==="P"&&!!o.textContent;if(c||l){n.push(o);continue}const s=Array.from(o.children);for(let r=s.length-1;r>=0;r--)i.push(s[r])}return n}function S(){var t;const e=(t=window.PlayPilotLinkInjections)==null?void 0:t.selector;if(e){const n=e.replace(/(:)/g,"\\$1"),i=document.querySelector(n);if(i)return i}return document.querySelector("article")||document.querySelector("main")||document.body}function v(e){return e.map(t=>t.innerText).join(`
2
2
 
3
- `)}function $(e){const t=S(),n=U(t,(e==null?void 0:e.exclude_elements_selector)||""),i=v(n);return{parentElement:t,elements:n,pageText:i}}function E(){const e=S();return{content_heading:z(e),content_modified_time:D(e),content_published_time:G(e)}}function z(e){const t=e.querySelector("h1")||document.querySelector("h1");return(t==null?void 0:t.innerText.trim())||null}function D(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=b().dateModified||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function G(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=b().datePublished||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function g(e){try{return new Date(e).toISOString()}catch{return null}}function b(){const e=document.querySelector('[type="application/ld+json"]');if(!e)return{};try{return JSON.parse(e.textContent||"")}catch{return{}}}function j(){const e=location.pathname.replace(/\/+/g,"/");return location.protocol+"//"+location.host+e}function H(e){return!!(e.exclude_urls_pattern&&j().match(new RegExp(e.exclude_urls_pattern)))}let p=null;async function f(e,{url:t=j(),hash:n=N(e||""),params:i={},method:o="GET"}={}){const c=m(),l=_()?await I():!1,s=R();if(!c)throw new Error("No token was provided");const r=`/external-pages/?api-token=${c}&include_title_details=true${l?"&editorial_mode_enabled=true":""}&language=${s}`;let u;return o==="POST"?(i.run_ai&&(i.hash=n,i.page_text=e),i.url=t,i.metadata=E(),u=await d(r,{method:"POST",body:i})):u=await d(r+`&url=${t}`,{method:"GET"}),window.PlayPilotLinkInjections.last_successful_fetch=u,u}async function B(e,{requireCompletedResult:t=!1,runAiWhenRelevant:n=!1,pollInterval:i=3e3,maxTries:o=600,onpoll:c=()=>null}={}){let l=0;p&&clearTimeout(p);const s=async(r,u)=>{let a;try{try{a=await f(e)}catch(w){throw(w==null?void 0:w.status)===404&&(a=await f(e,{method:"POST"}),a.ai_enabled&&(a=await f(e,{params:{run_ai:!0},method:"POST"}))),new Error}if(a&&n&&(a=await F(e,a)),t&&a.ai_enabled&&a.ai_running)throw new Error;a.manual_injections=L(a.manual_injections||[]),a.ai_injections=L(a.ai_injections||[]),r(a);return}catch{if(l++,l>=o){o>1&&console.error("Max poll limit exceeded. Please return later."),r();return}a&&c(a),p=setTimeout(()=>s(r),i)}};return new Promise(s)}async function F(e,t){if(!e||!t.ai_enabled||t.ai_running)return t;const n=E().content_modified_time,i=t.content_modified_time?g(t.content_modified_time):null,o=n&&i===n;return t.ai_last_run&&o||new Date(n||0)<=new Date(i||0)?t:await f(e,{params:{run_ai:!0},method:"POST"})}function L(e){return e.map(t=>({...t,key:J(t.sid)}))}function J(e){return e+"-"+M()}function K(e){window.PlayPilotLinkInjections&&(window.PlayPilotLinkInjections.consents=e)}function W(){const e=navigator.userAgent.toLowerCase();return/bot|crawl|spider|google|baidu|bing|msn|teoma|slurp|yandex|facebookexternalhit|facebot/i.test(e)}window.PlayPilotLinkInjections={token:"",editorial_token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,last_successful_fetch:null,tracked_events:[],queued_tracking_events:[],split_test_identifiers:{},evaluated_link_injections:[],initial_link_injections_promise:null,time_at_initialize:0,ads:[],require_consent:!0,no_affiliate:!1,consents:{ads:!1,pixels:!1,tracking:!1,split_tests:!1,affiliate:!1},config:{},app:null,async initialize(e={token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,editorial_token:"",require_consent:!0,no_affiliate:!1}){if(!e.token){console.error("An API token is required.");return}if(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.region=e.region,this.organization_sid=e.organization_sid,this.domain_sid=e.domain_sid,this.require_consent=e.require_consent,this.no_affiliate=e.no_affiliate,this.time_at_initialize=Date.now(),this.require_consent===!1&&K({ads:!0,pixels:!0,tracking:!0,split_tests:!0,affiliate:!0}),this.config=await O()||{},H(this.config))return;const{pageText:t}=$(this.config);this.initial_link_injections_promise=B(t,{maxTries:1,runAiWhenRelevant:!W()}),this.mount()},destroy(){var e;(e=window.PlayPilotMount)==null||e.destroy()},mount(){const e=_()||P(),t=document.createElement("script");t.id="playpilot-mount",t.src=`https://cdn.jsdelivr.net/npm/@playpilot/tpi@7.1.0/dist/${e?"editorial.":""}mount.js`,t.onload=()=>{var n;return(n=window.PlayPilotMount)==null?void 0:n.mount()},document.body.appendChild(t)}}})();
3
+ `)}function $(e){const t=S(),n=U(t,(e==null?void 0:e.exclude_elements_selector)||""),i=v(n);return{parentElement:t,elements:n,pageText:i}}function E(){const e=S();return{content_heading:z(e),content_modified_time:D(e),content_published_time:G(e)}}function z(e){const t=e.querySelector("h1")||document.querySelector("h1");return(t==null?void 0:t.innerText.trim())||null}function D(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=b().dateModified||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function G(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=b().datePublished||(t==null?void 0:t.getAttribute("content"))||(t==null?void 0:t.getAttribute("datetime"))||(t==null?void 0:t.innerText);return n?g(n):null}function g(e){try{return new Date(e).toISOString()}catch{return null}}function b(){const e=document.querySelector('[type="application/ld+json"]');if(!e)return{};try{return JSON.parse(e.textContent||"")}catch{return{}}}function j(){const e=location.pathname.replace(/\/+/g,"/");return location.protocol+"//"+location.host+e}function H(e){return!!(e.exclude_urls_pattern&&j().match(new RegExp(e.exclude_urls_pattern)))}let p=null;async function f(e,{url:t=j(),hash:n=N(e||""),params:i={},method:o="GET"}={}){const c=m(),l=_()?await I():!1,s=R();if(!c)throw new Error("No token was provided");const r=`/external-pages/?api-token=${c}&include_title_details=true${l?"&editorial_mode_enabled=true":""}&language=${s}`;let u;return o==="POST"?(i.run_ai&&(i.hash=n,i.page_text=e),i.url=t,i.metadata=E(),u=await d(r,{method:"POST",body:i})):u=await d(r+`&url=${t}`,{method:"GET"}),window.PlayPilotLinkInjections.last_successful_fetch=u,u}async function B(e,{requireCompletedResult:t=!1,runAiWhenRelevant:n=!1,pollInterval:i=3e3,maxTries:o=600,onpoll:c=()=>null}={}){let l=0;p&&clearTimeout(p);const s=async(r,u)=>{let a;try{try{a=await f(e)}catch(w){throw(w==null?void 0:w.status)===404&&(a=await f(e,{method:"POST"}),a.ai_enabled&&(a=await f(e,{params:{run_ai:!0},method:"POST"}))),new Error}if(a&&n&&(a=await F(e,a)),t&&a.ai_enabled&&a.ai_running)throw new Error;a.manual_injections=L(a.manual_injections||[]),a.ai_injections=L(a.ai_injections||[]),r(a);return}catch{if(l++,l>=o){o>1&&console.error("Max poll limit exceeded. Please return later."),r();return}a&&c(a),p=setTimeout(()=>s(r),i)}};return new Promise(s)}async function F(e,t){if(!e||!t.ai_enabled||t.ai_running)return t;const n=E().content_modified_time,i=t.content_modified_time?g(t.content_modified_time):null,o=n&&i===n;return t.ai_last_run&&o||new Date(n||0)<=new Date(i||0)?t:await f(e,{params:{run_ai:!0},method:"POST"})}function L(e){return e.map(t=>({...t,key:J(t.sid)}))}function J(e){return e+"-"+M()}function K(e){window.PlayPilotLinkInjections&&(window.PlayPilotLinkInjections.consents=e)}function W(){const e=navigator.userAgent.toLowerCase();return/bot|crawl|spider|google|baidu|bing|msn|teoma|slurp|yandex|facebookexternalhit|facebot/i.test(e)}window.PlayPilotLinkInjections={token:"",editorial_token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,last_successful_fetch:null,tracked_events:[],queued_tracking_events:[],split_test_identifiers:{},evaluated_link_injections:[],initial_link_injections_promise:null,time_at_initialize:0,ads:[],require_consent:!0,no_affiliate:!1,consents:{ads:!1,pixels:!1,tracking:!1,split_tests:!1,affiliate:!1},config:{},app:null,async initialize(e={token:"",selector:"",after_article_selector:"",after_article_insert_position:"",language:null,region:null,organization_sid:null,domain_sid:null,editorial_token:"",require_consent:!0,no_affiliate:!1}){if(!e.token){console.error("An API token is required.");return}if(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.region=e.region,this.organization_sid=e.organization_sid,this.domain_sid=e.domain_sid,this.require_consent=e.require_consent,this.no_affiliate=e.no_affiliate,this.time_at_initialize=Date.now(),this.require_consent===!1&&K({ads:!0,pixels:!0,tracking:!0,split_tests:!0,affiliate:!0}),this.config=await O()||{},H(this.config))return;const{pageText:t}=$(this.config);this.initial_link_injections_promise=B(t,{maxTries:1,runAiWhenRelevant:!W()}),this.mount()},destroy(){var e;(e=window.PlayPilotMount)==null||e.destroy()},mount(){const e=_()||P(),t=document.createElement("script");t.id="playpilot-mount",t.src=`https://cdn.jsdelivr.net/npm/@playpilot/tpi@8.0.0-beta.explore-home.2/dist/${e?"editorial.":""}mount.js`,t.onload=()=>{var n;return(n=window.PlayPilotMount)==null?void 0:n.mount()},document.body.appendChild(t)}}})();