@mz1999/defuddle 0.14.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.
- package/LICENSE +21 -0
- package/README.md +371 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +145 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.js +950 -0
- package/dist/constants.js.map +1 -0
- package/dist/defuddle.d.ts +136 -0
- package/dist/defuddle.js +1816 -0
- package/dist/defuddle.js.map +1 -0
- package/dist/elements/callouts.d.ts +6 -0
- package/dist/elements/callouts.js +74 -0
- package/dist/elements/callouts.js.map +1 -0
- package/dist/elements/code.d.ts +5 -0
- package/dist/elements/code.js +346 -0
- package/dist/elements/code.js.map +1 -0
- package/dist/elements/footnotes.d.ts +5 -0
- package/dist/elements/footnotes.js +619 -0
- package/dist/elements/footnotes.js.map +1 -0
- package/dist/elements/headings.d.ts +11 -0
- package/dist/elements/headings.js +100 -0
- package/dist/elements/headings.js.map +1 -0
- package/dist/elements/images.d.ts +8 -0
- package/dist/elements/images.js +877 -0
- package/dist/elements/images.js.map +1 -0
- package/dist/elements/math.base.d.ts +9 -0
- package/dist/elements/math.base.js +195 -0
- package/dist/elements/math.base.js.map +1 -0
- package/dist/elements/math.core.d.ts +7 -0
- package/dist/elements/math.core.js +52 -0
- package/dist/elements/math.core.js.map +1 -0
- package/dist/elements/math.d.ts +2 -0
- package/dist/elements/math.full.d.ts +8 -0
- package/dist/elements/math.js +7 -0
- package/dist/elements/math.js.map +1 -0
- package/dist/extractor-registry.d.ts +16 -0
- package/dist/extractor-registry.js +140 -0
- package/dist/extractor-registry.js.map +1 -0
- package/dist/extractors/_base.d.ts +22 -0
- package/dist/extractors/_base.js +27 -0
- package/dist/extractors/_base.js.map +1 -0
- package/dist/extractors/_conversation.d.ts +9 -0
- package/dist/extractors/_conversation.js +78 -0
- package/dist/extractors/_conversation.js.map +1 -0
- package/dist/extractors/chatgpt.d.ts +14 -0
- package/dist/extractors/chatgpt.js +138 -0
- package/dist/extractors/chatgpt.js.map +1 -0
- package/dist/extractors/claude.d.ts +10 -0
- package/dist/extractors/claude.js +91 -0
- package/dist/extractors/claude.js.map +1 -0
- package/dist/extractors/gemini.d.ts +14 -0
- package/dist/extractors/gemini.js +111 -0
- package/dist/extractors/gemini.js.map +1 -0
- package/dist/extractors/github.d.ts +20 -0
- package/dist/extractors/github.js +251 -0
- package/dist/extractors/github.js.map +1 -0
- package/dist/extractors/grok.d.ts +15 -0
- package/dist/extractors/grok.js +142 -0
- package/dist/extractors/grok.js.map +1 -0
- package/dist/extractors/hackernews.d.ts +21 -0
- package/dist/extractors/hackernews.js +155 -0
- package/dist/extractors/hackernews.js.map +1 -0
- package/dist/extractors/reddit.d.ts +22 -0
- package/dist/extractors/reddit.js +197 -0
- package/dist/extractors/reddit.js.map +1 -0
- package/dist/extractors/twitter.d.ts +16 -0
- package/dist/extractors/twitter.js +204 -0
- package/dist/extractors/twitter.js.map +1 -0
- package/dist/extractors/x-article.d.ts +24 -0
- package/dist/extractors/x-article.js +267 -0
- package/dist/extractors/x-article.js.map +1 -0
- package/dist/extractors/x-oembed.d.ts +20 -0
- package/dist/extractors/x-oembed.js +350 -0
- package/dist/extractors/x-oembed.js.map +1 -0
- package/dist/extractors/youtube.d.ts +87 -0
- package/dist/extractors/youtube.js +869 -0
- package/dist/extractors/youtube.js.map +1 -0
- package/dist/fetch.d.ts +18 -0
- package/dist/fetch.js +265 -0
- package/dist/fetch.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.full.d.ts +12 -0
- package/dist/index.full.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown.d.ts +30 -0
- package/dist/markdown.js +661 -0
- package/dist/markdown.js.map +1 -0
- package/dist/metadata.d.ts +25 -0
- package/dist/metadata.js +426 -0
- package/dist/metadata.js.map +1 -0
- package/dist/node.d.ts +19 -0
- package/dist/node.js +78 -0
- package/dist/node.js.map +1 -0
- package/dist/scoring.d.ts +31 -0
- package/dist/scoring.js +472 -0
- package/dist/scoring.js.map +1 -0
- package/dist/standardize.d.ts +2 -0
- package/dist/standardize.js +1101 -0
- package/dist/standardize.js.map +1 -0
- package/dist/types/extractors.d.ts +41 -0
- package/dist/types/extractors.js +3 -0
- package/dist/types/extractors.js.map +1 -0
- package/dist/types.d.ts +135 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/comments.d.ts +44 -0
- package/dist/utils/comments.js +103 -0
- package/dist/utils/comments.js.map +1 -0
- package/dist/utils/dom.d.ts +42 -0
- package/dist/utils/dom.js +104 -0
- package/dist/utils/dom.js.map +1 -0
- package/dist/utils/linkedom-compat.d.ts +5 -0
- package/dist/utils/linkedom-compat.js +23 -0
- package/dist/utils/linkedom-compat.js.map +1 -0
- package/dist/utils/transcript.d.ts +37 -0
- package/dist/utils/transcript.js +61 -0
- package/dist/utils/transcript.js.map +1 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.js +98 -0
- package/dist/utils.js.map +1 -0
- package/package.json +107 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Defuddle=e():t.Defuddle=e()}(Object("undefined"!=typeof self?self:this),(()=>(()=>{"use strict";var t={640(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.ALLOWED_ATTRIBUTES_DEBUG=e.ALLOWED_ATTRIBUTES=e.ALLOWED_EMPTY_ELEMENTS=e.FOOTNOTE_LIST_SELECTORS=e.FOOTNOTE_INLINE_REFERENCES=e.TEST_ATTRIBUTES_SELECTOR=e.PARTIAL_SELECTORS_REGEX=e.PARTIAL_SELECTORS=e.TEST_ATTRIBUTES=e.EXACT_SELECTORS_JOINED=e.EXACT_SELECTORS=e.HIDDEN_EXACT_SKIP_SELECTOR=e.HIDDEN_EXACT_SELECTOR=e.HIDDEN_EXACT_SELECTORS=e.HIDDEN_EXACT_SKIP_SELECTORS=e.CONTENT_ELEMENT_SELECTOR=e.INLINE_ELEMENTS=e.PRESERVE_ELEMENTS=e.BLOCK_LEVEL_ELEMENTS=e.BLOCK_ELEMENTS_SET=e.BLOCK_ELEMENTS_SELECTOR=e.BLOCK_ELEMENTS=e.MOBILE_WIDTH=e.ENTRY_POINT_ELEMENTS=void 0,e.ENTRY_POINT_ELEMENTS=["#post",".post-content",".post-body",".article-content","#article-content",".article_post",".article-wrapper",".entry-content",".content-article",".instapaper_body",".post",".markdown-body","article",'[role="article"]',"main",'[role="main"]',"#content","body"],e.MOBILE_WIDTH=600,e.BLOCK_ELEMENTS=["div","section","article","main","aside","header","footer","nav","content"],e.BLOCK_ELEMENTS_SELECTOR=e.BLOCK_ELEMENTS.join(","),e.BLOCK_ELEMENTS_SET=new Set(e.BLOCK_ELEMENTS),e.BLOCK_LEVEL_ELEMENTS=new Set([...e.BLOCK_ELEMENTS,"p","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","pre","blockquote","figure","figcaption","table","thead","tbody","tfoot","tr","td","th","details","summary","address","hr","form","fieldset"]),e.PRESERVE_ELEMENTS=new Set(["pre","code","table","thead","tbody","tr","td","th","ul","ol","li","dl","dt","dd","figure","figcaption","picture","details","summary","blockquote","form","fieldset"]),e.INLINE_ELEMENTS=new Set(["a","span","strong","em","i","b","u","code","br","small","sub","sup","mark","date","del","ins","q","abbr","cite","relative-time","time","font"]),e.CONTENT_ELEMENT_SELECTOR=["math","[data-mathml]",".katex",".katex-mathml",".katex-display",".MathJax",".MathJax_Display",".MathJax_SVG","mjx-container","pre","code","table","img","picture","video","blockquote","figure"].join(", "),e.HIDDEN_EXACT_SKIP_SELECTORS=["[hidden]",'[aria-hidden="true"]',".hidden",".invisible"],e.HIDDEN_EXACT_SELECTORS=e.HIDDEN_EXACT_SKIP_SELECTORS.map((t=>'[aria-hidden="true"]'===t?'[aria-hidden="true"]:not([class*="math"])':t)),e.HIDDEN_EXACT_SELECTOR=e.HIDDEN_EXACT_SELECTORS.join(","),e.HIDDEN_EXACT_SKIP_SELECTOR=e.HIDDEN_EXACT_SKIP_SELECTORS.join(","),e.EXACT_SELECTORS=["noscript",'script:not([type^="math/"])',"style","meta","link",'.ad:not([class*="gradient"])','[class^="ad-" i]','[class$="-ad" i]','[id^="ad-" i]','[id$="-ad" i]','[role="banner" i]','[alt*="advert" i]',".promo",".Promo","#barrier-page",".alert",'[id="comments" i]','[id="comment" i]','div[class*="cover-"]','div[id*="cover-"]',"header",".header:not(.banner)","#header","#Header","#banner","#Banner","nav",".navigation","#navigation",'[role="navigation" i]','[role="dialog" i]','[role*="complementary" i]','[class*="pagination" i]',".menu","#siteSub",".previous",".author",".Author",'[class$="_bio"]',"#categories",".contributor",".date","#date","[data-date]",".entry-meta",".meta",".tags","#tags",'[rel="tag"]',".toc",".Toc","#toc",".headline","#headline","#title","#Title","#articleTag",'[href*="/tag/"]','[href*="/tags/"]','[href*="/author/"]','[href*="/author?"]','[href$="/author"]','a[href*="copyright.com"]','a[href*="google.com/preferences"]','[href*="#toc"]','[href="#top"]','[href="#Top"]','[href="#page-header"]','[href="#content"]','[href="#site-content"]','[href="#main-content"]','[href^="#main"]','[src*="author"]',"footer",".aside",'aside:not([class*="callout"])',"button","canvas","date","dialog","fieldset","form",'input:not([type="checkbox"])',"label","option","select",'[role="listbox"]','[role="option"]',"textarea",...e.HIDDEN_EXACT_SELECTORS,"instaread-player",'iframe:not([src*="youtube"]):not([src*="youtu.be"]):not([src*="vimeo"]):not([src*="twitter"]):not([src*="x.com"]):not([src*="datawrapper"])','[class="logo" i]',"#logo","#Logo","#newsletter","#Newsletter",".subscribe",".noprint",'[data-print-layout="hide" i]','[data-block="donotprint" i]','[class*="clickable-icon" i]','li span[class*="ltx_tag" i][class*="ltx_tag_item" i]','a[href^="#"][class*="anchor" i]','a[href^="#"][class*="ref" i]:not(.ltx_ref)','[data-container*="most-viewed" i]',".sidebar",".Sidebar","#sidebar","#Sidebar","#side-bar","#sitesub",'[data-link-name*="skip" i]','[aria-label*="skip" i]',".copyright","#copyright",".licensebox","#page-info","#rss","#feed",".gutter","#primaryaudio","#NYT_ABOVE_MAIN_CONTENT_REGION",'[data-testid="photoviewer-children-figure"] > span',"table.infobox",'[data-optimizely="related-articles-section" i]','[data-orientation="vertical"]',".gh-header-sticky",'[data-testid="issue-metadata-sticky"]'],e.EXACT_SELECTORS_JOINED=e.EXACT_SELECTORS.join(","),e.TEST_ATTRIBUTES=["class","id","data-test","data-testid","data-test-id","data-qa","data-cy"],e.PARTIAL_SELECTORS=["a-statement","access-wall","activitypub","actioncall","addcomment","addtoany","advert","adlayout","ad-tldr","ad-placement","ads-container","_ad_","AdBlock_","AdUnit","after_content","after_main_article","afterpost","allterms","-alert-","alert-box","_archive","around-the-web","aroundpages","article-author","article-badges","article-banner","article-bottom-section","article-bottom","article-category","article-card","article-citation","article__copy","article_date","article-date","article-end ","article_header","article-header","article__header","article__hero","article__info","article-info","article-meta","article_meta","article__meta","articlename","article-subject","article_subject","article-snippet","article-separator","article--share","article--topics","articletags","article-tags","article_tags","articletitle","article-title","article_title","articletopics","article-topics","article-actions","article--lede","articlewell","associated-people","audio-card","author-bio","author-box","author-info","author_info","authorm","author-mini-bio","author-name","author-publish-info","authored-by","avatar","back-to-top","backlink_container","backlinks-section","bio-block","biobox","blog-pager","bookmark-","-bookmark","bottominfo","bottomnav","bottom-of-article","bottom-wrapper","brand-bar","bcrumb","breadcrumb","brdcrumb","button-wrapper","buttons-container","btn-","-btn","byline","captcha","card-text","card-media","card-post","carouselcontainer","carousel-container","cat_header","catlinks","_categories","card-author","card-content","chapter-list","collections","comments","-comment","commentbox","comment-button","commentcomp","comment-content","comment-count","comment-form","comment-number","comment-respond","comment-thread","comment-wrap","complementary","consent","contact-","content-card","content-topics","contentpromo","context-bar","context-widget","core-collateral","cover-image","cover-photo","cover-wrap","created-date","creative-commons_","c-subscribe","_cta","-cta","cta-","cta_","current-issue","custom-list-number","dateline","dateheader","date-header","date-pub","disclaimer","disclosure","discussion","discuss_","-dismiss","disqus","donate","donation","dropdown","element-invisible","eletters","emailsignup","emoji-bar","engagement-widget","enhancement-","entry-author-info","entry-categories","entry-date","entry-title","entry-utility","-error","error-","eyebrow","expand-reduce","external-anchor","externallinkembedwrapper","extra-services","extra-title","facebook","fancy-box","favorite","featured-content","feature_feed","feedback","feed-links","field-site-sections","fixheader","floating-vid","follower","footer","footnote-back","footnoteback","form-group","for-you","frontmatter","further-reading","fullbleedheader","gallery-count","gated-","gh-feed","gist-meta","goog-","graph-view","hamburger","header_logo","header-logo","header-pattern","hero-list","hide-for-print","hide-print","hide-when-no-script","hidden-print","hidden-sidenote","hidden-accessibility","infoline","inline-topic","instacartIntegration","interlude","interaction","itemendrow","intro-date","invisible","jp-no-solution","jp-relatedposts","jswarning","js-warning","jumplink","jumpto","jump-to-","js-skip-to-content","keepreading","keep-reading","keep_reading","keyword_wrap","kicker","labstab","-labels","language-name","lastupdated","latest-content","-ledes-","-license","license-","lightbox-popup","like-button","link-box","links-grid","links-title","listing-dynamic-terms","list-tags","listinks","loading","loa-info","logo_container","ltx_role_refnum","ltx_tag_bibitem","ltx_error","masthead","marketing","media-inquiry","-menu","menu-","metadata","meta-date","meta-row","might-like","minibio","more-about","mod-paywall","_modal","-modal","more-","morenews","morestories","more_wrapper","most-read","move-helper","mw-editsection","mw-cite-backlink","mw-indicators","mw-jump-link","nav-","nav_","navigation-post","next-","newsgallery","news-story-title","newsletter_","newsletterbanner","newslettercontainer","newsletter-form","newsletter-signup","newslettersignup","newsletterwidget","newsletterwrapper","not-found","notessection","nomobile","noprint","open-slideshow","originally-published","other-blogs","outline-view","pagehead","page-header","page-title","paywall_message","-partners","permission-","plea","popular","popup_links","pop_stories","pop-up","post-author","post-bottom","post__category","postcomment","postdate","post-date","post_date","post-details","post-feeds","postinfo","post-info","post_info","post-inline-date","post-links","postlist","post_list","post_meta","post-meta","postmeta","post_more","postnavi","post-navigation","postpath","post-preview","postsnippet","post_snippet","post-snippet","post-subject","posttax","post-tax","post_tax","posttag","post_tag","post-tag","post_time","posttitle","post-title","post_title","post__title","post-ufi-button","prev-post","prevnext","prev_next","prev-next","previousnext","press-inquiries","print-none","print-header","print:hidden","privacy-notice","privacy-settings","profile","promo_article","promo-bar","promo-box","pubdate","pub_date","pub-date","publish_date","publish-date","publication-date","publicationName","qr-code","qr_code","quick_up","_rail","ratingssection","read_also","readmore","read-next","read_next","read_time","read-time","reading_time","reading-time","reading-list","recent-","recent-articles","recentpost","recent_post","recent-post","recommend","redirectedfrom","recirc","register","related","relevant","reversefootnote","robots-nocontent","_rss","rss-link","screen-reader-text","scroll_to","scroll-to","_search","-search","section-nav","series-banner","share-box","sharedaddy","share-icons","sharelinks","share-post","share-print","share-section","shariff-","show-for-print","sidebartitle","sidebar-content","sidebar-wrapper","sideitems","sidebar-author","sidebar-item","side-box","side-logo","sign-in-gate","similar-","similar_","similars-","site-index","site-header","siteheader","site-logo","site-name","site-wordpress","skip-content","skip-to-content","skip-link","c-skip-link","_skip-link","-slider","slug-wrap","social-author","social-shar","social-date","speechify-ignore","speedbump","sponsor","springercitation","sr-only","_stats","story-date","story-navigation","storyreadtime","storysmall","storypublishdate","subject-label","subhead","submenu","-subscribe-","subscriber-drive","subscription-","_tags","tags__item","tag_list","taxonomy","table-of-contents","tabs-","terminaltout","time-rubric","timestamp","time-read","time-to-read","tip_off","tiptout","-tout-","toc-container","toggle-caption","tooltip-content","topbar","topic-authors","topic-footer","topic-list","topic-subnav","top-wrapper","tree-item","trending","trust-feat","trust-badge","trust-project","twitter","u-hide","upsell","viewbottom","yarpp-related","visually-hidden","welcomebox","widget_pages"],e.PARTIAL_SELECTORS_REGEX=new RegExp(e.PARTIAL_SELECTORS.join("|"),"i"),e.TEST_ATTRIBUTES_SELECTOR=e.TEST_ATTRIBUTES.map((t=>`[${t}]`)).join(","),e.FOOTNOTE_INLINE_REFERENCES=["sup.reference","cite.ltx_cite",'sup[id^="fnr"]','span[id^="fnr"]','span[class*="footnote_ref"]','span[class*="footnote-ref"]',"span.footnote-link","a.citation",'a[id^="ref-link"]','a[href^="#fn"]','a[href^="#cite"]','a[href^="#reference"]','a[href^="#footnote"]','a[href^="#r"]','a[href^="#b"]','a[href*="cite_note"]','a[href*="cite_ref"]',"a.footnote-anchor","span.footnote-hovercard-target a",'a[role="doc-biblioref"]','a[id^="fnref"]','a[id^="ref-link"]',"sup.footnoteref"].join(","),e.FOOTNOTE_LIST_SELECTORS=["div.footnote ol","div.footnotes ol",'div[role="doc-endnotes"]','div[role="doc-footnotes"]',"ol.footnotes-list","ol.footnotes","ol.references",'ol[class*="article-references"]',"section.footnotes ol",'section[role="doc-endnotes"]','section[role="doc-footnotes"]','section[role="doc-bibliography"]',"ul.footnotes-list","ul.ltx_biblist",'div.footnote[data-component-name="FootnoteToDOM"]',"div.footnotes-footer"].join(","),e.ALLOWED_EMPTY_ELEMENTS=new Set(["area","audio","base","br","circle","col","defs","ellipse","embed","figure","g","hr","iframe","img","input","line","link","mask","meta","object","param","path","pattern","picture","polygon","polyline","rect","source","stop","svg","td","th","track","use","video","wbr"]),e.ALLOWED_ATTRIBUTES=new Set(["alt","allow","allowfullscreen","aria-label","checked","colspan","controls","data-latex","data-src","data-srcset","data-callout","data-callout-title","data-lang","dir","display","frameborder","headers","height","href","kind","label","lang","role","rowspan","src","srclang","srcset","title","type","width","accent","accentunder","align","columnalign","columnlines","columnspacing","columnspan","data-mjx-texclass","depth","displaystyle","fence","frame","framespacing","linethickness","lspace","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","rowalign","rowlines","rowspacing","rowspan","rspace","scriptlevel","separator","stretchy","symmetric","voffset","xmlns"]),e.ALLOWED_ATTRIBUTES_DEBUG=new Set(["class","id"])},628(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{l(n.next(t))}catch(t){i(t)}}function a(t){try{l(n.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}l((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.Defuddle=void 0;const o=r(608),i=r(864),s=r(917),a=r(640),l=r(840),c=r(610),u=r(726),d=r(968),h=r(552),m=r(639),p=new Set(["title","author","published","site","description","image","language"]),f=/width\s*:\s*(\d+)/,g=/height\s*:\s*(\d+)/,v=/(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]*\s+\d{1,2}/i,y=/\d+\s*min(?:ute)?s?\s+read\b/i,b=[/^This (?:article|story|piece) (?:appeared|was published|originally appeared) in\b/i,/^A version of this (?:article|story) (?:appeared|was published) in\b/i,/^Originally (?:published|appeared) (?:in|on|at)\b/i],C=[/\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b/gi,/\b\d+(?:st|nd|rd|th)?\b/g,/\bmin(?:ute)?s?\b/gi,/\bread\b/gi,/[|\xb7\u2022\u2014\u2013\-,.\s]/g];e.Defuddle=class{constructor(t,e={}){this._schemaOrgData=void 0,this._schemaOrgExtracted=!1,this.doc=t,this.options=e,this.debug=e.debug||!1}getSchemaOrgData(){return this._schemaOrgExtracted||(this._schemaOrgData=this._extractSchemaOrgData(this.doc),this._schemaOrgExtracted=!0),this._schemaOrgData}parse(){let t=this.parseInternal();if(t.wordCount<200){this._log("Initial parse returned very little content, trying again");const e=this.parseInternal({removePartialSelectors:!1});e.wordCount>2*t.wordCount&&(this._log("Retry produced more content"),t=e)}if(t.wordCount<50){this._log("Still very little content, retrying without hidden-element removal");const e=this.parseInternal({removeHiddenElements:!1});e.wordCount>2*t.wordCount&&(this._log("Hidden-element retry produced more content"),t=e);const r=this.findLargestHiddenContentSelector();if(r){this._log("Retrying with hidden content selector:",r);const e=this.parseInternal({removeHiddenElements:!1,removePartialSelectors:!1,contentSelector:r});(e.wordCount>t.wordCount||e.wordCount>Math.max(20,.7*t.wordCount)&&e.content.length<t.content.length)&&(this._log("Hidden-selector retry produced better focused content"),t=e)}}if(t.wordCount<50){this._log("Still very little content, retrying without scoring/partial selectors (possible index page)");const e=this.parseInternal({removeLowScoring:!1,removePartialSelectors:!1,removeContentPatterns:!1});e.wordCount>t.wordCount&&(this._log("Index page retry produced more content"),t=e)}this._stripUnsafeElements();const e=this._getSchemaText(t.schemaOrgData);if(e&&this.countHtmlWords(e)>t.wordCount){const r=this._findContentBySchemaText(e);r?(this._log("Found DOM content matching schema.org text"),t.content=r,t.wordCount=this.countHtmlWords(r)):(this._log("Using schema.org text as content (DOM element not found)"),t.content=e,t.wordCount=this.countHtmlWords(e))}return t}_getSchemaText(t,e=0){if(!t||e>10)return"";const r=Array.isArray(t)?t:[t];for(const t of r)if(Array.isArray(t)){const r=this._getSchemaText(t,e+1);if(r)return r}else{if((null==t?void 0:t.text)&&"string"==typeof t.text)return t.text;if((null==t?void 0:t.articleBody)&&"string"==typeof t.articleBody)return t.articleBody;if((null==t?void 0:t["@graph"])&&Array.isArray(t["@graph"])){const r=this._getSchemaText(t["@graph"],e+1);if(r)return r}}return""}_stripUnsafeElements(){const t=this.doc.body;if(!t)return;const e=t.querySelectorAll('script:not([type^="math/"]), style, noscript, frame, frameset, object, embed, applet, base');for(const t of e)t.remove();const r=t.querySelectorAll("*");for(const t of r)for(const e of Array.from(t.attributes)){const r=e.name.toLowerCase();(r.startsWith("on")||"srcdoc"===r||["href","src","action","formaction","xlink:href"].includes(r)&&(0,m.isDangerousUrl)(e.value))&&t.removeAttribute(e.name)}}_findElementBySchemaText(t,e){var r;const n=((null===(r=e.split(/\n\s*\n/)[0])||void 0===r?void 0:r.trim())||"").substring(0,100).trim();if(!n)return null;const o=(0,h.countWords)(e);let i=null,s=1/0;const a=t.querySelectorAll("*");for(const e of a){if(e===t)continue;const r=e.textContent||"";if(!r.includes(n))continue;const a=(0,h.countWords)(r);a>=.8*o&&a<s&&(s=a,i=e)}return i}_findContentBySchemaText(t){const e=this.doc.body;if(!e)return"";const r=this._findElementBySchemaText(e,t);if(!r)return"";let n="",o="";const s=r.parentElement;if(s&&s!==e){const t=s.querySelectorAll("img");let e=null,i=0;for(const n of t){if(r.contains(n))continue;const t=parseInt(n.getAttribute("width")||"0",10)*parseInt(n.getAttribute("height")||"0",10);t>i&&(i=t,e=n)}if(e){n=this._getLargestImageSrc(e),o=e.getAttribute("alt")||"";try{const t=this.options.url||this.doc.URL;t&&(n=new URL(n,t).href)}catch(t){}}}(0,i.removeHeadingAnchors)(r),this.resolveRelativeUrls(r);let a=(0,m.serializeHTML)(r);if(n){const t=this.doc.createElement("img");t.setAttribute("src",n),t.setAttribute("alt",o),a+=t.outerHTML}return a}findLargestHiddenContentSelector(){const t=this.doc.body;if(!t)return;const e=Array.from(t.querySelectorAll(a.HIDDEN_EXACT_SKIP_SELECTOR)).filter((t=>!(t.getAttribute("class")||"").includes("math")));let r=null,n=0;for(const t of e){const e=(0,h.countWords)(t.textContent||"");e>n&&(r=t,n=e)}return!r||n<30?void 0:this.getElementSelector(r)}_getLargestImageSrc(t){const e=t.getAttribute("srcset")||"";if(!e)return t.getAttribute("src")||"";const r=/(.+?)\s+(\d+(?:\.\d+)?)w/g;let n,o="",i=0,s=0;for(;null!==(n=r.exec(e));){let t=n[1].trim();s>0&&(t=t.replace(/^,\s*/,"")),s=r.lastIndex;const e=parseFloat(n[2]);t&&e>i&&(i=e,o=t)}let a=o||t.getAttribute("src")||"";return a=a.replace(/,w_\d+/g,"").replace(/,c_\w+/g,""),a}parseAsync(){return n(this,void 0,void 0,(function*(){var t;if(!1!==this.options.useAsync){const t=yield this.tryAsyncExtractor(s.ExtractorRegistry.findPreferredAsyncExtractor.bind(s.ExtractorRegistry));if(t)return t}const e=this.parse();return e.wordCount>0||!1===this.options.useAsync?e:null!==(t=yield this.tryAsyncExtractor(s.ExtractorRegistry.findAsyncExtractor.bind(s.ExtractorRegistry)))&&void 0!==t?t:e}))}fetchAsyncVariables(){return n(this,void 0,void 0,(function*(){var t;if(!1===this.options.useAsync)return null;try{const e=this.options.url||this.doc.URL,r=this.getSchemaOrgData(),n={includeReplies:null!==(t=this.options.includeReplies)&&void 0!==t?t:"extractors",language:this.options.language},o=s.ExtractorRegistry.findPreferredAsyncExtractor(this.doc,e,r,n);if(o){const t=yield o.extractAsync();return this.getExtractorVariables(t.variables)||null}}catch(t){console.error("Defuddle","Error fetching async variables:",t)}return null}))}tryAsyncExtractor(t){return n(this,void 0,void 0,(function*(){var e;try{const r=this.options.url||this.doc.URL,n=this.getSchemaOrgData(),i={includeReplies:null!==(e=this.options.includeReplies)&&void 0!==e?e:"extractors",language:this.options.language},s=t(this.doc,r,n,i);if(s){const t=Date.now(),e=yield s.extractAsync(),r=this._collectMetaTags(),i=o.MetadataExtractor.extract(this.doc,n,r);return this.buildExtractorResponse(e,i,t,s,r)}}catch(t){console.error("Defuddle","Error in async extraction:",t)}return null}))}parseInternal(t={}){var e;const r=Date.now();if(!this.doc.documentElement){const t=this.options.url||"";return{content:"",title:"",description:"",domain:t?new URL(t).hostname:"",favicon:"",image:"",language:"",parseTime:Date.now()-r,published:"",author:"",site:"",schemaOrgData:null,wordCount:0}}const n=Object.assign(Object.assign({removeExactSelectors:!0,removePartialSelectors:!0,removeHiddenElements:!0,removeLowScoring:!0,removeSmallImages:!0,removeContentPatterns:!0,standardize:!0,includeReplies:"extractors"},this.options),t),i=[],a=this.getSchemaOrgData();this._metaTags||(this._metaTags=this._collectMetaTags());const h=this._metaTags;this._metadata||(this._metadata=o.MetadataExtractor.extract(this.doc,a,h));const p=this._metadata;n.removeImages&&this.removeImages(this.doc);try{const t=n.url||this.doc.URL,o={includeReplies:n.includeReplies,language:n.language},f=s.ExtractorRegistry.findExtractor(this.doc,t,a,o);if(f&&f.canExtract()){const t=f.extract();return this.buildExtractorResponse(t,p,r,f,h)}this._mobileStyles||(this._mobileStyles=this._evaluateMediaQueries(this.doc));const g=this._mobileStyles;this._smallImages||(this._smallImages=this.findSmallImages(this.doc));const v=this._smallImages,y=this.doc.cloneNode(!0);null===(e=y.body)||void 0===e||e.normalize(),this.flattenShadowRoots(this.doc,y),this.resolveStreamedContent(y),this.applyMobileStyles(y,g);let b=null;if(n.contentSelector&&(b=y.querySelector(n.contentSelector),this._log("Using contentSelector:",n.contentSelector,b?"found":"not found")),b||(b=this.findMainContent(y)),b&&"body"===b.tagName.toLowerCase()){const t=this._getSchemaText(a);if(t){const e=this._findElementBySchemaText(y.body,t);e&&(this._log("Found content element via schema.org text"),b=e)}}if(!b){const t=this.doc.body?this.resolveContentUrls((0,m.serializeHTML)(this.doc.body)):"",e=Date.now();return Object.assign(Object.assign({content:t},p),{wordCount:this.countHtmlWords(t),parseTime:Math.round(e-r),metaTags:h})}b.querySelectorAll("wbr").forEach((t=>t.remove())),n.standardize&&((0,c.standardizeFootnotes)(b),(0,u.standardizeCallouts)(b)),n.removeSmallImages&&this.removeSmallImages(y,v),n.removeHiddenElements&&this.removeHiddenElements(y,i),(n.removeExactSelectors||n.removePartialSelectors)&&this.removeBySelector(y,n.removeExactSelectors,n.removePartialSelectors,b,i,!1===n.removeHiddenElements),n.removeLowScoring&&d.ContentScorer.scoreAndRemove(y,this.debug,i,b),n.removeContentPatterns&&b&&this.removeByContentPattern(b,this.debug?i:void 0),n.standardize&&(0,l.standardizeContent)(b,p,this.doc,this.debug),this.resolveRelativeUrls(b);const C=b.outerHTML,E=Date.now(),x=Object.assign(Object.assign({content:C},p),{wordCount:this.countHtmlWords(C),parseTime:Math.round(E-r),metaTags:h});return this.debug&&(x.debug={contentSelector:this.getElementSelector(b),removals:i}),x}catch(t){console.error("Defuddle","Error processing document:",t);const e=this.doc.body?this.resolveContentUrls((0,m.serializeHTML)(this.doc.body)):"",n=Date.now();return Object.assign(Object.assign({content:e},p),{wordCount:this.countHtmlWords(e),parseTime:Math.round(n-r),metaTags:h})}}countHtmlWords(t){const e=t.replace(/<[^>]*>/g," ").replace(/ /gi," ").replace(/&/gi,"&").replace(/</gi,"<").replace(/>/gi,">").replace(/"/gi,'"').replace(/&#\d+;/g," ").replace(/&\w+;/g," ");return(0,h.countWords)(e)}_log(...t){this.debug&&console.log("Defuddle:",...t)}_evaluateMediaQueries(t){const e=[],r=/max-width[^:]*:\s*(\d+)/;try{if(!t.styleSheets)return e;const n=Array.from(t.styleSheets).filter((t=>{try{return t.cssRules,!0}catch(t){return t instanceof DOMException&&t.name,!1}}));n.flatMap((t=>{try{return"undefined"==typeof CSSMediaRule?[]:Array.from(t.cssRules).filter((t=>t instanceof CSSMediaRule&&t.conditionText.includes("max-width")))}catch(t){return this.debug&&console.warn("Defuddle: Failed to process stylesheet:",t),[]}})).forEach((t=>{const n=t.conditionText.match(r);if(n){const r=parseInt(n[1]);if(a.MOBILE_WIDTH<=r){Array.from(t.cssRules).filter((t=>t instanceof CSSStyleRule)).forEach((t=>{try{e.push({selector:t.selectorText,styles:t.style.cssText})}catch(t){this.debug&&console.warn("Defuddle: Failed to process CSS rule:",t)}}))}}}))}catch(t){console.error("Defuddle: Error evaluating media queries:",t)}return e}applyMobileStyles(t,e){e.forEach((({selector:e,styles:r})=>{try{t.querySelectorAll(e).forEach((t=>{t.setAttribute("style",(t.getAttribute("style")||"")+r)}))}catch(t){console.error("Defuddle","Error applying styles for selector:",e,t)}}))}removeImages(t){const e=t.getElementsByTagName("img");Array.from(e).forEach((t=>{t.remove()}))}removeHiddenElements(t,e){let r=0;const n=new Map,o=/(?:^|;\s*)(?:display\s*:\s*none|visibility\s*:\s*hidden|opacity\s*:\s*0)(?:\s*;|\s*$)/i,i=t.defaultView,s="undefined"!=typeof window&&i===window,a=t.querySelectorAll("*");for(const t of a){if(t.querySelector("math, [data-mathml], .katex-mathml")||"math"===t.tagName.toLowerCase())continue;const e=t.getAttribute("style");if(e&&o.test(e)){const o=e.includes("display")?"display:none":e.includes("visibility")?"visibility:hidden":"opacity:0";n.set(t,o),r++;continue}if(s)try{const e=i.getComputedStyle(t);let o="";if("none"===e.display?o="display:none":"hidden"===e.visibility?o="visibility:hidden":"0"===e.opacity&&(o="opacity:0"),o){n.set(t,o),r++;continue}}catch(t){}const a=t.getAttribute("class")||"";if(a){const e=a.split(/\s+/);for(const o of e)if("hidden"===o||o.endsWith(":hidden")||"invisible"===o||o.endsWith(":invisible")){n.set(t,`class:${o}`),r++;break}}}n.forEach(((t,r)=>{this.debug&&e&&e.push({step:"removeHiddenElements",reason:t,text:(0,h.textPreview)(r)}),r.remove()})),this._log("Removed hidden elements:",r)}removeBySelector(t,e=!0,r=!0,n,o,i=!1){const s=Date.now();let l=0,c=0;const u=new Map;if(e){t.querySelectorAll(a.EXACT_SELECTORS_JOINED).forEach((t=>{if(null==t?void 0:t.parentNode){if(i){const e=t.closest(a.HIDDEN_EXACT_SKIP_SELECTOR),r=(t.getAttribute("role")||"").toLowerCase();if(t.matches(a.HIDDEN_EXACT_SELECTOR)||e&&"dialog"===r)return}if(t.closest("pre, code"))return;u.set(t,{type:"exact"}),l++}}))}if(r){const e=this.debug?a.PARTIAL_SELECTORS.map((t=>({pattern:t,regex:new RegExp(t,"i")}))):null;t.querySelectorAll(a.TEST_ATTRIBUTES_SELECTOR).forEach((t=>{var r;if(u.has(t))return;const n=t.tagName;if("CODE"===n||"PRE"===n||t.querySelector("pre")||t.closest("code, pre"))return;const o=a.TEST_ATTRIBUTES.map((e=>"class"===e?(0,m.getClassName)(t):"id"===e?t.id||"":t.getAttribute(e)||"")).join(" ").toLowerCase();if(o.trim()&&a.PARTIAL_SELECTORS_REGEX.test(o)){const n=e?null===(r=e.find((t=>t.regex.test(o))))||void 0===r?void 0:r.pattern:void 0;u.set(t,{type:"partial",selector:n}),c++}}))}u.forEach((({type:t,selector:e},r)=>{if(!(n&&r.contains(n)||"A"===r.tagName&&r.closest("h1, h2, h3, h4, h5, h6"))){try{if(r.matches(a.FOOTNOTE_LIST_SELECTORS)||r.querySelector(a.FOOTNOTE_LIST_SELECTORS))return;const t=r.parentElement;if(t&&t.matches(a.FOOTNOTE_LIST_SELECTORS))return}catch(t){}this.debug&&o&&o.push({step:"removeBySelector",selector:"exact"===t?"exact":e,reason:"exact"===t?"exact selector match":`partial match: ${e}`,text:(0,h.textPreview)(r)}),r.remove()}}));const d=Date.now();this._log("Removed clutter elements:",{exactSelectors:l,partialSelectors:c,total:u.size,processingTime:`${(d-s).toFixed(2)}ms`})}findSmallImages(t){var e,r;const n=new Set;let o=0;const i=t.querySelectorAll("img, svg"),s=t.defaultView,a="undefined"!=typeof window&&s===window;for(const t of i){const i=parseInt(t.getAttribute("width")||"0"),l=parseInt(t.getAttribute("height")||"0"),c=t.getAttribute("style")||"",u=parseInt((null===(e=c.match(f))||void 0===e?void 0:e[1])||"0"),d=parseInt((null===(r=c.match(g))||void 0===r?void 0:r[1])||"0");let h=0,m=0;if(a){try{const e=s.getComputedStyle(t);h=parseInt(e.width)||0,m=parseInt(e.height)||0}catch(t){}try{const e=t.getBoundingClientRect();e.width>0&&(h=h||e.width),e.height>0&&(m=m||e.height)}catch(t){}}const p=[i,u,h].filter((t=>t>0)),v=[l,d,m].filter((t=>t>0));if(p.length>0&&v.length>0){const e=Math.min(...p),r=Math.min(...v);if(e<33||r<33){const e=this.getElementIdentifier(t);e&&(n.add(e),o++)}}}return this._log("Found small elements:",o),n}removeSmallImages(t,e){let r=0;["img","svg"].forEach((n=>{const o=t.getElementsByTagName(n);Array.from(o).forEach((t=>{const n=this.getElementIdentifier(t);n&&e.has(n)&&(t.remove(),r++)}))})),this._log("Removed small elements:",r)}getElementIdentifier(t){if("img"===t.tagName.toLowerCase()){const e=t.getAttribute("data-src");if(e)return`src:${e}`;const r=t.getAttribute("src")||"",n=t.getAttribute("srcset")||"",o=t.getAttribute("data-srcset");if(r)return`src:${r}`;if(n)return`srcset:${n}`;if(o)return`srcset:${o}`}const e=t.id||"",r=(0,m.getClassName)(t),n="svg"===t.tagName.toLowerCase()&&t.getAttribute("viewBox")||"";return e?`id:${e}`:n?`viewBox:${n}`:r?`class:${r}`:null}findMainContent(t){const e=[];if(a.ENTRY_POINT_ELEMENTS.forEach(((r,n)=>{t.querySelectorAll(r).forEach((t=>{let r=40*(a.ENTRY_POINT_ELEMENTS.length-n);r+=d.ContentScorer.scoreElement(t),e.push({element:t,score:r,selectorIndex:n})}))})),0===e.length)return this.findContentByScoring(t);if(e.sort(((t,e)=>e.score-t.score)),this.debug&&this._log("Content candidates:",e.map((t=>({element:t.element.tagName,selector:this.getElementSelector(t.element),score:t.score})))),1===e.length&&"body"===e[0].element.tagName.toLowerCase()){const e=this.findTableBasedContent(t);if(e)return e}const r=e[0];let n=r;for(let t=1;t<e.length;t++){const o=e[t],i=(0,h.countWords)(o.element.textContent||"");if(o.selectorIndex<n.selectorIndex&&n.element.contains(o.element)&&i>50){let t=0;for(const n of e)if(n.selectorIndex===o.selectorIndex&&r.element.contains(n.element)&&++t>1)break;if(t>1)continue;n=o}}return n!==r?n.element:r.element}findTableBasedContent(t){if(!Array.from(t.getElementsByTagName("table")).some((t=>{var e;const r=parseInt(t.getAttribute("width")||"0"),n=this.getComputedStyle(t);return r>400||(null===(e=null==n?void 0:n.width)||void 0===e?void 0:e.includes("px"))&&parseInt(n.width)>400||"center"===t.getAttribute("align")||(t.className||"").toLowerCase().includes("content")||(t.className||"").toLowerCase().includes("article")})))return null;const e=Array.from(t.getElementsByTagName("td"));return d.ContentScorer.findBestElement(e)}findContentByScoring(t){const e=[];return t.querySelectorAll(a.BLOCK_ELEMENTS_SELECTOR).forEach((t=>{const r=d.ContentScorer.scoreElement(t);r>0&&e.push({score:r,element:t})})),e.length>0?e.sort(((t,e)=>e.score-t.score))[0].element:null}getElementSelector(t){const e=[];let r=t;for(;r&&r!==this.doc.documentElement;){let t=r.tagName.toLowerCase();r.id?t+="#"+r.id:(0,m.getClassName)(r)&&(t+="."+(0,m.getClassName)(r).trim().split(/\s+/).join(".")),e.unshift(t),r=r.parentElement}return e.join(" > ")}getComputedStyle(t){return(0,h.getComputedStyle)(t)}resolveRelativeUrls(t){const e=this.options.url||this.doc.URL;if(!e)return;let r=e;const n=this.doc.querySelector("base[href]");if(n){const t=n.getAttribute("href");if(t)try{r=new URL(t,e).href}catch(t){}}const o=t=>{const e=t.trim().replace(/^\\?["']+/,"").replace(/\\?["']+$/,"");try{return new URL(e,r).href}catch(r){return e||t}};t.querySelectorAll("[href]").forEach((t=>{const e=t.getAttribute("href");e&&t.setAttribute("href",o(e))})),t.querySelectorAll("[src]").forEach((t=>{const e=t.getAttribute("src");e&&t.setAttribute("src",o(e))})),t.querySelectorAll("[srcset]").forEach((t=>{const e=t.getAttribute("srcset");if(e){const r=/(.+?)\s+(\d+(?:\.\d+)?[wx])/g,n=[];let i,s=0;for(;null!==(i=r.exec(e));){let t=i[1].trim();s>0&&(t=t.replace(/^,\s*/,"")),s=r.lastIndex,n.push(`${o(t)} ${i[2]}`)}if(n.length>0)t.setAttribute("srcset",n.join(", "));else{const r=e.split(",").map((t=>{const e=t.trim().split(/\s+/);return e[0]&&(e[0]=o(e[0])),e.join(" ")})).join(", ");t.setAttribute("srcset",r)}}})),t.querySelectorAll("[poster]").forEach((t=>{const e=t.getAttribute("poster");e&&t.setAttribute("poster",o(e))}))}flattenShadowRoots(t,e){var r,n,o;if(!t.body||!e.body)return;const i=Array.from(t.body.querySelectorAll("*")),s=i.find((t=>t.shadowRoot));if(!s)return;const a=Array.from(e.body.querySelectorAll("*"));if((null!==(o=null===(n=null===(r=s.shadowRoot)||void 0===r?void 0:r.childNodes)||void 0===n?void 0:n.length)&&void 0!==o?o:0)>0)for(let t=i.length-1;t>=0;t--){const r=i[t];if(!r.shadowRoot)continue;const n=a[t];if(!n)continue;const o=r.shadowRoot.innerHTML;o.length>0&&this.replaceShadowHost(n,o,e)}else{const t=[];for(let e=0;e<i.length;e++){const r=i[e],n=r.getAttribute("data-defuddle-shadow");if(!n)continue;const o=a[e];o&&(t.push({cloneEl:o,html:n}),r.removeAttribute("data-defuddle-shadow"),o.removeAttribute("data-defuddle-shadow"))}for(const{cloneEl:r,html:n}of t)this.replaceShadowHost(r,n,e)}}resolveStreamedContent(t){const e=t.querySelectorAll("script"),r=[],n=/\$RC\("(B:\d+)","(S:\d+)"\)/g;for(const t of e){const e=t.textContent||"";if(!e.includes("$RC("))continue;let o;for(n.lastIndex=0;null!==(o=n.exec(e));)r.push({templateId:o[1],contentId:o[2]})}if(0===r.length)return;let o=0;for(const{templateId:e,contentId:n}of r){const r=t.getElementById(e),i=t.getElementById(n);if(!r||!i)continue;const s=r.parentNode;if(!s)continue;let a=r.nextSibling,l=!1;for(;a;){const t=a.nextSibling;if(8===a.nodeType&&"/$"===a.data){a.remove(),l=!0;break}a.remove(),a=t}if(l){for(;i.firstChild;)s.insertBefore(i.firstChild,r);r.remove(),i.remove(),o++}}o>0&&this._log("Resolved streamed content:",o,"suspense boundaries")}replaceShadowHost(t,e,r){var n;const o=(0,m.parseHTML)(r,e);if(t.tagName.includes("-")){const e=r.createElement("div");e.appendChild(o),null===(n=t.parentNode)||void 0===n||n.replaceChild(e,t)}else t.textContent="",t.appendChild(o)}resolveContentUrls(t){if(!(this.options.url||this.doc.URL))return t;const e=this.doc.createElement("div");return e.appendChild((0,m.parseHTML)(this.doc,t)),this.resolveRelativeUrls(e),(0,m.serializeHTML)(e)}_extractSchemaOrgData(t){const e=t.querySelectorAll('script[type="application/ld+json"]'),r=[];e.forEach((t=>{let e=t.textContent||"";try{e=e.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm,"").replace(/^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/,"$1").replace(/^\s*(\*\/|\/\*)\s*|\s*(\*\/|\/\*)\s*$/g,"").trim();const t=JSON.parse(e);t["@graph"]&&Array.isArray(t["@graph"])?r.push(...t["@graph"]):r.push(t)}catch(t){console.error("Defuddle: Error parsing schema.org data:",t),this.debug&&console.error("Defuddle: Problematic JSON content:",e)}}));const n=t=>{if("string"==typeof t)return this._decodeHTMLEntities(t);if(Array.isArray(t))return t.map(n);if("object"==typeof t&&null!==t){const e={};for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=n(t[r]));return e}return t};return r.map(n)}_collectMetaTags(){const t=[];return this.doc.querySelectorAll("meta").forEach((e=>{const r=e.getAttribute("name"),n=e.getAttribute("property");let o=e.getAttribute("content");o&&t.push({name:r,property:n,content:this._decodeHTMLEntities(o)})})),t}_decodeHTMLEntities(t){return(0,m.decodeHTMLEntities)(this.doc,t)}buildExtractorResponse(t,e,r,n,o){var i,s,a,l,c;const u=this.resolveContentUrls(t.contentHtml),d=this.getExtractorVariables(t.variables);return Object.assign({content:u,title:(null===(i=t.variables)||void 0===i?void 0:i.title)||e.title,description:e.description,domain:e.domain,favicon:e.favicon,image:e.image,language:(null===(s=t.variables)||void 0===s?void 0:s.language)||e.language,published:(null===(a=t.variables)||void 0===a?void 0:a.published)||e.published,author:(null===(l=t.variables)||void 0===l?void 0:l.author)||e.author,site:(null===(c=t.variables)||void 0===c?void 0:c.site)||e.site,schemaOrgData:e.schemaOrgData,wordCount:this.countHtmlWords(t.contentHtml),parseTime:Math.round(Date.now()-r),extractorType:n.constructor.name.replace("Extractor","").toLowerCase(),metaTags:o},d?{variables:d}:{})}getExtractorVariables(t){if(!t)return;const e={};let r=!1;for(const[n,o]of Object.entries(t))p.has(n)||(e[n]=o,r=!0);return r?e:void 0}removeByContentPattern(t,e){var r,n,o,i,s,l,c,u,d,m,p,f,g,E;const x=Array.from(t.querySelectorAll("p, span, div, time"));for(const t of x){if(!t.parentNode)continue;if(t.closest("pre")||t.closest("code"))continue;const n=(null===(r=t.textContent)||void 0===r?void 0:r.trim())||"";if((0,h.countWords)(n)<=15&&v.test(n)&&y.test(n)&&0===t.querySelectorAll("p, div, section, article").length){let r=n;for(const t of C)r=r.replace(t,"");if(r.trim().length>0)continue;this.debug&&e&&e.push({step:"removeByContentPattern",reason:"read time metadata",text:(0,h.textPreview)(t)}),t.remove()}}const S=Array.from(t.querySelectorAll("time")),w=t.textContent||"";for(const r of S){if(!r.parentNode)continue;let s=r,a=(null===(n=s.textContent)||void 0===n?void 0:n.trim())||"";for(;s.parentElement&&s.parentElement!==t;){const t=s.parentElement.tagName.toLowerCase(),e=(null===(o=s.parentElement.textContent)||void 0===o?void 0:o.trim())||"";if("p"===t&&e===a){s=s.parentElement;break}if(!["i","em","span","b","strong","small"].includes(t)||e!==a)break;s=s.parentElement,a=e}const l=(null===(i=s.textContent)||void 0===i?void 0:i.trim())||"";if((0,h.countWords)(l)>10)continue;const c=w.indexOf(l),u=w.length-(c+l.length);c>200&&u>200||(this.debug&&e&&e.push({step:"removeByContentPattern",reason:"boundary date element",text:(0,h.textPreview)(s)}),s.remove())}const A=t.querySelectorAll("ul, ol");for(const r of A){if(!r.parentNode)continue;const n=Array.from(r.children).filter((t=>"LI"===t.tagName));if(n.length<2||n.length>8)continue;const o=(null===(s=r.textContent)||void 0===s?void 0:s.trim())||"",i=w.indexOf(o),a=w.length-(i+o.length);if(i>500&&a>500)continue;const d=r.previousElementSibling;if(d){if(((null===(l=d.textContent)||void 0===l?void 0:l.trim())||"").endsWith(":"))continue}let m=!0;for(const t of n){const e=(null===(c=t.textContent)||void 0===c?void 0:c.trim())||"";if((0,h.countWords)(e)>8){m=!1;break}if(/[.!?]$/.test(e)){m=!1;break}}if(!m)continue;if((0,h.countWords)(o)>30)continue;let p=r;for(;p.parentElement&&p.parentElement!==t;){if(((null===(u=p.parentElement.textContent)||void 0===u?void 0:u.trim())||"")!==o)break;p=p.parentElement}this.debug&&e&&e.push({step:"removeByContentPattern",reason:"blog metadata list",text:(0,h.textPreview)(p)}),p.remove()}const T=this.options.url||this.doc.URL||"";let _="",L="";try{const t=new URL(T);_=t.pathname,L=t.hostname.replace(/^www\./,"")}catch(t){}if(_){const r=t.querySelectorAll("div, span, p");for(const t of r){if(!t.parentNode)continue;const r=(null===(d=t.textContent)||void 0===d?void 0:d.trim())||"";if((0,h.countWords)(r)>10)continue;if(t.querySelectorAll("p, div, section, article").length>0)continue;const n=t.querySelector("a[href]");if(n)try{const r=new URL(n.getAttribute("href")||"",T).pathname;"/"!==r&&r!==_&&_.startsWith(r)&&(this.debug&&e&&e.push({step:"removeByContentPattern",reason:"section breadcrumb",text:(0,h.textPreview)(t)}),t.remove())}catch(t){}}}if(L){const r=t.querySelectorAll("h2, h3, h4, h5, h6");for(const n of r){if(!n.parentNode)continue;const r=n.nextElementSibling;if(!r||"UL"!==r.tagName&&"OL"!==r.tagName)continue;const o=Array.from(r.children).filter((t=>"LI"===t.tagName));if(o.length<2)continue;let i=!1,s=r;for(;s&&s!==t;){let t=s.nextElementSibling;for(;t;){if(((null===(m=t.textContent)||void 0===m?void 0:m.trim())||"").length>0){i=!0;break}t=t.nextElementSibling}if(i)break;s=s.parentElement}if(i)continue;let a=!0;for(const t of o){const e=t.querySelectorAll("a[href]");if(0===e.length){a=!1;break}const r=(null===(p=t.textContent)||void 0===p?void 0:p.trim())||"";let n=0;for(const t of e){n+=((null===(f=t.textContent)||void 0===f?void 0:f.trim())||"").length;try{if(new URL(t.getAttribute("href")||"",T).hostname.replace(/^www\./,"")===L){a=!1;break}}catch(t){}}if(!a)break;if(n<.6*r.length){a=!1;break}}a&&(this.debug&&e&&(e.push({step:"removeByContentPattern",reason:"trailing external link list",text:(0,h.textPreview)(n)}),e.push({step:"removeByContentPattern",reason:"trailing external link list",text:(0,h.textPreview)(r)})),r.remove(),n.remove())}}const N=(0,h.countWords)(t.textContent||"");if(N>300){const r=[];let n=0,o=t.lastElementChild;for(;o;){let t=0;for(const e of o.querySelectorAll("svg"))t+=(0,h.countWords)(e.textContent||"");const e=(0,h.countWords)((null===(g=o.textContent)||void 0===g?void 0:g.trim())||"")-t;if(e>25)break;n+=e,r.push(o),o=o.previousElementSibling}if(r.length>=1&&n<.15*N){const t=r.some((t=>/^H[1-6]$/.test(t.tagName)||t.querySelector("h1, h2, h3, h4, h5, h6"))),n=r.some((t=>t.querySelector(a.CONTENT_ELEMENT_SELECTOR)));if(t&&!n)for(const t of r)this.debug&&e&&e.push({step:"removeByContentPattern",reason:"trailing thin section",text:(0,h.textPreview)(t)}),t.remove()}}const q=t.textContent||"",k=t.querySelectorAll("p, div, span, section");for(const r of k){if(!r.parentNode)continue;const n=(null===(E=r.textContent)||void 0===E?void 0:E.trim())||"",o=(0,h.countWords)(n);if(!(o>50||o<3))for(const o of b)if(o.test(n)){let n=r;for(;n.parentElement&&n.parentElement!==t&&!n.nextElementSibling;)n=n.parentElement;const o=n.textContent||"";if(q.indexOf(o)<200)continue;const i=[];let s=n.parentElement;for(;s&&s!==t;)i.push(s),s=s.parentElement;this.removeTrailingSiblings(n,!0,e);for(const t of i)this.removeTrailingSiblings(t,!1,e);return}}}removeTrailingSiblings(t,e,r){let n=t.nextElementSibling;for(;n;){const t=n.nextElementSibling;this.debug&&r&&r.push({step:"removeByContentPattern",reason:"trailing non-content",text:(0,h.textPreview)(n)}),n.remove(),n=t}e&&(this.debug&&r&&r.push({step:"removeByContentPattern",reason:"boilerplate text",text:(0,h.textPreview)(t)}),t.remove())}}},726(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.standardizeCallouts=function(t){var e;const r=t.ownerDocument;if(!r)return;const n=Array.from(t.querySelectorAll(".markdown-alert"));for(const t of n){const e=Array.from(t.classList).find((t=>t.startsWith("markdown-alert-")&&"markdown-alert"!==t)),n=e?e.replace("markdown-alert-",""):"note",i=n.charAt(0).toUpperCase()+n.slice(1),s=t.querySelector(".markdown-alert-title");s&&s.remove(),t.replaceWith(o(r,n,i,t))}const i=Array.from(t.querySelectorAll('aside[class*="callout"]'));for(const t of i){const e=Array.from(t.classList).find((t=>t.startsWith("callout-"))),n=e?e.replace("callout-",""):"note",i=n.charAt(0).toUpperCase()+n.slice(1),s=t.querySelector(".callout-content");t.replaceWith(o(r,n,i,s||t))}const s=Array.from(t.querySelectorAll('.alert[class*="alert-"]'));for(const t of s){const n=Array.from(t.classList).find((t=>t.startsWith("alert-")&&"alert-dismissible"!==t)),i=n?n.replace("alert-",""):"note",s=t.querySelector(".alert-heading, .alert-title"),a=(null===(e=null==s?void 0:s.textContent)||void 0===e?void 0:e.trim())||i.charAt(0).toUpperCase()+i.slice(1);s&&s.remove(),t.replaceWith(o(r,i,a,t))}};const n=r(639);function o(t,e,r,o){const i=t.createElement("div");i.setAttribute("data-callout",e),i.className="callout";const s=t.createElement("div");s.className="callout-title";const a=t.createElement("div");a.className="callout-title-inner",a.textContent=r,s.appendChild(a),i.appendChild(s);const l=t.createElement("div");return l.className="callout-content",(0,n.transferContent)(o,l),i.appendChild(l),i}},754(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.codeBlockRules=void 0;const n=r(552),o=[/^language-(\w+)$/,/^lang-(\w+)$/,/^(\w+)-code$/,/^code-(\w+)$/,/^syntax-(\w+)$/,/^code-snippet__(\w+)$/,/^highlight-(\w+)$/,/^(\w+)-snippet$/,/(?:^|\s)(?:language|lang|brush|syntax)-(\w+)(?:\s|$)/i],i=new Set(["abap","actionscript","ada","adoc","agda","antlr4","applescript","arduino","armasm","asciidoc","aspnet","atom","bash","batch","c","clojure","cmake","cobol","coffeescript","cpp","c++","crystal","csharp","cs","dart","django","dockerfile","dotnet","elixir","elm","erlang","fortran","fsharp","gdscript","gitignore","glsl","golang","gradle","graphql","groovy","haskell","hs","haxe","hlsl","html","idris","java","javascript","js","jsx","jsdoc","json","jsonp","julia","kotlin","latex","lean","lean4","lisp","elisp","livescript","lua","makefile","markdown","md","markup","masm","mathml","matlab","mongodb","mysql","nasm","nginx","nim","nix","objc","ocaml","pascal","perl","php","postgresql","powershell","prolog","puppet","python","regex","rss","ruby","rb","rust","scala","scheme","shell","sh","solidity","sparql","sql","ssml","svg","swift","tcl","terraform","tex","toml","typescript","ts","tsx","unrealscript","verilog","vhdl","webassembly","wasm","xml","yaml","yml","zig"]);e.codeBlockRules=[{selector:["pre",'div[class*="prismjs"]',".syntaxhighlighter",".highlight",".highlight-source",".wp-block-syntaxhighlighter-code",".wp-block-code",'div[class*="language-"]',"code.hl.block"].join(", "),element:"pre",transform:(t,e)=>{if(!(t=>"classList"in t&&"getAttribute"in t&&"querySelector"in t)(t))return t;const r=t=>{var e;const r=t.getAttribute("data-lang")||t.getAttribute("data-language")||t.getAttribute("language");if(r)return r.toLowerCase();const n=Array.from(t.classList||[]);if(null===(e=t.classList)||void 0===e?void 0:e.contains("syntaxhighlighter")){const t=n.find((t=>!["syntaxhighlighter","nogutter"].includes(t)));if(t&&i.has(t.toLowerCase()))return t.toLowerCase()}for(const t of n)for(const e of o){const r=t.toLowerCase().match(e);if(r&&r[1]&&i.has(r[1].toLowerCase()))return r[1].toLowerCase()}for(const t of n)if(i.has(t.toLowerCase()))return t.toLowerCase();return""};let s="",a=t;for(;a&&!s;){s=r(a);const t=a.querySelector("code");!s&&t&&(s=r(t)),a=a.parentElement}const l=t=>{var e;if((0,n.isTextNode)(t))return(null===(e=t.parentElement)||void 0===e?void 0:e.querySelector("[data-line], .line"))&&!(t.textContent||"").trim()?"":t.textContent||"";let r="";if((0,n.isElement)(t)){if(t.matches(".hover-info, .hover-container"))return"";if("BR"===t.tagName)return"\n";if(t.matches('div[class*="line"], span[class*="line"], .ec-line, [data-line-number], [data-line]')){const e=t.querySelector('.code, .content, [class*="code-"], [class*="content-"]');if(e)return(e.textContent||"")+"\n";const r=t.querySelector('.line-number, .gutter, [class*="line-number"], [class*="gutter"]');if(r){return Array.from(t.childNodes).filter((t=>!r.contains(t))).map((t=>l(t))).join("")+"\n"}return t.textContent+"\n"}t.childNodes.forEach((t=>{r+=l(t)}))}return r};let c="";t.matches(".syntaxhighlighter, .wp-block-syntaxhighlighter-code")&&(c=(t=>{const e=t.querySelector(".syntaxhighlighter table .code .container");if(e)return Array.from(e.children).map((t=>{const e=Array.from(t.querySelectorAll("code")).map((t=>{var e;let r=t.textContent||"";return(null===(e=t.classList)||void 0===e?void 0:e.contains("spaces"))&&(r=" ".repeat(r.length)),r})).join("");return e||t.textContent||""})).join("\n");const r=t.querySelectorAll(".code .line");return r.length>0?Array.from(r).map((t=>{const e=Array.from(t.querySelectorAll("code")).map((t=>t.textContent||"")).join("");return e||t.textContent||""})).join("\n"):""})(t)),c||(c=l(t));c=t.matches("code.hl.block")?c.replace(/^[ \t]+|[ \t]+$/g,"").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/^\n+/,""):c.replace(/^\s+|\s+$/g,"").replace(/\t/g," ").replace(/\n{3,}/g,"\n\n").replace(/\u00a0/g," ").replace(/^\n+/,"").replace(/\n+$/,"");let u=t;for(let e=0;e<3&&u;e++){const e=u.parentElement;if(!e||"BODY"===e.tagName)break;const r=Array.from(e.children);for(const e of r){if(e.contains(t))continue;const r=e.tagName;if("DIV"!==r&&"SPAN"!==r)continue;const o=(e.textContent||"").trim();(0,n.countWords)(o)<=5&&!e.querySelector("pre, code, img, table, h1, h2, h3, h4, h5, h6, p, blockquote, ul, ol")&&e.remove()}u=e}const d=e.createElement("pre");t.matches("code.hl.block, pre.hl.lean.lean-output")&&d.setAttribute("data-verso-code","true");const h=e.createElement("code");return s&&(h.setAttribute("data-lang",s),h.setAttribute("class",`language-${s}`)),h.textContent=c,d.appendChild(h),d}}]},610(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.standardizeFootnotes=function(t){const e=t.ownerDocument;if(!e)return void console.warn("standardizeFootnotes: No document available");new i(e).standardizeFootnotes(t)};const n=r(640),o=r(639);class i{constructor(t){this.genericContainer=null,this.doc=t}createFootnoteItem(t,e,r){const n="string"==typeof e?this.doc:e.ownerDocument,i=n.createElement("li");if(i.className="footnote",i.id=`fn:${t}`,"string"==typeof e){const t=n.createElement("p");t.appendChild((0,o.parseHTML)(n,e)),i.appendChild(t)}else{const t=Array.from(e.querySelectorAll("p"));if(0===t.length){const t=n.createElement("p");(0,o.transferContent)(e,t),this.removeBackrefs(t),i.appendChild(t)}else t.forEach((t=>{const e=n.createElement("p");(0,o.transferContent)(t,e),this.removeBackrefs(e),i.appendChild(e)}))}const s=i.querySelector("p:last-of-type")||i;return r.forEach(((t,e)=>{const o=n.createElement("a");o.href=`#${t}`,o.title="return to article",o.className="footnote-backref",o.textContent="\u21a9",e<r.length-1&&(o.textContent+=" "),s.appendChild(o)})),i}collectFootnotes(t){const e={};let r=1;const i=new Set;if(t.querySelectorAll(n.FOOTNOTE_LIST_SELECTORS).forEach((n=>{if(n.matches("div.footnotes-footer")){return void n.querySelectorAll("div.footnote-footer").forEach((n=>{const s=(n.id||"").match(/^footnote-(\d+)$/);if(s){const a=s[1];if(!i.has(a)){const s=n.cloneNode(!0),l=s.querySelector("a");l&&l.remove();let c=(0,o.serializeHTML)(s);c=c.replace(/^\s*\.\s*/,"");const u=t.ownerDocument.createElement("div");u.appendChild((0,o.parseHTML)(t.ownerDocument,c.trim())),e[r]={content:u,originalId:a,refs:[]},i.add(a),r++}}}))}if(n.matches('div.footnote[data-component-name="FootnoteToDOM"]')){const t=n.querySelector("a.footnote-number"),o=n.querySelector(".footnote-content");if(t&&o){const n=t.id.replace("footnote-","").toLowerCase();n&&!i.has(n)&&(e[r]={content:o,originalId:n,refs:[]},i.add(n),r++)}return}n.querySelectorAll('li, div[role="listitem"]').forEach((t=>{var n,o,s,a;let l="",c=null;const u=t.querySelector(".citations");if(null===(n=null==u?void 0:u.id)||void 0===n?void 0:n.toLowerCase().startsWith("r")){l=u.id.toLowerCase();const t=u.querySelector(".citation-content");t&&(c=t)}else{if(t.id.toLowerCase().startsWith("bib.bib"))l=t.id.replace("bib.bib","").toLowerCase();else if(t.id.toLowerCase().startsWith("fn:"))l=t.id.replace("fn:","").toLowerCase();else if(t.id.toLowerCase().startsWith("fn"))l=t.id.replace("fn","").toLowerCase();else if(t.hasAttribute("data-counter"))l=(null===(s=null===(o=t.getAttribute("data-counter"))||void 0===o?void 0:o.replace(/\.$/,""))||void 0===s?void 0:s.toLowerCase())||"";else{const e=null===(a=t.id.split("/").pop())||void 0===a?void 0:a.match(/cite_note-(.+)/);l=e?e[1].toLowerCase():t.id.toLowerCase()}c=t}l&&!i.has(l)&&(e[r]={content:c||t,originalId:l,refs:[]},i.add(l),r++)}))})),1===r){const n=new Map;if(t.querySelectorAll('a[href*="#"]').forEach((t=>{var e,r;const o=null===(e=(t.getAttribute("href")||"").split("#").pop())||void 0===e?void 0:e.toLowerCase();if(!o)return;const i=(null===(r=t.textContent)||void 0===r?void 0:r.trim())||"";if(!/^\[?\(?\d{1,4}\)?\]?$/.test(i))return;const s=t.parentElement;if(!s)return;const a=s.tagName.toLowerCase();"sup"!==a&&"span"!==a&&"a"!==t.tagName.toLowerCase()||(n.has(o)||n.set(o,[]),n.get(o).push(t))})),n.size>=2){const o=new Set(n.keys()),s=t.querySelectorAll("div, section, aside, footer");let a=null,l=0;if(s.forEach((e=>{if(e===t)return;const r=e.querySelectorAll("p[id], li[id], div[id]");let n=0;r.forEach((t=>{o.has(t.id.toLowerCase())&&n++})),n>=2&&n>=l&&(l=n,a=e)})),a){const n=a.querySelectorAll("p[id], li[id], div[id]"),s=[];n.forEach((t=>{o.has(t.id.toLowerCase())&&s.push(t)})),s.forEach((n=>{const o=n.id.toLowerCase();if(i.has(o))return;const s=t.ownerDocument.createElement("div"),a=n.cloneNode(!0),l=a.childNodes[0];l&&3===l.nodeType&&(l.textContent=l.textContent.replace(/^\d+\.\s*/,"")),s.appendChild(a);let c=n.nextElementSibling;for(;c&&!c.id;){const t=c.cloneNode(!0);s.appendChild(t),c=c.nextElementSibling}e[r]={content:s,originalId:o,refs:[]},i.add(o),r++})),this.genericContainer=a}}}return e}removeBackrefs(t){for(t.querySelectorAll("a").forEach((t=>{var e,r;const n=(null===(e=t.textContent)||void 0===e?void 0:e.trim().replace(/\uFE0E|\uFE0F/g,""))||"";(/^[\u21A9\u21A5\u2191\u21B5\u2934\u2935\u23CE]+$/.test(n)||(null===(r=t.classList)||void 0===r?void 0:r.contains("footnote-backref")))&&t.remove()}));t.lastChild&&3===t.lastChild.nodeType;){const e=t.lastChild.textContent;if(!/^[\s,.;]*$/.test(e))break;t.lastChild.remove()}}findOuterFootnoteContainer(t){let e=t,r=t.parentElement;for(;r&&("span"===r.tagName.toLowerCase()||"sup"===r.tagName.toLowerCase());)e=r,r=r.parentElement;return e}createFootnoteReference(t,e){const r=this.doc.createElement("sup");r.id=e;const n=this.doc.createElement("a");return n.href=`#fn:${t}`,n.textContent=t,r.appendChild(n),r}collectInlineSidenotes(t){const e={},r=t.querySelectorAll("span.footnote-container, span.sidenote-container");if(0===r.length)return e;let n=1;return r.forEach((t=>{const r=t.querySelector("span.footnote, span.sidenote");if(!r)return;const o=r.cloneNode(!0);e[n]={content:o,originalId:String(n),refs:[`fnref:${n}`]};const i=this.createFootnoteReference(String(n),`fnref:${n}`);t.replaceWith(i),n++})),e}standardizeFootnotes(t){const e=this.collectInlineSidenotes(t),r=this.collectFootnotes(t),o=t.querySelectorAll(n.FOOTNOTE_INLINE_REFERENCES),i=new Map;o.forEach((t=>{var e,n,o,s;if(!t||!t.parentNode)return;let a="",l="";if(t.matches("sup.footnoteref")){const e=t.querySelector('a[id^="footnoteref-"]');if(e){const t=(e.id||"").match(/^footnoteref-(\d+)$/);t&&(a=t[1])}}else if(t.matches('a[id^="ref-link"]'))a=(null===(e=t.textContent)||void 0===e?void 0:e.trim())||"";else if(t.matches('a[role="doc-biblioref"]')){const e=t.getAttribute("data-xml-rid");if(e)a=e;else{const e=t.getAttribute("href");(null==e?void 0:e.startsWith("#core-R"))&&(a=e.replace("#core-",""))}}else if(t.matches("a.footnote-anchor, span.footnote-hovercard-target a")){const e=(null===(n=t.id)||void 0===n?void 0:n.replace("footnote-anchor-",""))||"";e&&(a=e.toLowerCase())}else if(t.matches("cite.ltx_cite")){const e=Array.from(t.querySelectorAll("a"));if(e.length>0){const n=[];if(e.forEach((t=>{var e;const o=t.getAttribute("href");if(!o)return;const i=null===(e=o.split("/").pop())||void 0===e?void 0:e.match(/bib\.bib(\d+)/);if(!i)return;const s=i[1].toLowerCase(),a=Object.entries(r).find((([t,e])=>e.originalId===s));if(!a)return;const[l,c]=a,u=c.refs.length>0?`fnref:${l}-${c.refs.length+1}`:`fnref:${l}`;c.refs.push(u),n.push(this.createFootnoteReference(l,u))})),n.length>0){const e=this.findOuterFootnoteContainer(t),r=t.ownerDocument.createDocumentFragment();return n.forEach(((e,n)=>{n>0&&r.appendChild(t.ownerDocument.createTextNode(" ")),r.appendChild(e)})),void e.replaceWith(r)}}}else if(t.matches("sup.reference")){const e=t.querySelectorAll("a");Array.from(e).forEach((t=>{var e;const r=t.getAttribute("href");if(r){const t=null===(e=r.split("/").pop())||void 0===e?void 0:e.match(/(?:cite_note|cite_ref)-(.+)/);t&&(a=t[1].toLowerCase())}}))}else if(t.matches('sup[id^="fnref:"]'))a=t.id.replace("fnref:","").toLowerCase();else if(t.matches('sup[id^="fnr"]'))a=t.id.replace("fnr","").toLowerCase();else if(t.matches("span.footnote-reference"))a=t.getAttribute("data-footnote-id")||"",!a&&(null===(o=t.id)||void 0===o?void 0:o.startsWith("fnref"))&&(a=t.id.replace("fnref","").toLowerCase());else if(t.matches("span.footnote-link"))a=t.getAttribute("data-footnote-id")||"",l=t.getAttribute("data-footnote-content")||"";else if(t.matches("a.citation"))a=(null===(s=t.textContent)||void 0===s?void 0:s.trim())||"",l=t.getAttribute("href")||"";else if(t.matches('a[id^="fnref"]'))a=t.id.replace("fnref","").toLowerCase();else{const e=t.getAttribute("href");if(e){const t=e.replace(/^[#]/,"");a=t.toLowerCase()}}if(a){const e=Object.entries(r).find((([t,e])=>e.originalId===a.toLowerCase()));if(e){const[r,n]=e,o=n.refs.length>0?`fnref:${r}-${n.refs.length+1}`:`fnref:${r}`;n.refs.push(o);const s=this.findOuterFootnoteContainer(t);if("sup"===s.tagName.toLowerCase()){i.has(s)||i.set(s,[]);i.get(s).push(this.createFootnoteReference(r,o))}else s.replaceWith(this.createFootnoteReference(r,o))}}}));const s=Object.entries(r).filter((([t,e])=>0===e.refs.length));if(s.length>0){const e=new Map,n=new Map;s.forEach((([t,r])=>{e.set(r.originalId,[t,r]),n.set(t,[t,r])}));t.querySelectorAll('a[href*="#"]').forEach((t=>{var r,n;if(!t.parentNode)return;if(t.closest('[id^="fnref:"]'))return;if(t.closest("#footnotes"))return;if(this.genericContainer&&this.genericContainer.contains(t))return;const o=null===(r=(t.getAttribute("href")||"").split("#").pop())||void 0===r?void 0:r.toLowerCase();if(!o)return;const i=e.get(o);if(!i)return;const s=(null===(n=t.textContent)||void 0===n?void 0:n.trim())||"";if(!/^[\[\(]?\d{1,4}[\]\)]?$/.test(s))return;const[a,l]=i,c=l.refs.length>0?`fnref:${a}-${l.refs.length+1}`:`fnref:${a}`;l.refs.push(c);this.findOuterFootnoteContainer(t).replaceWith(this.createFootnoteReference(a,c))}));if(Object.entries(r).filter((([t,e])=>0===e.refs.length)).length>0){t.querySelectorAll("sup, span.footnote-ref").forEach((t=>{var r,o;if(!t.parentNode)return;if(null===(r=t.id)||void 0===r?void 0:r.startsWith("fnref:"))return;if(t.closest("#footnotes"))return;const i=((null===(o=t.textContent)||void 0===o?void 0:o.trim())||"").match(/^[\[\(]?(\d{1,4})[\]\)]?$/);if(!i)return;const s=i[1],a=n.get(s)||e.get(s);if(!a)return;const[l,c]=a;if(c.refs.length>0)return;const u=`fnref:${l}`;c.refs.push(u);this.findOuterFootnoteContainer(t).replaceWith(this.createFootnoteReference(l,u))}))}}i.forEach(((t,e)=>{if(t.length>0){const r=this.doc.createDocumentFragment();t.forEach((t=>{const e=t.querySelector("a");if(e){const n=this.doc.createElement("sup");n.id=t.id,n.appendChild(e.cloneNode(!0)),r.appendChild(n)}})),e.replaceWith(r)}}));const a=this.doc.createElement("div");a.id="footnotes";const l=this.doc.createElement("ol"),c=Object.assign(Object.assign({},e),r);Object.entries(c).forEach((([t,e])=>{const r=this.createFootnoteItem(parseInt(t),e.content,e.refs);l.appendChild(r)}));t.querySelectorAll(n.FOOTNOTE_LIST_SELECTORS).forEach((t=>t.remove())),this.genericContainer&&this.genericContainer.parentNode&&this.genericContainer.remove(),l.children.length>0&&(a.appendChild(l),t.appendChild(a))}}},864(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.headingRules=void 0,e.removeHeadingAnchors=function(t){Array.from(t.querySelectorAll("h1 a, h2 a, h3 a, h4 a, h5 a, h6 a")).forEach((t=>{o(t)&&t.remove()}))},e.isPermalinkAnchor=o;const n=r(640);function o(t){if("a"!==t.tagName.toLowerCase())return!1;const e=t.getAttribute("href")||"",r=(t.getAttribute("title")||"").toLowerCase(),n=(t.getAttribute("class")||"").toLowerCase(),o=(t.textContent||"").trim();return!(!e.startsWith("#")&&!e.includes("#"))||(!!r.includes("permalink")||(!!(n.includes("permalink")||n.includes("heading-anchor")||n.includes("anchor-link"))||!!/^[#\xb6\xa7\ud83d\udd17]$/.test(o)))}e.headingRules=[{selector:"h1, h2, h3, h4, h5, h6",element:"keep",transform:t=>{var e;const r=t.ownerDocument;if(!r)return console.warn("No document available"),t;const i=r.createElement(t.tagName);Array.from(t.attributes).forEach((t=>{n.ALLOWED_ATTRIBUTES.has(t.name)&&i.setAttribute(t.name,t.value)}));const s=t.cloneNode(!0),a=new Map,l=[];Array.from(s.querySelectorAll("*")).forEach((t=>{var e,r,n,i;if(!function(t){const e=t.tagName.toLowerCase();return"button"===e||!("a"!==e||!o(t))||!(!t.classList.contains("anchor")&&!t.classList.contains("permalink-widget"))||!("span"!==e&&"div"!==e||!Array.from(t.querySelectorAll("a")).some((t=>o(t))))}(t))return;a.set(t,(null===(e=t.textContent)||void 0===e?void 0:e.trim())||"");const c=t.parentElement;c&&c!==s&&(null===(r=c.textContent)||void 0===r?void 0:r.trim())===(null===(n=t.textContent)||void 0===n?void 0:n.trim())&&a.set(c,(null===(i=t.textContent)||void 0===i?void 0:i.trim())||""),l.push(t)})),l.forEach((t=>t.remove()));let c=(null===(e=s.textContent)||void 0===e?void 0:e.trim())||"";return!c&&a.size>0&&(c=Array.from(a.values())[0]),i.textContent=c,i}}]},649(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.imageRules=void 0;const n=r(552),o=r(639),i=r(640),s=/^data:image\/([^;]+);base64,/,a=/\.(jpg|jpeg|png|webp)\s+\d/,l=/^\s*\S+\.(jpg|jpeg|png|webp)\S*\s*$/,c=/\.(jpg|jpeg|png|webp|gif|avif)(\?.*)?$/i,u=/\s(\d+)w/,d=/dpr=(\d+(?:\.\d+)?)/,h=/^([^\s]+)/,m=/^[\w\-\.\/\\]+\.(jpg|jpeg|png|gif|webp|svg)$/i,p=/^\d{4}-\d{2}-\d{2}$/;function f(t,e,r){const i=r.createElement("figure");i.appendChild(t.cloneNode(!0));const s=r.createElement("figcaption"),a=function(t){const e=[],r=new Set,i=t=>{var o;if((0,n.isTextNode)(t)){const n=(null===(o=t.textContent)||void 0===o?void 0:o.trim())||"";n&&!r.has(n)&&(e.push(n),r.add(n))}else if((0,n.isElement)(t)){const e=t.childNodes;for(let t=0;t<e.length;t++)i(e[t])}},s=t.childNodes;for(let t=0;t<s.length;t++)i(s[t]);if(e.length>0)return e.join(" ");return(0,o.serializeHTML)(t)}(e);return s.appendChild((0,o.parseHTML)(r,a)),i.appendChild(s),i}function g(t,e){e.setAttribute("srcset",t);const r=L(t);r&&C(r)&&e.setAttribute("src",r)}function v(t,e,r){for(let n=0;n<t.attributes.length;n++){const o=t.attributes[n];r.includes(o.name)||e.setAttribute(o.name,o.value)}}function y(t){const e=t.match(s);if(!e)return!1;if("svg+xml"===e[1])return!1;const r=e[0].length;return t.length-r<133}function b(t){return t.startsWith("data:image/svg+xml")}function C(t){return!t.startsWith("data:")&&(!(!t||""===t.trim())&&(c.test(t)||t.includes("image")||t.includes("img")||t.includes("photo")))}function E(t){if(x(t))return!0;return t.querySelectorAll("img, video, picture, source").length>0}function x(t){const e=t.tagName.toLowerCase();return"img"===e||"video"===e||"picture"===e||"source"===e}function S(t){if(x(t))return t;const e=t.querySelectorAll("picture");if(e.length>0)return e[0];const r=t.querySelectorAll("img"),n=[];for(let t=0;t<r.length;t++){const e=r[t],o=e.getAttribute("src")||"",i=e.getAttribute("alt")||"";o.includes("data:image/svg+xml")||(y(o)||!i.trim()&&r.length>1||n.push(e))}if(n.length>0)return n[0];const o=t.querySelectorAll("video");if(o.length>0)return o[0];const i=t.querySelectorAll("source");if(i.length>0)return i[0];const s=t.querySelectorAll("img, picture, source, video");return s.length>0?s[0]:null}function w(t){var e,r,n,o;const i=t.querySelector("figcaption");if(i)return i;const s=new Set,a=['[class*="caption"]','[class*="description"]','[class*="alt"]','[class*="title"]','[class*="credit"]','[class*="text"]','[class*="post-thumbnail-text"]','[class*="image-caption"]','[class*="photo-caption"]',"[aria-label]","[title]"].join(", "),l=t.querySelectorAll(a);for(let t=0;t<l.length;t++){const r=l[t];if(x(r))continue;const n=null===(e=r.textContent)||void 0===e?void 0:e.trim();if(n&&n.length>0&&!s.has(n))return s.add(n),r}const c=t.querySelector("img");if(c&&c.hasAttribute("alt")){const e=c.getAttribute("alt");if(e&&e.trim().length>0){const r=t.ownerDocument.createElement("div");return r.textContent=e,r}}if(t.parentElement){const e=t.parentElement.children;for(let n=0;n<e.length;n++){const o=e[n];if(o===t)continue;if(Array.from(o.classList).some((t=>t.includes("caption")||t.includes("credit")||t.includes("text")||t.includes("description")))){const t=null===(r=o.textContent)||void 0===r?void 0:r.trim();if(t&&t.length>0)return o}}}const u=t.querySelectorAll("img");for(let t=0;t<u.length;t++){const e=u[t];if(!e.parentElement)continue;let r=e.nextElementSibling;for(;r;){if(["EM","STRONG","SPAN","I","B","SMALL","CITE"].includes(r.tagName)){const t=null===(n=r.textContent)||void 0===n?void 0:n.trim();if(t&&t.length>0)return r}r=r.nextElementSibling}}for(let t=0;t<u.length;t++){const e=u[t],r=e.parentElement;if(!r)continue;const n=r.querySelectorAll("em, strong, span, i, b, small, cite");for(let t=0;t<n.length;t++){const r=n[t];if(r===e)continue;const i=null===(o=r.textContent)||void 0===o?void 0:o.trim();if(i&&i.length>0)return r}}return null}function A(t){var e;const r=(null===(e=t.textContent)||void 0===e?void 0:e.trim())||"";return!(r.length<10||r.startsWith("http://")||r.startsWith("https://"))&&(!m.test(r)&&(!r.match(/^\d+$/)&&!p.test(r)))}function T(t,e){const r=t.tagName.toLowerCase();if("img"===r)return _(t,e);if("picture"===r){const r=t.querySelector("img");return r?_(r,e):t.cloneNode(!0)}return"source"===r?function(t,e){const r=e.createElement("img"),n=t.getAttribute("srcset");n&&g(n,r);const o=t.parentElement;if(o){const t=o.querySelectorAll("img"),e=[];for(let r=0;r<t.length;r++){const n=t[r],o=n.getAttribute("src")||"";y(o)||b(o)||""===o||e.push(n)}if(e.length>0){if(v(e[0],r,["src","srcset"]),!r.hasAttribute("src")||!C(r.getAttribute("src")||"")){const t=e[0].getAttribute("src");t&&C(t)&&r.setAttribute("src",t)}}else{const t=o.querySelector("img[data-src]");if(t&&(v(t,r,["src","srcset"]),!r.hasAttribute("src")||!C(r.getAttribute("src")||""))){const e=t.getAttribute("data-src");e&&C(e)&&r.setAttribute("src",e)}}}return r}(t,e):t.cloneNode(!0)}function _(t,e){const r=t.getAttribute("src")||"";if(y(r)||b(r)){const r=t.parentElement;if(r){const n=r.querySelectorAll("source"),o=[];for(let t=0;t<n.length;t++){const e=n[t];e.hasAttribute("data-srcset")&&""!==e.getAttribute("data-srcset")&&o.push(e)}if(o.length>0){const r=e.createElement("img"),n=t.getAttribute("data-src");return n&&!b(n)&&r.setAttribute("src",n),v(t,r,["src"]),r}}}return t.cloneNode(!0)}function L(t){if(!t||!t.trim())return null;const e=t.trim(),r=/(.+?)\s+(\d+(?:\.\d+)?[wx])/g;let n,o=0;for(;null!==(n=r.exec(e));){let t=n[1].trim();if(o>0&&(t=t.replace(/^,\s*/,"")),o=r.lastIndex,t&&!b(t))return t}const i=e.match(h);return i&&i[1]&&!b(i[1])?i[1]:null}function N(t){if(0===t.length)return null;if(1===t.length)return t[0];for(let e=0;e<t.length;e++)if(!t[e].hasAttribute("media"))return t[e];let e=null,r=0;for(let n=0;n<t.length;n++){const o=t[n],i=o.getAttribute("srcset");if(!i)continue;const s=i.match(u),a=i.match(d);if(s&&s[1]){const t=parseInt(s[1],10)*(a?parseFloat(a[1]):1);t>r&&(r=t,e=o)}}return e||t[0]}e.imageRules=[{selector:"picture",element:"picture",transform:(t,e)=>{const r=t.querySelectorAll("source"),n=t.querySelector("img");if(!n){console.warn("Picture element without img fallback:",t.outerHTML);const n=N(r);if(n){const r=n.getAttribute("srcset");if(r){const n=e.createElement("img");return g(r,n),t.replaceChildren(n),t}}return t}let o=null,i=null;if(r.length>0){const t=N(r);t&&(o=t.getAttribute("srcset"),o&&(i=L(o)))}if(o&&n.setAttribute("srcset",o),i&&C(i))n.setAttribute("src",i);else if(!n.hasAttribute("src")||!C(n.getAttribute("src")||"")){const t=L(n.getAttribute("srcset")||o||"");t&&C(t)&&n.setAttribute("src",t)}return r.forEach((t=>t.remove())),t}},{selector:"uni-image-full-width",element:"figure",transform:(t,e)=>{var r;const n=e.createElement("figure"),i=e.createElement("img"),s=t.querySelector("img");if(!s)return console.warn("uni-image-full-width without img:",t.outerHTML),n;let a=s.getAttribute("src");const l=s.getAttribute("data-loading");if(l)try{const t=JSON.parse(l);t.desktop&&C(t.desktop)&&(a=t.desktop)}catch(t){console.warn("Failed to parse data-loading attribute:",l,t)}if(!a||!C(a))return console.warn("Could not find valid src for uni-image-full-width:",t.outerHTML),n;i.setAttribute("src",a);let c=s.getAttribute("alt");c||(c=t.getAttribute("alt-text")),c&&i.setAttribute("alt",c),n.appendChild(i);const u=t.querySelector("figcaption");if(u){const t=null===(r=u.textContent)||void 0===r?void 0:r.trim();if(t&&t.length>5){const r=e.createElement("figcaption"),i=u.querySelector(".rich-text p");i?(0,o.transferContent)(i,r):r.textContent=t,n.appendChild(r)}}return n}},{selector:'img[data-src], img[data-srcset], img[loading="lazy"], img.lazy, img.lazyload',element:"img",transform:(t,e)=>{const r=t.getAttribute("src")||"",n=function(t){if(t.hasAttribute("data-src")||t.hasAttribute("data-srcset"))return!0;for(let e=0;e<t.attributes.length;e++){const r=t.attributes[e];if("src"!==r.name){if(r.name.startsWith("data-")&&/\.(jpg|jpeg|png|webp|gif)(\?.*)?$/i.test(r.value))return!0;if(/\.(jpg|jpeg|png|webp|gif)(\?.*)?$/i.test(r.value))return!0}}return!1}(t);y(r)&&n&&t.removeAttribute("src");const o=t.getAttribute("data-src");o&&!t.getAttribute("src")&&t.setAttribute("src",o);const i=t.getAttribute("data-srcset");i&&!t.getAttribute("srcset")&&t.setAttribute("srcset",i);for(let e=0;e<t.attributes.length;e++){const r=t.attributes[e];if("src"===r.name||"srcset"===r.name||"alt"===r.name)continue;const n=r.value.charAt(0);"{"!==n&&"["!==n&&(a.test(r.value)?t.setAttribute("srcset",r.value):l.test(r.value)&&t.setAttribute("src",r.value))}return t.classList.remove("lazy","lazyload"),t.removeAttribute("data-ll-status"),t.removeAttribute("data-src"),t.removeAttribute("data-srcset"),t.removeAttribute("loading"),t}},{selector:"span:has(img)",element:"span",transform:(t,e)=>{try{if(!E(t))return t;for(const e of t.children)if(i.BLOCK_LEVEL_ELEMENTS.has(e.tagName.toLowerCase()))return t;const r=S(t);if(!r)return t;const n=w(t),o=T(r,e);if(n&&A(n)){const t=f(o,n,e);return n.parentNode&&n.parentNode.removeChild(n),t}return o}catch(e){return console.warn("Error processing span with image:",e),t}}},{selector:'figure, p:has([class*="caption"])',element:"figure",transform:(t,e)=>{try{if(!E(t))return t;const r=S(t);if(!r)return t;const n=w(t);if(n&&A(n)){const o=S(t);let i;return o?i=o:(console.warn("Figure rule couldn't find current image element in:",t.outerHTML),i=T(r,e)),f(i,n,e)}return t}catch(e){return console.warn("Error processing complex image element:",e),t}}}]},282(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.mathSelectors=e.isBlockDisplay=e.getBasicLatexFromElement=e.getMathMLFromElement=void 0;const n=r(639);e.getMathMLFromElement=t=>{if("math"===t.tagName.toLowerCase()){const e="block"===t.getAttribute("display");return{mathml:t.outerHTML,latex:t.getAttribute("alttext")||null,isBlock:e}}const e=t.getAttribute("data-mathml");if(e){const r=t.ownerDocument||document,o=(0,n.parseHTML)(r,e).querySelector("math");if(o){const t="block"===o.getAttribute("display");return{mathml:o.outerHTML,latex:o.getAttribute("alttext")||null,isBlock:t}}}const r=t.querySelector(".MJX_Assistive_MathML, mjx-assistive-mml");if(r){const t=r.querySelector("math");if(t){const e=t.getAttribute("display"),n=r.getAttribute("display"),o="block"===e||"block"===n;return{mathml:t.outerHTML,latex:t.getAttribute("alttext")||null,isBlock:o}}}const o=t.querySelector(".katex-mathml math");return o?{mathml:o.outerHTML,latex:null,isBlock:!1}:null};e.getBasicLatexFromElement=t=>{var e,r,n;const o=t.getAttribute("data-latex");if(o)return o;if("img"===t.tagName.toLowerCase()&&t.classList.contains("latex")){const e=t.getAttribute("alt");if(e)return e;const r=t.getAttribute("src");if(r){const t=r.match(/latex\.php\?latex=([^&]+)/);if(t)return decodeURIComponent(t[1]).replace(/\+/g," ").replace(/%5C/g,"\\")}}const i=t.querySelector('annotation[encoding="application/x-tex"]');if(null==i?void 0:i.textContent)return i.textContent.trim();if(t.matches(".katex")){const e=t.querySelector('.katex-mathml annotation[encoding="application/x-tex"]');if(null==e?void 0:e.textContent)return e.textContent.trim()}if(t.matches('script[type="math/tex"]')||t.matches('script[type="math/tex; mode=display"]'))return(null===(e=t.textContent)||void 0===e?void 0:e.trim())||null;if(t.parentElement){const e=t.parentElement.querySelector('script[type="math/tex"], script[type="math/tex; mode=display"]');if(e)return(null===(r=e.textContent)||void 0===r?void 0:r.trim())||null}return"math"===t.tagName.toLowerCase()&&(null===(n=t.textContent)||void 0===n?void 0:n.trim())?t.textContent.trim():t.getAttribute("alt")||null};e.isBlockDisplay=t=>{if("block"===t.getAttribute("display"))return!0;const e=(0,n.getClassName)(t).toLowerCase();if(e.includes("display")||e.includes("block"))return!0;if(t.closest('.katex-display, .MathJax_Display, [data-display="block"]'))return!0;const r=t.previousElementSibling;if("p"===(null==r?void 0:r.tagName.toLowerCase()))return!0;if(t.matches(".mwe-math-fallback-image-display"))return!0;if(t.matches(".katex"))return null!==t.closest(".katex-display");if(t.hasAttribute("display"))return"true"===t.getAttribute("display");if(t.matches('script[type="math/tex; mode=display"]'))return!0;const o=t.closest("[display]");return!!o&&"true"===o.getAttribute("display")},e.mathSelectors=['img.latex[src*="latex.php"]',"span.MathJax","mjx-container",'script[type="math/tex"]','script[type="math/tex; mode=display"]','.MathJax_Preview + script[type="math/tex"]',".MathJax_Display",".MathJax_SVG",".MathJax_MathML",".mwe-math-element",".mwe-math-fallback-image-inline",".mwe-math-fallback-image-display",".mwe-math-mathml-inline",".mwe-math-mathml-display",".katex",".katex-display",".katex-mathml",".katex-html","[data-katex]",'script[type="math/katex"]',"math","[data-math]","[data-latex]","[data-tex]",'script[type^="math/"]','annotation[encoding="application/x-tex"]'].join(",")},0(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.mathRules=e.createCleanMathEl=void 0;const n=r(282),o=r(639);e.createCleanMathEl=(t,e,r,n)=>{const i=t.createElement("math");if(i.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),i.setAttribute("display",n?"block":"inline"),i.setAttribute("data-latex",r||""),null==e?void 0:e.mathml){const r=(0,o.parseHTML)(t,e.mathml).querySelector("math");r&&(0,o.transferContent)(r,i)}else r&&(i.textContent=r);return i},e.mathRules=[{selector:n.mathSelectors,element:"math",transform:(t,r)=>{if(!function(t){return"classList"in t&&"getAttribute"in t&&"querySelector"in t}(t))return t;const o=(0,n.getMathMLFromElement)(t),i=(0,n.getBasicLatexFromElement)(t),s=(0,n.isBlockDisplay)(t),a=(0,e.createCleanMathEl)(r,o,i,s);if(t.parentElement&&!t.matches('script[type^="math/"]')){t.parentElement.querySelectorAll('script[type^="math/"], .MathJax_Preview, script[type="text/javascript"][src*="mathjax"], script[type="text/javascript"][src*="katex"]').forEach((t=>t.remove()))}return a}}]},917(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.ExtractorRegistry=void 0;const n=r(959),o=r(248),i=r(64),s=r(258),a=r(458),l=r(632),c=r(397),u=r(20),d=r(732),h=r(588),m=r(666);class p{static initialize(){this.register({patterns:["x.com","twitter.com"],extractor:i.XArticleExtractor}),this.register({patterns:["twitter.com",/\/x\.com\/.*/],extractor:o.TwitterExtractor}),this.register({patterns:["x.com","twitter.com"],extractor:m.XOembedExtractor}),this.register({patterns:["reddit.com","old.reddit.com","new.reddit.com",/^https:\/\/[^\/]+\.reddit\.com/],extractor:n.RedditExtractor}),this.register({patterns:["youtube.com","youtu.be",/youtube\.com\/watch\?v=.*/,/youtu\.be\/.*/],extractor:s.YoutubeExtractor}),this.register({patterns:[/news\.ycombinator\.com\/item\?id=.*/],extractor:a.HackerNewsExtractor}),this.register({patterns:[/^https?:\/\/chatgpt\.com\/(c|share)\/.*/],extractor:l.ChatGPTExtractor}),this.register({patterns:["claude.ai",/^https?:\/\/claude\.ai\/(chat|share)\/.*/],extractor:c.ClaudeExtractor}),this.register({patterns:[/^https?:\/\/grok\.com\/(chat|share)(\/.*)?$/],extractor:u.GrokExtractor}),this.register({patterns:[/^https?:\/\/gemini\.google\.com\/app\/.*/],extractor:d.GeminiExtractor}),this.register({patterns:["github.com",/^https?:\/\/github\.com\/.*/],extractor:h.GitHubExtractor})}static register(t){this.mappings.push(t)}static findExtractor(t,e,r,n){return this.findByPredicate(t,e,r,(t=>t.canExtract()),n)}static findAsyncExtractor(t,e,r,n){return this.findByPredicate(t,e,r,(t=>t.canExtractAsync()),n)}static findPreferredAsyncExtractor(t,e,r,n){return this.findByPredicate(t,e,r,(t=>t.canExtractAsync()&&t.prefersAsync()),n)}static findByPredicate(t,e,r,n,o){try{const i=new URL(e).hostname;for(const{patterns:s,extractor:a}of this.mappings){if(s.some((t=>t instanceof RegExp?t.test(e):i.includes(t)))){const i=new a(t,e,r,o);if(n(i))return i}}return null}catch(t){return console.error("Error finding extractor:",t),null}}}e.ExtractorRegistry=p,p.mappings=[],p.initialize()},279(t,e){var r=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{l(n.next(t))}catch(t){i(t)}}function a(t){try{l(n.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}l((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.BaseExtractor=void 0;e.BaseExtractor=class{constructor(t,e,r,n){this.document=t,this.url=e,this.schemaOrgData=r,this.options=n||{}}canExtractAsync(){return!1}prefersAsync(){return!1}extractAsync(){return r(this,void 0,void 0,(function*(){return this.extract()}))}}},181(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.ConversationExtractor=void 0;const n=r(279),o=r(628),i=r(639);class s extends n.BaseExtractor{getFootnotes(){return[]}extract(){var t;const e=this.extractMessages(),r=this.getMetadata(),n=this.getFootnotes(),s=this.createContentHtml(e,n),a=this.document.implementation.createHTMLDocument(),l=a.createElement("article");l.appendChild((0,i.parseHTML)(a,s)),a.body.appendChild(l);const c=new o.Defuddle(a).parse(),u=c.content;return{content:u,contentHtml:u,extractedContent:{messageCount:e.length.toString()},variables:{title:r.title||"Conversation",site:r.site,description:r.description||`${r.site} conversation with ${e.length} messages`,wordCount:(null===(t=c.wordCount)||void 0===t?void 0:t.toString())||""}}}createContentHtml(t,e){return`${t.map(((e,r)=>{const n=e.timestamp?`<div class="message-timestamp">${e.timestamp}</div>`:"",o=/<p[^>]*>[\s\S]*?<\/p>/i.test(e.content)?e.content:`<p>${e.content}</p>`,i=e.metadata?Object.entries(e.metadata).map((([t,e])=>`data-${t}="${e}"`)).join(" "):"";return`\n\t\t\t<div class="message message-${e.author.toLowerCase()}" ${i}>\n\t\t\t\t<div class="message-header">\n\t\t\t\t\t<p class="message-author"><strong>${e.author}</strong></p>\n\t\t\t\t\t${n}\n\t\t\t\t</div>\n\t\t\t\t<div class="message-content">\n\t\t\t\t\t${o}\n\t\t\t\t</div>\n\t\t\t</div>${r<t.length-1?"\n<hr>":""}`})).join("\n").trim()}\n${e.length>0?`\n\t\t\t<div id="footnotes">\n\t\t\t\t<ol>\n\t\t\t\t\t${e.map(((t,e)=>`\n\t\t\t\t\t\t<li class="footnote" id="fn:${e+1}">\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t<a href="${t.url}" target="_blank">${t.text}</a> <a href="#fnref:${e+1}" class="footnote-backref">\u21a9</a>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t`)).join("")}\n\t\t\t\t</ol>\n\t\t\t</div>`:""}`.trim()}}e.ConversationExtractor=s},632(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.ChatGPTExtractor=void 0;const n=r(181),o=r(639);class i extends n.ConversationExtractor{constructor(t,e){super(t,e),this.cachedMessages=null,this.articles=t.querySelectorAll('article[data-testid^="conversation-turn-"]'),this.footnotes=[],this.footnoteCounter=0}canExtract(){return!!this.articles&&this.articles.length>0}extractMessages(){if(this.cachedMessages)return this.cachedMessages;const t=[];return this.footnotes=[],this.footnoteCounter=0,this.articles?(this.articles.forEach((e=>{var r,n;const i=e.querySelector("h5.sr-only, h6.sr-only"),s=(null===(n=null===(r=null==i?void 0:i.textContent)||void 0===r?void 0:r.trim())||void 0===n?void 0:n.replace(/:\s*$/,""))||"";let a="";const l=e.getAttribute("data-message-author-role");l&&(a=l);let c=(0,o.serializeHTML)(e);c=c.replace(/\u200B/g,"");const u=this.document.createElement("div");u.appendChild((0,o.parseHTML)(this.document,c)),u.querySelectorAll('h5.sr-only, h6.sr-only, span[data-state="closed"]').forEach((t=>t.remove())),c=(0,o.serializeHTML)(u);c=c.replace(/(​)?(<span[^>]*?>\s*<a(?=[^>]*?href="([^"]+)")(?=[^>]*?target="_blank")(?=[^>]*?rel="noopener")[^>]*?>[\s\S]*?<\/a>\s*<\/span>)/gi,((t,e,r,n)=>{let o="",i="";try{o=new URL(n).hostname.replace(/^www\./,"");const t=n.split("#:~:text=");if(t.length>1){i=decodeURIComponent(t[1]),i=i.replace(/%2C/g,",");const e=i.split(",");i=e.length>1&&e[0].trim()?` \u2014 ${e[0].trim()}...`:e[0].trim()?` \u2014 ${i.trim()}`:""}}catch(t){console.error(`Failed to parse URL: ${n}`,t),o=n}let s,a=this.footnotes.findIndex((t=>t.url===n));return-1===a?(this.footnoteCounter++,s=this.footnoteCounter,this.footnotes.push({url:n,text:`<a href="${n}">${o}</a>${i}`})):s=a+1,`<sup id="fnref:${s}"><a href="#fn:${s}">${s}</a></sup>`})),c=c.replace(/<p[^>]*>\s*<\/p>/g,""),t.push({author:s,content:c.trim(),metadata:{role:a||"unknown"}})})),this.cachedMessages=t,t):t}getFootnotes(){return this.footnotes}getMetadata(){const t=this.getTitle(),e=this.extractMessages();return{title:t,site:"ChatGPT",url:this.url,messageCount:e.length,description:`ChatGPT conversation with ${e.length} messages`}}getTitle(){var t,e,r;const n=null===(t=this.document.title)||void 0===t?void 0:t.trim();if(n&&"ChatGPT"!==n)return n;const o=null===(r=null===(e=this.articles)||void 0===e?void 0:e.item(0))||void 0===r?void 0:r.querySelector(".text-message");if(o){const t=o.textContent||"";return t.length>50?t.slice(0,50)+"...":t}return"ChatGPT Conversation"}}e.ChatGPTExtractor=i},397(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.ClaudeExtractor=void 0;const n=r(181),o=r(639);class i extends n.ConversationExtractor{constructor(t,e){super(t,e),this.articles=t.querySelectorAll('div[data-testid="user-message"], div[data-testid="assistant-message"], div.font-claude-response')}canExtract(){return!!this.articles&&this.articles.length>0}extractMessages(){const t=[];return this.articles?(this.articles.forEach((e=>{let r,n;if(e.hasAttribute("data-testid")){if("user-message"!==e.getAttribute("data-testid"))return;r="you",n=(0,o.serializeHTML)(e)}else{if(!e.classList.contains("font-claude-response"))return;{r="assistant";const t=e.querySelector(".standard-markdown")||e;n=(0,o.serializeHTML)(t)}}n&&(n=n.replace(/\u200B/g,"").replace(/<p[^>]*>\s*<\/p>/g,""),t.push({author:"you"===r?"You":"Claude",content:n.trim(),metadata:{role:r}}))})),t):t}getMetadata(){const t=this.getTitle(),e=this.extractMessages();return{title:t,site:"Claude",url:this.url,messageCount:e.length,description:`Claude conversation with ${e.length} messages`}}getTitle(){var t,e,r,n,o;const i=null===(t=this.document.title)||void 0===t?void 0:t.trim();if(i&&"Claude"!==i)return i.replace(/ - Claude$/,"");const s=null===(r=null===(e=this.document.querySelector("header .font-tiempos"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim();if(s)return s;const a=null===(o=null===(n=this.articles)||void 0===n?void 0:n.item(0))||void 0===o?void 0:o.querySelector('[data-testid="user-message"]');if(a){const t=a.textContent||"";return t.length>50?t.slice(0,50)+"...":t}return"Claude Conversation"}}e.ClaudeExtractor=i},732(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.GeminiExtractor=void 0;const n=r(181),o=r(639);class i extends n.ConversationExtractor{constructor(t,e){super(t,e),this.messageCount=null,this.conversationContainers=t.querySelectorAll("div.conversation-container"),this.footnotes=[]}canExtract(){return!!this.conversationContainers&&this.conversationContainers.length>0}extractMessages(){this.messageCount=0;const t=[];return this.conversationContainers?(this.extractSources(),this.conversationContainers.forEach((e=>{const r=e.querySelector("user-query");if(r){const e=r.querySelector(".query-text");if(e){const r=(0,o.serializeHTML)(e);t.push({author:"You",content:r.trim(),metadata:{role:"user"}})}}const n=e.querySelector("model-response");if(n){const e=n.querySelector(".model-response-text .markdown"),r=n.querySelector("#extended-response-markdown-content")||e;if(r){let e=(0,o.serializeHTML)(r);const n=this.document.createElement("div");n.appendChild((0,o.parseHTML)(this.document,e)),n.querySelectorAll(".table-content").forEach((t=>{t.classList.remove("table-content")})),e=(0,o.serializeHTML)(n),t.push({author:"Gemini",content:e.trim(),metadata:{role:"assistant"}})}}})),this.messageCount=t.length,t):t}extractSources(){const t=this.document.querySelectorAll("browse-item");t&&t.length>0&&t.forEach((t=>{var e,r,n,o;const i=t.querySelector("a");if(i instanceof HTMLAnchorElement){const t=i.href,s=(null===(r=null===(e=i.querySelector(".domain"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||"",a=(null===(o=null===(n=i.querySelector(".title"))||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.trim())||"";t&&(s||a)&&this.footnotes.push({url:t,text:a?`${s}: ${a}`:s})}}))}getFootnotes(){return this.footnotes}getMetadata(){var t;const e=this.getTitle(),r=null!==(t=this.messageCount)&&void 0!==t?t:this.extractMessages().length;return{title:e,site:"Gemini",url:this.url,messageCount:r,description:`Gemini conversation with ${r} messages`}}getTitle(){var t,e,r,n,o;const i=null===(t=this.document.title)||void 0===t?void 0:t.trim();if(i&&"Gemini"!==i&&!i.includes("Gemini"))return i;const s=null===(r=null===(e=this.document.querySelector(".title-text"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim();if(s)return s;const a=null===(o=null===(n=this.conversationContainers)||void 0===n?void 0:n.item(0))||void 0===o?void 0:o.querySelector(".query-text");if(a){const t=a.textContent||"";return t.length>50?t.slice(0,50)+"...":t}return"Gemini Conversation"}}e.GeminiExtractor=i},588(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.GitHubExtractor=void 0;const n=r(279),o=r(639),i=r(77);class s extends n.BaseExtractor{constructor(t,e){super(t,e),this.isIssue=/\/issues\/\d+/.test(e),this.isPR=/\/pull\/\d+/.test(e)}canExtract(){return!!['meta[name="expected-hostname"][content="github.com"]','meta[name="octolytics-url"]','meta[name="github-keyboard-shortcuts"]',".js-header-wrapper","#js-repo-pjax-container"].some((t=>null!==this.document.querySelector(t)))&&(this.isIssue?['[data-testid="issue-metadata-sticky"]','[data-testid="issue-title"]'].some((t=>null!==this.document.querySelector(t))):!!this.isPR&&[".pull-discussion-timeline",".discussion-timeline",".gh-header-title",".js-issue-title"].some((t=>null!==this.document.querySelector(t))))}extract(){const t=this.extractRepoInfo(),e=this.extractNumber(),r=this.isPR?"pull":"issue",n=this.isPR?this.getPRBody():null,{content:o,author:i,published:s}=this.isPR?this.getPRContent(n):this.getIssueContent(),a=!1!==this.options.includeReplies?this.isPR?this.extractPRComments(n):this.extractComments():"",l=this.createContentHtml(o,a);return{content:l,contentHtml:l,extractedContent:{type:r,number:e,repository:t.repo,owner:t.owner},variables:{title:this.document.title,author:i,published:s,site:`GitHub - ${t.owner}/${t.repo}`,description:this.createDescription(l)}}}createContentHtml(t,e){return(0,i.buildContentHtml)("github",t,e)}getIssueContent(){const t=this.document.querySelector('[data-testid="issue-viewer-issue-container"]');if(!t)return{content:"",author:"",published:""};const e=this.extractAuthor(t,['a[data-testid="issue-body-header-author"]',".IssueBodyHeaderAuthor-module__authorLoginLink--_S7aT",".ActivityHeader-module__AuthorLink--iofTU",'a[href*="/users/"][data-hovercard-url*="/users/"]','a[aria-label*="profile"]']),r=t.querySelector("relative-time"),n=(null==r?void 0:r.getAttribute("datetime"))||"",o=t.querySelector('[data-testid="issue-body-viewer"] .markdown-body');if(!o)return{content:"",author:e,published:n};return{content:this.cleanBodyContent(o),author:e,published:n}}extractComments(){const t=Array.from(this.document.querySelectorAll("[data-wrapper-timeline-id]")),e=new Set,r=[];for(const n of t){const t=n.querySelector(".react-issue-comment");if(!t)continue;const o=n.getAttribute("data-wrapper-timeline-id");if(!o||e.has(o))continue;e.add(o);const i=this.extractAuthor(t,[".ActivityHeader-module__AuthorLink--iofTU",'a[data-testid="avatar-link"]','a[href^="/"][data-hovercard-url*="/users/"]']),s=t.querySelector("relative-time"),a=(null==s?void 0:s.getAttribute("datetime"))||"",l=a?new Date(a).toISOString().split("T")[0]:"",c=t.querySelector(".markdown-body");if(!c)continue;const u=this.cleanBodyContent(c);u&&r.push({author:i,date:l,content:u})}return(0,i.buildCommentTree)(r)}getPRBody(){return this.document.querySelector('[id^="pullrequest-"]')||this.document.querySelector(".timeline-comment")}getPRContent(t){var e;const r=(null==t?void 0:t.querySelector(".comment-body.markdown-body"))||this.document.querySelector(".comment-body.markdown-body"),n=r?this.cleanBodyContent(r):"",o=(null==t?void 0:t.querySelector(".author"))||this.document.querySelector(".gh-header-meta .author"),i=(null===(e=null==o?void 0:o.textContent)||void 0===e?void 0:e.trim())||"",s=null==t?void 0:t.querySelector("relative-time");return{content:n,author:i,published:(null==s?void 0:s.getAttribute("datetime"))||""}}extractPRComments(t){var e;const r=Array.from(this.document.querySelectorAll(".timeline-comment, .review-comment")),n=[];for(const o of r){if(t&&(o===t||t.contains(o)))continue;const r=o.querySelector(".author"),i=(null===(e=null==r?void 0:r.textContent)||void 0===e?void 0:e.trim())||"",s=o.querySelector("relative-time"),a=(null==s?void 0:s.getAttribute("datetime"))||"",l=a?new Date(a).toISOString().split("T")[0]:"",c=o.querySelector(".comment-body.markdown-body");if(!c)continue;const u=this.cleanBodyContent(c);u&&n.push({author:i,date:l,content:u})}return(0,i.buildCommentTree)(n)}extractAuthor(t,e){for(const r of e){const e=t.querySelector(r);if(e){const t=e.getAttribute("href");if(t){if(t.startsWith("/"))return t.substring(1);if(t.includes("github.com/")){const e=t.match(/github\.com\/([^\/\?#]+)/);if(e&&e[1])return e[1]}}}}return"Unknown"}cleanBodyContent(t){const e=t.cloneNode(!0);return e.querySelectorAll('button, [data-testid*="button"], [data-testid*="menu"]').forEach((t=>t.remove())),e.querySelectorAll(".js-clipboard-copy, .zeroclipboard-container").forEach((t=>t.remove())),e.querySelectorAll('div.highlight[class*="highlight-source-"] pre, div.highlight pre').forEach((t=>{const e=t.parentElement;if(!e)return;const r=e.className.match(/highlight-source-(\w+)/),n=(null==r?void 0:r[1])||"",o=e.getAttribute("data-snippet-clipboard-copy-content")||t.textContent||"",i=this.document.createElement("code");n&&(i.setAttribute("class",`language-${n}`),i.setAttribute("data-lang",n)),i.textContent=o;const s=this.document.createElement("pre");s.appendChild(i),e.replaceWith(s)})),(0,o.serializeHTML)(e).trim()}extractNumber(){var t;const e=this.url.match(/\/(issues|pull)\/(\d+)/);if(e)return e[2];const r=this.document.querySelector("h1"),n=null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.match(/#(\d+)/);return n?n[1]:""}extractRepoInfo(){const t=this.url.match(/github\.com\/([^\/]+)\/([^\/]+)/);if(t)return{owner:t[1],repo:t[2]};const e=this.document.title.match(/([^\/\s]+)\/([^\/\s]+)/);return e?{owner:e[1],repo:e[2]}:{owner:"",repo:""}}createDescription(t){var e;if(!t)return"";const r=this.document.createElement("div");return r.appendChild((0,o.parseHTML)(this.document,t)),(null===(e=r.textContent)||void 0===e?void 0:e.trim().slice(0,140).replace(/\s+/g," "))||""}}e.GitHubExtractor=s},20(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.GrokExtractor=void 0;const n=r(181),o=r(639);class i extends n.ConversationExtractor{constructor(t,e){super(t,e),this.messageContainerSelector=".relative.group.flex.flex-col.justify-center.w-full",this.messageBubbles=t.querySelectorAll(this.messageContainerSelector),this.footnotes=[],this.footnoteCounter=0}canExtract(){return!!this.messageBubbles&&this.messageBubbles.length>0}extractMessages(){const t=[];return this.footnotes=[],this.footnoteCounter=0,this.messageBubbles&&0!==this.messageBubbles.length?(this.messageBubbles.forEach((e=>{var r;const n=e.classList.contains("items-end"),i=e.classList.contains("items-start");if(!n&&!i)return;const s=e.querySelector(".message-bubble");if(!s)return;let a="",l="",c="";if(n)a=s.textContent||"",l="user",c="You";else if(i){l="assistant",c="Grok";const t=s.cloneNode(!0);null===(r=t.querySelector(".relative.border.border-border-l1.bg-surface-base"))||void 0===r||r.remove(),a=(0,o.serializeHTML)(t),a=this.processFootnotes(a)}a.trim()&&t.push({author:c,content:a.trim(),metadata:{role:l}})})),t):t}getFootnotes(){return this.footnotes}getMetadata(){var t;const e=this.getTitle(),r=(null===(t=this.messageBubbles)||void 0===t?void 0:t.length)||0;return{title:e,site:"Grok",url:this.url,messageCount:r,description:`Grok conversation with ${r} messages`}}getTitle(){var t,e;const r=null===(t=this.document.title)||void 0===t?void 0:t.trim();if(r&&"Grok"!==r&&!r.startsWith("Grok by "))return r.replace(/\s-\s*Grok$/,"").trim();const n=this.document.querySelector(`${this.messageContainerSelector}.items-end`);if(n){const t=n.querySelector(".message-bubble");if(t){const r=(null===(e=t.textContent)||void 0===e?void 0:e.trim())||"";return r.length>50?r.slice(0,50)+"...":r}}return"Grok Conversation"}processFootnotes(t){return t.replace(/<a\s+(?:[^>]*?\s+)?href="([^"]*)"[^>]*>(.*?)<\/a>/gi,((t,e,r)=>{if(!e||e.startsWith("#")||!e.match(/^https?:\/\//i))return t;let n;if(this.footnotes.find((t=>t.url===e)))n=this.footnotes.findIndex((t=>t.url===e))+1;else{this.footnoteCounter++,n=this.footnoteCounter;let t=e;try{const r=new URL(e).hostname.replace(/^www\./,"");t=`<a href="${e}" target="_blank" rel="noopener noreferrer">${r}</a>`}catch(r){t=`<a href="${e}" target="_blank" rel="noopener noreferrer">${e}</a>`,console.warn(`GrokExtractor: Could not parse URL for footnote: ${e}`)}this.footnotes.push({url:e,text:t})}return`${r}<sup id="fnref:${n}" class="footnote-ref"><a href="#fn:${n}" class="footnote-link">${n}</a></sup>`}))}}e.GrokExtractor=i},458(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.HackerNewsExtractor=void 0;const n=r(279),o=r(639),i=r(77);class s extends n.BaseExtractor{constructor(t,e){super(t,e),this.mainPost=t.querySelector(".fatitem"),this.isCommentPage=this.detectCommentPage(),this.mainComment=this.isCommentPage?this.findMainComment():null}detectCommentPage(){var t,e;return!!(null===(t=this.mainPost)||void 0===t?void 0:t.querySelector(".onstory"))&&!(null===(e=this.mainPost)||void 0===e?void 0:e.querySelector(".titleline"))}findMainComment(){var t;return(null===(t=this.mainPost)||void 0===t?void 0:t.querySelector("tr.athing"))||null}canExtract(){return!!this.mainPost}extract(){const t=this.getPostContent(),e=!1!==this.options.includeReplies?this.extractComments():"",r=this.createContentHtml(t,e),n=this.getPostTitle(),o=this.getPostAuthor(),i=this.createDescription(),s=this.getPostDate();return{content:r,contentHtml:r,extractedContent:{postId:this.getPostId(),postAuthor:o},variables:{title:n,author:o,site:"Hacker News",description:i,published:s}}}createContentHtml(t,e){return(0,i.buildContentHtml)("hackernews",t,e)}getPostContent(){var t,e,r,n;if(!this.mainPost)return"";if(this.isCommentPage&&this.mainComment){const n=(null===(t=this.mainComment.querySelector(".hnuser"))||void 0===t?void 0:t.textContent)||"[deleted]",s=this.mainComment.querySelector(".commtext"),a=s?(0,o.serializeHTML)(s):"",l=this.mainComment.querySelector(".age"),c=((null==l?void 0:l.getAttribute("title"))||"").split("T")[0]||"",u=(null===(r=null===(e=this.mainComment.querySelector(".score"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||"";return(0,i.buildComment)({author:n,date:c,content:a,score:u||void 0})}const s=this.mainPost.querySelector("tr.athing"),a=(null==s||s.nextElementSibling,(null===(n=null==s?void 0:s.querySelector(".titleline a"))||void 0===n?void 0:n.getAttribute("href"))||"");let l="";a&&(l+=`<p><a href="${a}" target="_blank">${a}</a></p>`);const c=this.mainPost.querySelector(".toptext");return c&&(l+=`<div class="post-text">${(0,o.serializeHTML)(c)}</div>`),l}extractComments(){const t=Array.from(this.document.querySelectorAll("tr.comtr"));return this.processComments(t)}processComments(t){var e,r,n,s;const a=[],l=new Set;for(const i of t){const t=i.getAttribute("id");if(!t||l.has(t))continue;l.add(t);const c=(null===(e=i.querySelector(".ind img"))||void 0===e?void 0:e.getAttribute("width"))||"0",u=parseInt(c)/40,d=i.querySelector(".commtext"),h=(null===(r=i.querySelector(".hnuser"))||void 0===r?void 0:r.textContent)||"[deleted]",m=i.querySelector(".age"),p=(null===(s=null===(n=i.querySelector(".score"))||void 0===n?void 0:n.textContent)||void 0===s?void 0:s.trim())||"";if(!d)continue;const f=`https://news.ycombinator.com/item?id=${t}`,g=((null==m?void 0:m.getAttribute("title"))||"").split("T")[0]||"";a.push({author:h,date:g,content:(0,o.serializeHTML)(d),depth:u,score:p||void 0,url:f})}return(0,i.buildCommentTree)(a)}getPostId(){const t=this.url.match(/id=(\d+)/);return(null==t?void 0:t[1])||""}getPostTitle(){var t,e,r,n,o;if(this.isCommentPage&&this.mainComment){const r=(null===(t=this.mainComment.querySelector(".hnuser"))||void 0===t?void 0:t.textContent)||"[deleted]",n=(null===(e=this.mainComment.querySelector(".commtext"))||void 0===e?void 0:e.textContent)||"";return`Comment by ${r}: ${n.trim().slice(0,50)+(n.length>50?"...":"")}`}return(null===(o=null===(n=null===(r=this.mainPost)||void 0===r?void 0:r.querySelector(".titleline"))||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.trim())||""}getPostAuthor(){var t,e,r;return(null===(r=null===(e=null===(t=this.mainPost)||void 0===t?void 0:t.querySelector(".hnuser"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||""}createDescription(){const t=this.getPostTitle(),e=this.getPostAuthor();return this.isCommentPage?`Comment by ${e} on Hacker News`:`${t} - by ${e} on Hacker News`}getPostDate(){if(!this.mainPost)return"";const t=this.mainPost.querySelector(".age");return((null==t?void 0:t.getAttribute("title"))||"").split("T")[0]||""}}e.HackerNewsExtractor=s},959(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{l(n.next(t))}catch(t){i(t)}}function a(t){try{l(n.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}l((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.RedditExtractor=void 0;const o=r(279),i=r(639),s=r(77);class a extends o.BaseExtractor{constructor(t,e){super(t,e),this.shredditPost=t.querySelector("shreddit-post"),this.isOldReddit=!!t.querySelector(".thing.link")}canExtract(){return!!this.shredditPost||this.isOldReddit}canExtractAsync(){return this.isCommentsPage()&&!this.isOldReddit}isCommentsPage(){return/\/r\/.+\/comments\//.test(this.url)}extractAsync(){return n(this,void 0,void 0,(function*(){var t,e;const r=new URL(this.url);r.hostname="old.reddit.com";const n=yield fetch(r.toString(),{headers:{"User-Agent":"Mozilla/5.0 (compatible; Defuddle/1.0)"}});if(!n.ok)throw new Error(`Failed to fetch old.reddit.com: ${n.status}`);const o=yield n.text(),i=null!==(e=null===(t=this.document.defaultView)||void 0===t?void 0:t.DOMParser)&&void 0!==e?e:"undefined"!=typeof DOMParser?DOMParser:null;if(!i)throw new Error("DOMParser is not available in this environment");const s=(new i).parseFromString(o,"text/html");return this.extractOldReddit(s)}))}extract(){var t,e;if(this.isOldReddit)return this.extractOldReddit(this.document);const r=this.document.querySelectorAll("shreddit-comment").length>0;if(this.isCommentsPage()&&!r)return{content:"",contentHtml:""};const n=this.getPostContent(),o=!1!==this.options.includeReplies?this.extractComments():"",i=this.createContentHtml(n,o),s=(null===(e=null===(t=this.document.querySelector("h1"))||void 0===t?void 0:t.textContent)||void 0===e?void 0:e.trim())||"",a=this.getSubreddit(),l=this.getPostAuthor(),c=this.createDescription(n);return{content:i,contentHtml:i,extractedContent:{postId:this.getPostId(),subreddit:a,postAuthor:l},variables:{title:s,author:l,site:`r/${a}`,description:c}}}extractOldReddit(t){var e,r;const n=t.querySelector(".thing.link"),o=(null===(r=null===(e=null==n?void 0:n.querySelector("a.title"))||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||"",a=(null==n?void 0:n.getAttribute("data-author"))||"",l=(null==n?void 0:n.getAttribute("data-subreddit"))||"",c=null==n?void 0:n.querySelector(".usertext-body .md"),u=c?(0,i.serializeHTML)(c):"";let d="";if(!1!==this.options.includeReplies){const e=t.querySelector(".commentarea .sitetable"),r=e?this.collectOldRedditComments(e):[];d=r.length>0?(0,s.buildCommentTree)(r):""}const h=this.createContentHtml(u,d),m=this.createDescription(u);return{content:h,contentHtml:h,extractedContent:{postId:this.getPostId(),subreddit:l,postAuthor:a},variables:{title:o,author:a,site:`r/${l}`,description:m}}}getPostContent(){var t,e,r;const n=null===(t=this.shredditPost)||void 0===t?void 0:t.querySelector('[slot="text-body"]');return(n?(0,i.serializeHTML)(n):"")+((null===(r=null===(e=this.shredditPost)||void 0===e?void 0:e.querySelector("#post-image"))||void 0===r?void 0:r.outerHTML)||"")}createContentHtml(t,e){return(0,s.buildContentHtml)("reddit",t,e)}extractComments(){const t=Array.from(this.document.querySelectorAll("shreddit-comment"));return this.processComments(t)}getPostId(){const t=this.url.match(/comments\/([a-zA-Z0-9]+)/);return(null==t?void 0:t[1])||""}getSubreddit(){const t=this.url.match(/\/r\/([^/]+)/);return(null==t?void 0:t[1])||""}getPostAuthor(){var t;return(null===(t=this.shredditPost)||void 0===t?void 0:t.getAttribute("author"))||""}createDescription(t){var e;if(!t)return"";const r=this.document.createElement("div");return r.appendChild((0,i.parseHTML)(this.document,t)),(null===(e=r.textContent)||void 0===e?void 0:e.trim().slice(0,140).replace(/\s+/g," "))||""}collectOldRedditComments(t,e=0){var r,n;const o=[],s=Array.from(t.querySelectorAll(":scope > .thing.comment"));for(const t of s){const s=t.getAttribute("data-author")||"",a=t.getAttribute("data-permalink")||"",l=(null===(n=null===(r=t.querySelector(".entry .tagline .score.unvoted"))||void 0===r?void 0:r.textContent)||void 0===n?void 0:n.trim())||"",c=t.querySelector(".entry .tagline time[datetime]"),u=(null==c?void 0:c.getAttribute("datetime"))||"",d=u?new Date(u).toISOString().split("T")[0]:"",h=t.querySelector(".entry .usertext-body .md"),m=h?(0,i.serializeHTML)(h):"";o.push({author:s,date:d,content:m,depth:e,score:l||void 0,url:a?`https://reddit.com${a}`:void 0});const p=t.querySelector(".child > .sitetable");p&&o.push(...this.collectOldRedditComments(p,e+1))}return o}processComments(t){var e;const r=[];for(const n of t){const t=parseInt(n.getAttribute("depth")||"0"),o=n.getAttribute("author")||"",s=n.getAttribute("score")||"0",a=n.getAttribute("permalink")||"",l=n.querySelector('[slot="comment"]'),c=l?(0,i.serializeHTML)(l):"",u=n.getAttribute("created")||(null===(e=n.querySelector("time"))||void 0===e?void 0:e.getAttribute("datetime"))||"",d=u?new Date(u).toISOString().split("T")[0]:"";r.push({author:o,date:d,content:c,depth:t,score:`${s} points`,url:a?`https://reddit.com${a}`:void 0})}return(0,s.buildCommentTree)(r)}}e.RedditExtractor=a},248(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.TwitterExtractor=void 0;const n=r(279),o=r(639);class i extends n.BaseExtractor{constructor(t,e){var r;super(t,e),this.mainTweet=null,this.threadTweets=[];const n=t.querySelector('[aria-label="Timeline: Conversation"]');if(!n){const e=t.querySelector('article[data-testid="tweet"]');return void(e&&(this.mainTweet=e))}let o=Array.from(n.querySelectorAll('article[data-testid="tweet"]'));const i=null===(r=n.querySelector("section, h2"))||void 0===r?void 0:r.parentElement;if(i){const t=o.findIndex((t=>i.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING));-1!==t&&(o=o.slice(0,t))}this.mainTweet=o[0]||null,this.threadTweets=o.slice(1)}canExtract(){return!!this.mainTweet}extract(){const t=this.extractTweet(this.mainTweet),e=!1!==this.options.includeReplies?this.threadTweets.map((t=>this.extractTweet(t))).join("\n<hr>\n"):"",r=`\n\t\t\t<div class="tweet-thread">\n\t\t\t\t<div class="main-tweet">\n\t\t\t\t\t${t}\n\t\t\t\t</div>\n\t\t\t\t${e?`\n\t\t\t\t\t<hr>\n\t\t\t\t\t<div class="thread-tweets">\n\t\t\t\t\t\t${e}\n\t\t\t\t\t</div>\n\t\t\t\t`:""}\n\t\t\t</div>\n\t\t`.trim(),n=this.getTweetId(),o=this.getTweetAuthor();return{content:r,contentHtml:r,extractedContent:{tweetId:n,tweetAuthor:o},variables:{title:`Thread by ${o}`,author:o,site:"X (Twitter)",description:this.createDescription(this.mainTweet)}}}formatTweetText(t){if(!t)return"";const e=this.document.createElement("div");e.appendChild((0,o.parseHTML)(this.document,t)),e.querySelectorAll("a").forEach((t=>{var e;const r=(null===(e=t.textContent)||void 0===e?void 0:e.trim())||"";t.replaceWith(r)})),e.querySelectorAll("span, div").forEach((t=>{t.replaceWith(...Array.from(t.childNodes))}));return(0,o.serializeHTML)(e).split("\n").map((t=>t.trim())).filter((t=>t)).map((t=>`<p>${t}</p>`)).join("\n")}extractTweet(t){var e,r;if(!t)return"";const n=t.cloneNode(!0);n.querySelectorAll('img[src*="/emoji/"]').forEach((t=>{if("img"===t.tagName.toLowerCase()&&t.getAttribute("alt")){const e=t.getAttribute("alt");e&&t.replaceWith(e)}}));const i=n.querySelector('[data-testid="tweetText"]'),s=i?(0,o.serializeHTML)(i):"",a=this.formatTweetText(s),l=this.extractImages(t),c=this.extractUserInfo(t),u=null===(r=null===(e=t.querySelector('[aria-labelledby*="id__"]'))||void 0===e?void 0:e.querySelector('[data-testid="User-Name"]'))||void 0===r?void 0:r.closest('[aria-labelledby*="id__"]'),d=u?this.extractTweet(u):"";return`\n\t\t\t<div class="tweet">\n\t\t\t\t<div class="tweet-header">\n\t\t\t\t\t<span class="tweet-author"><strong>${c.fullName}</strong> <span class="tweet-handle">${c.handle}</span></span>\n\t\t\t\t\t${c.date?`<a href="${c.permalink}" class="tweet-date">${c.date}</a>`:""}\n\t\t\t\t</div>\n\t\t\t\t${a?`<div class="tweet-text">${a}</div>`:""}\n\t\t\t\t${l.length?`\n\t\t\t\t\t<div class="tweet-media">\n\t\t\t\t\t\t${l.join("\n")}\n\t\t\t\t\t</div>\n\t\t\t\t`:""}\n\t\t\t\t${d?`\n\t\t\t\t\t<blockquote class="quoted-tweet">\n\t\t\t\t\t\t${d}\n\t\t\t\t\t</blockquote>\n\t\t\t\t`:""}\n\t\t\t</div>\n\t\t`.trim()}extractUserInfo(t){var e,r,n,o,i,s,a,l,c;const u=t.querySelector('[data-testid="User-Name"]');if(!u)return{fullName:"",handle:"",date:"",permalink:""};const d=u.querySelectorAll("a");let h=(null===(r=null===(e=null==d?void 0:d[0])||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||"",m=(null===(o=null===(n=null==d?void 0:d[1])||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.trim())||"";h&&m||(h=(null===(s=null===(i=u.querySelector('span[style*="color: rgb(15, 20, 25)"] span'))||void 0===i?void 0:i.textContent)||void 0===s?void 0:s.trim())||"",m=(null===(l=null===(a=u.querySelector('span[style*="color: rgb(83, 100, 113)"]'))||void 0===a?void 0:a.textContent)||void 0===l?void 0:l.trim())||"");const p=t.querySelector("time"),f=(null==p?void 0:p.getAttribute("datetime"))||"";return{fullName:h,handle:m,date:f?new Date(f).toISOString().split("T")[0]:"",permalink:(null===(c=null==p?void 0:p.closest("a"))||void 0===c?void 0:c.href)||""}}extractImages(t){var e,r;const n=['[data-testid="tweetPhoto"]','[data-testid="tweet-image"]','img[src*="media"]'],o=[],i=null===(r=null===(e=t.querySelector('[aria-labelledby*="id__"]'))||void 0===e?void 0:e.querySelector('[data-testid="User-Name"]'))||void 0===r?void 0:r.closest('[aria-labelledby*="id__"]');for(const e of n){t.querySelectorAll(e).forEach((t=>{var e,r;if(!(null==i?void 0:i.contains(t))&&"img"===t.tagName.toLowerCase()&&t.getAttribute("alt")){const n=(null===(e=t.getAttribute("src"))||void 0===e?void 0:e.replace(/&name=\w+$/,"&name=large"))||"",i=(null===(r=t.getAttribute("alt"))||void 0===r?void 0:r.replace(/\s+/g," ").trim())||"";o.push(`<img src="${n}" alt="${i}" />`)}}))}return o}getTweetId(){const t=this.url.match(/status\/(\d+)/);return(null==t?void 0:t[1])||""}getTweetAuthor(){var t,e,r;const n=null===(t=this.mainTweet)||void 0===t?void 0:t.querySelector('[data-testid="User-Name"]'),o=null==n?void 0:n.querySelectorAll("a"),i=(null===(r=null===(e=null==o?void 0:o[1])||void 0===e?void 0:e.textContent)||void 0===r?void 0:r.trim())||"";return i.startsWith("@")?i:`@${i}`}createDescription(t){var e;if(!t)return"";return((null===(e=t.querySelector('[data-testid="tweetText"]'))||void 0===e?void 0:e.textContent)||"").trim().slice(0,140).replace(/\s+/g," ")}}e.TwitterExtractor=i},64(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.XArticleExtractor=void 0;const n=r(279),o=r(639),i='[data-testid="twitterArticleRichTextView"]',s='[data-testid="twitter-article-title"]',a='[itemprop="author"]',l='meta[itemprop="name"]',c='meta[itemprop="additionalName"]',u='[data-testid="tweetPhoto"] img',d=".longform-unstyled, .public-DraftStyleDefault-block",h='span[style*="font-weight: bold"]',m="[data-offset-key]",p='[data-testid="simpleTweet"]',f='[data-testid="tweetText"]',g='[data-testid="User-Name"]',v='[data-testid="markdown-code-block"]';class y extends n.BaseExtractor{constructor(t,e,r){super(t,e,r),this.articleContainer=t.querySelector(i)}canExtract(){return!!this.articleContainer}extract(){const t=this.extractTitle(),e=this.extractAuthor(),r=this.extractContent(),n=this.createDescription();return{content:r,contentHtml:r,extractedContent:{articleId:this.getArticleId()},variables:{title:t,author:e,site:"X (Twitter)",description:n}}}extractTitle(){var t;const e=this.document.querySelector(s);return(null===(t=null==e?void 0:e.textContent)||void 0===t?void 0:t.trim())||"Untitled X Article"}extractAuthor(){var t,e;const r=this.document.querySelector(a);if(!r)return this.getAuthorFromUrl();const n=null===(t=r.querySelector(l))||void 0===t?void 0:t.getAttribute("content"),o=null===(e=r.querySelector(c))||void 0===e?void 0:e.getAttribute("content");return n&&o?`${n} (@${o})`:n||o||this.getAuthorFromUrl()}getAuthorFromUrl(){const t=this.url.match(/\/([a-zA-Z][a-zA-Z0-9_]{0,14})\/article\/\d+/);return t?`@${t[1]}`:this.getAuthorFromOgTitle()}getAuthorFromOgTitle(){var t;const e=((null===(t=this.document.querySelector('meta[property="og:title"]'))||void 0===t?void 0:t.getAttribute("content"))||"").match(/^(?:\(\d+\)\s+)?(.+?)\s+on\s+X\s*:/);return e?e[1].trim():"Unknown"}getArticleId(){const t=this.url.match(/article\/(\d+)/);return t?t[1]:""}extractContent(){if(!this.articleContainer)return"";const t=this.articleContainer.cloneNode(!0);return this.cleanContent(t),`<article class="x-article">${(0,o.serializeHTML)(t)}</article>`}cleanContent(t){const e=t.ownerDocument||this.document;this.convertEmbeddedTweets(t,e),this.convertCodeBlocks(t,e),this.convertHeaders(t,e),this.unwrapLinkedImages(t,e),this.upgradeImageQuality(t),this.convertBoldSpans(t,e),this.convertDraftParagraphs(t,e),this.removeDraftAttributes(t)}convertEmbeddedTweets(t,e){t.querySelectorAll(p).forEach((t=>{var r,n,o,i,s;const a=e.createElement("blockquote");a.className="embedded-tweet";const l=t.querySelector(g),c=null==l?void 0:l.querySelectorAll("a"),u=(null===(n=null===(r=null==c?void 0:c[0])||void 0===r?void 0:r.textContent)||void 0===n?void 0:n.trim())||"",d=(null===(i=null===(o=null==c?void 0:c[1])||void 0===o?void 0:o.textContent)||void 0===i?void 0:i.trim())||"",h=t.querySelector(f),m=(null===(s=null==h?void 0:h.textContent)||void 0===s?void 0:s.trim())||"";if(u||d){const t=e.createElement("cite");t.textContent=d?`${u} ${d}`:u,a.appendChild(t)}if(m){const t=e.createElement("p");t.textContent=m,a.appendChild(t)}t.replaceWith(a)}))}convertCodeBlocks(t,e){t.querySelectorAll(v).forEach((t=>{var r;const n=t.querySelector("pre"),o=t.querySelector("code");if(!n||!o)return;let i="";const s=o.className.match(/language-(\w+)/);if(s)i=s[1];else{const e=t.querySelector("span");i=(null===(r=null==e?void 0:e.textContent)||void 0===r?void 0:r.trim())||""}const a=e.createElement("pre"),l=e.createElement("code");i&&(l.setAttribute("data-lang",i),l.className=`language-${i}`),l.textContent=o.textContent||"",a.appendChild(l),t.replaceWith(a)}))}convertHeaders(t,e){t.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach((t=>{var r;const n=t.tagName.toLowerCase(),o=(null===(r=t.textContent)||void 0===r?void 0:r.trim())||"";if(!o)return;const i=e.createElement(n);i.textContent=o,t.replaceWith(i)}))}unwrapLinkedImages(t,e){t.querySelectorAll(u).forEach((r=>{var n;const o=r.closest("a");if(!o||!t.contains(o))return;let i=r.getAttribute("src")||"";const s=(null===(n=r.getAttribute("alt"))||void 0===n?void 0:n.replace(/\s+/g," ").trim())||"Image";i=i.includes("&name=")?i.replace(/&name=\w+/,"&name=large"):i.includes("?")?`${i}&name=large`:`${i}?name=large`;const a=e.createElement("img");a.setAttribute("src",i),a.setAttribute("alt",s),o.replaceWith(a)}))}upgradeImageQuality(t){t.querySelectorAll(u).forEach((t=>{const e=t.getAttribute("src");e&&(e.includes("&name=")?t.setAttribute("src",e.replace(/&name=\w+/,"&name=large")):e.includes("?")?t.setAttribute("src",`${e}&name=large`):t.setAttribute("src",`${e}?name=large`))}))}convertDraftParagraphs(t,e){t.querySelectorAll(d).forEach((t=>{const r=e.createElement("p"),n=t=>{if(3===t.nodeType)r.appendChild(e.createTextNode(t.textContent||""));else if(1===t.nodeType){const o=t,i=o.tagName.toLowerCase();if("strong"===i){const t=e.createElement("strong");t.textContent=o.textContent||"",r.appendChild(t)}else if("a"===i){const t=e.createElement("a");t.setAttribute("href",o.getAttribute("href")||""),t.textContent=o.textContent||"",r.appendChild(t)}else if("code"===i){const t=e.createElement("code");t.textContent=o.textContent||"",r.appendChild(t)}else o.childNodes.forEach((t=>n(t)))}};t.childNodes.forEach((t=>n(t))),t.replaceWith(r)}))}convertBoldSpans(t,e){t.querySelectorAll(h).forEach((t=>{const r=e.createElement("strong");r.textContent=t.textContent||"",t.replaceWith(r)}))}removeDraftAttributes(t){t.querySelectorAll(m).forEach((t=>{t.removeAttribute("data-offset-key")}))}createDescription(){var t,e;const r=(null===(e=null===(t=this.articleContainer)||void 0===t?void 0:t.textContent)||void 0===e?void 0:e.trim())||"";return r.slice(0,140)+(r.length>140?"...":"")}}e.XArticleExtractor=y},666(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{l(n.next(t))}catch(t){i(t)}}function a(t){try{l(n.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}l((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.XOembedExtractor=void 0;const o=r(279),i=r(639);class s extends o.BaseExtractor{canExtract(){return!1}extract(){return{content:"",contentHtml:""}}canExtractAsync(){return/\/(status|article)\/\d+/.test(this.url)}extractAsync(){return n(this,void 0,void 0,(function*(){const t=yield this.tryExtractFxTwitter();return t||this.extractOembed()}))}extractOembed(){return n(this,void 0,void 0,(function*(){var t;const e=`https://publish.twitter.com/oembed?url=${encodeURIComponent(this.url)}&omit_script=true`,r=yield fetch(e);if(!r.ok)throw new Error(`oEmbed request failed: ${r.status}`);const n=yield r.json(),o=this.document.createElement("div");o.appendChild((0,i.parseHTML)(this.document,n.html));const s=o.querySelector("blockquote"),a=(null==s?void 0:s.querySelectorAll("p"))||[],l=Array.from(a).map((t=>`<p>${(0,i.serializeHTML)(t)}</p>`)).join("\n"),c=n.author_url?`@${n.author_url.split("/").pop()}`:"",u=null==s?void 0:s.querySelector("a:last-child"),d=(null===(t=null==u?void 0:u.textContent)||void 0===t?void 0:t.trim())||"",h=(null==u?void 0:u.getAttribute("href"))||this.url,m=(0,i.escapeHtml)(n.author_name),p=(0,i.escapeHtml)(c),f=(0,i.escapeHtml)(d),g=(0,i.escapeHtml)(h),v=`\n\t\t\t<div class="tweet-thread">\n\t\t\t\t<div class="main-tweet">\n\t\t\t\t\t<div class="tweet">\n\t\t\t\t\t\t<div class="tweet-header">\n\t\t\t\t\t\t\t<span class="tweet-author"><strong>${m}</strong> <span class="tweet-handle">${p}</span></span>\n\t\t\t\t\t\t\t${d?`<a href="${g}" class="tweet-date">${f}</a>`:""}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t${l?`<div class="tweet-text">${l}</div>`:""}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t`.trim();return{content:v,contentHtml:v,variables:{title:`Post by ${c||n.author_name}`,author:c||n.author_name,site:"X (Twitter)"}}}))}tryExtractFxTwitter(){return n(this,void 0,void 0,(function*(){var t,e;const r=this.url.match(/\/([a-zA-Z][a-zA-Z0-9_]{0,14})\/(status|article)\/(\d+)/);if(!r)return null;try{const n=yield this.fetchFxTwitter(r[1],r[3]);return(null===(t=n.tweet)||void 0===t?void 0:t.article)?this.buildArticleResult(n):(null===(e=n.tweet)||void 0===e?void 0:e.text)?this.buildTweetResult(n):null}catch(t){return null}}))}fetchFxTwitter(t,e){return n(this,void 0,void 0,(function*(){const r=`https://api.fxtwitter.com/${t}/status/${e}`,n=yield fetch(r,{headers:{"User-Agent":"Mozilla/5.0 (compatible; Defuddle/1.0; +https://defuddle.md)"}});if(!n.ok)throw new Error(`FxTwitter API request failed: ${n.status}`);return n.json()}))}buildArticleResult(t){const e=t.tweet.article,{blocks:r,entityMap:n}=e.content,o=this.renderArticle(r,n,e.cover_media),i=`@${t.tweet.author.screen_name}`;return{content:o,contentHtml:o,variables:{title:e.title,author:i,site:"X (Twitter)",description:e.preview_text}}}buildTweetResult(t){const e=t.tweet,r=`@${e.author.screen_name}`,n=this.renderTweet(e);return{content:n,contentHtml:n,variables:{title:`Post by ${r}`,author:r,site:"X (Twitter)"}}}renderTweet(t){var e,r,n;const o=(null===(e=t.raw_text)||void 0===e?void 0:e.text)||t.text,s=((null===(r=t.raw_text)||void 0===r?void 0:r.facets)||[]).filter((t=>"media"!==t.type)),a=o.split(/\n\n+/);let l=0;const c=[];for(const t of a){const e=o.indexOf(t,l),r=e+t.length;l=r;const n=t.trimStart().startsWith(">");let i=n?t.trimStart().slice(1).trimStart():t;const a=n?e+(t.length-t.trimStart().length)+1+(t.trimStart().slice(1).length-t.trimStart().slice(1).trimStart().length):e,u=this.applyFacets(i,a,r,s).replace(/\n/g,"<br>");n?c.push(`<blockquote><p>${u}</p></blockquote>`):u.trim()&&c.push(`<p>${u}</p>`)}if(null===(n=t.media)||void 0===n?void 0:n.photos)for(const e of t.media.photos)c.push(`<img src="${(0,i.escapeHtml)(e.url)}" alt="">`);const u=(0,i.escapeHtml)(`@${t.author.screen_name}`);return`<div class="tweet-thread"><div class="main-tweet"><div class="tweet"><div class="tweet-header"><span class="tweet-author"><strong>${(0,i.escapeHtml)(t.author.name)}</strong> <span class="tweet-handle">${u}</span></span></div><div class="tweet-text">${c.join("\n")}</div></div></div></div>`}applyMarkers(t,e){if(0===e.length)return(0,i.escapeHtml)(t);e.sort(((t,e)=>t.offset!==e.offset?t.offset-e.offset:"close"===t.type&&"open"===e.type?-1:"open"===t.type&&"close"===e.type?1:0));let r="",n=0;for(const o of e)o.offset>n&&(r+=(0,i.escapeHtml)(t.slice(n,o.offset))),r+=o.tag,n=o.offset;return n<t.length&&(r+=(0,i.escapeHtml)(t.slice(n))),r}applyFacets(t,e,r,n){const o=[];for(const s of n){const[n,a]=s.indices;if(a<=e||n>=r)continue;const l=Math.max(0,n-e),c=Math.min(t.length,a-e);if("italic"===s.type)o.push({offset:l,type:"open",tag:"<em>"}),o.push({offset:c,type:"close",tag:"</em>"});else if("mention"===s.type&&s.text){const t=`https://x.com/${(0,i.escapeHtml)(s.text)}`;o.push({offset:l,type:"open",tag:`<a href="${t}">`}),o.push({offset:c,type:"close",tag:"</a>"})}else if("url"===s.type&&s.original){const t=(0,i.escapeHtml)(s.original);o.push({offset:l,type:"open",tag:`<a href="${t}">`}),o.push({offset:c,type:"close",tag:"</a>"})}}return this.applyMarkers(t,o)}renderArticle(t,e,r){var n;const o=[];(null===(n=null==r?void 0:r.media_info)||void 0===n?void 0:n.original_img_url)&&o.push(`<img src="${(0,i.escapeHtml)(r.media_info.original_img_url)}" alt="Cover image">`);let s=0;for(;s<t.length;){const r=t[s];if("unordered-list-item"===r.type){const r=[];for(;s<t.length&&"unordered-list-item"===t[s].type;)r.push(`<li>${this.renderInlineContent(t[s],e)}</li>`),s++;o.push(`<ul>${r.join("")}</ul>`);continue}const n=this.renderBlock(r,e);n&&o.push(n),s++}return`<article class="x-article">${o.join("")}</article>`}renderBlock(t,e){switch(t.type){case"unstyled":default:return t.text.trim()?`<p>${this.renderInlineContent(t,e)}</p>`:"";case"header-two":return`<h2>${this.renderInlineContent(t,e)}</h2>`;case"header-three":return`<h3>${this.renderInlineContent(t,e)}</h3>`;case"atomic":return this.renderAtomicBlock(t,e)}}renderAtomicBlock(t,e){if(0===t.entityRanges.length)return"";const r=e.find((e=>e.key===String(t.entityRanges[0].key)));if(!r)return"";const n=r.value;switch(n.type){case"MEDIA":{const t=n.data.caption;return t?`<figure><figcaption>${(0,i.escapeHtml)(t)}</figcaption></figure>`:""}case"MARKDOWN":{const t=n.data.markdown||"",e=t.match(/^```(\w*)\n([\s\S]*?)\n?```$/);if(e){const t=e[1],r=e[2];return`<pre><code${t?` class="language-${(0,i.escapeHtml)(t)}" data-lang="${(0,i.escapeHtml)(t)}"`:""}>${(0,i.escapeHtml)(r)}</code></pre>`}return`<pre><code>${(0,i.escapeHtml)(t)}</code></pre>`}default:return""}}renderInlineContent(t,e){var r,n;const o=t.text;if(!o)return"";const s=[];for(const e of t.inlineStyleRanges)"Bold"===e.style&&(s.push({offset:e.offset,type:"open",tag:"<strong>"}),s.push({offset:e.offset+e.length,type:"close",tag:"</strong>"}));for(const r of t.entityRanges){const t=e.find((t=>t.key===String(r.key)));if("LINK"===(null==t?void 0:t.value.type)&&t.value.data.url){const e=(0,i.escapeHtml)(t.value.data.url);s.push({offset:r.offset,type:"open",tag:`<a href="${e}">`}),s.push({offset:r.offset+r.length,type:"close",tag:"</a>"})}}if(null===(r=t.data)||void 0===r?void 0:r.mentions)for(const e of t.data.mentions){const t=`https://x.com/${(0,i.escapeHtml)(e.text)}`;s.push({offset:e.fromIndex,type:"open",tag:`<a href="${t}">`}),s.push({offset:e.toIndex,type:"close",tag:"</a>"})}if(null===(n=t.data)||void 0===n?void 0:n.urls)for(const e of t.data.urls){const t=(0,i.escapeHtml)(e.text);s.push({offset:e.fromIndex,type:"open",tag:`<a href="${t}">`}),s.push({offset:e.toIndex,type:"close",tag:"</a>"})}return this.applyMarkers(o,s)}}e.XOembedExtractor=s},258(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{l(n.next(t))}catch(t){i(t)}}function a(t){try{l(n.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}l((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.YoutubeExtractor=void 0;const o=r(279),i=r(552),s=r(497),a=/[.!?]["'\u2019\u201D)]*\s*$/,l=/\?["'\u2019\u201D)]*\s*$/,c="20.10.38",u={client:{clientName:"ANDROID",clientVersion:c}},d=`com.google.android.youtube/${c} (Linux; U; Android 14)`,h={client:{clientName:"WEB",clientVersion:"2.20240101.00.00"}},m={segments:"ytd-transcript-segment-renderer",timestamp:".segment-timestamp",text:".segment-text"},p={segments:"transcript-segment-view-model",timestamp:".ytwTranscriptSegmentViewModelTimestamp",text:"span.yt-core-attributed-string",chapters:"timeline-chapter-view-model h3"};class f extends o.BaseExtractor{constructor(t,e,r){super(t,e,r),this.inlineJsonCache=new Map,this.videoElement=t.querySelector("video"),this.schemaOrgData=r}canExtract(){return!0}canExtractAsync(){return!0}prefersAsync(){return!0}extract(){return this.buildResult(this.extractTranscriptFromExistingDom())}extractAsync(){return n(this,void 0,void 0,(function*(){const t=this.extractTranscriptFromExistingDom()||(yield this.fetchTranscript())||(yield this.extractTranscriptFromOpenedDom());return this.buildResult(t)}))}getCaptionTracks(t){var e,r;const n=null===(r=null===(e=null==t?void 0:t.captions)||void 0===e?void 0:e.playerCaptionsTracklistRenderer)||void 0===r?void 0:r.captionTracks;return Array.isArray(n)?n:[]}pickCaptionTrack(t){const e=this.options.language;if(e){const r=t.find((t=>t.languageCode===e));if(r)return r}return t.find((t=>"en"===t.languageCode))||t[0]}getTrackDisplayName(t){var e,r,n;return(null===(e=null==t?void 0:t.name)||void 0===e?void 0:e.simpleText)||(null===(n=null===(r=null==t?void 0:t.name)||void 0===r?void 0:r.runs)||void 0===n?void 0:n.map((t=>(null==t?void 0:t.text)||"")).join("").trim())||""}normalizeLanguageLabel(t){return t.replace(/\s*\([^)]*\)\s*/g," ").replace(/\s+/g," ").trim().toLocaleLowerCase()}getTranscriptLanguageCodeFromDom(){var t;const e=this.document.querySelector('ytd-engagement-panel-section-list-renderer[target-id="engagement-panel-searchable-transcript"] #footer yt-sort-filter-sub-menu-renderer yt-dropdown-menu button'),r=null===(t=null==e?void 0:e.textContent)||void 0===t?void 0:t.trim(),n=this.getCaptionTracks(this.parseInlineJson("ytInitialPlayerResponse")),o=this.pickCaptionTrack(n);if(!r)return(null==o?void 0:o.languageCode)||"en";const i=this.normalizeLanguageLabel(r),s=n.find((t=>this.normalizeLanguageLabel(this.getTrackDisplayName(t))===i));return(null==s?void 0:s.languageCode)||(null==o?void 0:o.languageCode)||"en"}getInlineChapters(){const t=this.parseInlineJson("ytInitialData");if(!t)return[];const e=this.extractChaptersFromPlayerBar(t);return e.length>0?e:this.extractChaptersFromEngagementPanels(t)}getTranscriptContainer(){const t=this.document.querySelector('ytd-engagement-panel-section-list-renderer[target-id="engagement-panel-searchable-transcript"] #segments-container');return t||this.document.querySelector("ytm-macro-markers-list-renderer .ytm-macro-markers-list-container")}getTranscriptSelectors(t){return t.querySelectorAll("ytd-transcript-segment-renderer").length>0?m:t.querySelectorAll("transcript-segment-view-model").length>0?p:void 0}buildTranscriptFromContainer(t,e){var r;if(0===t.children.length)return;const n=this.getTranscriptSelectors(t);if(!n)return;const o=[],i=[];if(n.chapters){const e=t.querySelectorAll(n.chapters);for(const t of e){const e=(t.textContent||"").trim();if(!e)continue;const o=t.closest("macro-markers-panel-item-view-model"),s=null===(r=null==o?void 0:o.nextElementSibling)||void 0===r?void 0:r.querySelector(n.timestamp),a=((null==s?void 0:s.textContent)||"").trim(),l=this.parseTimestamp(a);null!==l&&i.push({title:e,start:l})}}const a=t.querySelectorAll(n.segments);for(const t of a){const e=t.querySelector(n.timestamp),r=t.querySelector(n.text);if(!e||!r)continue;const i=(e.textContent||"").trim(),s=(r.textContent||"").trim();if(!s)continue;const a=this.parseTimestamp(i);null!==a&&o.push({start:a,text:s})}if(0===o.length)return;const l=e.length>0?e:i,c=this.groupTranscriptSegments(o),{html:u,text:d}=(0,s.buildTranscript)("youtube",c,l);return{html:u,text:d,languageCode:this.getTranscriptLanguageCodeFromDom()}}extractTranscriptFromExistingDom(){try{const t=this.getTranscriptContainer();if(!t)return;return this.buildTranscriptFromContainer(t,this.getInlineChapters())}catch(t){return void console.error("YoutubeExtractor: failed to extract transcript from existing DOM",t)}}canOpenTranscriptPanel(){var t;return"function"==typeof(null===(t=this.document.defaultView)||void 0===t?void 0:t.MutationObserver)}buildResult(t){const e=this.getVideoData(),r=this.getChannelName(e),n=e.description||"",o=this.formatDescription(n);let i=`<iframe width="560" height="315" src="https://www.youtube.com/embed/${this.getVideoId()}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>${o}`;(null==t?void 0:t.html)&&(i+=t.html);const s={title:e.name||"",author:r,site:"YouTube",image:Array.isArray(e.thumbnailUrl)&&e.thumbnailUrl[0]||"",published:e.uploadDate,description:n.slice(0,200).trim()};return(null==t?void 0:t.text)&&(s.transcript=t.text),(null==t?void 0:t.languageCode)&&(s.language=t.languageCode),{content:i,contentHtml:i,extractedContent:{videoId:this.getVideoId(),author:r},variables:s}}formatDescription(t){return`<p>${t.replace(/\n/g,"<br>")}</p>`}getVideoData(){if(!this.schemaOrgData)return{};return(Array.isArray(this.schemaOrgData)?this.schemaOrgData.find((t=>"VideoObject"===t["@type"])):"VideoObject"===this.schemaOrgData["@type"]?this.schemaOrgData:null)||{}}getChannelName(t){const e=this.getChannelNameFromDom();if(e)return e;const r=this.getChannelNameFromPlayerResponse();return r||((null==t?void 0:t.author)||"")}getChannelNameFromDom(){var t;const e=['ytd-video-owner-renderer #channel-name a[href^="/@"]','#owner-name a[href^="/@"]'];for(const r of e){const e=this.document.querySelector(r),n=null===(t=null==e?void 0:e.textContent)||void 0===t?void 0:t.trim();if(n)return n}return this.getChannelNameFromMicrodata()}getChannelNameFromMicrodata(){var t;const e=this.document.querySelector('[itemprop="author"]');if(!e)return"";const r=e.querySelector('meta[itemprop="name"]');if(null==r?void 0:r.getAttribute("content"))return r.getAttribute("content").trim();const n=e.querySelector('link[itemprop="name"]');if(null==n?void 0:n.getAttribute("content"))return n.getAttribute("content").trim();const o=e.querySelector('[itemprop="name"], a, span');return(null===(t=null==o?void 0:o.textContent)||void 0===t?void 0:t.trim())||""}getChannelNameFromPlayerResponse(){var t,e,r,n;const o=this.parseInlineJson("ytInitialPlayerResponse");if(!o)return"";const i=(null===(t=null==o?void 0:o.videoDetails)||void 0===t?void 0:t.author)||(null===(e=null==o?void 0:o.videoDetails)||void 0===e?void 0:e.ownerChannelName);if(i)return i;return(null===(n=null===(r=null==o?void 0:o.microformat)||void 0===r?void 0:r.playerMicroformatRenderer)||void 0===n?void 0:n.ownerChannelName)||""}parseInlineJson(t){if(this.inlineJsonCache.has(t))return this.inlineJsonCache.get(t);const e=Array.from(this.document.querySelectorAll("script"));for(const r of e){const e=r.textContent||"";if(!e.includes(t))continue;const n=e.indexOf("{",e.indexOf(t));if(-1===n)continue;let o=0;for(let r=n;r<e.length;r++){const i=e[r];if("{"===i)o+=1;else if("}"===i&&(o-=1,0===o)){const o=e.slice(n,r+1);try{const e=JSON.parse(o);return this.inlineJsonCache.set(t,e),e}catch(t){console.error("YoutubeExtractor: failed to parse inline JSON",t);break}}}}return null}fetchTranscript(){return n(this,void 0,void 0,(function*(){try{const t=this.getVideoId();if(!t)return;const[e,r]=yield Promise.all([this.fetchPlayerData(t),this.fetchChapters(t)]);if(!e)return;const n=this.getCaptionTracks(e);if(0===n.length)return;const o=this.pickCaptionTrack(n);if(!(null==o?void 0:o.baseUrl))return;try{if(!new URL(o.baseUrl).hostname.endsWith(".youtube.com"))return}catch(t){return}const i={"User-Agent":"Mozilla/5.0"};this.options.language&&(i["Accept-Language"]=this.options.language);const s=yield fetch(o.baseUrl,{headers:i});if(!s.ok)return;let a;try{a=yield s.text()}catch(t){return void console.error("YoutubeExtractor: response.text() failed:",t)}if(!a)return;return this.parseTranscriptXml(a,o.languageCode||"en",r)}catch(t){return void console.error("YoutubeExtractor: failed to fetch transcript",t)}}))}pollFor(t,e=20){return new Promise((r=>{let n=0;const o=()=>{const i=t();i?r(i):n++<e?setTimeout(o,250):r(null)};o()}))}waitForTranscriptSegments(){return this.pollFor((()=>{const t=this.getTranscriptContainer();return t&&0!==t.children.length&&t.querySelectorAll(p.segments).length>0?t:null}))}waitForTranscriptContainer(){return this.pollFor((()=>{const t=this.getTranscriptContainer();return t&&t.children.length>0?t:null}))}waitForElement(t){return this.pollFor((()=>this.document.querySelector(t)))}isMobileYoutube(){return!!this.document.querySelector("ytm-slim-video-metadata-section-renderer")}extractTranscriptFromOpenedDom(){return n(this,void 0,void 0,(function*(){try{if(!this.canOpenTranscriptPanel())return;if(this.isMobileYoutube())return this.openMobileTranscriptPanel();const t=this.document.querySelector("ytd-video-description-transcript-section-renderer button");if(!t)return;t.click();const e=yield this.waitForTranscriptContainer();if(!e)return;const r=this.getVideoId(),n=r?yield this.fetchChapters(r):this.getInlineChapters();return this.buildTranscriptFromContainer(e,n)}catch(t){return void console.error("YoutubeExtractor: failed to extract transcript from opened DOM",t)}}))}openMobileTranscriptPanel(){return n(this,void 0,void 0,(function*(){try{const t=this.document.querySelector('button[aria-label="Show more"]');t&&t.click();const e=yield this.waitForElement('button[aria-label="View all"]');if(!e)return;e.click();const r=yield this.waitForElement('button[aria-label="Timeline"]');if(!r)return;r.click();const n=yield this.waitForTranscriptSegments();if(!n)return;return this.buildTranscriptFromContainer(n,[])}catch(t){return void console.error("YoutubeExtractor: failed to open mobile transcript panel",t)}}))}fetchPlayerData(t){return n(this,void 0,void 0,(function*(){try{const e={"Content-Type":"application/json","User-Agent":d};this.options.language&&(e["Accept-Language"]=this.options.language);const r=yield fetch("https://www.youtube.com/youtubei/v1/player?prettyPrint=false",{method:"POST",headers:e,body:JSON.stringify({context:u,videoId:t})});if(r.ok){const t=yield r.json();if(this.getCaptionTracks(t).length>0)return t}}catch(t){}const e=this.parseInlineJson("ytInitialPlayerResponse");if(this.getCaptionTracks(e).length>0)return e}))}fetchChapters(t){return n(this,void 0,void 0,(function*(){const e=this.getInlineChapters();if(e.length>0)return e;try{const e={"Content-Type":"application/json"};this.options.language&&(e["Accept-Language"]=this.options.language);const r=yield fetch("https://www.youtube.com/youtubei/v1/next?prettyPrint=false",{method:"POST",headers:e,body:JSON.stringify({context:h,videoId:t})});if(!r.ok)return[];const n=yield r.json(),o=this.extractChaptersFromPlayerBar(n);return o.length>0?o:this.extractChaptersFromEngagementPanels(n)}catch(t){return[]}}))}extractChaptersFromPlayerBar(t){var e,r,n,o,i,s,a,l;const c=[],u=null===(s=null===(i=null===(o=null===(n=null===(r=null===(e=null==t?void 0:t.playerOverlays)||void 0===e?void 0:e.playerOverlayRenderer)||void 0===r?void 0:r.decoratedPlayerBarRenderer)||void 0===n?void 0:n.decoratedPlayerBarRenderer)||void 0===o?void 0:o.playerBar)||void 0===i?void 0:i.multiMarkersPlayerBarRenderer)||void 0===s?void 0:s.markersMap;if(!Array.isArray(u))return c;for(const t of u){const e=null===(a=null==t?void 0:t.value)||void 0===a?void 0:a.chapters;if(Array.isArray(e))for(const t of e){const e=null==t?void 0:t.chapterRenderer;if(!e)continue;const r=(null===(l=e.title)||void 0===l?void 0:l.simpleText)||"",n=e.timeRangeStartMillis;r&&"number"==typeof n&&c.push({title:r,start:n/1e3})}}return c}extractChaptersFromEngagementPanels(t){var e,r,n,o;const i=[],s=null==t?void 0:t.engagementPanels;if(!Array.isArray(s))return i;for(const t of s){const s=null===(e=null==t?void 0:t.engagementPanelSectionListRenderer)||void 0===e?void 0:e.content,a=null===(r=null==s?void 0:s.macroMarkersListRenderer)||void 0===r?void 0:r.contents;if(Array.isArray(a))for(const t of a){const e=null==t?void 0:t.macroMarkersListItemRenderer;if(!e)continue;const r=(null===(n=e.title)||void 0===n?void 0:n.simpleText)||"",s=(null===(o=e.timeDescription)||void 0===o?void 0:o.simpleText)||"";if(!r||!s)continue;const a=this.parseTimestamp(s);null!==a&&i.push({title:r,start:a})}}return i}parseTimestamp(t){const e=t.split(":").map(Number);return e.some(isNaN)?null:3===e.length?3600*e[0]+60*e[1]+e[2]:2===e.length?60*e[0]+e[1]:null}parseTranscriptXml(t,e,r=[]){const n=[],o=/<p\s+t="(\d+)"[^>]*>([\s\S]*?)<\/p>/g;let i;for(;null!==(i=o.exec(t));){const t=parseInt(i[1],10),e=i[2];let r="";const o=/<s[^>]*>([^<]*)<\/s>/g;let s;for(;null!==(s=o.exec(e));)r+=s[1];r||(r=e.replace(/<[^>]+>/g,"")),r=this.decodeEntities(r),r.trim()&&n.push({start:t/1e3,text:r.trim()})}if(0===n.length){const e=/<text\s+start="([^"]*)"[^>]*>([\s\S]*?)<\/text>/g;for(;null!==(i=e.exec(t));){const t=parseFloat(i[1]);let e=this.decodeEntities(i[2].replace(/<[^>]+>/g,""));e.trim()&&n.push({start:t,text:e.trim()})}}if(0===n.length)return;const a=this.groupTranscriptSegments(n),{html:l,text:c}=(0,s.buildTranscript)("youtube",a,r);return{html:l,text:c,languageCode:e}}decodeEntities(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'").replace(/&#x([0-9a-fA-F]+);/g,((t,e)=>String.fromCodePoint(parseInt(e,16)))).replace(/&#(\d+);/g,((t,e)=>String.fromCodePoint(parseInt(e,10))))}getVideoId(){const t=new URL(this.url);return"youtu.be"===t.hostname?t.pathname.slice(1):new URLSearchParams(t.search).get("v")||""}groupTranscriptSegments(t){if(0===t.length)return[];return t.some((t=>/^>>/.test(t.text)))?this.groupBySpeaker(t):this.groupBySentence(t)}groupBySpeaker(t){const e=[];let r=null,n=-1,o="";for(const i of t){const t=/^>>/.test(i.text),s=i.text.replace(/^>>\s*/,"").replace(/^-\s+/,""),l=/,\s*$/.test(o),c=(a.test(o)||!o)&&!l;t&&c?(r&&e.push(r),n=(n+1)%2,r={start:i.start,segments:[{start:i.start,text:s}],speakerChange:!0,speaker:n}):(r||(r={start:i.start,segments:[],speakerChange:!1}),r.segments.push({start:i.start,text:s})),o=s}r&&e.push(r),this.splitAffirmativeTurns(e);const i=[];for(const t of e){const e=void 0===t.speaker?this.groupBySentence(t.segments):this.mergeSentenceGroupsWithinTurn(this.groupBySentence(t.segments));for(let r=0;r<e.length;r++)i.push(Object.assign(Object.assign({},e[r]),{speakerChange:0===r&&t.speakerChange,speaker:t.speaker}))}return i}splitAffirmativeTurns(t){const e=/^(mhm|yeah|yes|yep|right|okay|ok|absolutely|sure|exactly|uh-huh|mm-hmm)[.!,]?\s+/i;for(let r=0;r<t.length;r++){const n=t[r];if(void 0===n.speaker||0===n.segments.length)continue;const o=n.segments[0],s=e.exec(o.text);if(!s)continue;if(/,\s*$/.test(s[0]))continue;const a=o.text.slice(s[0].length).trim(),l=n.segments.slice(1);if((0,i.countWords)(a)+l.reduce(((t,e)=>t+(0,i.countWords)(e.text)),0)<30)continue;const c=s[0].trimEnd(),u=a?[{start:o.start,text:a},...l]:l,d={start:n.start,segments:[{start:o.start,text:c}],speakerChange:n.speakerChange,speaker:n.speaker},h={start:u[0].start,segments:u,speakerChange:!0,speaker:0===n.speaker?1:0};t.splice(r,1,d,h),r++}}mergeSentenceGroupsWithinTurn(t){if(t.length<=1)return t;const e=[];let r=Object.assign({},t[0]),n=!0;for(let o=1;o<t.length;o++){const i=t[o];this.shouldMergeSentenceGroups(r,i,n)?r.text=`${r.text} ${i.text}`:(e.push(r),r=Object.assign({},i),n=!1)}return e.push(r),e}shouldMergeSentenceGroups(t,e,r){const n=(0,i.countWords)(t.text),o=(0,i.countWords)(e.text);return!this.isShortStandaloneUtterance(t.text,n)&&!this.isShortStandaloneUtterance(e.text,o)&&(!(r&&n<8)&&(!l.test(t.text)&&!l.test(e.text)&&(!(n+o>80)&&!(e.start-t.start>45))))}isShortStandaloneUtterance(t,e){const r=null!=e?e:(0,i.countWords)(t);return r>0&&r<=3&&a.test(t)}groupBySentence(t){const e=[];let r="",n=0,o=0;const i=()=>{r.trim()&&(e.push({start:n,text:r.trim(),speakerChange:!1}),r="")};for(const e of t)r&&e.start-o>20&&i(),r||(n=e.start),r+=(r?" ":"")+e.text,o=e.start,a.test(e.text)&&i();return i(),e}}e.YoutubeExtractor=f},608(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.MetadataExtractor=void 0;class r{static extract(t,e,r){var n,o;let i="",s="";try{if(s=(null===(n=t.location)||void 0===n?void 0:n.href)||"",s||(s=this.getMetaContent(r,"property","og:url")||this.getMetaContent(r,"property","twitter:url")||this.getSchemaProperty(e,"url")||this.getSchemaProperty(e,"mainEntityOfPage.url")||this.getSchemaProperty(e,"mainEntity.url")||this.getSchemaProperty(e,"WebSite.url")||(null===(o=t.querySelector('link[rel="canonical"]'))||void 0===o?void 0:o.getAttribute("href"))||""),s)try{i=new URL(s).hostname.replace(/^www\./,"")}catch(t){console.warn("Failed to parse URL:",t)}}catch(e){const r=t.querySelector("base[href]");if(r)try{s=r.getAttribute("href")||"",i=new URL(s).hostname.replace(/^www\./,"")}catch(t){console.warn("Failed to parse base URL:",t)}}return{title:this.getTitle(t,e,r),description:this.getDescription(t,e,r),domain:i,favicon:this.getFavicon(t,s,r),image:this.getImage(t,e,r),language:this.getLanguage(t,e,r),published:this.getPublished(t,e,r),author:this.getAuthor(t,e,r),site:this.getSite(t,e,r),schemaOrgData:e,wordCount:0,parseTime:0}}static getAuthor(t,e,r){var n,o;let i;if(i=this.getMetaContent(r,"name","sailthru.author")||this.getMetaContent(r,"property","author")||this.getMetaContent(r,"name","author")||this.getMetaContent(r,"name","byl")||this.getMetaContent(r,"name","authorList"),i)return i;let s=this.getMetaContents(r,"name","citation_author");if(0===s.length&&(s=this.getMetaContents(r,"property","dc.creator")),s.length>0)return i=s.map((t=>{if(!t.includes(","))return t.trim();const e=/(.*),\s(.*)/.exec(t);return e&&3===e.length?`${e[2]} ${e[1]}`:t.trim()})).join(", "),i;let a=this.getSchemaProperty(e,"author.name")||this.getSchemaProperty(e,"author.[].name");if(a){const t=a.split(",").map((t=>t.trim().replace(/,$/,"").trim())).filter(Boolean);if(t.length>0){let e=[...new Set(t)];return e.length>10&&(e=e.slice(0,10)),e.join(", ")}}const l=[],c=[{selector:'[itemprop="author"]'},{selector:".author",maxMatches:3},{selector:'[href*="/author/"]',maxMatches:3},{selector:".authors a",maxMatches:3}];for(const{selector:e,maxMatches:r}of c){const n=t.querySelectorAll(e);r&&n.length>r||n.forEach((t=>{var e;(e=t.textContent)&&e.split(",").forEach((t=>{const e=t.trim().replace(/,$/,"").trim(),r=e.toLowerCase();e&&"author"!==r&&"authors"!==r&&l.push(e)}))}))}if(l.length>0){let t=[...new Set(l.map((t=>t.trim())).filter(Boolean))];if(t.length>0)return t.length>10&&(t=t.slice(0,10)),t.join(", ")}const u=t.querySelector("h1");if(u){let t=u.nextElementSibling;for(let e=0;e<3&&t;e++){const e=(null===(n=t.textContent)||void 0===n?void 0:n.trim())||"";if(this.parseDateText(e)){const e=t.querySelectorAll("a");for(const t of e){const e=((null===(o=t.textContent)||void 0===o?void 0:o.trim())||"").replace(/\u00a0/g," ");if(e.length>0&&e.length<100&&!this.parseDateText(e))return e}}t=t.nextElementSibling}let e=u;for(let t=0;t<3&&e;t++){let t=e.previousElementSibling;for(let e=0;e<3&&t;e++){const e=this.extractByline(t);if(e)return e;t=t.previousElementSibling}t=e.nextElementSibling;for(let e=0;e<3&&t;e++){const e=this.extractByline(t);if(e)return e;t=t.nextElementSibling}e=e.parentElement}}return this.getSiteName(e,r)}static extractByline(t){var e;const r=[t,...t.querySelectorAll("p, span, address")];for(const t of r){const r=((null===(e=t.textContent)||void 0===e?void 0:e.trim())||"").replace(/\u00a0/g," ");if(r.length>0&&r.length<50){const t=r.match(/^By\s+([A-Z].+)$/i);if(t)return t[1].trim()}}return null}static getSiteName(t,e){return this.getSchemaProperty(t,"publisher.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(t,"WebSite.name")||this.getSchemaProperty(t,"sourceOrganization.name")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(t,"copyrightHolder.name")||this.getSchemaProperty(t,"isPartOf.name")||this.getMetaContent(e,"name","application-name")||""}static getSite(t,e,r){return this.getSiteName(e,r)||this.getAuthor(t,e,r)||""}static getTitle(t,e,r){var n,o;const i=this.getMetaContent(r,"property","og:title")||this.getMetaContent(r,"name","twitter:title")||this.getSchemaProperty(e,"headline")||this.getMetaContent(r,"name","title")||this.getMetaContent(r,"name","sailthru.title")||(null===(o=null===(n=t.querySelector("title"))||void 0===n?void 0:n.textContent)||void 0===o?void 0:o.trim())||"";return this.cleanTitle(i,this.getSite(t,e,r))}static cleanTitle(t,e){if(!t||!e)return t;const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),n=[`\\s*[\\|\\-\u2013\u2014]\\s*${r}\\s*$`,`^\\s*${r}\\s*[\\|\\-\u2013\u2014]\\s*`];for(const e of n){const r=new RegExp(e,"i");if(r.test(t)){t=t.replace(r,"");break}}return t.trim()}static getDescription(t,e,r){return this.getMetaContent(r,"name","description")||this.getMetaContent(r,"property","description")||this.getMetaContent(r,"property","og:description")||this.getSchemaProperty(e,"description")||this.getMetaContent(r,"name","twitter:description")||this.getMetaContent(r,"name","sailthru.description")||""}static getImage(t,e,r){return this.getMetaContent(r,"property","og:image")||this.getMetaContent(r,"name","twitter:image")||this.getSchemaProperty(e,"image.url")||this.getMetaContent(r,"name","sailthru.image.full")||""}static getLanguage(t,e,r){var n,o,i,s;const a=null===(o=null===(n=t.documentElement)||void 0===n?void 0:n.getAttribute("lang"))||void 0===o?void 0:o.trim();if(a)return this.normalizeLangCode(a);const l=this.getMetaContent(r,"name","content-language")||this.getMetaContent(r,"property","og:locale");if(l)return this.normalizeLangCode(l);const c=null===(s=null===(i=t.querySelector('meta[http-equiv="Content-Language" i]'))||void 0===i?void 0:i.getAttribute("content"))||void 0===s?void 0:s.trim();if(c)return this.normalizeLangCode(c);const u=this.getSchemaProperty(e,"inLanguage");return u?this.normalizeLangCode(u):""}static normalizeLangCode(t){return t.replace(/_/g,"-")}static getFavicon(t,e,r){var n,o;const i=this.getMetaContent(r,"property","og:image:favicon");if(i)return i;const s=null===(n=t.querySelector("link[rel='icon']"))||void 0===n?void 0:n.getAttribute("href");if(s)return s;const a=null===(o=t.querySelector("link[rel='shortcut icon']"))||void 0===o?void 0:o.getAttribute("href");if(a)return a;if(e&&/^https?:\/\//.test(e))try{return new URL("/favicon.ico",e).href}catch(t){}return""}static getPublished(t,e,r){var n,o,i;const s=this.getSchemaProperty(e,"datePublished")||this.getMetaContent(r,"name","publishDate")||this.getMetaContent(r,"property","article:published_time")||(null===(o=null===(n=t.querySelector('abbr[itemprop="datePublished"]'))||void 0===n?void 0:n.title)||void 0===o?void 0:o.trim())||this.getTimeElement(t)||this.getMetaContent(r,"name","sailthru.date");if(s)return s;const a=t.querySelector("h1");if(a){let t=a.nextElementSibling;for(let e=0;e<3&&t;e++){const e=this.parseDateText((null===(i=t.textContent)||void 0===i?void 0:i.trim())||"");if(e)return e;t=t.nextElementSibling}}return""}static getMetaContent(t,e,r){var n;return null!==(n=this.getMetaContents(t,e,r)[0])&&void 0!==n?n:""}static getMetaContents(t,e,r){return t.filter((t=>{const n="name"===e?t.name:t.property;return(null==n?void 0:n.toLowerCase())===r.toLowerCase()})).map((t=>{var e,r;return null!==(r=null===(e=t.content)||void 0===e?void 0:e.trim())&&void 0!==r?r:""}))}static getTimeElement(t){var e,r,n,o;const i=Array.from(t.querySelectorAll("time"))[0];return i&&null!==(o=null!==(r=null===(e=i.getAttribute("datetime"))||void 0===e?void 0:e.trim())&&void 0!==r?r:null===(n=i.textContent)||void 0===n?void 0:n.trim())&&void 0!==o?o:""}static parseDateText(t){let e=t.match(/\b(\d{1,2})\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s+(\d{4})\b/i);if(e){const t=e[1].padStart(2,"0"),r=this.MONTH_MAP[e[2].toLowerCase()];return`${e[3]}-${r}-${t}T00:00:00+00:00`}if(e=t.match(/\b(January|February|March|April|May|June|July|August|September|October|November|December)\s+(\d{1,2}),?\s+(\d{4})\b/i),e){const t=this.MONTH_MAP[e[1].toLowerCase()],r=e[2].padStart(2,"0");return`${e[3]}-${t}-${r}T00:00:00+00:00`}return""}static getSchemaProperty(t,e,r=""){if(!t)return r;const n=(t,e,r,o=!0)=>{if("string"==typeof t)return 0===e.length?[t]:[];if(!t||"object"!=typeof t)return[];if(Array.isArray(t)){const i=e[0];if(/^\[\d+\]$/.test(i)){const s=parseInt(i.slice(1,-1));return t[s]?n(t[s],e.slice(1),r,o):[]}return 0===e.length&&t.every((t=>"string"==typeof t||"number"==typeof t))?t.map(String):t.flatMap((t=>n(t,e,r,o)))}const[i,...s]=e;if(!i)return"string"==typeof t?[t]:"object"==typeof t&&t.name?[t.name]:[];if(t.hasOwnProperty(i))return n(t[i],s,r?`${r}.${i}`:i,!0);if(!o){const o=[];for(const i in t)if("object"==typeof t[i]){const s=n(t[i],e,r?`${r}.${i}`:i,!1);o.push(...s)}if(o.length>0)return o}return[]};try{let o=n(t,e.split("."),"",!0);0===o.length&&(o=n(t,e.split("."),"",!1));return o.length>0?o.filter(Boolean).join(", "):r}catch(t){return console.error(`Error in getSchemaProperty for ${e}:`,t),r}}}e.MetadataExtractor=r,r.MONTH_MAP={january:"01",february:"02",march:"03",april:"04",may:"05",june:"06",july:"07",august:"08",september:"09",october:"10",november:"11",december:"12"}},968(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.ContentScorer=void 0;const n=r(640),o=r(552),i=r(639),s=["admonition","article","content","entry","image","img","font","figure","figcaption","pre","main","post","story","table"],a=["advertisement","all rights reserved","banner","cookie","comments","copyright","follow me","follow us","footer","header","homepage","login","menu","more articles","more like this","most read","nav","navigation","newsletter","popular","privacy","recommended","register","related","responses","share","sidebar","sign in","sign up","signup","social","sponsored","subscribe","terms","trending"],l=/\b(linkedin\.com\/(in|company)\/|twitter\.com\/(?!intent\b)\w|x\.com\/(?!intent\b)\w|facebook\.com\/(?!share\b)\w|instagram\.com\/\w|threads\.net\/\w|mastodon\.\w)/i,c=/(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]*\s+\d{1,2}/i,u=/\bBy\s+[A-Z]/,d=a.map((t=>new RegExp(`\\b${t.replace(/\s+/g,"\\s+")}\\b`))),h=new RegExp(a.map((t=>t.replace(/\s+/g,"\\s+"))).join("|"),"i"),m=/\b(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]*\s+\d{1,2},?\s+\d{4}\b/i,p=/\b(?:by|written by|author:)\s+[A-Za-z\s]+\b/i,f=["advert","ad-","ads","banner","cookie","copyright","footer","header","homepage","menu","nav","newsletter","popular","privacy","recommended","related","rights","share","sidebar","social","sponsored","subscribe","terms","trending","widget"];class g{constructor(t,e=!1){this.doc=t,this.debug=e}static scoreElement(t){let e=0;const r=t.textContent||"",s=(0,o.countWords)(r);e+=s;e+=10*t.getElementsByTagName("p").length;e+=r.split(/,/).length-1;e-=3*(t.getElementsByTagName("img").length/(s||1));try{const r=t.getAttribute("style")||"",n=t.getAttribute("align")||"";(r.includes("float: right")||r.includes("text-align: right")||"right"===n)&&(e+=5)}catch(t){}m.test(r)&&(e+=10);p.test(r)&&(e+=10);const a=(0,i.getClassName)(t).toLowerCase();(a.includes("content")||a.includes("article")||a.includes("post"))&&(e+=15);t.querySelector(n.FOOTNOTE_INLINE_REFERENCES)&&(e+=10);t.querySelector(n.FOOTNOTE_LIST_SELECTORS)&&(e+=10);if(e-=5*t.getElementsByTagName("table").length,"td"===t.tagName.toLowerCase()){const r=t.closest("table");if(r){const n=parseInt(r.getAttribute("width")||"0"),o=r.getAttribute("align")||"",s=(0,i.getClassName)(r).toLowerCase();if(n>400||"center"===o||s.includes("content")||s.includes("article")){const n=Array.from(r.getElementsByTagName("td")),o=n.indexOf(t);o>0&&o<n.length-1&&(e+=10)}}}const l=t.getElementsByTagName("a");let c=0;for(let t=0;t<l.length;t++)c+=(l[t].textContent||"").length;const u=r.length||1;return e*=1-Math.min(c/u,.5),e}static findBestElement(t,e=50){let r=null,n=0;return t.forEach((t=>{const e=this.scoreElement(t);e>n&&(n=e,r=t)})),n>e?r:null}static scoreAndRemove(t,e=!1,r,i){const s=Date.now(),a=new Map;Array.from(t.querySelectorAll(n.BLOCK_ELEMENTS_SELECTOR)).forEach((t=>{if(a.has(t))return;if(i&&t.contains(i))return;if(t.closest("pre"))return;if(g.isLikelyContent(t))return;const e=g.scoreNonContentBlock(t);e<0&&a.set(t,e)})),a.forEach(((t,n)=>{e&&r&&r.push({step:"scoreAndRemove",reason:`score: ${t}`,text:(0,o.textPreview)(n)}),n.remove()}));const l=Date.now();e&&console.log("Defuddle","Removed non-content blocks:",{count:a.size,processingTime:`${(l-s).toFixed(2)}ms`})}static isLikelyContent(t){const e=t.getAttribute("role");if(e&&["article","main","contentinfo"].includes(e))return!0;const r=(0,i.getClassName)(t).toLowerCase(),n=t.id.toLowerCase();for(const t of s)if(r.includes(t)||n.includes(t))return!0;if(t.querySelector("pre, table"))return!0;const a=t.textContent||"",c=(0,o.countWords)(a);if(c<1e3){const e=t.querySelectorAll("h1, h2, h3, h4, h5, h6");let r=!1;for(let t=0;t<e.length;t++){const n=(e[t].textContent||"").toLowerCase().trim();if(h.test(n)){r=!0;break}}if(r){if(c<200)return!1;if(t.getElementsByTagName("a").length/(c||1)>.2)return!1}}if(g.isCardGrid(t,c))return!1;if(c<80){const e=t.getElementsByTagName("a");for(let t=0;t<e.length;t++){const r=(e[t].getAttribute("href")||"").toLowerCase();if(l.test(r))return!1}}const u=t.getElementsByTagName("p").length+t.getElementsByTagName("li").length;if(c>50&&u>1)return!0;if(c>100)return!0;if(c>30&&u>0)return!0;if(c>=10&&/[.?!]/.test(a)){if(t.getElementsByTagName("a").length/c<.1)return!0}return!1}static scoreNonContentBlock(t){try{if(t.matches(n.FOOTNOTE_LIST_SELECTORS)||t.querySelector(n.FOOTNOTE_LIST_SELECTORS)||t.closest(n.FOOTNOTE_LIST_SELECTORS))return 0}catch(t){}let e=0;const r=t.textContent||"",s=(0,o.countWords)(r);if(s<3)return 0;e+=r.split(/,/).length-1;const a=r.toLowerCase();let h=0;for(const t of d)t.test(a)&&h++;e-=10*h;const m=t.getElementsByTagName("a"),p=m.length;if(p/(s||1)>.5&&(e-=15),p>1&&s<80){let t=0;for(let e=0;e<m.length;e++)t+=(m[e].textContent||"").length;const n=r.length;n>0&&t/n>.8&&(e-=15)}const v=t.getElementsByTagName("ul").length+t.getElementsByTagName("ol").length;if(v>0&&p>3*v&&(e-=10),s<80){const r=t.getElementsByTagName("a");for(let t=0;t<r.length;t++){const n=(r[t].getAttribute("href")||"").toLowerCase();if(l.test(n)){e-=15;break}}}s<15&&u.test(r)&&c.test(r)&&(e-=10),g.isCardGrid(t,s)&&(e-=15);const y=(0,i.getClassName)(t).toLowerCase(),b=t.id.toLowerCase();for(const t of f)(y.includes(t)||b.includes(t))&&(e-=8);return e}static isCardGrid(t,e){if(e<3||e>=500)return!1;const r=t.querySelectorAll("h2, h3, h4");if(r.length<3)return!1;if(t.querySelectorAll("img").length<2)return!1;let n=0;for(let t=0;t<r.length;t++)n+=(0,o.countWords)(r[t].textContent||"");return(e-n)/r.length<20}}e.ContentScorer=g},840(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.standardizeContent=function(t,e,r,o=!1){u=o,function(t){const e=t=>{if((0,l.isElement)(t)){const e=t.tagName.toLowerCase();if("pre"===e||"code"===e)return}if((0,l.isTextNode)(t)){const e=t.textContent||"",r=e.replace(/\xA0/g," ");r!==e&&(t.textContent=r)}t.hasChildNodes()&&Array.from(t.childNodes).forEach(e)};e(t)}(t),function(t){var e;let r=0;const n=t.ownerDocument.createTreeWalker(t,128),o=[];for(;n.nextNode();)o.push(n.currentNode);for(const t of o)null===(e=t.parentNode)||void 0===e||e.removeChild(t),r++;(0,l.logDebug)(u,"Removed HTML comments:",r)}(t),function(t,e,r){const o=t=>t.replace(/\u00A0/g," ").replace(/\s+/g," ").trim().toLowerCase(),i=t.getElementsByTagName("h1");Array.from(i).forEach((t=>{var e;const o=r.createElement("h2");(0,c.transferContent)(t,o),Array.from(t.attributes).forEach((t=>{n.ALLOWED_ATTRIBUTES.has(t.name)&&o.setAttribute(t.name,t.value)})),null===(e=t.parentNode)||void 0===e||e.replaceChild(o,t)}));const s=t.getElementsByTagName("h2");if(s.length>0){const t=s[0],r=o(t.textContent||""),n=o(e);n&&n===r&&t.remove()}}(t,e.title,r),function(t,e){var r;const n=Array.from(t.querySelectorAll("code"));for(const t of n){if(t.closest("pre"))continue;const n=t.getAttribute("style")||"";if(!/white-space\s*:\s*pre/.test(n))continue;const o=e.createElement("pre");null===(r=t.parentNode)||void 0===r||r.insertBefore(o,t),o.appendChild(t)}}(t,r),function(t,e){let r=0;d.forEach((n=>{let o;try{o=t.querySelectorAll(n.selector)}catch(t){return}o.forEach((t=>{if(n.transform){const o=n.transform(t,e);t.replaceWith(o),r++}}))}));Array.from(t.querySelectorAll("table.ltx_equation, table.ltx_eqn_table, table.ltx_equationgroup")).forEach((t=>{const n=t.querySelectorAll("math");if(0===n.length)return;const o=e.createDocumentFragment();n.forEach((r=>{var n;const i=r.getAttribute("alttext"),s=r.querySelector('annotation[encoding="application/x-tex"]'),a=i||(null===(n=null==s?void 0:s.textContent)||void 0===n?void 0:n.trim())||"";if(!a)return;const l="block"===r.getAttribute("display")||t.classList.contains("ltx_equation")||t.classList.contains("ltx_equationgroup"),c=e.createElement("math");c.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),c.setAttribute("display",l?"block":"inline"),c.setAttribute("data-latex",a),c.textContent=a,o.appendChild(c)})),o.childNodes.length>0&&(t.replaceWith(o),r++)}));Array.from(t.querySelectorAll("span.ltx_note_outer")).forEach((t=>{t.remove(),r++}));Array.from(t.querySelectorAll("a.ltx_ref")).forEach((t=>{if(t.querySelector("span.ltx_ref_tag, span.ltx_text.ltx_ref_tag")){const n=e.createTextNode(t.textContent||"");t.replaceWith(n),r++}}));Array.from(t.querySelectorAll("table")).forEach((t=>{if(!t.parentNode)return;const n=Array.from(t.querySelectorAll("td, th")).filter((e=>(0,c.isDirectTableChild)(e,t)));if(n.some((t=>"TH"===t.tagName)))return;const o=Array.from(t.querySelectorAll("tr")).filter((e=>(0,c.isDirectTableChild)(e,t)));if(0===o.length)return;if(!o.every((t=>n.filter((e=>e.parentNode===t)).length<=1)))return;const i=e.createDocumentFragment();n.forEach((t=>{for(;t.firstChild;)i.appendChild(t.firstChild)})),t.replaceWith(i),r++}));t.querySelectorAll("lite-youtube").forEach((t=>{const n=t.getAttribute("videoid");if(!n)return;const o=e.createElement("iframe");o.width="560",o.height="315",o.src=`https://www.youtube.com/embed/${n}`,o.title=t.getAttribute("videotitle")||"YouTube video player",o.frameBorder="0",o.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",o.setAttribute("allowfullscreen",""),t.replaceWith(o),r++})),(0,l.logDebug)(u,"Converted embedded elements:",r),function(t){var e;const r=t=>{let e=null;for(const r of t.children){if("code"!==r.tagName.toLowerCase())return null;if(e)return null;e=r}return e},n=t=>{var e;const r=(t.getAttribute("data-lang")||"").toLowerCase();if(r)return r;const n=(t.getAttribute("class")||"").match(/(?:^|\s)language-([a-z0-9_+-]+)(?:\s|$)/i);return(null===(e=null==n?void 0:n[1])||void 0===e?void 0:e.toLowerCase())||""},o=t.querySelectorAll('pre[data-verso-code="true"]'),i=new Set;for(const t of o){const e=t.parentElement;e&&i.add(e)}for(const t of i){const o=Array.from(t.childNodes);for(let t=0;t<o.length;t++){const i=o[t];if(!(0,l.isElement)(i)||"pre"!==i.tagName.toLowerCase())continue;if("true"!==i.getAttribute("data-verso-code"))continue;const s=r(i);if(!s)continue;const a=n(s);if("lean"!==a&&"lean4"!==a)continue;const c=[{pre:i,code:s}],u=[];let d=t+1;for(;d<o.length;){const t=o[d];if((0,l.isTextNode)(t)&&!(t.textContent||"").trim()){u.push(t),d++;continue}if(!(0,l.isElement)(t)||"pre"!==t.tagName.toLowerCase())break;const e=t;if("true"!==e.getAttribute("data-verso-code"))break;const i=r(e);if(!i||n(i)!==a)break;c.push({pre:e,code:i}),d++}if(c.length<=1)continue;const h=c.map((({code:t})=>(t.textContent||"").replace(/\r?\n$/,""))).join("\n").replace(/\n{3,}/g,"\n\n").replace(/^\n+|\n+$/g,"");s.textContent=h;for(let t=1;t<c.length;t++)c[t].pre.remove();for(const t of u)null===(e=t.parentNode)||void 0===e||e.removeChild(t);t=d-1}}}(t)}(t,r),o?(m(t,o),h(t),f(t),(0,l.logDebug)(u,"Debug mode: Skipping div flattening to preserve structure")):(v(t,r),m(t,o),function(t){const e=Array.from(t.querySelectorAll("span")).reverse();let r=0;for(const t of e){if(!t.parentNode)continue;if(t.attributes.length>0)continue;const e=t.parentNode;if(e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);t.remove(),r++}}r>0&&t.normalize();(0,l.logDebug)(u,"Unwrapped bare spans:",r)}(t),Array.from(t.querySelectorAll("code a")).forEach(p),Array.from(t.querySelectorAll('a[href^="javascript:"]')).forEach(p),Array.from(t.querySelectorAll('a[href^="#"]')).forEach((t=>{t.querySelector("h1, h2, h3, h4, h5, h6")&&p(t)})),(0,s.removeHeadingAnchors)(t),t.querySelectorAll("object, embed, applet").forEach((t=>t.remove())),function(t){let e=0;const r=t=>{var e;if(n.ALLOWED_EMPTY_ELEMENTS.has(t.tagName.toLowerCase()))return!1;if("DIV"===t.tagName){const r=t.children;if(r.length>0){let t=!0;for(let n=0;n<r.length;n++){const o=r[n];if("SPAN"!==o.tagName){t=!1;break}const i=(null===(e=o.textContent)||void 0===e?void 0:e.trim())||"";if(","!==i&&""!==i&&" "!==i){t=!1;break}}if(t)return!0}}const r=t.textContent||"";if(r.trim().length>0||r.includes("\xa0"))return!1;if(!t.hasChildNodes())return!0;const o=t.childNodes;for(let t=0;t<o.length;t++){const e=o[t];if(!(0,l.isTextNode)(e))return!1;const r=e.textContent||"";if(r.trim().length>0||r.includes("\xa0"))return!1}return!0},o=Array.from(t.querySelectorAll("*")).reverse();for(const t of o)t.parentNode&&r(t)&&(t.remove(),e++);(0,l.logDebug)(u,"Removed empty elements:",e)}(t),h(t),function(t){for(;;){let e=t.firstChild;for(;e&&(0,l.isTextNode)(e)&&!(e.textContent||"").trim();)e=e.nextSibling;if(!e||!(0,l.isElement)(e)||"hr"!==e.tagName.toLowerCase())break;e.remove()}for(;;){let e=t.lastChild;for(;e&&(0,l.isTextNode)(e)&&!(e.textContent||"").trim();)e=e.previousSibling;if(!e||!(0,l.isElement)(e)||"hr"!==e.tagName.toLowerCase())break;e.remove()}}(t),v(t,r),f(t),function(t,e){let r=0;const o=Date.now(),i=t=>{var e;if((0,l.isElement)(t)){const e=t.tagName.toLowerCase();if("pre"===e||"code"===e)return}if(Array.from(t.childNodes).forEach(i),(0,l.isTextNode)(t)){const n=t.textContent||"";if(!n||/^[\u200C\u200B\u200D\u200E\u200F\uFEFF]*$/.test(n))null===(e=t.parentNode)||void 0===e||e.removeChild(t),r++;else{const e=n.replace(/[\n\r]+/g," ").replace(/\t+/g," ").replace(/ {2,}/g," ").replace(/^[ ]+$/," ").replace(/\s+([,.!?:;])/g,"$1").replace(/[\u200B\u200D\u200E\u200F\uFEFF]+/g,"").replace(/(?:\xA0){2,}/g,"\xa0");e!==n&&(t.textContent=e,r+=n.length-e.length)}}},s=t=>{var o;if(!(0,l.isElement)(t))return;const i=t.tagName.toLowerCase();if("pre"===i||"code"===i)return;Array.from(t.childNodes).filter(l.isElement).forEach(s),t.normalize();const a="block"===(null===(o=(0,l.getComputedStyle)(t))||void 0===o?void 0:o.display),c=a?/^[\n\r\t \u200C\u200B\u200D\u200E\u200F\uFEFF\xA0]*$/:/^[\n\r\t\u200C\u200B\u200D\u200E\u200F\uFEFF]*$/;for(;t.firstChild&&(0,l.isTextNode)(t.firstChild)&&(t.firstChild.textContent||"").match(c);)t.removeChild(t.firstChild),r++;for(;t.lastChild&&(0,l.isTextNode)(t.lastChild)&&(t.lastChild.textContent||"").match(c);)t.removeChild(t.lastChild),r++;if(!a&&n.INLINE_ELEMENTS.has(i)&&t.parentNode&&(r+=g(t,e,"leading"),r+=g(t,e,"trailing")),!a){const r=Array.from(t.childNodes);for(let n=0;n<r.length-1;n++){const o=r[n],i=r[n+1];if((0,l.isElement)(o)||(0,l.isElement)(i)){const r=i.textContent||"",n=o.textContent||"",s=r.match(/^[,.!?:;)\]]/),a=n.match(/[,.!?:;(\[]\s*$/),c=(0,l.isTextNode)(o)&&(o.textContent||"").endsWith(" ")||(0,l.isTextNode)(i)&&(i.textContent||"").startsWith(" ");if(!s&&!a&&!c){const r=e.createTextNode(" ");t.insertBefore(r,i)}}}}};i(t),s(t);const a=Date.now();(0,l.logDebug)(u,"Removed empty lines:",{charactersRemoved:r,processingTime:`${(a-o).toFixed(2)}ms`})}(t,r))};const n=r(640),o=r(0),i=r(754),s=r(864),a=r(649),l=r(552),c=r(639);let u=!1;const d=[...o.mathRules,...i.codeBlockRules,...s.headingRules,...a.imageRules,{selector:'div[data-testid^="paragraph"], div[role="paragraph"]',element:"p",transform:(t,e)=>{const r=e.createElement("p");return(0,c.transferContent)(t,r),Array.from(t.attributes).forEach((t=>{n.ALLOWED_ATTRIBUTES.has(t.name)&&r.setAttribute(t.name,t.value)})),r}},{selector:'div[role="list"]',element:"ul",transform:(t,e)=>{var r;const n=t.querySelector('div[role="listitem"] .label'),o=((null===(r=null==n?void 0:n.textContent)||void 0===r?void 0:r.trim())||"").match(/^\d+\)/),i=e.createElement(o?"ol":"ul");return t.querySelectorAll('div[role="listitem"]').forEach((t=>{const r=e.createElement("li"),n=t.querySelector(".content");if(n){n.querySelectorAll('div[role="paragraph"]').forEach((t=>{const r=e.createElement("p");(0,c.transferContent)(t,r),t.replaceWith(r)}));n.querySelectorAll('div[role="list"]').forEach((t=>{var r;const n=t.querySelector('div[role="listitem"] .label'),o=((null===(r=null==n?void 0:n.textContent)||void 0===r?void 0:r.trim())||"").match(/^\d+\)/),i=e.createElement(o?"ol":"ul");t.querySelectorAll('div[role="listitem"]').forEach((t=>{const r=e.createElement("li"),n=t.querySelector(".content");if(n){n.querySelectorAll('div[role="paragraph"]').forEach((t=>{const r=e.createElement("p");(0,c.transferContent)(t,r),t.replaceWith(r)})),(0,c.transferContent)(n,r)}i.appendChild(r)})),t.replaceWith(i)})),(0,c.transferContent)(n,r)}i.appendChild(r)})),i}},{selector:'div[role="listitem"]',element:"li",transform:(t,e)=>{const r=t.querySelector(".content");if(!r)return t;return r.querySelectorAll('div[role="paragraph"]').forEach((t=>{const r=e.createElement("p");(0,c.transferContent)(t,r),t.replaceWith(r)})),r}}];function h(t){let e=0;const r=e=>{let n="",o=e.nextSibling;for(;o;)((0,l.isTextNode)(o)||(0,l.isElement)(o))&&(n+=o.textContent||""),o=o.nextSibling;if(n.trim())return!0;const i=e.parentElement;return!(!i||i===t)&&r(i)},n=Array.from(t.querySelectorAll("h1, h2, h3, h4, h5, h6")).reverse();for(const t of n){if(r(t))break;t.remove(),e++}e>0&&(0,l.logDebug)(u,"Removed trailing headings:",e)}function m(t,e){let r=0;const o=t=>{if("svg"===t.tagName.toLowerCase()||"http://www.w3.org/2000/svg"===t.namespaceURI)return;const o=Array.from(t.attributes),i=t.tagName.toLowerCase();o.forEach((o=>{const s=o.name.toLowerCase(),a=o.value;"id"===s&&(a.startsWith("fnref:")||a.startsWith("fn:")||"footnotes"===a)||"class"===s&&("code"===i&&a.startsWith("language-")||"footnote-backref"===a||/^callout(?:-|$)/.test(a))||(e?n.ALLOWED_ATTRIBUTES.has(s)||n.ALLOWED_ATTRIBUTES_DEBUG.has(s)||s.startsWith("data-")||(t.removeAttribute(o.name),r++):n.ALLOWED_ATTRIBUTES.has(s)||(t.removeAttribute(o.name),r++))}))};o(t),t.querySelectorAll("*").forEach(o),(0,l.logDebug)(u,"Stripped attributes:",r)}function p(t){for(var e;t.firstChild;)null===(e=t.parentNode)||void 0===e||e.insertBefore(t.firstChild,t);t.remove()}function f(t){let e=0;const r=Date.now(),n=Array.from(t.getElementsByTagName("br"));let o=[];const i=()=>{if(o.length>2)for(let t=2;t<o.length;t++)o[t].remove(),e++;o=[]};n.forEach((t=>{var e;let r=!1;if(o.length>0){const n=o[o.length-1];let i=t.previousSibling;for(;i&&(0,l.isTextNode)(i)&&!(null===(e=i.textContent)||void 0===e?void 0:e.trim());)i=i.previousSibling;i===n&&(r=!0)}r?o.push(t):(i(),o=[t])})),i();const s=Date.now();(0,l.logDebug)(u,"Standardized br elements:",{removed:e,processingTime:`${(s-r).toFixed(2)}ms`})}function g(t,e,r){const n="leading"===r?t.firstChild:t.lastChild;if(!n||!(0,l.isTextNode)(n))return 0;const o=n.textContent||"",i="leading"===r?o.replace(/^\s+/,""):o.replace(/\s+$/,"");if(i===o||!t.parentNode)return 0;n.textContent=i;const s="leading"===r?t.previousSibling:t.nextSibling;if(!(s&&(0,l.isTextNode)(s)&&("leading"===r?(s.textContent||"").endsWith(" "):(s.textContent||"").startsWith(" ")))){const n="leading"===r?t:t.nextSibling;t.parentNode.insertBefore(e.createTextNode(" "),n)}return 1}function v(t,e){let r=0;const o=Date.now();let i=!0;function s(t){var e;for(const r of t.childNodes){if((0,l.isTextNode)(r)&&(null===(e=r.textContent)||void 0===e?void 0:e.trim()))return!0;if((0,l.isElement)(r)&&n.INLINE_ELEMENTS.has(r.nodeName.toLowerCase()))return!0}return!1}const a=t=>{var e;const r=t.tagName.toLowerCase();if(n.PRESERVE_ELEMENTS.has(r))return!0;if(t.getAttribute("data-callout")||(null===(e=t.closest)||void 0===e?void 0:e.call(t,"[data-callout]")))return!0;const o=t.getAttribute("role");if(o&&["article","main","navigation","banner","contentinfo"].includes(o))return!0;const i=(0,c.getClassName)(t);if(i&&i.toLowerCase().match(/(?:article|main|content|footnote|reference|bibliography)/))return!0;return!!Array.from(t.children).some((t=>n.PRESERVE_ELEMENTS.has(t.tagName.toLowerCase())||"article"===t.getAttribute("role")||!!(0,c.getClassName)(t)&&(0,c.getClassName)(t).toLowerCase().match(/(?:article|main|content|footnote|reference|bibliography)/)))},d=t=>{var e;if(s(t))return!1;if(!(null===(e=t.textContent)||void 0===e?void 0:e.trim()))return!0;const r=Array.from(t.children);if(0===r.length)return!0;if(r.every((t=>n.BLOCK_LEVEL_ELEMENTS.has(t.tagName.toLowerCase()))))return!0;const o=(0,c.getClassName)(t).toLowerCase();if(/(?:wrapper|container|layout|row|col|grid|flex|outer|inner|content-area)/i.test(o))return!0;const i=Array.from(t.childNodes).filter((t=>{var e;return(0,l.isTextNode)(t)&&(null===(e=t.textContent)||void 0===e?void 0:e.trim())}));if(0===i.length)return!0;return!(!(r.length>0)||r.some((t=>{const e=t.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(e)})))},h=o=>{var i,c;if(!o.parentNode||a(o))return!1;const u=o.tagName.toLowerCase();if(!n.ALLOWED_EMPTY_ELEMENTS.has(u)&&!o.children.length&&!(null===(i=o.textContent)||void 0===i?void 0:i.trim()))return o.remove(),r++,!0;if(o.parentElement===t){const t=Array.from(o.children);if(t.length>0&&!t.some((t=>{const e=t.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(e)}))){const t=e.createDocumentFragment();for(;o.firstChild;)t.appendChild(o.firstChild);return o.replaceWith(t),r++,!0}}if(d(o)){const t=e.createDocumentFragment();for(;o.firstChild;)t.appendChild(o.firstChild);return o.replaceWith(t),r++,!0}const h=Array.from(o.childNodes);if(h.length>0&&h.every((t=>(0,l.isTextNode)(t)||(0,l.isElement)(t)&&n.INLINE_ELEMENTS.has(t.nodeName.toLowerCase())))&&(null===(c=o.textContent)||void 0===c?void 0:c.trim())){const t=e.createElement("p");for(;o.firstChild;)t.appendChild(o.firstChild);return o.replaceWith(t),r++,!0}if(1===o.children.length){const t=o.firstElementChild,e=t.tagName.toLowerCase();if(n.BLOCK_ELEMENTS_SET.has(e)&&!a(t))return o.replaceWith(t),r++,!0}let m=0,p=o.parentElement;for(;p;){const t=p.tagName.toLowerCase();n.BLOCK_ELEMENTS_SET.has(t)&&m++,p=p.parentElement}if(m>0&&!s(o)){const t=e.createDocumentFragment();for(;o.firstChild;)t.appendChild(o.firstChild);return o.replaceWith(t),r++,!0}return!1},m=()=>{const e=Array.from(t.children).filter((t=>n.BLOCK_ELEMENTS_SET.has(t.tagName.toLowerCase())));let r=!1;return e.forEach((t=>{h(t)&&(r=!0)})),r},p=()=>{const e=Array.from(t.querySelectorAll(n.BLOCK_ELEMENTS_SELECTOR)).sort(((t,e)=>{const r=t=>{let e=0,r=t.parentElement;for(;r;){const t=r.tagName.toLowerCase();n.BLOCK_ELEMENTS_SET.has(t)&&e++,r=r.parentElement}return e};return r(e)-r(t)}));let r=!1;return e.forEach((t=>{h(t)&&(r=!0)})),r},f=()=>{const o=Array.from(t.querySelectorAll(n.BLOCK_ELEMENTS_SELECTOR));let i=!1;return o.forEach((t=>{const n=Array.from(t.children);if(n.length>0&&n.every((t=>"p"===t.tagName.toLowerCase()))||!a(t)&&d(t)){const n=e.createDocumentFragment();for(;t.firstChild;)n.appendChild(t.firstChild);t.replaceWith(n),r++,i=!0}})),i};do{i=!1,m()&&(i=!0),p()&&(i=!0),f()&&(i=!0)}while(i);const g=Date.now();(0,l.logDebug)(u,"Flattened wrapper elements:",{count:r,processingTime:`${(g-o).toFixed(2)}ms`})}},552(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.isElement=function(t){return t.nodeType===r},e.isTextNode=function(t){return t.nodeType===n},e.isCommentNode=function(t){return t.nodeType===o},e.getComputedStyle=function(t){const e=i(t.ownerDocument);return e?e.getComputedStyle(t):null},e.getWindow=i,e.textPreview=function(t){return(t.textContent||"").trim().substring(0,200)},e.logDebug=function(t,e,...r){t&&console.log("Defuddle:",e,...r)},e.countWords=function(t){if(!t)return 0;let e=0,r=0,n=!1;for(let o=0;o<t.length;o++){const i=t.charCodeAt(o);i>=12352&&i<=12447||i>=12448&&i<=12543||i>=13312&&i<=19903||i>=19968&&i<=40959||i>=63744&&i<=64255||i>=44032&&i<=55215?(e++,n=!1):i<=32?n=!1:n||(r++,n=!0)}return e+r};const r=1,n=3,o=8;function i(t){return t.defaultView?t.defaultView:t.ownerWindow?t.ownerWindow:t.window?t.window:null}},77(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.buildContentHtml=function(t,e,r){return`\n\t\t<div class="${t} post">\n\t\t\t<div class="post-content">\n\t\t\t\t${e}\n\t\t\t</div>\n\t\t</div>\n\t\t${r?`\n\t\t\t<hr>\n\t\t\t<div class="${t} comments">\n\t\t\t\t<h2>Comments</h2>\n\t\t\t\t${r}\n\t\t\t</div>\n\t\t`:""}\n\t`.trim()},e.buildCommentTree=function(t){var e,r,n;const i=[],s=[];for(const a of t){const t=null!==(e=a.depth)&&void 0!==e?e:0;if(0===t){for(;s.length>0;)i.push("</blockquote>"),s.pop();i.push("<blockquote>"),s.push(0)}else{if(t<(null!==(r=s[s.length-1])&&void 0!==r?r:-1))for(;s.length>0&&s[s.length-1]>=t;)i.push("</blockquote>"),s.pop();t>(null!==(n=s[s.length-1])&&void 0!==n?n:-1)&&(i.push("<blockquote>"),s.push(t))}i.push(o(a))}for(;s.length>0;)i.push("</blockquote>"),s.pop();return i.join("")},e.buildComment=o;const n=r(639);function o(t){const e=`<span class="comment-author"><strong>${(0,n.escapeHtml)(t.author)}</strong></span>`,r=t.url&&!(0,n.isDangerousUrl)(t.url)?t.url:"";return`<div class="comment">\n\t<div class="comment-metadata">\n\t\t${e} \xb7 ${r?`<a href="${(0,n.escapeHtml)(r)}" class="comment-link">${(0,n.escapeHtml)(t.date)}</a>`:`<span class="comment-date">${(0,n.escapeHtml)(t.date)}</span>`}${t.score?` \xb7 <span class="comment-points">${(0,n.escapeHtml)(t.score)}</span>`:""}\n\t</div>\n\t<div class="comment-content">${t.content}</div>\n</div>`}},639(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.transferContent=function(t,e){if("replaceChildren"in e)e.replaceChildren();else for(;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)},e.serializeHTML=function(t){return t.innerHTML},e.decodeHTMLEntities=function(t,e){const r=t.createElement("textarea");return r.innerHTML=e,r.value},e.escapeHtml=function(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},e.getClassName=function(t){return"string"==typeof t.className?t.className:t.getAttribute("class")||""},e.isDangerousUrl=function(t){const e=t.replace(/[\s\u0000-\u001F]+/g,"").toLowerCase();return e.startsWith("javascript:")||e.startsWith("data:text/html")},e.isDirectTableChild=function(t,e){let r=t.parentNode;for(;r&&r!==e;){if("TABLE"===r.nodeName)return!1;r=r.parentNode}return r===e},e.parseHTML=function(t,e){if(!e)return t.createDocumentFragment();const r=t.createElement("template");if(r.innerHTML=e,r.content)return r.content;const n=t.createElement("div");n.innerHTML=e;const o=t.createDocumentFragment();for(;n.firstChild;)o.appendChild(n.firstChild);return o}},497(t,e,r){Object.defineProperty(e,"__esModule",{value:!0}),e.formatTimestamp=o,e.buildTranscript=function(t,e,r=[]){const i=[...r].sort(((t,e)=>t.start-e.start));let s=0;const a=[],l=[];for(const t of e){for(;s<i.length&&i[s].start<=t.start;){const t=i[s].title;a.push(`<h3>${(0,n.escapeHtml)(t)}</h3>`),l.length>0&&l.push(""),l.push(`### ${t}`),l.push(""),s++}const e=o(t.start),r=void 0!==t.speaker?` speaker-${t.speaker}`:"",c=`<strong><span class="timestamp" data-timestamp="${t.start}">${e}</span></strong>`;a.push(`<p class="transcript-segment${r}">${c} \xb7 ${(0,n.escapeHtml)(t.text)}</p>`),t.speakerChange&&l.length>0&&l.push(""),l.push(`**${e}** \xb7 ${t.text}`)}return{html:`<div class="${t} transcript">\n<h2>Transcript</h2>\n${a.join("\n")}\n</div>`,text:l.join("\n")}};const n=r(639);function o(t){const e=Math.floor(t/3600),r=Math.floor(t%3600/60),n=Math.floor(t%60);return e>0?`${e}:${String(r).padStart(2,"0")}:${String(n).padStart(2,"0")}`:`${r}:${String(n).padStart(2,"0")}`}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}var n={};return(()=>{var t=n;const e=r(628);t.default=e.Defuddle})(),n=n.default})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,yCAAsC;AAGtC,6BAA6B;AAC7B,kBAAe,mBAAQ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DefuddleResponse, DefuddleOptions } from './types';
|
|
2
|
+
type GenericElement = {
|
|
3
|
+
classList?: {
|
|
4
|
+
contains: (className: string) => boolean;
|
|
5
|
+
};
|
|
6
|
+
getAttribute: (name: string) => string | null;
|
|
7
|
+
hasAttribute: (name: string) => boolean;
|
|
8
|
+
querySelector: (selector: string) => Element | null;
|
|
9
|
+
querySelectorAll: (selector: string) => NodeListOf<Element>;
|
|
10
|
+
rows?: ArrayLike<{
|
|
11
|
+
cells?: ArrayLike<{}>;
|
|
12
|
+
}>;
|
|
13
|
+
parentNode?: GenericElement | null;
|
|
14
|
+
nextSibling?: GenericElement | null;
|
|
15
|
+
nodeName: string;
|
|
16
|
+
innerHTML: string;
|
|
17
|
+
children?: ArrayLike<GenericElement>;
|
|
18
|
+
cloneNode: (deep?: boolean) => Node;
|
|
19
|
+
textContent?: string | null;
|
|
20
|
+
attributes?: NamedNodeMap;
|
|
21
|
+
className?: string;
|
|
22
|
+
tagName?: string;
|
|
23
|
+
nodeType: number;
|
|
24
|
+
closest?: (selector: string) => Element | null;
|
|
25
|
+
};
|
|
26
|
+
export declare function isGenericElement(node: unknown): node is GenericElement;
|
|
27
|
+
export declare function asGenericElement(node: any): GenericElement;
|
|
28
|
+
export declare function createMarkdownContent(content: string, url: string): string;
|
|
29
|
+
export declare function toMarkdown(result: DefuddleResponse, options: DefuddleOptions, url: string): void;
|
|
30
|
+
export {};
|