import{a as C}from"./chunk-SSSSNVF5.js";import{Jb as S,Kb as H,Qa as g,Ra as h,fb as P,jc as k,na as v,qa as x,ra as p,ua as y,vb as L,wb as f}from"./chunk-RISKGE32.js";import{ba as O,fa as N}from"./chunk-6O6MLDWR.js";import"./chunk-F4AZU7R4.js";import"./chunk-GQY3J744.js";import{d as F,g as T,n as M}from"./chunk-CLPINNGF.js";M();T();var A=F(O());var _=e=>{let o=document.createRange();return e.length===0?document.body:(o.setStartBefore(e[0]),o.setEndAfter(e[e.length-1]),o.commonAncestorContainer??document.body)},q=async({awaitedElement:e,startingNode:o,shouldParseShadowRoot:t,useHybridParsingMode:n})=>{e&&await y(e);let a=o?document.querySelector(o)??document.body:document.body;return g({getContent:await h(async({invalidateCache:s})=>({content:await k.getParsedElements({useHybridParsingMode:n,invalidateCache:s,shouldParseShadowRoot:t,startingNodeElement:a}),chunksBefore:0,chunksAfter:0})),converter:s=>({text:C(s),ref:{ref:s}}),options:{sideEffects:!1,autoplay:!1,experimentalEdits:async function*(s){let r=f({ignoreCache:!1,startingNode:a??document.body,shouldParseShadowRoot:t}),i=a??_(r),l=()=>new Promise(d=>{let c=[],u=()=>{E.disconnect(),d([])},m=(0,A.default)(b=>{c=[];let R=f({startingNode:a??document.body,shouldParseShadowRoot:t,ignoreCache:!0});r.length!==R.length&&(r=R,E.disconnect(),s.removeEventListener("abort",u),d(b))},1e3),E=new MutationObserver(b=>{c.push(...b),m(c)});s.addEventListener("abort",u),E.observe(i,{childList:!0,subtree:!0})});for(;!s.aborted&&r.length<1e3;)yield await l()}},metadata:{source:"PillPlayer"}},!0)},w=e=>{let o=[],t=e.heading?x(e.heading):null,n=Array.from(p(e.paragraphChunks));if(e.subHeading){let r=Array.from(p(e.subHeading));r.length>0&&n.unshift(...r)}let a=0;return(t?[t,...n]:n).forEach(r=>{if(v(r)&&!L(r)){let i=P(r).textContent??"";a+=i.length,o.push(r)}}),a<100&&(o=f()),o},D=async e=>{e.awaitedElement&&await y(e.awaitedElement);let o=window.location.origin.includes("wikipedia.org");return g({getContent:await h(async()=>({content:w(e),chunksBefore:0,chunksAfter:0})),converter:t=>{let n=t instanceof HTMLElement?P(t):t;return{text:C(n),ref:{ref:t,highlightInfo:{startOffset:0,unsetColor:o}}}},options:{sideEffects:!1,autoplay:!1,experimentalEdits:async function*(t){let n=w(e),a=_(n),s=()=>new Promise(r=>{let i=[],l=()=>{c.disconnect(),r([])},d=(0,A.default)(u=>{i=[];let m=w(e);n.length!==m.length&&(n=m,c.disconnect(),t.removeEventListener("abort",l),r(u))},1e3),c=new MutationObserver(u=>{i.push(...u),d(i)});t.addEventListener("abort",l),c.observe(a,{childList:!0,subtree:!0})});for(;!t.aborted&&n.length<1e3;)yield await s()}},metadata:{source:"PillPlayer"}},!0)},I=async(e,o)=>{if(e&&S(e))return D(e.selectors);let t=o.ceParsingMode,n=e&&H(e)?e.config:{awaitedElement:null,startingNode:{selector:null,parseShadowRoot:!1},useHybridParsingMode:t==="hybrid"&&e?.mode!=="extract"};return q({awaitedElement:n?.awaitedElement,startingNode:n?.startingNode?.selector??null,shouldParseShadowRoot:n?.startingNode?.parseShadowRoot,useHybridParsingMode:n?.useHybridParsingMode??!1})};async function B(e,o,t,n){let a=await I(e,n);N("restart-page-content",async()=>g(a,!0),"standard-player")}export{B as default,I as queueContent};
//# sourceMappingURL=init-RJHVH3KI.js.map
