defuddle 0.3.2 → 0.3.4
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/README.md +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/defuddle.d.ts +2 -1
- package/dist/index.full.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Defuddle=t():e.Defuddle=t()}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var e={608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MetadataExtractor=void 0;t.MetadataExtractor=class{static extract(e,t){var r,o;let n="",a="";try{a=(null===(r=e.location)||void 0===r?void 0:r.href)||"",a||(a=this.getMetaContent(e,"property","og:url")||this.getMetaContent(e,"property","twitter:url")||this.getSchemaProperty(e,t,"url")||this.getSchemaProperty(e,t,"mainEntityOfPage.url")||this.getSchemaProperty(e,t,"mainEntity.url")||this.getSchemaProperty(e,t,"WebSite.url")||(null===(o=e.querySelector('link[rel="canonical"]'))||void 0===o?void 0:o.getAttribute("href"))||""),a&&(n=new URL(a).hostname.replace(/^www\./,""))}catch(t){const r=e.querySelector("base[href]");if(r)try{a=r.getAttribute("href")||"",n=new URL(a).hostname.replace(/^www\./,"")}catch(e){console.warn("Failed to parse base URL:",e)}}return{title:this.getTitle(e,t),description:this.getDescription(e,t),domain:n,favicon:this.getFavicon(e,a),image:this.getImage(e,t),published:this.getPublished(e,t),author:this.getAuthor(e,t),site:this.getSite(e,t),schemaOrgData:t,wordCount:0,parseTime:0}}static getAuthor(e,t){return this.getMetaContent(e,"name","sailthru.author")||this.getSchemaProperty(e,t,"author.name")||this.getMetaContent(e,"property","author")||this.getMetaContent(e,"name","byl")||this.getMetaContent(e,"name","author")||this.getMetaContent(e,"name","authorList")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(e,t,"copyrightHolder.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(e,t,"publisher.name")||this.getSchemaProperty(e,t,"sourceOrganization.name")||this.getSchemaProperty(e,t,"isPartOf.name")||this.getMetaContent(e,"name","twitter:creator")||this.getMetaContent(e,"name","application-name")||""}static getSite(e,t){return this.getSchemaProperty(e,t,"publisher.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(e,t,"WebSite.name")||this.getSchemaProperty(e,t,"sourceOrganization.name")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(e,t,"copyrightHolder.name")||this.getSchemaProperty(e,t,"isPartOf.name")||this.getMetaContent(e,"name","application-name")||this.getAuthor(e,t)||""}static getTitle(e,t){var r,o;const n=this.getMetaContent(e,"property","og:title")||this.getMetaContent(e,"name","twitter:title")||this.getSchemaProperty(e,t,"headline")||this.getMetaContent(e,"name","title")||this.getMetaContent(e,"name","sailthru.title")||(null===(o=null===(r=e.querySelector("title"))||void 0===r?void 0:r.textContent)||void 0===o?void 0:o.trim())||"";return this.cleanTitle(n,this.getSite(e,t))}static cleanTitle(e,t){if(!e||!t)return e;const r=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=[`\\s*[\\|\\-\u2013\u2014]\\s*${r}\\s*$`,`^\\s*${r}\\s*[\\|\\-\u2013\u2014]\\s*`];for(const t of o){const r=new RegExp(t,"i");if(r.test(e)){e=e.replace(r,"");break}}return e.trim()}static getDescription(e,t){return this.getMetaContent(e,"name","description")||this.getMetaContent(e,"property","description")||this.getMetaContent(e,"property","og:description")||this.getSchemaProperty(e,t,"description")||this.getMetaContent(e,"name","twitter:description")||this.getMetaContent(e,"name","sailthru.description")||""}static getImage(e,t){return this.getMetaContent(e,"property","og:image")||this.getMetaContent(e,"name","twitter:image")||this.getSchemaProperty(e,t,"image.url")||this.getMetaContent(e,"name","sailthru.image.full")||""}static getFavicon(e,t){var r,o;const n=this.getMetaContent(e,"property","og:image:favicon");if(n)return n;const a=null===(r=e.querySelector("link[rel='icon']"))||void 0===r?void 0:r.getAttribute("href");if(a)return a;const i=null===(o=e.querySelector("link[rel='shortcut icon']"))||void 0===o?void 0:o.getAttribute("href");if(i)return i;if(t)try{return new URL("/favicon.ico",t).href}catch(e){console.warn("Failed to construct favicon URL:",e)}return""}static getPublished(e,t){return this.getSchemaProperty(e,t,"datePublished")||this.getMetaContent(e,"name","publishDate")||this.getMetaContent(e,"property","article:published_time")||this.getTimeElement(e)||this.getMetaContent(e,"name","sailthru.date")||""}static getMetaContent(e,t,r){var o,n;const a=`meta[${t}]`,i=Array.from(e.querySelectorAll(a)).find((e=>{var o;return(null===(o=e.getAttribute(t))||void 0===o?void 0:o.toLowerCase())===r.toLowerCase()})),s=i&&null!==(n=null===(o=i.getAttribute("content"))||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(s,e)}static getTimeElement(e){var t,r,o,n;const a=Array.from(e.querySelectorAll("time"))[0],i=a&&null!==(n=null!==(r=null===(t=a.getAttribute("datetime"))||void 0===t?void 0:t.trim())&&void 0!==r?r:null===(o=a.textContent)||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(i,e)}static decodeHTMLEntities(e,t){const r=t.createElement("textarea");return r.innerHTML=e,r.value}static getSchemaProperty(e,t,r,o=""){if(!t)return o;const n=(e,t,r,o=!0)=>{if("string"==typeof e)return 0===t.length?[e]:[];if(!e||"object"!=typeof e)return[];if(Array.isArray(e)){const a=t[0];if(/^\[\d+\]$/.test(a)){const i=parseInt(a.slice(1,-1));return e[i]?n(e[i],t.slice(1),r,o):[]}return 0===t.length&&e.every((e=>"string"==typeof e||"number"==typeof e))?e.map(String):e.flatMap((e=>n(e,t,r,o)))}const[a,...i]=t;if(!a)return"string"==typeof e?[e]:"object"==typeof e&&e.name?[e.name]:[];if(e.hasOwnProperty(a))return n(e[a],i,r?`${r}.${a}`:a,!0);if(!o){const o=[];for(const a in e)if("object"==typeof e[a]){const i=n(e[a],t,r?`${r}.${a}`:a,!1);o.push(...i)}if(o.length>0)return o}return[]};try{let a=n(t,r.split("."),"",!0);0===a.length&&(a=n(t,r.split("."),"",!1));const i=a.length>0?a.filter(Boolean).join(", "):o;return this.decodeHTMLEntities(i,e)}catch(e){return console.error(`Error in getSchemaProperty for ${r}:`,e),o}}static extractSchemaOrgData(e){const t=e.querySelectorAll('script[type="application/ld+json"]'),r=[];return t.forEach((e=>{let t=e.textContent||"";try{t=t.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm,"").replace(/^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/,"$1").replace(/^\s*(\*\/|\/\*)\s*|\s*(\*\/|\/\*)\s*$/g,"").trim();const e=JSON.parse(t);e["@graph"]&&Array.isArray(e["@graph"])?r.push(...e["@graph"]):r.push(e)}catch(e){console.error("Error parsing schema.org data:",e),console.error("Problematic JSON content:",t)}})),r}}},628:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Defuddle=void 0;const o=r(608),n=r(640),a=[...r(826).mathStandardizationRules,{selector:"pre",element:"pre",transform:e=>{if(!(e instanceof HTMLElement))return e;const t=e=>{const t=e.getAttribute("data-lang")||e.getAttribute("data-language");if(t)return t.toLowerCase();const r=[/^language-(\w+)$/,/^lang-(\w+)$/,/^(\w+)-code$/,/^code-(\w+)$/,/^syntax-(\w+)$/,/^code-snippet__(\w+)$/,/^highlight-(\w+)$/,/^(\w+)-snippet$/];if(e.className&&"string"==typeof e.className){for(const t of r){const r=e.className.toLowerCase().match(t);if(r)return r[1].toLowerCase()}if(n.SUPPORTED_LANGUAGES.has(e.className.toLowerCase()))return e.className.toLowerCase()}const o=Array.from(e.classList);for(const e of o)for(const t of r){const r=e.match(t);if(r)return r[1].toLowerCase()}for(const e of o)if(n.SUPPORTED_LANGUAGES.has(e.toLowerCase()))return e.toLowerCase();return""};let r="",o=e;for(;o&&!r;)r=t(o),!r&&o.querySelector("code")&&(r=t(o.querySelector("code"))),o=o.parentElement;const a=e=>{if(e.nodeType===Node.TEXT_NODE)return e.textContent||"";let t="";if(e instanceof HTMLElement){if("BR"===e.tagName)return"\n";if(e.matches('div[class*="line"], span[class*="line"], .ec-line, [data-line-number], [data-line]')){const t=e.querySelector('.code, .content, [class*="code-"], [class*="content-"]');if(t)return(t.textContent||"")+"\n";const r=e.querySelector('.line-number, .gutter, [class*="line-number"], [class*="gutter"]');if(r){return Array.from(e.childNodes).filter((e=>!r.contains(e))).map((e=>a(e))).join("")+"\n"}return e.textContent+"\n"}e.childNodes.forEach((e=>{t+=a(e)}))}return t};let i=a(e);i=i.replace(/^\n+/,"").replace(/\n+$/,"").replace(/\n{3,}/g,"\n\n");const s=document.createElement("pre");Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&s.setAttribute(e.name,e.value)}));const l=document.createElement("code");return r&&(l.setAttribute("data-lang",r),l.setAttribute("class",`language-${r}`)),l.textContent=i,s.appendChild(l),s}},{selector:"h1, h2, h3, h4, h5, h6",element:"keep",transform:e=>{var t;const r=document.createElement(e.tagName);Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&r.setAttribute(e.name,e.value)}));const o=e.cloneNode(!0);Array.from(o.querySelectorAll("*")).filter((e=>{if(e instanceof HTMLAnchorElement){const t=e.getAttribute("href");return(null==t?void 0:t.includes("#"))||(null==t?void 0:t.startsWith("#"))}return!!e.classList.contains("anchor")||(e instanceof HTMLButtonElement||!(!(e instanceof HTMLSpanElement||e instanceof HTMLDivElement)||!e.querySelector('a[href^="#"]')))})).forEach((e=>e.remove()));const a=(null===(t=o.textContent)||void 0===t?void 0:t.trim())||"";return r.textContent=a,r}},{selector:'div[data-testid^="paragraph"], div[role="paragraph"]',element:"p",transform:e=>{const t=document.createElement("p");return t.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&t.setAttribute(e.name,e.value)})),t}},{selector:'div[role="list"]',element:"ul",transform:e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");return e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");if(r){r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)}));r.querySelectorAll('div[role="list"]').forEach((e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");if(r){r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t.innerHTML=r.innerHTML}n.appendChild(t)})),e.replaceWith(n)})),t.innerHTML=r.innerHTML}n.appendChild(t)})),n}},{selector:'div[role="listitem"]',element:"li",transform:e=>{const t=e.querySelector(".content");if(!t)return e;return t.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t}},{selector:'.wp-block-syntaxhighlighter-code, .syntaxhighlighter, .highlight, .highlight-source, .wp-block-code, pre[class*="language-"], pre[class*="brush:"]',element:"pre",transform:e=>{if(!(e instanceof HTMLElement))return e;const t=document.createElement("pre");let r="";const o=e.querySelector(".syntaxhighlighter");if(o){const e=Array.from(o.classList).find((e=>!["syntaxhighlighter","nogutter"].includes(e)));e&&n.SUPPORTED_LANGUAGES.has(e.toLowerCase())&&(r=e.toLowerCase())}if(!r){const t=Array.from(e.classList),o=[/(?:^|\s)(?:language|lang|brush|syntax)-(\w+)(?:\s|$)/i,/(?:^|\s)(\w+)(?:\s|$)/i];for(const e of t){for(const t of o){const o=e.match(t);if(o&&o[1]&&n.SUPPORTED_LANGUAGES.has(o[1].toLowerCase())){r=o[1].toLowerCase();break}}if(r)break}}let a="";const i=e.querySelector(".syntaxhighlighter table .code .container");if(i){a=Array.from(i.children).map((e=>{const t=Array.from(e.querySelectorAll("code")).map((e=>{let t=e.textContent||"";return e.classList.contains("spaces")&&(t=" ".repeat(t.length)),t})).join("");return t||e.textContent||""})).join("\n")}else{const t=e.querySelectorAll(".code .line");a=t.length>0?Array.from(t).map((e=>{const t=Array.from(e.querySelectorAll("code")).map((e=>e.textContent||"")).join("");return t||e.textContent||""})).join("\n"):e.textContent||""}a=a.replace(/^\s+|\s+$/g,"").replace(/\t/g," ").replace(/\n{3,}/g,"\n\n").replace(/\u00a0/g," ");const s=document.createElement("code");return r&&(s.setAttribute("data-lang",r),s.setAttribute("class",`language-${r}`)),s.textContent=a,t.appendChild(s),t}}];t.Defuddle=class{constructor(e,t={}){this.doc=e,this.options=t,this.debug=t.debug||!1}parse(){const e=performance.now(),t=o.MetadataExtractor.extractSchemaOrgData(this.doc),r=o.MetadataExtractor.extract(this.doc,t);try{const t=this._evaluateMediaQueries(this.doc),o=this.findSmallImages(this.doc),n=this.doc.cloneNode(!0);this.applyMobileStyles(n,t);const a=this.findMainContent(n);if(!a){const t=performance.now();return Object.assign(Object.assign({content:this.doc.body.innerHTML},r),{wordCount:this.countWords(this.doc.body.innerHTML),parseTime:Math.round(t-e)})}this.removeSmallImages(n,o),this.removeHiddenElements(n),this.removeClutter(n),this.cleanContent(a,r);const i=a?a.outerHTML:this.doc.body.innerHTML,s=performance.now();return Object.assign(Object.assign({content:i},r),{wordCount:this.countWords(i),parseTime:Math.round(s-e)})}catch(t){console.error("Defuddle","Error processing document:",t);const o=performance.now();return Object.assign(Object.assign({content:this.doc.body.innerHTML},r),{wordCount:this.countWords(this.doc.body.innerHTML),parseTime:Math.round(o-e)})}}countWords(e){const t=document.createElement("div");t.innerHTML=e;return(t.textContent||"").trim().replace(/\s+/g," ").split(" ").filter((e=>e.length>0)).length}_log(...e){this.debug&&console.log("Defuddle:",...e)}_evaluateMediaQueries(e){const t=[],r=/max-width[^:]*:\s*(\d+)/;try{const o=Array.from(e.styleSheets).filter((e=>{try{return e.cssRules,!0}catch(e){if(e instanceof DOMException&&"SecurityError"===e.name)return!1;throw e}}));o.flatMap((e=>{try{return Array.from(e.cssRules).filter((e=>e instanceof CSSMediaRule&&e.conditionText.includes("max-width")))}catch(e){return this.debug&&console.warn("Defuddle: Failed to process stylesheet:",e),[]}})).forEach((e=>{const o=e.conditionText.match(r);if(o){const r=parseInt(o[1]);if(n.MOBILE_WIDTH<=r){Array.from(e.cssRules).filter((e=>e instanceof CSSStyleRule)).forEach((e=>{try{t.push({selector:e.selectorText,styles:e.style.cssText})}catch(e){this.debug&&console.warn("Defuddle: Failed to process CSS rule:",e)}}))}}}))}catch(e){console.error("Defuddle: Error evaluating media queries:",e)}return t}applyMobileStyles(e,t){t.forEach((({selector:t,styles:r})=>{try{e.querySelectorAll(t).forEach((e=>{e.setAttribute("style",(e.getAttribute("style")||"")+r)}))}catch(e){console.error("Defuddle","Error applying styles for selector:",t,e)}}))}removeHiddenElements(e){let t=0;const r=new Set,o=e.querySelectorAll(n.HIDDEN_ELEMENT_SELECTORS);o.forEach((e=>r.add(e))),t+=o.length;const a=e.createTreeWalker(e.body,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>r.has(e)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),i=[];let s;for(;s=a.nextNode();)i.push(s);for(let e=0;e<i.length;e+=100){const o=i.slice(e,e+100),n=o.map((e=>window.getComputedStyle(e)));o.forEach(((e,o)=>{const a=n[o];"none"!==a.display&&"hidden"!==a.visibility&&"0"!==a.opacity||(r.add(e),t++)}))}r.forEach((e=>e.remove())),this._log("Removed hidden elements:",t)}removeClutter(e){const t=performance.now();let r=0,o=0;const a=new Set;e.querySelectorAll(n.EXACT_SELECTORS.join(",")).forEach((e=>{(null==e?void 0:e.parentNode)&&(a.add(e),r++)}));const i=n.PARTIAL_SELECTORS.join("|"),s=new RegExp(i,"i");e.querySelectorAll("[class],[id],[data-testid],[data-test-id],[data-qa],[data-cy]").forEach((e=>{if(a.has(e))return;const t=[e.className&&"string"==typeof e.className?e.className:"",e.id||"",e.getAttribute("data-testid")||"",e.getAttribute("data-test-id")||"",e.getAttribute("data-qa")||"",e.getAttribute("data-cy")||""].join(" ").toLowerCase();t.trim()&&s.test(t)&&(a.add(e),o++)})),a.forEach((e=>e.remove()));const l=performance.now();this._log("Removed clutter elements:",{exactSelectors:r,partialSelectors:o,total:a.size,processingTime:`${(l-t).toFixed(2)}ms`})}flattenDivs(e){let t=0;const r=performance.now();let o=!0;const a=e=>{const t=e.tagName.toLowerCase();if(n.PRESERVE_ELEMENTS.has(t))return!0;const r=e.getAttribute("role");if(r&&["article","main","navigation","banner","contentinfo"].includes(r))return!0;if(e.className.toLowerCase().match(/(?:article|main|content|footnote|reference|bibliography)/))return!0;if("div"===t){if(Array.from(e.children).some((e=>n.PRESERVE_ELEMENTS.has(e.tagName.toLowerCase())||"article"===e.getAttribute("role")||e.className.toLowerCase().includes("article"))))return!0}return!1},i=e=>{var t;if(!(null===(t=e.textContent)||void 0===t?void 0:t.trim()))return!0;const r=Array.from(e.children);if(0===r.length)return!0;if(r.every((e=>{const t=e.tagName.toLowerCase();return"div"===t||"p"===t||"h1"===t||"h2"===t||"h3"===t||"h4"===t||"h5"===t||"h6"===t||"ul"===t||"ol"===t||"pre"===t||"blockquote"===t||"figure"===t})))return!0;const o=e.className.toLowerCase();if(/(?:wrapper|container|layout|row|col|grid|flex|outer|inner|content-area)/i.test(o))return!0;const a=Array.from(e.childNodes).filter((e=>{var t;return e.nodeType===Node.TEXT_NODE&&(null===(t=e.textContent)||void 0===t?void 0:t.trim())}));if(0===a.length)return!0;return!(!(r.length>0)||r.some((e=>{const t=e.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(t)})))},s=r=>{var o,s;if(!r.isConnected||a(r))return!1;if(!r.hasChildNodes()||!(null===(o=r.textContent)||void 0===o?void 0:o.trim()))return r.remove(),t++,!0;if(r.parentElement===e){const e=Array.from(r.children);if(e.length>0&&!e.some((e=>{const t=e.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(t)}))){const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}}if(i(r)){if(!Array.from(r.children).some((e=>{const t=e.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(t)}))){const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}if(!r.children.length&&(null===(s=r.textContent)||void 0===s?void 0:s.trim())){const e=document.createElement("p");return e.textContent=r.textContent,r.replaceWith(e),t++,!0}if(1===r.children.length){const e=r.firstElementChild,o=e.tagName.toLowerCase();if(!n.INLINE_ELEMENTS.has(o)&&!a(e))return r.replaceWith(e),t++,!0}let l=0,c=r.parentElement;for(;c;)"div"===c.tagName.toLowerCase()&&l++,c=c.parentElement;if(l>0){const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}return!1},l=()=>{const t=Array.from(e.children).filter((e=>"div"===e.tagName.toLowerCase()));let r=!1;return t.forEach((e=>{s(e)&&(r=!0)})),r},c=()=>{const t=Array.from(e.getElementsByTagName("div")).sort(((e,t)=>{const r=e=>{let t=0,r=e.parentElement;for(;r;)"div"===r.tagName.toLowerCase()&&t++,r=r.parentElement;return t};return r(t)-r(e)}));let r=!1;return t.forEach((e=>{s(e)&&(r=!0)})),r},d=()=>{const r=Array.from(e.getElementsByTagName("div"));let o=!1;return r.forEach((e=>{if(Array.from(e.children).every((e=>"p"===e.tagName.toLowerCase()))||!a(e)&&i(e)){const r=document.createDocumentFragment();for(;e.firstChild;)r.appendChild(e.firstChild);e.replaceWith(r),t++,o=!0}})),o};do{o=!1,l()&&(o=!0),c()&&(o=!0),d()&&(o=!0)}while(o);const m=performance.now();this._log("Flattened divs:",{count:t,processingTime:`${(m-r).toFixed(2)}ms`})}cleanContent(e,t){this.removeHtmlComments(e),this.handleHeadings(e,t.title),this.standardizeFootnotes(e),this.handleLazyImages(e),this.standardizeElements(e),this.debug?(this.stripUnwantedAttributes(e),this.removeEmptyElements(e),this.removeTrailingHeadings(e),this._log("Debug mode: Skipping div flattening to preserve structure")):(this.flattenDivs(e),this.stripUnwantedAttributes(e),this.removeEmptyElements(e),this.removeTrailingHeadings(e),this.flattenDivs(e),this.removeEmptyLines(e))}removeTrailingHeadings(e){let t=0;const r=t=>{let o="",n=t.nextSibling;for(;n;)(n.nodeType===Node.TEXT_NODE||n.nodeType===Node.ELEMENT_NODE)&&(o+=n.textContent||""),n=n.nextSibling;if(o.trim())return!0;const a=t.parentElement;return!(!a||a===e)&&r(a)};Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6")).reverse().forEach((e=>{r(e)||(e.remove(),t++)})),t>0&&this._log("Removed trailing headings:",t)}handleHeadings(e,t){const r=e=>e.replace(/\u00A0/g," ").replace(/\s+/g," ").trim().toLowerCase(),o=e.getElementsByTagName("h1");Array.from(o).forEach((e=>{var t;const r=document.createElement("h2");r.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&r.setAttribute(e.name,e.value)})),null===(t=e.parentNode)||void 0===t||t.replaceChild(r,e)}));const a=e.getElementsByTagName("h2");if(a.length>0){const e=a[0],o=r(e.textContent||""),n=r(t);n&&n===o&&e.remove()}}removeHtmlComments(e){const t=[],r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT,null);let o;for(;o=r.nextNode();)t.push(o);t.forEach((e=>{e.remove()})),this._log("Removed HTML comments:",t.length)}stripUnwantedAttributes(e){let t=0;const r=e=>{if(e instanceof SVGElement)return;Array.from(e.attributes).forEach((r=>{const o=r.name.toLowerCase();this.debug?n.ALLOWED_ATTRIBUTES.has(o)||n.ALLOWED_ATTRIBUTES_DEBUG.has(o)||o.startsWith("data-")||(e.removeAttribute(r.name),t++):n.ALLOWED_ATTRIBUTES.has(o)||(e.removeAttribute(r.name),t++)}))};r(e),e.querySelectorAll("*").forEach(r),this._log("Stripped attributes:",t)}removeEmptyElements(e){let t=0,r=0,o=!0;for(;o;){r++,o=!1;const a=Array.from(e.getElementsByTagName("*")).filter((e=>{if(n.ALLOWED_EMPTY_ELEMENTS.has(e.tagName.toLowerCase()))return!1;const t=e.textContent||"",r=0===t.trim().length,o=t.includes("\xa0"),a=!e.hasChildNodes()||Array.from(e.childNodes).every((e=>{if(e.nodeType===Node.TEXT_NODE){const t=e.textContent||"";return 0===t.trim().length&&!t.includes("\xa0")}return!1}));if("div"===e.tagName.toLowerCase()){const t=Array.from(e.children);if(t.length>0&&t.every((e=>{var t;if("span"!==e.tagName.toLowerCase())return!1;const r=(null===(t=e.textContent)||void 0===t?void 0:t.trim())||"";return","===r||""===r||" "===r})))return!0}return r&&!o&&a}));a.length>0&&(a.forEach((e=>{e.remove(),t++})),o=!0)}this._log("Removed empty elements:",{count:t,iterations:r})}removeEmptyLines(e){let t=0;const r=performance.now(),o=e=>{var r;if(e instanceof Element){const t=e.tagName.toLowerCase();if("pre"===t||"code"===t)return}if(Array.from(e.childNodes).forEach(o),e.nodeType===Node.TEXT_NODE){const o=e.textContent||"";if(!o||o.match(/^[\u200C\u200B\u200D\u200E\u200F\uFEFF\xA0\s]*$/))null===(r=e.parentNode)||void 0===r||r.removeChild(e),t++;else{const r=o.replace(/\n{3,}/g,"\n\n").replace(/^[\n\r\t]+/,"").replace(/[\n\r\t]+$/,"").replace(/[ \t]*\n[ \t]*/g,"\n").replace(/[ \t]{3,}/g," ").replace(/^[ ]+$/," ").replace(/\s+([,.!?:;])/g,"$1").replace(/[\u200C\u200B\u200D\u200E\u200F\uFEFF]+/g,"").replace(/(?:\xA0){2,}/g,"\xa0");r!==o&&(e.textContent=r,t+=o.length-r.length)}}},n=e=>{if(!(e instanceof Element))return;const r=e.tagName.toLowerCase();if("pre"===r||"code"===r)return;Array.from(e.children).forEach(n),e.normalize();const o="block"===getComputedStyle(e).display,a=o?/^[\n\r\t \u200C\u200B\u200D\u200E\u200F\uFEFF\xA0]*$/:/^[\n\r\t\u200C\u200B\u200D\u200E\u200F\uFEFF]*$/,i=o?/^[\n\r\t \u200C\u200B\u200D\u200E\u200F\uFEFF\xA0]*$/:/^[\n\r\t\u200C\u200B\u200D\u200E\u200F\uFEFF]*$/;for(;e.firstChild&&e.firstChild.nodeType===Node.TEXT_NODE&&(e.firstChild.textContent||"").match(a);)e.removeChild(e.firstChild),t++;for(;e.lastChild&&e.lastChild.nodeType===Node.TEXT_NODE&&(e.lastChild.textContent||"").match(i);)e.removeChild(e.lastChild),t++;if(!o){const t=e.previousSibling,r=e.nextSibling;if(t&&t.nodeType===Node.TEXT_NODE){const r=t.textContent||"",o=e.textContent||"";r.endsWith(" ")||r.endsWith("\n")||r.endsWith("\xa0")||o.match(/^[,.!?:;]/)||(t.textContent=r+" ")}if(r&&r.nodeType===Node.TEXT_NODE){const e=r.textContent||"";e.startsWith(" ")||e.startsWith("\n")||e.startsWith("\xa0")||e.match(/^[,.!?:;]/)||(r.textContent=" "+e)}}};o(e),n(e);const a=performance.now();this._log("Removed empty lines:",{charactersRemoved:t,processingTime:`${(a-r).toFixed(2)}ms`})}createFootnoteItem(e,t,r){const o=document.createElement("li");if(o.className="footnote",o.id=`fn:${e}`,"string"==typeof t){const e=document.createElement("p");e.innerHTML=t,o.appendChild(e)}else{const e=Array.from(t.querySelectorAll("p"));if(0===e.length){const e=document.createElement("p");e.innerHTML=t.innerHTML,o.appendChild(e)}else e.forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,o.appendChild(t)}))}const n=o.querySelector("p:last-of-type")||o;return r.forEach(((e,t)=>{const o=document.createElement("a");o.href=`#${e}`,o.title="return to article",o.className="footnote-backref",o.innerHTML="\u21a9",t<r.length-1&&(o.innerHTML+=" "),n.appendChild(o)})),o}collectFootnotes(e){const t={};let r=1;const o=new Set;return e.querySelectorAll(n.FOOTNOTE_LIST_SELECTORS).forEach((e=>{if(e.matches('div.footnote[data-component-name="FootnoteToDOM"]')){const n=e.querySelector("a.footnote-number"),a=e.querySelector(".footnote-content");if(n&&a){const e=n.id.replace("footnote-","").toLowerCase();e&&!o.has(e)&&(t[r]={content:a,originalId:e,refs:[]},o.add(e),r++)}return}e.querySelectorAll('li, div[role="listitem"]').forEach((e=>{var n,a,i,s;let l="",c=null;const d=e.querySelector(".citations");if(null===(n=null==d?void 0:d.id)||void 0===n?void 0:n.toLowerCase().startsWith("r")){l=d.id.toLowerCase();const e=d.querySelector(".citation-content");e&&(c=e)}else{if(e.id.toLowerCase().startsWith("bib.bib"))l=e.id.replace("bib.bib","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn:"))l=e.id.replace("fn:","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn"))l=e.id.replace("fn","").toLowerCase();else if(e.hasAttribute("data-counter"))l=(null===(i=null===(a=e.getAttribute("data-counter"))||void 0===a?void 0:a.replace(/\.$/,""))||void 0===i?void 0:i.toLowerCase())||"";else{const t=null===(s=e.id.split("/").pop())||void 0===s?void 0:s.match(/cite_note-(.+)/);l=t?t[1].toLowerCase():e.id.toLowerCase()}c=e}l&&!o.has(l)&&(t[r]={content:c||e,originalId:l,refs:[]},o.add(l),r++)}))})),t}findOuterFootnoteContainer(e){let t=e,r=e.parentElement;for(;r&&("span"===r.tagName.toLowerCase()||"sup"===r.tagName.toLowerCase());)t=r,r=r.parentElement;return t}createFootnoteReference(e,t){const r=document.createElement("sup");r.id=t;const o=document.createElement("a");return o.href=`#fn:${e}`,o.textContent=e,r.appendChild(o),r}standardizeFootnotes(e){const t=this.collectFootnotes(e),r=e.querySelectorAll(n.FOOTNOTE_INLINE_REFERENCES),o=new Map;r.forEach((e=>{var r,n,a,i;if(!(e instanceof HTMLElement))return;let s="",l="";if(e.matches('a[id^="ref-link"]'))s=(null===(r=e.textContent)||void 0===r?void 0:r.trim())||"";else if(e.matches('a[role="doc-biblioref"]')){const t=e.getAttribute("data-xml-rid");if(t)s=t;else{const t=e.getAttribute("href");(null==t?void 0:t.startsWith("#core-R"))&&(s=t.replace("#core-",""))}}else if(e.matches("a.footnote-anchor, span.footnote-hovercard-target a")){const t=(null===(n=e.id)||void 0===n?void 0:n.replace("footnote-anchor-",""))||"";t&&(s=t.toLowerCase())}else if(e.matches("cite.ltx_cite")){const t=e.querySelector("a");if(t){const e=t.getAttribute("href");if(e){const t=null===(a=e.split("/").pop())||void 0===a?void 0:a.match(/bib\.bib(\d+)/);t&&(s=t[1].toLowerCase())}}}else if(e.matches("sup.reference")){const t=e.querySelectorAll("a");Array.from(t).forEach((e=>{var t;const r=e.getAttribute("href");if(r){const e=null===(t=r.split("/").pop())||void 0===t?void 0:t.match(/(?:cite_note|cite_ref)-(.+)/);e&&(s=e[1].toLowerCase())}}))}else if(e.matches('sup[id^="fnref:"]'))s=e.id.replace("fnref:","").toLowerCase();else if(e.matches('sup[id^="fnr"]'))s=e.id.replace("fnr","").toLowerCase();else if(e.matches("span.footnote-reference"))s=e.getAttribute("data-footnote-id")||"";else if(e.matches("span.footnote-link"))s=e.getAttribute("data-footnote-id")||"",l=e.getAttribute("data-footnote-content")||"";else if(e.matches("a.citation"))s=(null===(i=e.textContent)||void 0===i?void 0:i.trim())||"",l=e.getAttribute("href")||"";else if(e.matches('a[id^="fnref"]'))s=e.id.replace("fnref","").toLowerCase();else{const t=e.getAttribute("href");if(t){const e=t.replace(/^[#]/,"");s=e.toLowerCase()}}if(s){const r=Object.entries(t).find((([e,t])=>t.originalId===s.toLowerCase()));if(r){const[t,n]=r,a=n.refs.length>0?`fnref:${t}-${n.refs.length+1}`:`fnref:${t}`;n.refs.push(a);const i=this.findOuterFootnoteContainer(e);if("sup"===i.tagName.toLowerCase()){o.has(i)||o.set(i,[]);o.get(i).push(this.createFootnoteReference(t,a))}else i.replaceWith(this.createFootnoteReference(t,a))}}})),o.forEach(((e,t)=>{if(e.length>0){const r=document.createDocumentFragment();e.forEach(((e,t)=>{const o=e.querySelector("a");if(o){const t=document.createElement("sup");t.id=e.id,t.appendChild(o.cloneNode(!0)),r.appendChild(t)}})),t.replaceWith(r)}}));const a=document.createElement("footnotes");a.className="footnotes";const i=document.createElement("ol");Object.entries(t).forEach((([e,t])=>{const r=this.createFootnoteItem(parseInt(e),t.content,t.refs);i.appendChild(r)}));e.querySelectorAll(n.FOOTNOTE_LIST_SELECTORS).forEach((e=>e.remove())),i.children.length>0&&(a.appendChild(i),e.appendChild(a))}handleLazyImages(e){let t=0;e.querySelectorAll("img[data-src], img[data-srcset]").forEach((e=>{if(!(e instanceof HTMLImageElement))return;const r=e.getAttribute("data-src");r&&!e.src&&(e.src=r,t++);const o=e.getAttribute("data-srcset");o&&!e.srcset&&(e.srcset=o,t++),e.classList.remove("lazy","lazyload"),e.removeAttribute("data-ll-status"),e.removeAttribute("data-src"),e.removeAttribute("data-srcset")})),this._log("Processed lazy images:",t)}standardizeElements(e){let t=0;a.forEach((r=>{e.querySelectorAll(r.selector).forEach((e=>{if(r.transform){const o=r.transform(e);e.replaceWith(o),t++}}))}));e.querySelectorAll("lite-youtube").forEach((e=>{const r=e.getAttribute("videoid");if(!r)return;const o=document.createElement("iframe");o.width="560",o.height="315",o.src=`https://www.youtube.com/embed/${r}`,o.title=e.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",""),e.replaceWith(o),t++})),this._log("Converted embedded elements:",t)}findSmallImages(e){const t=new Set,r=/scale\(([\d.]+)\)/,o=performance.now();let n=0;const a=[...Array.from(e.getElementsByTagName("img")),...Array.from(e.getElementsByTagName("svg"))].filter((e=>{if(e instanceof HTMLImageElement){return!(e.classList.contains("lazy")||e.classList.contains("lazyload")||e.classList.contains("latex")||e.hasAttribute("decoding")||e.hasAttribute("data-src")||e.hasAttribute("data-srcset"))}return!0}));if(0===a.length)return t;const i=a.map((e=>({element:e,naturalWidth:e instanceof HTMLImageElement?e.naturalWidth:0,naturalHeight:e instanceof HTMLImageElement?e.naturalHeight:0,attrWidth:parseInt(e.getAttribute("width")||"0"),attrHeight:parseInt(e.getAttribute("height")||"0")})));for(let e=0;e<i.length;e+=50){const o=i.slice(e,e+50);try{const e=o.map((({element:e})=>window.getComputedStyle(e))),a=o.map((({element:e})=>e.getBoundingClientRect()));o.forEach(((o,i)=>{var s;try{const l=e[i],c=a[i],d=l.transform,m=d?parseFloat((null===(s=d.match(r))||void 0===s?void 0:s[1])||"1"):1,u=[o.naturalWidth,o.attrWidth,parseInt(l.width)||0,c.width*m].filter((e=>"number"==typeof e&&e>0)),h=[o.naturalHeight,o.attrHeight,parseInt(l.height)||0,c.height*m].filter((e=>"number"==typeof e&&e>0));if(u.length>0&&h.length>0){const e=Math.min(...u),r=Math.min(...h);if(e<33||r<33){const e=this.getElementIdentifier(o.element);e&&(t.add(e),n++)}}}catch(e){this.debug&&console.warn("Defuddle: Failed to process element dimensions:",e)}}))}catch(e){this.debug&&console.warn("Defuddle: Failed to process batch:",e)}}const s=performance.now();return this._log("Found small elements:",{count:n,totalElements:a.length,processingTime:`${(s-o).toFixed(2)}ms`}),t}removeSmallImages(e,t){let r=0;["img","svg"].forEach((o=>{const n=e.getElementsByTagName(o);Array.from(n).forEach((e=>{const o=this.getElementIdentifier(e);o&&t.has(o)&&(e.remove(),r++)}))})),this._log("Removed small elements:",r)}getElementIdentifier(e){if(e instanceof HTMLImageElement){const t=e.getAttribute("data-src");if(t)return`src:${t}`;const r=e.src||"",o=e.srcset||"",n=e.getAttribute("data-srcset");if(r)return`src:${r}`;if(o)return`srcset:${o}`;if(n)return`srcset:${n}`}const t=e.id||"",r=e.className||"",o=e instanceof SVGElement&&e.getAttribute("viewBox")||"";return t?`id:${t}`:o?`viewBox:${o}`:r?`class:${r}`:null}findMainContent(e){const t=[];return n.ENTRY_POINT_ELEMENTS.forEach(((r,o)=>{e.querySelectorAll(r).forEach((e=>{let r=10*(n.ENTRY_POINT_ELEMENTS.length-o);r+=this.scoreElement(e),t.push({element:e,score:r})}))})),0===t.length?this.findContentByScoring(e):(t.sort(((e,t)=>t.score-e.score)),this.debug&&this._log("Content candidates:",t.map((e=>({element:e.element.tagName,selector:this.getElementSelector(e.element),score:e.score})))),t[0].element)}findContentByScoring(e){const t=this.scoreElements(e);return t.length>0?t[0].element:null}getElementSelector(e){const t=[];let r=e;for(;r&&r!==this.doc.documentElement;){let e=r.tagName.toLowerCase();r.id?e+="#"+r.id:r.className&&"string"==typeof r.className&&(e+="."+r.className.trim().split(/\s+/).join(".")),t.unshift(e),r=r.parentElement}return t.join(" > ")}scoreElements(e){const t=[];return n.BLOCK_ELEMENTS.forEach((r=>{Array.from(e.getElementsByTagName(r)).forEach((e=>{const r=this.scoreElement(e);r>0&&t.push({score:r,element:e})}))})),t.sort(((e,t)=>t.score-e.score))}scoreElement(e){let t=0;e.className&&"string"==typeof e.className&&e.className.toLowerCase(),e.id&&e.id.toLowerCase();const r=e.textContent||"",o=r.split(/\s+/).length;t+=Math.min(Math.floor(o/100),3);const n=e.getElementsByTagName("a"),a=Array.from(n).reduce(((e,t)=>{var r;return e+((null===(r=t.textContent)||void 0===r?void 0:r.length)||0)}),0);(r.length?a/r.length:0)>.5&&(t-=10);t+=e.getElementsByTagName("p").length;const i=e.getElementsByTagName("img").length;return t+=Math.min(3*i,9),t}}},640:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SUPPORTED_LANGUAGES=t.ALLOWED_ATTRIBUTES_DEBUG=t.ALLOWED_ATTRIBUTES=t.ALLOWED_EMPTY_ELEMENTS=t.FOOTNOTE_LIST_SELECTORS=t.FOOTNOTE_INLINE_REFERENCES=t.PARTIAL_SELECTORS=t.EXACT_SELECTORS=t.HIDDEN_ELEMENT_SELECTORS=t.INLINE_ELEMENTS=t.PRESERVE_ELEMENTS=t.BLOCK_ELEMENTS=t.MOBILE_WIDTH=t.ENTRY_POINT_ELEMENTS=void 0,t.ENTRY_POINT_ELEMENTS=["article",'[role="article"]',".post-content",".article-content","#article-content",".content-article","main",'[role="main"]',"body"],t.MOBILE_WIDTH=600,t.BLOCK_ELEMENTS=["div","section","article","main"],t.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"]),t.INLINE_ELEMENTS=new Set(["a","span","strong","em","i","b","u","code","br","small","sub","sup","mark","del","ins","q","abbr","cite","time"]),t.HIDDEN_ELEMENT_SELECTORS=["[hidden]",'[style*="visibility: hidden"]','[style*="visibility:hidden"]',".hidden",".invisible"].join(","),t.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]',".promo",".Promo","#barrier-page",'[id="comments" i]',"header",".header","#header","nav",".navigation","#navigation",'[role="navigation" i]','[role="dialog" i]','[role*="complementary" i]','[class*="pagination" i]',".menu","#menu","#siteSub",".author",".Author",".contributor",".date","[data-date]",".meta",".tags",".toc",".Toc","#toc","#title","#Title","#articleTag",'[href*="/category"]','[href*="/categories"]','[href*="/tag/"]','[href*="/tags/"]','[href*="/topics"]','[href*="author"]','[href="#top"]','[href="#Top"]','[href="#site-content"]','[src*="author"]',"footer","aside","button","canvas","dialog","fieldset","form",'input:not([type="checkbox"])',"label","option","select","textarea","time","instaread-player",'iframe:not([src*="youtube"]):not([src*="youtu.be"]):not([src*="vimeo"]):not([src*="twitter"])','[class="logo" i]',"#logo","#Logo","#newsletter","#Newsletter",".noprint",'[data-link-name*="skip" i]','[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]','[data-container*="most-viewed" i]',".sidebar",".Sidebar","#sidebar","#Sidebar","#sitesub",".gutter","#primaryaudio","#NYT_ABOVE_MAIN_CONTENT_REGION",'[data-testid="photoviewer-children-figure"] > span',"table.infobox",".pencraft:not(.pc-display-contents)",'[data-optimizely="related-articles-section" i]'],t.PARTIAL_SELECTORS=["access-wall","activitypub","actioncall","appendix","avatar","advert","ad-placement","_ad_","allterms","alert-box","around-the-web","article-bottom-section","article-bottom","article-citation","article__copy","article_date","article-end ","article_header","article-header","article__header","article__info","article-info","article-meta","article_meta","article__meta","article-subject","article_subject","article-snippet","article-separator","article--share","article--topics","articletags","article-tags","article_tags","article-title","article_title","articletopics","article-topics","article-type","article--lede","articlewell","associated-people","audio-card","authored-by","author-box","author-info","author-name","author-bio","author-mini-bio","back-to-top","backlinks-section","banner","bio-block","blog-pager","bookmark-","-bookmark","bottom-of-article","brand-bar","breadcrumb","button-wrapper","btn-","-btn","byline","captcha","card-text","card-media","cat_header","catlinks","chapter-list","collections","comments","commentbox","comment-count","comment-content","comment-form","comment-number","comment-respond","comment-thread","complementary","consent","content-card","content-topics","contentpromo","context-bar","context-widget","core-collateral","creative-commons_","_cta","-cta","cta-","cta_","current-issue","custom-list-number","dateline","dateheader","date-header","date_header-","disclaimer","disclosure","discussion","discuss_","disqus","donate","dropdown","eletters","emailsignup","engagement-widget","entry-author-info","entry-categories","entry-date","entry-meta","entry-title","entry-utility","eyebrow","expand-reduce","externallinkembedwrapper","extra-services","extra-title","facebook","favorite","feedback","feed-links","field-site-sections","fixed","floating-vid","follow","footer","footnote-back","footnoteback","for-you","frontmatter","further-reading","gist-meta","google","goog-","graph-view","header-logo","header-pattern","hero-list","hide-for-print","hide-print","hide-when-no-script","hidden-sidenote","hidden-accessibility","interlude","interaction","jumplink","jump-to-","kicker","labstab","-labels","language-name","latest-content","-ledes-","-license","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","marketing","media-inquiry","menu-","metadata","might-like","more-about","_modal","-modal","more-","morenews","morestories","move-helper","mw-editsection","mw-cite-backlink","mw-indicators","mw-jump-link","nav-","nav_","navbar","next-","newsgallery","news-story-title","newsletter_","newsletter-form","newsletter-signup","newslettersignup","newsletterwidget","newsletterwrapper","not-found","nomobile","noprint","originally-published","outline-view","overlay","page-title","paywall_message","-partners","plea","popular","pop-up","popover","post-bottom","post__category","postcomment","postdate","post-author","post-date","post_date","post-feeds","postinfo","post-info","post_info","post-inline-date","post-links","post-meta","postmeta","postsnippet","post_snippet","post-snippet","posttitle","post-title","post_title","post__title","posttax","post-tax","post_tax","posttag","post_tag","post-tag","prevnext","previousnext","press-inquiries","print-none","print-header","profile","promo_article","promo-box","pubdate","pub_date","pub-date","publication-date","publicationName","qr-code","qr_code","_rail","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","screen-reader-text","share-box","sharedaddy","share-icons","sharelinks","share-section","sidebartitle","sidebar_","sidebar-content","similar-","similar_","similars-","sideitems","sidebar-author","sidebar-item","side-box","site-index","site-header","site-logo","site-name","skip-content","c-skip-link","_skip-link","slug-wrap","social","speechify-ignore","sponsor","springercitation","_stats","storyreadtime","storypublishdate","subject-label","subscribe","_tags","tags__item","tag_list","taxonomy","table-content","table-of-contents","tabs-","terminaltout","time-rubric","timestamp","tip_off","tiptout","-tout-","-toc","toggle-caption","topic-list","toolbar","tooltip","top-wrapper","tree-item","trending","trust-feat","trust-badge","twitter","u-hide","visually-hidden","welcomebox"],t.FOOTNOTE_INLINE_REFERENCES=["sup.reference","cite.ltx_cite",'sup[id^="fnr"]','sup[id^="fnref:"]',"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"]'].join(","),t.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"]'].join(","),t.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"]),t.ALLOWED_ATTRIBUTES=new Set(["alt","allow","allowfullscreen","aria-label","checked","colspan","controls","data-latex","data-src","data-srcset","data-lang","dir","display","frameborder","headers","height","href","lang","role","rowspan","src","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"]),t.ALLOWED_ATTRIBUTES_DEBUG=new Set(["class","id"]),t.SUPPORTED_LANGUAGES=new Set(["markup","html","xml","svg","mathml","ssml","atom","rss","javascript","js","jsx","typescript","ts","tsx","webassembly","wasm","python","java","csharp","cs","dotnet","aspnet","cpp","c++","c","objc","ruby","rb","php","golang","rust","swift","kotlin","scala","dart","bash","shell","sh","powershell","batch","json","jsonp","yaml","yml","toml","dockerfile","gitignore","sql","mysql","postgresql","graphql","mongodb","sparql","markdown","md","latex","tex","asciidoc","adoc","jsdoc","haskell","hs","elm","elixir","erlang","ocaml","fsharp","scheme","lisp","elisp","clojure","matlab","fortran","cobol","pascal","perl","lua","julia","groovy","crystal","nim","zig","regex","gradle","cmake","makefile","nix","terraform","solidity","glsl","hlsl","nasm","masm","armasm","gdscript","unrealscript","abap","actionscript","ada","agda","antlr4","applescript","arduino","coffeescript","django","erlang","fortran","haxe","idris","kotlin","livescript","matlab","nginx","pascal","prolog","puppet","scala","scheme","tcl","verilog","vhdl"])},648:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.mathSelectors=t.isBlockDisplay=t.getBasicLatexFromElement=t.getMathMLFromElement=void 0;t.getMathMLFromElement=e=>{if("math"===e.tagName.toLowerCase()){const t="block"===e.getAttribute("display");return{mathml:e.outerHTML,latex:e.getAttribute("alttext")||null,isBlock:t}}const t=e.getAttribute("data-mathml");if(t){const e=document.createElement("div");e.innerHTML=t;const r=e.querySelector("math");if(r){const e="block"===r.getAttribute("display");return{mathml:r.outerHTML,latex:r.getAttribute("alttext")||null,isBlock:e}}}const r=e.querySelector(".MJX_Assistive_MathML, mjx-assistive-mml");if(r){const e=r.querySelector("math");if(e){const t=e.getAttribute("display"),o=r.getAttribute("display"),n="block"===t||"block"===o;return{mathml:e.outerHTML,latex:e.getAttribute("alttext")||null,isBlock:n}}}const o=e.querySelector(".katex-mathml math");return o?{mathml:o.outerHTML,latex:null,isBlock:!1}:null};t.getBasicLatexFromElement=e=>{var t,r,o;const n=e.getAttribute("data-latex");if(n)return n;if(e instanceof HTMLImageElement&&e.classList.contains("latex")){const t=e.getAttribute("alt");if(t)return t;const r=e.getAttribute("src");if(r){const e=r.match(/latex\.php\?latex=([^&]+)/);if(e)return decodeURIComponent(e[1]).replace(/\+/g," ").replace(/%5C/g,"\\")}}const a=e.querySelector('annotation[encoding="application/x-tex"]');if(null==a?void 0:a.textContent)return a.textContent.trim();if(e.matches(".katex")){const t=e.querySelector('.katex-mathml annotation[encoding="application/x-tex"]');if(null==t?void 0:t.textContent)return t.textContent.trim()}if(e.matches('script[type="math/tex"]')||e.matches('script[type="math/tex; mode=display"]'))return(null===(t=e.textContent)||void 0===t?void 0:t.trim())||null;if(e.parentElement){const t=e.parentElement.querySelector('script[type="math/tex"], script[type="math/tex; mode=display"]');if(t)return(null===(r=t.textContent)||void 0===r?void 0:r.trim())||null}return e.getAttribute("alt")||(null===(o=e.textContent)||void 0===o?void 0:o.trim())||null};t.isBlockDisplay=e=>{if("block"===e.getAttribute("display"))return!0;const t=e.className.toLowerCase();if(t.includes("display")||t.includes("block"))return!0;if(e.closest('.katex-display, .MathJax_Display, [data-display="block"]'))return!0;const r=e.previousElementSibling;if("p"===(null==r?void 0:r.tagName.toLowerCase()))return!0;if(e.matches(".mwe-math-fallback-image-display"))return!0;if(e.matches(".katex"))return null!==e.closest(".katex-display");if(e.hasAttribute("display"))return"true"===e.getAttribute("display");if(e.matches('script[type="math/tex; mode=display"]'))return!0;if(e.hasAttribute("display"))return"true"===e.getAttribute("display");const o=e.closest("[display]");return!!o&&"true"===o.getAttribute("display")},t.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(",")},826:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.mathStandardizationRules=t.createCleanMathEl=void 0;const o=r(648);t.createCleanMathEl=(e,t,r)=>{const o=document.createElement("math");if(o.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),o.setAttribute("display",r?"block":"inline"),o.setAttribute("data-latex",t||""),null==e?void 0:e.mathml){const t=document.createElement("div");t.innerHTML=e.mathml;const r=t.querySelector("math");r&&(o.innerHTML=r.innerHTML)}else t&&(o.textContent=t);return o},t.mathStandardizationRules=[{selector:o.mathSelectors,element:"math",transform:e=>{if(!(e instanceof HTMLElement))return e;const r=(0,o.getMathMLFromElement)(e),n=(0,o.getBasicLatexFromElement)(e),a=(0,o.isBlockDisplay)(e),i=(0,t.createCleanMathEl)(r,n,a);if(e.parentElement){e.parentElement.querySelectorAll('\n\t\t\t\t\t/* MathJax scripts and previews */\n\t\t\t\t\tscript[type^="math/"],\n\t\t\t\t\t.MathJax_Preview,\n\n\t\t\t\t\t/* External math library scripts */\n\t\t\t\t\tscript[type="text/javascript"][src*="mathjax"],\n\t\t\t\t\tscript[type="text/javascript"][src*="katex"]\n\t\t\t\t').forEach((e=>e.remove()))}return i}}]}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.Defuddle=void 0;var t=r(628);Object.defineProperty(e,"Defuddle",{enumerable:!0,get:function(){return t.Defuddle}})})(),o})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Defuddle=t():e.Defuddle=t()}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var e={608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MetadataExtractor=void 0;t.MetadataExtractor=class{static extract(e,t){var r,o;let n="",a="";try{a=(null===(r=e.location)||void 0===r?void 0:r.href)||"",a||(a=this.getMetaContent(e,"property","og:url")||this.getMetaContent(e,"property","twitter:url")||this.getSchemaProperty(e,t,"url")||this.getSchemaProperty(e,t,"mainEntityOfPage.url")||this.getSchemaProperty(e,t,"mainEntity.url")||this.getSchemaProperty(e,t,"WebSite.url")||(null===(o=e.querySelector('link[rel="canonical"]'))||void 0===o?void 0:o.getAttribute("href"))||""),a&&(n=new URL(a).hostname.replace(/^www\./,""))}catch(t){const r=e.querySelector("base[href]");if(r)try{a=r.getAttribute("href")||"",n=new URL(a).hostname.replace(/^www\./,"")}catch(e){console.warn("Failed to parse base URL:",e)}}return{title:this.getTitle(e,t),description:this.getDescription(e,t),domain:n,favicon:this.getFavicon(e,a),image:this.getImage(e,t),published:this.getPublished(e,t),author:this.getAuthor(e,t),site:this.getSite(e,t),schemaOrgData:t,wordCount:0,parseTime:0}}static getAuthor(e,t){return this.getMetaContent(e,"name","sailthru.author")||this.getSchemaProperty(e,t,"author.name")||this.getMetaContent(e,"property","author")||this.getMetaContent(e,"name","byl")||this.getMetaContent(e,"name","author")||this.getMetaContent(e,"name","authorList")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(e,t,"copyrightHolder.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(e,t,"publisher.name")||this.getSchemaProperty(e,t,"sourceOrganization.name")||this.getSchemaProperty(e,t,"isPartOf.name")||this.getMetaContent(e,"name","twitter:creator")||this.getMetaContent(e,"name","application-name")||""}static getSite(e,t){return this.getSchemaProperty(e,t,"publisher.name")||this.getMetaContent(e,"property","og:site_name")||this.getSchemaProperty(e,t,"WebSite.name")||this.getSchemaProperty(e,t,"sourceOrganization.name")||this.getMetaContent(e,"name","copyright")||this.getSchemaProperty(e,t,"copyrightHolder.name")||this.getSchemaProperty(e,t,"isPartOf.name")||this.getMetaContent(e,"name","application-name")||this.getAuthor(e,t)||""}static getTitle(e,t){var r,o;const n=this.getMetaContent(e,"property","og:title")||this.getMetaContent(e,"name","twitter:title")||this.getSchemaProperty(e,t,"headline")||this.getMetaContent(e,"name","title")||this.getMetaContent(e,"name","sailthru.title")||(null===(o=null===(r=e.querySelector("title"))||void 0===r?void 0:r.textContent)||void 0===o?void 0:o.trim())||"";return this.cleanTitle(n,this.getSite(e,t))}static cleanTitle(e,t){if(!e||!t)return e;const r=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=[`\\s*[\\|\\-\u2013\u2014]\\s*${r}\\s*$`,`^\\s*${r}\\s*[\\|\\-\u2013\u2014]\\s*`];for(const t of o){const r=new RegExp(t,"i");if(r.test(e)){e=e.replace(r,"");break}}return e.trim()}static getDescription(e,t){return this.getMetaContent(e,"name","description")||this.getMetaContent(e,"property","description")||this.getMetaContent(e,"property","og:description")||this.getSchemaProperty(e,t,"description")||this.getMetaContent(e,"name","twitter:description")||this.getMetaContent(e,"name","sailthru.description")||""}static getImage(e,t){return this.getMetaContent(e,"property","og:image")||this.getMetaContent(e,"name","twitter:image")||this.getSchemaProperty(e,t,"image.url")||this.getMetaContent(e,"name","sailthru.image.full")||""}static getFavicon(e,t){var r,o;const n=this.getMetaContent(e,"property","og:image:favicon");if(n)return n;const a=null===(r=e.querySelector("link[rel='icon']"))||void 0===r?void 0:r.getAttribute("href");if(a)return a;const i=null===(o=e.querySelector("link[rel='shortcut icon']"))||void 0===o?void 0:o.getAttribute("href");if(i)return i;if(t)try{return new URL("/favicon.ico",t).href}catch(e){console.warn("Failed to construct favicon URL:",e)}return""}static getPublished(e,t){return this.getSchemaProperty(e,t,"datePublished")||this.getMetaContent(e,"name","publishDate")||this.getMetaContent(e,"property","article:published_time")||this.getTimeElement(e)||this.getMetaContent(e,"name","sailthru.date")||""}static getMetaContent(e,t,r){var o,n;const a=`meta[${t}]`,i=Array.from(e.querySelectorAll(a)).find((e=>{var o;return(null===(o=e.getAttribute(t))||void 0===o?void 0:o.toLowerCase())===r.toLowerCase()})),s=i&&null!==(n=null===(o=i.getAttribute("content"))||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(s,e)}static getTimeElement(e){var t,r,o,n;const a=Array.from(e.querySelectorAll("time"))[0],i=a&&null!==(n=null!==(r=null===(t=a.getAttribute("datetime"))||void 0===t?void 0:t.trim())&&void 0!==r?r:null===(o=a.textContent)||void 0===o?void 0:o.trim())&&void 0!==n?n:"";return this.decodeHTMLEntities(i,e)}static decodeHTMLEntities(e,t){const r=t.createElement("textarea");return r.innerHTML=e,r.value}static getSchemaProperty(e,t,r,o=""){if(!t)return o;const n=(e,t,r,o=!0)=>{if("string"==typeof e)return 0===t.length?[e]:[];if(!e||"object"!=typeof e)return[];if(Array.isArray(e)){const a=t[0];if(/^\[\d+\]$/.test(a)){const i=parseInt(a.slice(1,-1));return e[i]?n(e[i],t.slice(1),r,o):[]}return 0===t.length&&e.every((e=>"string"==typeof e||"number"==typeof e))?e.map(String):e.flatMap((e=>n(e,t,r,o)))}const[a,...i]=t;if(!a)return"string"==typeof e?[e]:"object"==typeof e&&e.name?[e.name]:[];if(e.hasOwnProperty(a))return n(e[a],i,r?`${r}.${a}`:a,!0);if(!o){const o=[];for(const a in e)if("object"==typeof e[a]){const i=n(e[a],t,r?`${r}.${a}`:a,!1);o.push(...i)}if(o.length>0)return o}return[]};try{let a=n(t,r.split("."),"",!0);0===a.length&&(a=n(t,r.split("."),"",!1));const i=a.length>0?a.filter(Boolean).join(", "):o;return this.decodeHTMLEntities(i,e)}catch(e){return console.error(`Error in getSchemaProperty for ${r}:`,e),o}}static extractSchemaOrgData(e){const t=e.querySelectorAll('script[type="application/ld+json"]'),r=[];return t.forEach((e=>{let t=e.textContent||"";try{t=t.replace(/\/\*[\s\S]*?\*\/|^\s*\/\/.*$/gm,"").replace(/^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/,"$1").replace(/^\s*(\*\/|\/\*)\s*|\s*(\*\/|\/\*)\s*$/g,"").trim();const e=JSON.parse(t);e["@graph"]&&Array.isArray(e["@graph"])?r.push(...e["@graph"]):r.push(e)}catch(e){console.error("Error parsing schema.org data:",e),console.error("Problematic JSON content:",t)}})),r}}},628:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Defuddle=void 0;const o=r(608),n=r(640),a=[...r(826).mathStandardizationRules,{selector:"pre",element:"pre",transform:e=>{if(!(e instanceof HTMLElement))return e;const t=e=>{const t=e.getAttribute("data-lang")||e.getAttribute("data-language");if(t)return t.toLowerCase();const r=[/^language-(\w+)$/,/^lang-(\w+)$/,/^(\w+)-code$/,/^code-(\w+)$/,/^syntax-(\w+)$/,/^code-snippet__(\w+)$/,/^highlight-(\w+)$/,/^(\w+)-snippet$/];if(e.className&&"string"==typeof e.className){for(const t of r){const r=e.className.toLowerCase().match(t);if(r)return r[1].toLowerCase()}if(n.SUPPORTED_LANGUAGES.has(e.className.toLowerCase()))return e.className.toLowerCase()}const o=Array.from(e.classList);for(const e of o)for(const t of r){const r=e.match(t);if(r)return r[1].toLowerCase()}for(const e of o)if(n.SUPPORTED_LANGUAGES.has(e.toLowerCase()))return e.toLowerCase();return""};let r="",o=e;for(;o&&!r;)r=t(o),!r&&o.querySelector("code")&&(r=t(o.querySelector("code"))),o=o.parentElement;const a=e=>{if(e.nodeType===Node.TEXT_NODE)return e.textContent||"";let t="";if(e instanceof HTMLElement){if("BR"===e.tagName)return"\n";if(e.matches('div[class*="line"], span[class*="line"], .ec-line, [data-line-number], [data-line]')){const t=e.querySelector('.code, .content, [class*="code-"], [class*="content-"]');if(t)return(t.textContent||"")+"\n";const r=e.querySelector('.line-number, .gutter, [class*="line-number"], [class*="gutter"]');if(r){return Array.from(e.childNodes).filter((e=>!r.contains(e))).map((e=>a(e))).join("")+"\n"}return e.textContent+"\n"}e.childNodes.forEach((e=>{t+=a(e)}))}return t};let i=a(e);i=i.replace(/^\n+/,"").replace(/\n+$/,"").replace(/\n{3,}/g,"\n\n");const s=document.createElement("pre");Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&s.setAttribute(e.name,e.value)}));const l=document.createElement("code");return r&&(l.setAttribute("data-lang",r),l.setAttribute("class",`language-${r}`)),l.textContent=i,s.appendChild(l),s}},{selector:"h1, h2, h3, h4, h5, h6",element:"keep",transform:e=>{var t;const r=document.createElement(e.tagName);Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&r.setAttribute(e.name,e.value)}));const o=e.cloneNode(!0),a=new Map;Array.from(o.querySelectorAll("*")).forEach((e=>{var t,r,n,i,s,l;let c=!1;if(e instanceof HTMLAnchorElement){const r=e.getAttribute("href");((null==r?void 0:r.includes("#"))||(null==r?void 0:r.startsWith("#")))&&(a.set(e,(null===(t=e.textContent)||void 0===t?void 0:t.trim())||""),c=!0)}if(e.classList.contains("anchor")&&(a.set(e,(null===(r=e.textContent)||void 0===r?void 0:r.trim())||""),c=!0),e instanceof HTMLButtonElement&&(c=!0),(e instanceof HTMLSpanElement||e instanceof HTMLDivElement)&&e.querySelector('a[href^="#"]')){const t=e.querySelector('a[href^="#"]');t&&a.set(e,(null===(n=t.textContent)||void 0===n?void 0:n.trim())||""),c=!0}if(c){const t=e.parentElement;t&&t!==o&&(null===(i=t.textContent)||void 0===i?void 0:i.trim())===(null===(s=e.textContent)||void 0===s?void 0:s.trim())&&a.set(t,(null===(l=e.textContent)||void 0===l?void 0:l.trim())||"")}}));Array.from(o.querySelectorAll("*")).filter((e=>{if(e instanceof HTMLAnchorElement){const t=e.getAttribute("href");return(null==t?void 0:t.includes("#"))||(null==t?void 0:t.startsWith("#"))}return!!e.classList.contains("anchor")||(e instanceof HTMLButtonElement||!(!(e instanceof HTMLSpanElement||e instanceof HTMLDivElement)||!e.querySelector('a[href^="#"]')))})).forEach((e=>e.remove()));let i=(null===(t=o.textContent)||void 0===t?void 0:t.trim())||"";return!i&&a.size>0&&(i=Array.from(a.values())[0]),r.textContent=i,r}},{selector:'div[data-testid^="paragraph"], div[role="paragraph"]',element:"p",transform:e=>{const t=document.createElement("p");return t.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&t.setAttribute(e.name,e.value)})),t}},{selector:'div[role="list"]',element:"ul",transform:e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");return e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");if(r){r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)}));r.querySelectorAll('div[role="list"]').forEach((e=>{var t;const r=e.querySelector('div[role="listitem"] .label'),o=((null===(t=null==r?void 0:r.textContent)||void 0===t?void 0:t.trim())||"").match(/^\d+\)/),n=document.createElement(o?"ol":"ul");e.querySelectorAll('div[role="listitem"]').forEach((e=>{const t=document.createElement("li"),r=e.querySelector(".content");if(r){r.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t.innerHTML=r.innerHTML}n.appendChild(t)})),e.replaceWith(n)})),t.innerHTML=r.innerHTML}n.appendChild(t)})),n}},{selector:'div[role="listitem"]',element:"li",transform:e=>{const t=e.querySelector(".content");if(!t)return e;return t.querySelectorAll('div[role="paragraph"]').forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,e.replaceWith(t)})),t}},{selector:'div[class*="prismjs"], .wp-block-syntaxhighlighter-code, .syntaxhighlighter, .highlight, .highlight-source, .wp-block-code, pre[class*="language-"], pre[class*="brush:"]',element:"pre",transform:e=>{if(!(e instanceof HTMLElement))return e;const t=document.createElement("pre");let r="";const o=e.querySelector(".syntaxhighlighter");if(o){const e=Array.from(o.classList).find((e=>!["syntaxhighlighter","nogutter"].includes(e)));e&&n.SUPPORTED_LANGUAGES.has(e.toLowerCase())&&(r=e.toLowerCase())}if(!r){const t=Array.from(e.classList),o=[/(?:^|\s)(?:language|lang|brush|syntax)-(\w+)(?:\s|$)/i,/(?:^|\s)(\w+)(?:\s|$)/i];for(const e of t){for(const t of o){const o=e.match(t);if(o&&o[1]&&n.SUPPORTED_LANGUAGES.has(o[1].toLowerCase())){r=o[1].toLowerCase();break}}if(r)break}}let a="";const i=e.querySelector(".syntaxhighlighter table .code .container");if(i){a=Array.from(i.children).map((e=>{const t=Array.from(e.querySelectorAll("code")).map((e=>{let t=e.textContent||"";return e.classList.contains("spaces")&&(t=" ".repeat(t.length)),t})).join("");return t||e.textContent||""})).join("\n")}else{const t=e.querySelectorAll(".code .line");a=t.length>0?Array.from(t).map((e=>{const t=Array.from(e.querySelectorAll("code")).map((e=>e.textContent||"")).join("");return t||e.textContent||""})).join("\n"):e.textContent||""}a=a.replace(/^\s+|\s+$/g,"").replace(/\t/g," ").replace(/\n{3,}/g,"\n\n").replace(/\u00a0/g," ");const s=document.createElement("code");return r&&(s.setAttribute("data-lang",r),s.setAttribute("class",`language-${r}`)),s.textContent=a,t.appendChild(s),t}}];t.Defuddle=class{constructor(e,t={}){this.doc=e,this.options=t,this.debug=t.debug||!1}parse(){const e=performance.now(),t=o.MetadataExtractor.extractSchemaOrgData(this.doc),r=o.MetadataExtractor.extract(this.doc,t);try{const t=this._evaluateMediaQueries(this.doc),o=this.findSmallImages(this.doc),n=this.doc.cloneNode(!0);this.applyMobileStyles(n,t);const a=this.findMainContent(n);if(!a){const t=performance.now();return Object.assign(Object.assign({content:this.doc.body.innerHTML},r),{wordCount:this.countWords(this.doc.body.innerHTML),parseTime:Math.round(t-e)})}this.removeSmallImages(n,o),this.removeHiddenElements(n),this.removeClutter(n),this.cleanContent(a,r);const i=a?a.outerHTML:this.doc.body.innerHTML,s=performance.now();return Object.assign(Object.assign({content:i},r),{wordCount:this.countWords(i),parseTime:Math.round(s-e)})}catch(t){console.error("Defuddle","Error processing document:",t);const o=performance.now();return Object.assign(Object.assign({content:this.doc.body.innerHTML},r),{wordCount:this.countWords(this.doc.body.innerHTML),parseTime:Math.round(o-e)})}}countWords(e){const t=document.createElement("div");t.innerHTML=e;return(t.textContent||"").trim().replace(/\s+/g," ").split(" ").filter((e=>e.length>0)).length}_log(...e){this.debug&&console.log("Defuddle:",...e)}_evaluateMediaQueries(e){const t=[],r=/max-width[^:]*:\s*(\d+)/;try{const o=Array.from(e.styleSheets).filter((e=>{try{return e.cssRules,!0}catch(e){if(e instanceof DOMException&&"SecurityError"===e.name)return!1;throw e}}));o.flatMap((e=>{try{return Array.from(e.cssRules).filter((e=>e instanceof CSSMediaRule&&e.conditionText.includes("max-width")))}catch(e){return this.debug&&console.warn("Defuddle: Failed to process stylesheet:",e),[]}})).forEach((e=>{const o=e.conditionText.match(r);if(o){const r=parseInt(o[1]);if(n.MOBILE_WIDTH<=r){Array.from(e.cssRules).filter((e=>e instanceof CSSStyleRule)).forEach((e=>{try{t.push({selector:e.selectorText,styles:e.style.cssText})}catch(e){this.debug&&console.warn("Defuddle: Failed to process CSS rule:",e)}}))}}}))}catch(e){console.error("Defuddle: Error evaluating media queries:",e)}return t}applyMobileStyles(e,t){t.forEach((({selector:t,styles:r})=>{try{e.querySelectorAll(t).forEach((e=>{e.setAttribute("style",(e.getAttribute("style")||"")+r)}))}catch(e){console.error("Defuddle","Error applying styles for selector:",t,e)}}))}removeHiddenElements(e){let t=0;const r=new Set,o=e.querySelectorAll(n.HIDDEN_ELEMENT_SELECTORS);o.forEach((e=>r.add(e))),t+=o.length;const a=e.createTreeWalker(e.body,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>r.has(e)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),i=[];let s;for(;s=a.nextNode();)i.push(s);for(let e=0;e<i.length;e+=100){const o=i.slice(e,e+100),n=o.map((e=>window.getComputedStyle(e)));o.forEach(((e,o)=>{const a=n[o];"none"!==a.display&&"hidden"!==a.visibility&&"0"!==a.opacity||(r.add(e),t++)}))}r.forEach((e=>e.remove())),this._log("Removed hidden elements:",t)}removeClutter(e){const t=performance.now();let r=0,o=0;const a=new Set;e.querySelectorAll(n.EXACT_SELECTORS.join(",")).forEach((e=>{(null==e?void 0:e.parentNode)&&(a.add(e),r++)}));const i=n.PARTIAL_SELECTORS.join("|"),s=new RegExp(i,"i"),l=n.TEST_ATTRIBUTES.map((e=>`[${e}]`)).join(",");e.querySelectorAll(l).forEach((e=>{if(a.has(e))return;const t=n.TEST_ATTRIBUTES.map((t=>"class"===t?e.className&&"string"==typeof e.className?e.className:"":"id"===t?e.id||"":e.getAttribute(t)||"")).join(" ").toLowerCase();t.trim()&&s.test(t)&&(a.add(e),o++)})),a.forEach((e=>e.remove()));const c=performance.now();this._log("Removed clutter elements:",{exactSelectors:r,partialSelectors:o,total:a.size,processingTime:`${(c-t).toFixed(2)}ms`})}flattenDivs(e){let t=0;const r=performance.now();let o=!0;const a=e=>{const t=e.tagName.toLowerCase();if(n.PRESERVE_ELEMENTS.has(t))return!0;const r=e.getAttribute("role");if(r&&["article","main","navigation","banner","contentinfo"].includes(r))return!0;if(e.className.toLowerCase().match(/(?:article|main|content|footnote|reference|bibliography)/))return!0;if("div"===t){if(Array.from(e.children).some((e=>n.PRESERVE_ELEMENTS.has(e.tagName.toLowerCase())||"article"===e.getAttribute("role")||e.className.toLowerCase().includes("article"))))return!0}return!1},i=e=>{var t;if(!(null===(t=e.textContent)||void 0===t?void 0:t.trim()))return!0;const r=Array.from(e.children);if(0===r.length)return!0;if(r.every((e=>{const t=e.tagName.toLowerCase();return"div"===t||"p"===t||"h1"===t||"h2"===t||"h3"===t||"h4"===t||"h5"===t||"h6"===t||"ul"===t||"ol"===t||"pre"===t||"blockquote"===t||"figure"===t})))return!0;const o=e.className.toLowerCase();if(/(?:wrapper|container|layout|row|col|grid|flex|outer|inner|content-area)/i.test(o))return!0;const a=Array.from(e.childNodes).filter((e=>{var t;return e.nodeType===Node.TEXT_NODE&&(null===(t=e.textContent)||void 0===t?void 0:t.trim())}));if(0===a.length)return!0;return!(!(r.length>0)||r.some((e=>{const t=e.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(t)})))},s=r=>{var o,s;if(!r.isConnected||a(r))return!1;if(!r.hasChildNodes()||!(null===(o=r.textContent)||void 0===o?void 0:o.trim()))return r.remove(),t++,!0;if(r.parentElement===e){const e=Array.from(r.children);if(e.length>0&&!e.some((e=>{const t=e.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(t)}))){const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}}if(i(r)){if(!Array.from(r.children).some((e=>{const t=e.tagName.toLowerCase();return n.INLINE_ELEMENTS.has(t)}))){const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}if(!r.children.length&&(null===(s=r.textContent)||void 0===s?void 0:s.trim())){const e=document.createElement("p");return e.textContent=r.textContent,r.replaceWith(e),t++,!0}if(1===r.children.length){const e=r.firstElementChild,o=e.tagName.toLowerCase();if(!n.INLINE_ELEMENTS.has(o)&&!a(e))return r.replaceWith(e),t++,!0}let l=0,c=r.parentElement;for(;c;)"div"===c.tagName.toLowerCase()&&l++,c=c.parentElement;if(l>0){const e=document.createDocumentFragment();for(;r.firstChild;)e.appendChild(r.firstChild);return r.replaceWith(e),t++,!0}return!1},l=()=>{const t=Array.from(e.children).filter((e=>"div"===e.tagName.toLowerCase()));let r=!1;return t.forEach((e=>{s(e)&&(r=!0)})),r},c=()=>{const t=Array.from(e.getElementsByTagName("div")).sort(((e,t)=>{const r=e=>{let t=0,r=e.parentElement;for(;r;)"div"===r.tagName.toLowerCase()&&t++,r=r.parentElement;return t};return r(t)-r(e)}));let r=!1;return t.forEach((e=>{s(e)&&(r=!0)})),r},d=()=>{const r=Array.from(e.getElementsByTagName("div"));let o=!1;return r.forEach((e=>{if(Array.from(e.children).every((e=>"p"===e.tagName.toLowerCase()))||!a(e)&&i(e)){const r=document.createDocumentFragment();for(;e.firstChild;)r.appendChild(e.firstChild);e.replaceWith(r),t++,o=!0}})),o};do{o=!1,l()&&(o=!0),c()&&(o=!0),d()&&(o=!0)}while(o);const m=performance.now();this._log("Flattened divs:",{count:t,processingTime:`${(m-r).toFixed(2)}ms`})}cleanContent(e,t){this.standardizeSpaces(e),this.removeHtmlComments(e),this.standardizeHeadings(e,t.title),this.standardizeFootnotes(e),this.handleLazyImages(e),this.standardizeElements(e),this.debug?(this.stripUnwantedAttributes(e),this.removeEmptyElements(e),this.removeTrailingHeadings(e),this._log("Debug mode: Skipping div flattening to preserve structure")):(this.flattenDivs(e),this.stripUnwantedAttributes(e),this.removeEmptyElements(e),this.removeTrailingHeadings(e),this.flattenDivs(e),this.removeEmptyLines(e))}standardizeSpaces(e){const t=e=>{if(e instanceof Element){const t=e.tagName.toLowerCase();if("pre"===t||"code"===t)return}if(e.nodeType===Node.TEXT_NODE){const t=e.textContent||"",r=t.replace(/\xA0+/g,(t=>{var r,o,n,a;if(1===t.length){const t=null===(o=null===(r=e.previousSibling)||void 0===r?void 0:r.textContent)||void 0===o?void 0:o.slice(-1),i=null===(a=null===(n=e.nextSibling)||void 0===n?void 0:n.textContent)||void 0===a?void 0:a.charAt(0);if((null==t?void 0:t.match(/\w/))&&(null==i?void 0:i.match(/\w/)))return"\xa0"}return" ".repeat(t.length)}));r!==t&&(e.textContent=r)}e.hasChildNodes()&&Array.from(e.childNodes).forEach(t)};t(e)}removeTrailingHeadings(e){let t=0;const r=t=>{let o="",n=t.nextSibling;for(;n;)(n.nodeType===Node.TEXT_NODE||n.nodeType===Node.ELEMENT_NODE)&&(o+=n.textContent||""),n=n.nextSibling;if(o.trim())return!0;const a=t.parentElement;return!(!a||a===e)&&r(a)};Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6")).reverse().forEach((e=>{r(e)||(e.remove(),t++)})),t>0&&this._log("Removed trailing headings:",t)}standardizeHeadings(e,t){const r=e=>e.replace(/\u00A0/g," ").replace(/\s+/g," ").trim().toLowerCase(),o=e.getElementsByTagName("h1");Array.from(o).forEach((e=>{var t;const r=document.createElement("h2");r.innerHTML=e.innerHTML,Array.from(e.attributes).forEach((e=>{n.ALLOWED_ATTRIBUTES.has(e.name)&&r.setAttribute(e.name,e.value)})),null===(t=e.parentNode)||void 0===t||t.replaceChild(r,e)}));const a=e.getElementsByTagName("h2");if(a.length>0){const e=a[0],o=r(e.textContent||""),n=r(t);n&&n===o&&e.remove()}}removeHtmlComments(e){const t=[],r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT,null);let o;for(;o=r.nextNode();)t.push(o);t.forEach((e=>{e.remove()})),this._log("Removed HTML comments:",t.length)}stripUnwantedAttributes(e){let t=0;const r=e=>{if(e instanceof SVGElement)return;const r=Array.from(e.attributes),o=e.tagName.toLowerCase();r.forEach((r=>{const a=r.name.toLowerCase(),i=r.value;"id"===a&&(i.startsWith("fnref:")||i.startsWith("fn:"))||"class"===a&&"code"===o&&i.startsWith("language-")||(this.debug?n.ALLOWED_ATTRIBUTES.has(a)||n.ALLOWED_ATTRIBUTES_DEBUG.has(a)||a.startsWith("data-")||(e.removeAttribute(r.name),t++):n.ALLOWED_ATTRIBUTES.has(a)||(e.removeAttribute(r.name),t++))}))};r(e),e.querySelectorAll("*").forEach(r),this._log("Stripped attributes:",t)}removeEmptyElements(e){let t=0,r=0,o=!0;for(;o;){r++,o=!1;const a=Array.from(e.getElementsByTagName("*")).filter((e=>{if(n.ALLOWED_EMPTY_ELEMENTS.has(e.tagName.toLowerCase()))return!1;const t=e.textContent||"",r=0===t.trim().length,o=t.includes("\xa0"),a=!e.hasChildNodes()||Array.from(e.childNodes).every((e=>{if(e.nodeType===Node.TEXT_NODE){const t=e.textContent||"";return 0===t.trim().length&&!t.includes("\xa0")}return!1}));if("div"===e.tagName.toLowerCase()){const t=Array.from(e.children);if(t.length>0&&t.every((e=>{var t;if("span"!==e.tagName.toLowerCase())return!1;const r=(null===(t=e.textContent)||void 0===t?void 0:t.trim())||"";return","===r||""===r||" "===r})))return!0}return r&&!o&&a}));a.length>0&&(a.forEach((e=>{e.remove(),t++})),o=!0)}this._log("Removed empty elements:",{count:t,iterations:r})}removeEmptyLines(e){let t=0;const r=performance.now(),o=e=>{var r;if(e instanceof Element){const t=e.tagName.toLowerCase();if("pre"===t||"code"===t)return}if(Array.from(e.childNodes).forEach(o),e.nodeType===Node.TEXT_NODE){const o=e.textContent||"";if(!o||o.match(/^[\u200C\u200B\u200D\u200E\u200F\uFEFF\xA0\s]*$/))null===(r=e.parentNode)||void 0===r||r.removeChild(e),t++;else{const r=o.replace(/\n{3,}/g,"\n\n").replace(/^[\n\r\t]+/,"").replace(/[\n\r\t]+$/,"").replace(/[ \t]*\n[ \t]*/g,"\n").replace(/[ \t]{3,}/g," ").replace(/^[ ]+$/," ").replace(/\s+([,.!?:;])/g,"$1").replace(/[\u200C\u200B\u200D\u200E\u200F\uFEFF]+/g,"").replace(/(?:\xA0){2,}/g,"\xa0");r!==o&&(e.textContent=r,t+=o.length-r.length)}}},n=e=>{if(!(e instanceof Element))return;const r=e.tagName.toLowerCase();if("pre"===r||"code"===r)return;Array.from(e.children).forEach(n),e.normalize();const o="block"===getComputedStyle(e).display,a=o?/^[\n\r\t \u200C\u200B\u200D\u200E\u200F\uFEFF\xA0]*$/:/^[\n\r\t\u200C\u200B\u200D\u200E\u200F\uFEFF]*$/,i=o?/^[\n\r\t \u200C\u200B\u200D\u200E\u200F\uFEFF\xA0]*$/:/^[\n\r\t\u200C\u200B\u200D\u200E\u200F\uFEFF]*$/;for(;e.firstChild&&e.firstChild.nodeType===Node.TEXT_NODE&&(e.firstChild.textContent||"").match(a);)e.removeChild(e.firstChild),t++;for(;e.lastChild&&e.lastChild.nodeType===Node.TEXT_NODE&&(e.lastChild.textContent||"").match(i);)e.removeChild(e.lastChild),t++;if(!o){const t=Array.from(e.childNodes);for(let r=0;r<t.length-1;r++){const o=t[r],n=t[r+1];if(o instanceof Element||n instanceof Element){const t=n.textContent||"",r=o.textContent||"";if(!t.match(/^[,.!?:;]/)&&!r.match(/[,.!?:;]$/)){if(!(o.nodeType===Node.TEXT_NODE&&(o.textContent||"").endsWith(" ")||n.nodeType===Node.TEXT_NODE&&(n.textContent||"").startsWith(" "))){const t=document.createTextNode(" ");e.insertBefore(t,n)}}}}}};o(e),n(e);const a=performance.now();this._log("Removed empty lines:",{charactersRemoved:t,processingTime:`${(a-r).toFixed(2)}ms`})}createFootnoteItem(e,t,r){const o=document.createElement("li");if(o.className="footnote",o.id=`fn:${e}`,"string"==typeof t){const e=document.createElement("p");e.innerHTML=t,o.appendChild(e)}else{const e=Array.from(t.querySelectorAll("p"));if(0===e.length){const e=document.createElement("p");e.innerHTML=t.innerHTML,o.appendChild(e)}else e.forEach((e=>{const t=document.createElement("p");t.innerHTML=e.innerHTML,o.appendChild(t)}))}const n=o.querySelector("p:last-of-type")||o;return r.forEach(((e,t)=>{const o=document.createElement("a");o.href=`#${e}`,o.title="return to article",o.className="footnote-backref",o.innerHTML="\u21a9",t<r.length-1&&(o.innerHTML+=" "),n.appendChild(o)})),o}collectFootnotes(e){const t={};let r=1;const o=new Set;return e.querySelectorAll(n.FOOTNOTE_LIST_SELECTORS).forEach((e=>{if(e.matches('div.footnote[data-component-name="FootnoteToDOM"]')){const n=e.querySelector("a.footnote-number"),a=e.querySelector(".footnote-content");if(n&&a){const e=n.id.replace("footnote-","").toLowerCase();e&&!o.has(e)&&(t[r]={content:a,originalId:e,refs:[]},o.add(e),r++)}return}e.querySelectorAll('li, div[role="listitem"]').forEach((e=>{var n,a,i,s;let l="",c=null;const d=e.querySelector(".citations");if(null===(n=null==d?void 0:d.id)||void 0===n?void 0:n.toLowerCase().startsWith("r")){l=d.id.toLowerCase();const e=d.querySelector(".citation-content");e&&(c=e)}else{if(e.id.toLowerCase().startsWith("bib.bib"))l=e.id.replace("bib.bib","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn:"))l=e.id.replace("fn:","").toLowerCase();else if(e.id.toLowerCase().startsWith("fn"))l=e.id.replace("fn","").toLowerCase();else if(e.hasAttribute("data-counter"))l=(null===(i=null===(a=e.getAttribute("data-counter"))||void 0===a?void 0:a.replace(/\.$/,""))||void 0===i?void 0:i.toLowerCase())||"";else{const t=null===(s=e.id.split("/").pop())||void 0===s?void 0:s.match(/cite_note-(.+)/);l=t?t[1].toLowerCase():e.id.toLowerCase()}c=e}l&&!o.has(l)&&(t[r]={content:c||e,originalId:l,refs:[]},o.add(l),r++)}))})),t}findOuterFootnoteContainer(e){let t=e,r=e.parentElement;for(;r&&("span"===r.tagName.toLowerCase()||"sup"===r.tagName.toLowerCase());)t=r,r=r.parentElement;return t}createFootnoteReference(e,t){const r=document.createElement("sup");r.id=t;const o=document.createElement("a");return o.href=`#fn:${e}`,o.textContent=e,r.appendChild(o),r}standardizeFootnotes(e){const t=this.collectFootnotes(e),r=e.querySelectorAll(n.FOOTNOTE_INLINE_REFERENCES),o=new Map;r.forEach((e=>{var r,n,a,i;if(!(e instanceof HTMLElement))return;let s="",l="";if(e.matches('a[id^="ref-link"]'))s=(null===(r=e.textContent)||void 0===r?void 0:r.trim())||"";else if(e.matches('a[role="doc-biblioref"]')){const t=e.getAttribute("data-xml-rid");if(t)s=t;else{const t=e.getAttribute("href");(null==t?void 0:t.startsWith("#core-R"))&&(s=t.replace("#core-",""))}}else if(e.matches("a.footnote-anchor, span.footnote-hovercard-target a")){const t=(null===(n=e.id)||void 0===n?void 0:n.replace("footnote-anchor-",""))||"";t&&(s=t.toLowerCase())}else if(e.matches("cite.ltx_cite")){const t=e.querySelector("a");if(t){const e=t.getAttribute("href");if(e){const t=null===(a=e.split("/").pop())||void 0===a?void 0:a.match(/bib\.bib(\d+)/);t&&(s=t[1].toLowerCase())}}}else if(e.matches("sup.reference")){const t=e.querySelectorAll("a");Array.from(t).forEach((e=>{var t;const r=e.getAttribute("href");if(r){const e=null===(t=r.split("/").pop())||void 0===t?void 0:t.match(/(?:cite_note|cite_ref)-(.+)/);e&&(s=e[1].toLowerCase())}}))}else if(e.matches('sup[id^="fnref:"]'))s=e.id.replace("fnref:","").toLowerCase();else if(e.matches('sup[id^="fnr"]'))s=e.id.replace("fnr","").toLowerCase();else if(e.matches("span.footnote-reference"))s=e.getAttribute("data-footnote-id")||"";else if(e.matches("span.footnote-link"))s=e.getAttribute("data-footnote-id")||"",l=e.getAttribute("data-footnote-content")||"";else if(e.matches("a.citation"))s=(null===(i=e.textContent)||void 0===i?void 0:i.trim())||"",l=e.getAttribute("href")||"";else if(e.matches('a[id^="fnref"]'))s=e.id.replace("fnref","").toLowerCase();else{const t=e.getAttribute("href");if(t){const e=t.replace(/^[#]/,"");s=e.toLowerCase()}}if(s){const r=Object.entries(t).find((([e,t])=>t.originalId===s.toLowerCase()));if(r){const[t,n]=r,a=n.refs.length>0?`fnref:${t}-${n.refs.length+1}`:`fnref:${t}`;n.refs.push(a);const i=this.findOuterFootnoteContainer(e);if("sup"===i.tagName.toLowerCase()){o.has(i)||o.set(i,[]);o.get(i).push(this.createFootnoteReference(t,a))}else i.replaceWith(this.createFootnoteReference(t,a))}}})),o.forEach(((e,t)=>{if(e.length>0){const r=document.createDocumentFragment();e.forEach(((e,t)=>{const o=e.querySelector("a");if(o){const t=document.createElement("sup");t.id=e.id,t.appendChild(o.cloneNode(!0)),r.appendChild(t)}})),t.replaceWith(r)}}));const a=document.createElement("footnotes");a.className="footnotes";const i=document.createElement("ol");Object.entries(t).forEach((([e,t])=>{const r=this.createFootnoteItem(parseInt(e),t.content,t.refs);i.appendChild(r)}));e.querySelectorAll(n.FOOTNOTE_LIST_SELECTORS).forEach((e=>e.remove())),i.children.length>0&&(a.appendChild(i),e.appendChild(a))}handleLazyImages(e){let t=0;e.querySelectorAll("img[data-src], img[data-srcset]").forEach((e=>{if(!(e instanceof HTMLImageElement))return;const r=e.getAttribute("data-src");r&&!e.src&&(e.src=r,t++);const o=e.getAttribute("data-srcset");o&&!e.srcset&&(e.srcset=o,t++),e.classList.remove("lazy","lazyload"),e.removeAttribute("data-ll-status"),e.removeAttribute("data-src"),e.removeAttribute("data-srcset")})),this._log("Processed lazy images:",t)}standardizeElements(e){let t=0;a.forEach((r=>{e.querySelectorAll(r.selector).forEach((e=>{if(r.transform){const o=r.transform(e);e.replaceWith(o),t++}}))}));e.querySelectorAll("lite-youtube").forEach((e=>{const r=e.getAttribute("videoid");if(!r)return;const o=document.createElement("iframe");o.width="560",o.height="315",o.src=`https://www.youtube.com/embed/${r}`,o.title=e.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",""),e.replaceWith(o),t++})),this._log("Converted embedded elements:",t)}findSmallImages(e){const t=new Set,r=/scale\(([\d.]+)\)/,o=performance.now();let n=0;const a=[...Array.from(e.getElementsByTagName("img")),...Array.from(e.getElementsByTagName("svg"))].filter((e=>{if(e instanceof HTMLImageElement){return!(e.classList.contains("lazy")||e.classList.contains("lazyload")||e.classList.contains("latex")||e.hasAttribute("decoding")||e.hasAttribute("data-src")||e.hasAttribute("data-srcset")||e.hasAttribute("loading"))}return!0}));if(0===a.length)return t;const i=a.map((e=>({element:e,naturalWidth:e instanceof HTMLImageElement?e.naturalWidth:0,naturalHeight:e instanceof HTMLImageElement?e.naturalHeight:0,attrWidth:parseInt(e.getAttribute("width")||"0"),attrHeight:parseInt(e.getAttribute("height")||"0")})));for(let e=0;e<i.length;e+=50){const o=i.slice(e,e+50);try{const e=o.map((({element:e})=>window.getComputedStyle(e))),a=o.map((({element:e})=>e.getBoundingClientRect()));o.forEach(((o,i)=>{var s;try{const l=e[i],c=a[i],d=l.transform,m=d?parseFloat((null===(s=d.match(r))||void 0===s?void 0:s[1])||"1"):1,u=[o.naturalWidth,o.attrWidth,parseInt(l.width)||0,c.width*m].filter((e=>"number"==typeof e&&e>0)),h=[o.naturalHeight,o.attrHeight,parseInt(l.height)||0,c.height*m].filter((e=>"number"==typeof e&&e>0));if(u.length>0&&h.length>0){const e=Math.min(...u),r=Math.min(...h);if(e<33||r<33){const e=this.getElementIdentifier(o.element);e&&(t.add(e),n++)}}}catch(e){this.debug&&console.warn("Defuddle: Failed to process element dimensions:",e)}}))}catch(e){this.debug&&console.warn("Defuddle: Failed to process batch:",e)}}const s=performance.now();return this._log("Found small elements:",{count:n,totalElements:a.length,processingTime:`${(s-o).toFixed(2)}ms`}),t}removeSmallImages(e,t){let r=0;["img","svg"].forEach((o=>{const n=e.getElementsByTagName(o);Array.from(n).forEach((e=>{const o=this.getElementIdentifier(e);o&&t.has(o)&&(e.remove(),r++)}))})),this._log("Removed small elements:",r)}getElementIdentifier(e){if(e instanceof HTMLImageElement){const t=e.getAttribute("data-src");if(t)return`src:${t}`;const r=e.src||"",o=e.srcset||"",n=e.getAttribute("data-srcset");if(r)return`src:${r}`;if(o)return`srcset:${o}`;if(n)return`srcset:${n}`}const t=e.id||"",r=e.className||"",o=e instanceof SVGElement&&e.getAttribute("viewBox")||"";return t?`id:${t}`:o?`viewBox:${o}`:r?`class:${r}`:null}findMainContent(e){const t=[];return n.ENTRY_POINT_ELEMENTS.forEach(((r,o)=>{e.querySelectorAll(r).forEach((e=>{let r=10*(n.ENTRY_POINT_ELEMENTS.length-o);r+=this.scoreElement(e),t.push({element:e,score:r})}))})),0===t.length?this.findContentByScoring(e):(t.sort(((e,t)=>t.score-e.score)),this.debug&&this._log("Content candidates:",t.map((e=>({element:e.element.tagName,selector:this.getElementSelector(e.element),score:e.score})))),t[0].element)}findContentByScoring(e){const t=this.scoreElements(e);return t.length>0?t[0].element:null}getElementSelector(e){const t=[];let r=e;for(;r&&r!==this.doc.documentElement;){let e=r.tagName.toLowerCase();r.id?e+="#"+r.id:r.className&&"string"==typeof r.className&&(e+="."+r.className.trim().split(/\s+/).join(".")),t.unshift(e),r=r.parentElement}return t.join(" > ")}scoreElements(e){const t=[];return n.BLOCK_ELEMENTS.forEach((r=>{Array.from(e.getElementsByTagName(r)).forEach((e=>{const r=this.scoreElement(e);r>0&&t.push({score:r,element:e})}))})),t.sort(((e,t)=>t.score-e.score))}scoreElement(e){let t=0;e.className&&"string"==typeof e.className&&e.className.toLowerCase(),e.id&&e.id.toLowerCase();const r=e.textContent||"",o=r.split(/\s+/).length;t+=Math.min(Math.floor(o/100),3);const n=e.getElementsByTagName("a"),a=Array.from(n).reduce(((e,t)=>{var r;return e+((null===(r=t.textContent)||void 0===r?void 0:r.length)||0)}),0);(r.length?a/r.length:0)>.5&&(t-=10);t+=e.getElementsByTagName("p").length;const i=e.getElementsByTagName("img").length;return t+=Math.min(3*i,9),t}}},640:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SUPPORTED_LANGUAGES=t.ALLOWED_ATTRIBUTES_DEBUG=t.ALLOWED_ATTRIBUTES=t.ALLOWED_EMPTY_ELEMENTS=t.FOOTNOTE_LIST_SELECTORS=t.FOOTNOTE_INLINE_REFERENCES=t.PARTIAL_SELECTORS=t.TEST_ATTRIBUTES=t.EXACT_SELECTORS=t.HIDDEN_ELEMENT_SELECTORS=t.INLINE_ELEMENTS=t.PRESERVE_ELEMENTS=t.BLOCK_ELEMENTS=t.MOBILE_WIDTH=t.ENTRY_POINT_ELEMENTS=void 0,t.ENTRY_POINT_ELEMENTS=["article",'[role="article"]',".post-content",".article-content","#article-content",".content-article","main",'[role="main"]',"body"],t.MOBILE_WIDTH=600,t.BLOCK_ELEMENTS=["div","section","article","main"],t.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"]),t.INLINE_ELEMENTS=new Set(["a","span","strong","em","i","b","u","code","br","small","sub","sup","mark","del","ins","q","abbr","cite","time"]),t.HIDDEN_ELEMENT_SELECTORS=["[hidden]",'[style*="visibility: hidden"]','[style*="visibility:hidden"]',".hidden",".invisible"].join(","),t.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]',".promo",".Promo","#barrier-page",'[id="comments" i]',"header",".header:not(.banner)","#header","#Header","#banner","#Banner","nav",".navigation","#navigation",'[role="navigation" i]','[role="dialog" i]','[role*="complementary" i]','[class*="pagination" i]',".menu","#menu","#siteSub",".fixed",".author",".Author",".contributor",".date","[data-date]",".meta",".tags",".toc",".Toc","#toc","#title","#Title","#articleTag",'[href*="/category"]','[href*="/categories"]','[href*="/tag/"]','[href*="/tags/"]','[href*="/topics"]','[href*="author"]','[href="#top"]','[href="#Top"]','[href="#site-content"]','[src*="author"]',"footer","aside","button","canvas","dialog","fieldset","form",'input:not([type="checkbox"])',"label","option","select","textarea","time","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",".noprint",'[data-link-name*="skip" i]','[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]','[data-container*="most-viewed" i]',".sidebar",".Sidebar","#sidebar","#Sidebar","#sitesub",".gutter","#primaryaudio","#NYT_ABOVE_MAIN_CONTENT_REGION",'[data-testid="photoviewer-children-figure"] > span',"table.infobox",".pencraft:not(.pc-display-contents)",'[data-optimizely="related-articles-section" i]'],t.TEST_ATTRIBUTES=["class","id","data-test","data-testid","data-test-id","data-qa","data-cy"],t.PARTIAL_SELECTORS=["access-wall","activitypub","actioncall","appendix","avatar","advert","ad-placement","_ad_","allterms","alert-box","around-the-web","aroundpages","article-author","article-bottom-section","article-bottom","article-category","article-citation","article__copy","article_date","article-end ","article_header","article-header","article__header","article__info","article-info","article-meta","article_meta","article__meta","article-subject","article_subject","article-snippet","article-separator","article--share","article--topics","articletags","article-tags","article_tags","article-title","article_title","articletopics","article-topics","article-type","article--lede","articlewell","associated-people","audio-card","authored-by","author-box","author-info","author-name","author-bio","author-mini-bio","back-to-top","backlinks-section","bio-block","blog-pager","bookmark-","-bookmark","bottom-of-article","brand-bar","breadcrumb","button-wrapper","btn-","-btn","byline","captcha","card-text","card-media","cat_header","catlinks","chapter-list","collections","comments","commentbox","comment-button","comment-count","comment-content","comment-form","comment-number","comment-respond","comment-thread","complementary","consent","content-card","content-topics","contentpromo","context-bar","context-widget","core-collateral","creative-commons_","_cta","-cta","cta-","cta_","current-issue","custom-list-number","dateline","dateheader","date-header","date_header-","disclaimer","disclosure","discussion","discuss_","disqus","donate","dropdown","eletters","emailsignup","engagement-widget","entry-author-info","entry-categories","entry-date","entry-meta","entry-title","entry-utility","eyebrow","expand-reduce","externallinkembedwrapper","extra-services","extra-title","facebook","favorite","feedback","feed-links","field-site-sections","floating-vid","follow","footer","footnote-back","footnoteback","for-you","frontmatter","further-reading","fullbleedheader","gist-meta","google","goog-","graph-view","header-logo","header-pattern","hero-list","hide-for-print","hide-print","hide-when-no-script","hidden-sidenote","hidden-accessibility","interlude","interaction","jumplink","jump-to-","kicker","labstab","-labels","language-name","latest-content","-ledes-","-license","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","marketing","media-inquiry","menu-","metadata","might-like","more-about","_modal","-modal","more-","morenews","morestories","move-helper","mw-editsection","mw-cite-backlink","mw-indicators","mw-jump-link","nav-","nav_","navbar","next-","newsgallery","news-story-title","newsletter_","newsletter-form","newsletter-signup","newslettersignup","newsletterwidget","newsletterwrapper","not-found","nomobile","noprint","originally-published","outline-view","overlay","page-title","paywall_message","-partners","plea","popular","pop-up","popover","post-author","post-bottom","post__category","postcomment","postdate","post-date","post_date","post-feeds","postinfo","post-info","post_info","post-inline-date","post-links","post_meta","post-meta","postmeta","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","prevnext","previousnext","press-inquiries","print-none","print-header","privacy-notice","privacy-settings","profile","promo_article","promo-box","pubdate","pub_date","pub-date","publication-date","publicationName","qr-code","qr_code","_rail","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","screen-reader-text","share-box","sharedaddy","share-icons","sharelinks","share-section","sidebartitle","sidebar_","sidebar-content","similar-","similar_","similars-","sideitems","sidebar-author","sidebar-item","side-box","side-logo","site-index","site-header","site-logo","site-name","skip-content","c-skip-link","_skip-link","slug-wrap","social","speechify-ignore","sponsor","springercitation","_stats","storyreadtime","storypublishdate","subject-label","subscribe","_tags","tags__item","tag_list","taxonomy","table-content","table-of-contents","tabs-","terminaltout","time-rubric","timestamp","time-to-read","tip_off","tiptout","-tout-","-toc","toggle-caption","topic-list","toolbar","tooltip","top-wrapper","tree-item","trending","trust-feat","trust-badge","twitter","u-hide","visually-hidden","welcomebox"],t.FOOTNOTE_INLINE_REFERENCES=["sup.reference","cite.ltx_cite",'sup[id^="fnr"]','sup[id^="fnref:"]',"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"]'].join(","),t.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"]'].join(","),t.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"]),t.ALLOWED_ATTRIBUTES=new Set(["alt","allow","allowfullscreen","aria-label","checked","colspan","controls","data-latex","data-src","data-srcset","data-lang","dir","display","frameborder","headers","height","href","lang","role","rowspan","src","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"]),t.ALLOWED_ATTRIBUTES_DEBUG=new Set(["class","id"]),t.SUPPORTED_LANGUAGES=new Set(["markup","html","xml","svg","mathml","ssml","atom","rss","javascript","js","jsx","typescript","ts","tsx","webassembly","wasm","python","java","csharp","cs","dotnet","aspnet","cpp","c++","c","objc","ruby","rb","php","golang","rust","swift","kotlin","scala","dart","bash","shell","sh","powershell","batch","json","jsonp","yaml","yml","toml","dockerfile","gitignore","sql","mysql","postgresql","graphql","mongodb","sparql","markdown","md","latex","tex","asciidoc","adoc","jsdoc","haskell","hs","elm","elixir","erlang","ocaml","fsharp","scheme","lisp","elisp","clojure","matlab","fortran","cobol","pascal","perl","lua","julia","groovy","crystal","nim","zig","regex","gradle","cmake","makefile","nix","terraform","solidity","glsl","hlsl","nasm","masm","armasm","gdscript","unrealscript","abap","actionscript","ada","agda","antlr4","applescript","arduino","coffeescript","django","erlang","fortran","haxe","idris","kotlin","livescript","matlab","nginx","pascal","prolog","puppet","scala","scheme","tcl","verilog","vhdl"])},648:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.mathSelectors=t.isBlockDisplay=t.getBasicLatexFromElement=t.getMathMLFromElement=void 0;t.getMathMLFromElement=e=>{if("math"===e.tagName.toLowerCase()){const t="block"===e.getAttribute("display");return{mathml:e.outerHTML,latex:e.getAttribute("alttext")||null,isBlock:t}}const t=e.getAttribute("data-mathml");if(t){const e=document.createElement("div");e.innerHTML=t;const r=e.querySelector("math");if(r){const e="block"===r.getAttribute("display");return{mathml:r.outerHTML,latex:r.getAttribute("alttext")||null,isBlock:e}}}const r=e.querySelector(".MJX_Assistive_MathML, mjx-assistive-mml");if(r){const e=r.querySelector("math");if(e){const t=e.getAttribute("display"),o=r.getAttribute("display"),n="block"===t||"block"===o;return{mathml:e.outerHTML,latex:e.getAttribute("alttext")||null,isBlock:n}}}const o=e.querySelector(".katex-mathml math");return o?{mathml:o.outerHTML,latex:null,isBlock:!1}:null};t.getBasicLatexFromElement=e=>{var t,r,o;const n=e.getAttribute("data-latex");if(n)return n;if(e instanceof HTMLImageElement&&e.classList.contains("latex")){const t=e.getAttribute("alt");if(t)return t;const r=e.getAttribute("src");if(r){const e=r.match(/latex\.php\?latex=([^&]+)/);if(e)return decodeURIComponent(e[1]).replace(/\+/g," ").replace(/%5C/g,"\\")}}const a=e.querySelector('annotation[encoding="application/x-tex"]');if(null==a?void 0:a.textContent)return a.textContent.trim();if(e.matches(".katex")){const t=e.querySelector('.katex-mathml annotation[encoding="application/x-tex"]');if(null==t?void 0:t.textContent)return t.textContent.trim()}if(e.matches('script[type="math/tex"]')||e.matches('script[type="math/tex; mode=display"]'))return(null===(t=e.textContent)||void 0===t?void 0:t.trim())||null;if(e.parentElement){const t=e.parentElement.querySelector('script[type="math/tex"], script[type="math/tex; mode=display"]');if(t)return(null===(r=t.textContent)||void 0===r?void 0:r.trim())||null}return e.getAttribute("alt")||(null===(o=e.textContent)||void 0===o?void 0:o.trim())||null};t.isBlockDisplay=e=>{if("block"===e.getAttribute("display"))return!0;const t=e.className.toLowerCase();if(t.includes("display")||t.includes("block"))return!0;if(e.closest('.katex-display, .MathJax_Display, [data-display="block"]'))return!0;const r=e.previousElementSibling;if("p"===(null==r?void 0:r.tagName.toLowerCase()))return!0;if(e.matches(".mwe-math-fallback-image-display"))return!0;if(e.matches(".katex"))return null!==e.closest(".katex-display");if(e.hasAttribute("display"))return"true"===e.getAttribute("display");if(e.matches('script[type="math/tex; mode=display"]'))return!0;if(e.hasAttribute("display"))return"true"===e.getAttribute("display");const o=e.closest("[display]");return!!o&&"true"===o.getAttribute("display")},t.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(",")},826:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.mathStandardizationRules=t.createCleanMathEl=void 0;const o=r(648);t.createCleanMathEl=(e,t,r)=>{const o=document.createElement("math");if(o.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),o.setAttribute("display",r?"block":"inline"),o.setAttribute("data-latex",t||""),null==e?void 0:e.mathml){const t=document.createElement("div");t.innerHTML=e.mathml;const r=t.querySelector("math");r&&(o.innerHTML=r.innerHTML)}else t&&(o.textContent=t);return o},t.mathStandardizationRules=[{selector:o.mathSelectors,element:"math",transform:e=>{if(!(e instanceof HTMLElement))return e;const r=(0,o.getMathMLFromElement)(e),n=(0,o.getBasicLatexFromElement)(e),a=(0,o.isBlockDisplay)(e),i=(0,t.createCleanMathEl)(r,n,a);if(e.parentElement){e.parentElement.querySelectorAll('\n\t\t\t\t\t/* MathJax scripts and previews */\n\t\t\t\t\tscript[type^="math/"],\n\t\t\t\t\t.MathJax_Preview,\n\n\t\t\t\t\t/* External math library scripts */\n\t\t\t\t\tscript[type="text/javascript"][src*="mathjax"],\n\t\t\t\t\tscript[type="text/javascript"][src*="katex"]\n\t\t\t\t').forEach((e=>e.remove()))}return i}}]}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.Defuddle=void 0;var t=r(628);Object.defineProperty(e,"Defuddle",{enumerable:!0,get:function(){return t.Defuddle}})})(),o})()));
|