@contentcredits/sdk 2.10.0 → 2.11.0
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ContentCreditsSDK={})}(this,function(e){"use strict";function n(e){try{const n=e.split(".");if(3!==n.length)return null;const t=n[1].replace(/-/g,"+").replace(/_/g,"/"),o=t.padEnd(t.length+(4-t.length%4)%4,"="),i=decodeURIComponent(atob(o).split("").map(e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)).join(""));return JSON.parse(i)}catch(e){return null}}function t(e){const t=n(e);return!t||"number"!=typeof t.exp||Date.now()/1e3>t.exp}const o="cc_sdk_token",i="cc_rt";let c=null;const r={set(e){c=e;try{sessionStorage.setItem(o,e)}catch(e){}},get(){if(c)return t(c)?(this.clear(),null):c;try{const e=sessionStorage.getItem(o);if(e)return t(e)?(this.clear(),null):(c=e,e)}catch(e){}return null},clear(){c=null;try{sessionStorage.removeItem(o)}catch(e){}},has(){return null!==this.get()}},a={set(e){try{localStorage.setItem(i,e)}catch(e){}},get(){try{return localStorage.getItem(i)}catch(e){return null}},clear(){try{localStorage.removeItem(i)}catch(e){}},has(){return null!==this.get()}};async function s(e){const n=a.get();if(!n)return!1;const t=new AbortController,o=setTimeout(()=>t.abort(),8e3);try{const i=await fetch(`${e}/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:n}),credentials:"omit",signal:t.signal});if(clearTimeout(o),!i.ok)return a.clear(),!1;const c=await i.json();return(null==c?void 0:c.accessToken)&&(null==c?void 0:c.refreshToken)?(r.set(c.accessToken),a.set(c.refreshToken),!0):(a.clear(),!1)}catch(e){return clearTimeout(o),!1}}const l=new Map;class d extends Error{constructor(e,n,t){super(n),this.status=e,this.data=t,this.name="ApiError"}}const u="data-cc-gated";function p(e){let n=!1,t=null,o=[];return{hide:function(){if(t=document.querySelector(e.selector),!t)return!1;if(t.hasAttribute(u))return!0;const i=Array.from(t.querySelectorAll("p, h2, h3, h4, blockquote, ul, ol"));if(i.length>e.teaserParagraphs){const n=i[e.teaserParagraphs],c=Array.from(t.childNodes),r=c.findIndex(e=>e===n||t.contains(e)&&e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING);o=c.slice(r<0?e.teaserParagraphs:r),o.forEach(e=>{var n,t,o,i;(e instanceof HTMLElement||e instanceof Text)&&(null===(t=null===(n=e.style)||void 0===n?void 0:n.setProperty)||void 0===t||t.call(n,"display","none"),null===(i=(o=e).setAttribute)||void 0===i||i.call(o,"data-cc-hidden","true"))})}else o=Array.from(t.childNodes),o.forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")});if(t.setAttribute(u,"true"),n=!0,!t.querySelector("[data-cc-fade]")){const e=t.style.position;e&&"static"!==e||(t.style.position="relative");const n=document.createElement("div");n.setAttribute("data-cc-fade","true"),n.style.cssText="position:absolute;bottom:0;left:0;width:100%;height:160px;background:linear-gradient(to bottom,transparent 0%,var(--cc-bg,#fff) 100%);pointer-events:none;z-index:1;",t.appendChild(n)}return!0},reveal:function(){if(!n)return;o.forEach(e=>{e instanceof HTMLElement&&(e.style.removeProperty("display"),e.removeAttribute("data-cc-hidden"))});const e=null==t?void 0:t.querySelector("[data-cc-fade]");e&&e.remove(),o=[],null==t||t.removeAttribute(u),n=!1},isGated:function(){return n}}}function h(e){const n=document.getElementById(e);n&&n.remove()}function m(e,n){const t=e.querySelector("style[data-cc-styles]");if(t)return void(t.textContent=n);const o=document.createElement("style");o.dataset.ccStyles="true",o.textContent=n,e.appendChild(o)}function f(e,n){e.textContent=n}function g(e,n,t){const o=document.createElement(e);return void 0!==n&&(o.textContent=n),o}const b="cc-paywall-host";function y(){const e=navigator.userAgent;return!!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(e)||!("function"!=typeof window.matchMedia||!window.matchMedia("(pointer: coarse)").matches||!window.matchMedia("(max-width: 768px)").matches)}function v(){var e,n;try{const t=new URL(window.location.href),o=null!==(e=t.searchParams.get("token"))&&void 0!==e?e:t.searchParams.get("cc_token"),i=null!==(n=t.searchParams.get("refresh_token"))&&void 0!==n?n:t.searchParams.get("cc_refresh_token");if(function(){try{const e=new URL(window.location.href);let n=!1;["token","cc_token","refresh_token","cc_refresh_token"].forEach(t=>{e.searchParams.has(t)&&(e.searchParams.delete(t),n=!0)}),n&&history.replaceState(null,"",e.toString())}catch(e){}}(),i&&a.set(i),o){r.set(o);const e=window.opener;if(e&&!e.closed){try{e.postMessage({type:"cc_auth_callback",token:o,refreshToken:null!=i?i:null},window.location.origin)}catch(e){}setTimeout(()=>{try{window.close()}catch(e){}},300)}return o}}catch(e){}return null}function x(e){return new Promise(n=>{let t=null,o=!1;function i(e){o||(o=!0,clearInterval(l),window.removeEventListener("message",c),n(e))}function c(e){if(e.origin!==window.location.origin)return;if("object"!=typeof(n=e.data)||null===n||"cc_auth_callback"!==n.type)return;var n;const o=e.data.token,c=e.data.refreshToken;if(o){r.set(o),c&&a.set(c);try{null==t||t.close()}catch(e){}i(o)}}window.addEventListener("message",c);try{t=window.open(e,"ccAuthPopup",`scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=600,height=650,left=${Math.round(window.screenX+(window.outerWidth-600)/2)},top=${Math.round(window.screenY+(window.outerHeight-650)/2)}`)}catch(e){return window.removeEventListener("message",c),void n(null)}if(!t||t.closed)return window.removeEventListener("message",c),void n(null);let s=0;const l=setInterval(()=>{var e,n;if(s+=200,t&&!t.closed)if(s>3e5){try{t.close()}catch(e){}i(null)}else try{const o=t.location.href;if(o.includes("/auth/callback")||o.includes("cc_token=")||o.includes("token=")){const o=new URLSearchParams(t.location.search),c=null!==(e=o.get("token"))&&void 0!==e?e:o.get("cc_token"),s=null!==(n=o.get("refresh_token"))&&void 0!==n?n:o.get("cc_refresh_token");if(c){r.set(c),s&&a.set(s);try{t.close()}catch(e){}i(c)}}}catch(e){}else i(r.get())},200)})}function w(e,n,t,o,i){const c=null!=i?i:p({selector:e.contentSelector,teaserParagraphs:e.teaserParagraphs}),a=function(e){let n=null,t=null;function o(){const o=document.querySelector(e.contentSelector);if(!o)return;const{root:i}=function(e,n){let t=document.getElementById(e);t||(t=document.createElement("div"),t.id=e,n.parentNode.insertBefore(t,n.nextSibling));const o=t._ccShadow;if(o)return{host:t,root:o};const i=t.attachShadow({mode:"open"});return t._ccShadow=i,{host:t,root:i}}(b,o);var c,r;n=i,m(n,`\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n /* Inline paywall panel — sits below the teaser content in the page flow */\n .cc-paywall-inline {\n width: 100%;\n padding: 36px 24px 32px;\n background: #fff;\n border: 1px solid #e5e7eb;\n border-top: 3px solid ${c=e.theme.primaryColor};\n border-radius: 0 0 12px 12px;\n text-align: center;\n font-family: ${r=e.theme.fontFamily};\n box-sizing: border-box;\n }\n\n .cc-paywall-inline h2 {\n font-size: 20px;\n font-weight: 700;\n color: #111827;\n margin-bottom: 8px;\n }\n\n .cc-paywall-inline p {\n font-size: 14px;\n color: #6b7280;\n margin-bottom: 24px;\n line-height: 1.6;\n }\n\n .cc-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n height: 44px;\n padding: 0 20px;\n border: none;\n border-radius: 8px;\n font-family: ${r};\n font-size: 15px;\n font-weight: 600;\n cursor: pointer;\n transition: opacity 0.15s ease, transform 0.1s ease;\n width: 100%;\n max-width: 320px;\n }\n .cc-btn:hover:not(:disabled) { opacity: 0.88; }\n .cc-btn:active:not(:disabled) { transform: scale(0.98); }\n .cc-btn:disabled { opacity: 0.55; cursor: not-allowed; }\n\n .cc-btn-primary {\n background: ${c};\n color: #fff;\n }\n\n .cc-btn-secondary {\n background: #111827;\n color: #fff;\n margin-top: 10px;\n }\n\n .cc-btn-outline {\n background: transparent;\n color: #111827;\n border: 2px solid #111827;\n margin-top: 10px;\n }\n\n .cc-credit-badge {\n display: inline-block;\n background: #fef3c7;\n color: #92400e;\n border-radius: 20px;\n padding: 2px 10px;\n font-size: 13px;\n font-weight: 600;\n margin-bottom: 16px;\n }\n\n .cc-spinner {\n width: 18px; height: 18px;\n border: 2px solid rgba(255,255,255,0.4);\n border-top-color: #fff;\n border-radius: 50%;\n animation: cc-spin 0.7s linear infinite;\n flex-shrink: 0;\n }\n @keyframes cc-spin { to { transform: rotate(360deg); } }\n\n .cc-powered-by {\n margin-top: 20px;\n font-size: 12px;\n color: #9ca3af;\n }\n .cc-powered-by a {\n color: ${c};\n text-decoration: none;\n font-weight: 600;\n }\n .cc-powered-by a:hover { text-decoration: underline; }\n `),t=g("div"),t.className="cc-paywall-inline",n.appendChild(t)}function i(){const e=g("div");e.className="cc-powered-by",e.textContent="Powered by ";const n=g("a","Content Credits");return n.setAttribute("href","https://contentcredits.com"),n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer"),e.appendChild(n),e}function c(){h(b),n=null,t=null}return{init:o,render:function(e,n,r){var a,s,l;if("checking"!==e&&(t||o(),t)){for(;t.firstChild;)t.removeChild(t.firstChild);switch(e){case"login":!function(e,n){e.appendChild(g("h2","This article requires a subscription")),e.appendChild(g("p","Log in with your Content Credits account to unlock this article."));const t=g("button","Login & Buy with Content Credits");t.className="cc-btn cc-btn-primary",t.addEventListener("click",()=>{n.onLogin()}),e.appendChild(t),e.appendChild(i())}(t,n);break;case"purchase":!function(e,n,t){if(e.appendChild(g("h2","Unlock this article")),null!==t){const n=g("span",`${t} credit${1!==t?"s":""}`);n.className="cc-credit-badge",e.appendChild(n)}e.appendChild(g("p","Use your Content Credits balance to instantly access this premium article."));const o=g("button",null!==t?`Buy for ${t} Credit${1!==t?"s":""}`:"Buy with Content Credits");o.className="cc-btn cc-btn-primary",o.addEventListener("click",()=>{n.onPurchase()}),e.appendChild(o),e.appendChild(i())}(t,n,null!==(a=null==r?void 0:r.requiredCredits)&&void 0!==a?a:null);break;case"insufficient":!function(e,n,t,o){e.appendChild(g("h2","Not enough credits"));const c=null!==t&&null!==o?`You need ${t} credit${1!==t?"s":""} but have ${o}. Top up to unlock this article.`:"You don't have enough credits to unlock this article. Purchase more to continue.";e.appendChild(g("p",c));const r=g("button","Buy More Credits");r.className="cc-btn cc-btn-primary",r.addEventListener("click",()=>n.onBuyMoreCredits()),e.appendChild(r),e.appendChild(i())}(t,n,null!==(s=null==r?void 0:r.requiredCredits)&&void 0!==s?s:null,null!==(l=null==r?void 0:r.creditBalance)&&void 0!==l?l:null);break;case"loading":!function(e){const n=g("button");n.className="cc-btn cc-btn-primary",n.disabled=!0;const t=g("span");t.className="cc-spinner",n.appendChild(t),n.appendChild(document.createTextNode(" Processing…")),e.appendChild(n)}(t);break;case"granted":c()}}},setButtonLoading:function(e){if(!t)return;const n=t.querySelector(".cc-btn");if(n&&(n.disabled=e,e)){const e=g("span");e.className="cc-spinner",f(n,""),n.appendChild(e),n.appendChild(document.createTextNode(" Processing…"))}},destroy:c}}(e),s=function(){let e=null,n=null;function t(t){var o,i,c,r;if(!function(){const e=["https://accounts.contentcredits.com"];try{e.push(window.location.origin)}catch(e){}return e}().includes(t.origin)&&t.origin!==window.location.origin)return;const a=t.data;if(a&&"object"==typeof a&&a.type)switch(a.type){case"authorization_response":{const n=null!==(o=a.data)&&void 0!==o?o:null===(i=t.detail)||void 0===i?void 0:i.data;n&&e&&e(n);break}case"purchase_response":{const e=null!==(c=a.data)&&void 0!==c?c:null===(r=t.detail)||void 0===r?void 0:r.data;e&&n&&n(e);break}}}return{attach:function(){window.addEventListener("message",t),window.addEventListener("authorization_response",n=>{const t=n.detail;(null==t?void 0:t.data)&&e&&e(t.data)}),window.addEventListener("purchase_response",e=>{const t=e.detail;(null==t?void 0:t.data)&&n&&n(t.data)})},detach:function(){window.removeEventListener("message",t)},requestAuthorization:function(e,n){window.postMessage({type:"request_authorization",data:{articleId:e,hostName:n}},window.location.origin)},requestPurchase:function(e){window.postMessage({type:"request_purchase",data:e},window.location.origin)},requestLogin:function(e){window.postMessage({type:"request_login",data:{hostName:e}},window.location.origin)},onAuthorizationResponse:function(n){e=n},onPurchaseResponse:function(e){n=e}}}();let l=!1;function u(n=0,i=0){var r;t.set({hasAccess:!0,isLoaded:!0,isLoading:!1}),e.headless||(c.reveal(),a.render("granted",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),o.emit("paywall:hidden",{}),o.emit("article:purchased",{creditsSpent:n,remainingBalance:i}),null===(r=e.onAccessGranted)||void 0===r||r.call(e)}async function w(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;l?s.requestLogin(e.hostName):y()?window.location.href=n:(e.headless||a.render("loading",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),await x(n)?(t.set({isLoggedIn:!0}),await L()):e.headless||a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}))}async function C(){var i,c,p,h,m;if(r.has())if(l)s.requestPurchase({articleId:e.apiKey,hostName:e.hostName,location:e.articleUrl,title:e.pageTitle});else{e.headless||a.render("loading",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),t.set({isLoading:!0});try{const c=await n.purchaseArticle({apiKey:e.apiKey,postUrl:e.articleUrl,postName:e.pageTitle,hostName:e.hostName});c.success?u(0,0):(t.set({isLoading:!1}),e.headless||a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),o.emit("error",{message:null!==(i=c.message)&&void 0!==i?i:"Purchase failed"}))}catch(n){if(t.set({isLoading:!1}),n instanceof d&&402===n.status){e.headless||a.render("insufficient",{onLogin:w,onPurchase:C,onBuyMoreCredits:k},{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance});const n=null!==(c=t.get().requiredCredits)&&void 0!==c?c:0,i=null!==(p=t.get().creditBalance)&&void 0!==p?p:0;null===(h=e.onInsufficientCredits)||void 0===h||h.call(e,{required:n,available:i}),o.emit("credits:insufficient",{required:n,available:i})}else e.headless||a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),null===(m=e.onPurchaseRequired)||void 0===m||m.call(e,{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance}),o.emit("error",{message:"Purchase failed",error:n})}}else await w()}function k(){window.open("https://accounts.contentcredits.com/consumer/dashboard","_blank","noopener,noreferrer")}async function L(){var i,p,h;if(t.set({isLoading:!0}),e.headless||a.render("checking",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),l)s.requestAuthorization(e.apiKey,e.hostName);else{if(!r.has())return t.set({isLoading:!1,isLoaded:!0}),e.headless||(c.hide(),a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(i=e.onLoginRequired)||void 0===i||i.call(e),void o.emit("paywall:shown",{});try{const i=await n.checkAccess({apiKey:e.apiKey,postUrl:e.articleUrl,postName:e.pageTitle,hostName:e.hostName});t.set({isLoading:!1,isLoaded:!0,hasAccess:i.success,isLoggedIn:!0}),i.success?u(0,0):(e.headless||(c.hide(),a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(p=e.onPurchaseRequired)||void 0===p||p.call(e,{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance}),o.emit("paywall:shown",{}))}catch(n){t.set({isLoading:!1,isLoaded:!0}),e.headless||(c.hide(),a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(h=e.onLoginRequired)||void 0===h||h.call(e),n instanceof d&&401===n.status||o.emit("error",{message:"Access check failed",error:n})}}}return{init:async function(){var n;v()&&t.set({isLoggedIn:!0}),l=await(n=e.extensionId,n&&"string"==typeof n?new Promise(e=>{let t=!1;function o(n){t||(t=!0,e(n))}if(!0===window.__CC_EXTENSION_LOADED)return void o(!0);const i=new Image;i.onload=()=>o(!0),i.onerror=()=>o(!1),i.src=`chrome-extension://${n}/icons/icon16.png`,setTimeout(()=>o(!1),2e3)}):Promise.resolve(!1)),t.set({isExtensionAvailable:l}),l&&(s.attach(),s.onAuthorizationResponse(n=>{var i,r,s,l,d,p,h;t.set({isLoggedIn:n.isAuthenticated,hasAccess:n.doesHaveAccess,isLoaded:!0,isLoading:!1,creditBalance:null!==(i=n.creditBalance)&&void 0!==i?i:null,requiredCredits:null!==(r=n.requiredCredits)&&void 0!==r?r:null}),n.isAuthenticated?n.doesHaveAccess?u(0,null!==(l=n.creditBalance)&&void 0!==l?l:0):(e.headless||(c.hide(),a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k},{requiredCredits:n.requiredCredits,creditBalance:n.creditBalance})),null===(d=e.onPurchaseRequired)||void 0===d||d.call(e,{requiredCredits:null!==(p=n.requiredCredits)&&void 0!==p?p:null,creditBalance:null!==(h=n.creditBalance)&&void 0!==h?h:null}),o.emit("paywall:shown",{})):(e.headless||(c.hide(),a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(s=e.onLoginRequired)||void 0===s||s.call(e),o.emit("paywall:shown",{}))}),s.onPurchaseResponse(e=>{var n,i;t.set({isLoading:!1,isLoaded:!0,hasAccess:e.doesHaveAccess}),e.doesHaveAccess?u(null!==(n=e.creditsSpent)&&void 0!==n?n:0,null!==(i=e.creditBalance)&&void 0!==i?i:0):(a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),o.emit("error",{message:"Purchase failed via extension"}))})),await L()},checkAccess:L,destroy:function(){s.detach(),e.headless||(a.destroy(),c.reveal())},login:w,purchase:C,buyMoreCredits:k}}const C="cc-widget-pos",k="cc-comments-host",L=["#6366f1","#ec4899","#8b5cf6","#14b8a6","#f59e0b","#ef4444"];function E(e,t,o,i){let c=null,a=null,s=null,l=[],d="TOP",u=null,p=null,b=null;function w(){if(c)return c;const{root:n}=function(e){let n=document.getElementById(e);n||(n=document.createElement("div"),n.id=e,n.style.cssText="position:fixed;top:0;left:0;width:0;height:0;pointer-events:none;z-index:2147483647;",document.body.appendChild(n));const t=n._ccShadow;if(t)return{host:n,root:t};const o=n.attachShadow({mode:"open"});return n._ccShadow=o,{host:n,root:o}}(k);var t,o;return c=n,m(c,`\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n /* ── Widget Button ───────────────────────────────────── */\n .cc-widget-btn {\n position: fixed;\n top: 50%;\n right: 0;\n transform: translateY(-50%);\n width: auto;\n height: 60px;\n background: ${t=e.theme.primaryColor};\n border-radius: 10px 0 0 10px;\n display: flex;\n align-items: center;\n gap: 8px;\n padding-left: 12px;\n padding-right: 6px;\n z-index: 2147483646;\n box-shadow: -2px 0 16px rgba(0,0,0,0.12);\n cursor: pointer;\n user-select: none;\n font-family: ${o=e.theme.fontFamily};\n transition: background 0.2s;\n pointer-events: all;\n }\n .cc-widget-btn:hover { filter: brightness(1.08); }\n\n .cc-widget-icon { color: #fff; display: flex; align-items: center; }\n .cc-widget-badge {\n background: #fff;\n color: ${t};\n border-radius: 12px;\n padding: 2px 7px;\n font-size: 12px;\n font-weight: 700;\n min-width: 20px;\n text-align: center;\n }\n .cc-widget-drag-handle {\n color: rgba(255,255,255,0.7);\n cursor: grab;\n display: flex;\n align-items: center;\n padding: 0 4px;\n }\n .cc-widget-drag-handle:active { cursor: grabbing; }\n\n /* ── Panel Overlay ───────────────────────────────────── */\n .cc-panel-backdrop {\n position: fixed;\n inset: 0;\n background: rgba(0,0,0,0.35);\n z-index: 2147483645;\n opacity: 0;\n transition: opacity 0.25s;\n pointer-events: all;\n }\n .cc-panel-backdrop.cc-visible { opacity: 1; }\n\n .cc-panel {\n position: fixed;\n top: 0; right: -500px;\n width: 460px;\n max-width: 95vw;\n height: 100%;\n background: #f9fafb;\n z-index: 2147483646;\n display: flex;\n flex-direction: column;\n box-shadow: -4px 0 32px rgba(0,0,0,0.12);\n transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);\n font-family: ${o};\n pointer-events: all;\n }\n .cc-panel.cc-open { right: 0; }\n\n /* ── Panel Header ────────────────────────────────────── */\n .cc-panel-header {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 16px 20px;\n border-bottom: 1px solid #e5e7eb;\n background: #fff;\n flex-shrink: 0;\n }\n .cc-panel-title {\n font-size: 16px;\n font-weight: 700;\n color: #111827;\n flex: 1;\n }\n .cc-panel-count {\n font-size: 13px;\n color: #6b7280;\n font-weight: 400;\n }\n .cc-panel-close-btn {\n background: transparent;\n border: none;\n cursor: pointer;\n color: #6b7280;\n padding: 4px;\n display: flex;\n align-items: center;\n border-radius: 6px;\n transition: background 0.15s;\n }\n .cc-panel-close-btn:hover { background: #f3f4f6; }\n\n .cc-back-btn {\n background: transparent;\n border: none;\n cursor: pointer;\n color: #6b7280;\n padding: 4px;\n display: none;\n align-items: center;\n border-radius: 6px;\n transition: background 0.15s;\n }\n .cc-back-btn.cc-visible { display: flex; }\n .cc-back-btn:hover { background: #f3f4f6; }\n\n /* ── Sort Bar ────────────────────────────────────────── */\n .cc-sort-bar {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 10px 20px;\n border-bottom: 1px solid #f3f4f6;\n background: #fff;\n flex-shrink: 0;\n }\n .cc-sort-label { font-size: 12px; color: #9ca3af; font-weight: 500; }\n .cc-sort-btn {\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 12px;\n font-weight: 600;\n color: #6b7280;\n padding: 4px 8px;\n border-radius: 6px;\n font-family: ${o};\n transition: background 0.15s, color 0.15s;\n }\n .cc-sort-btn:hover { background: #f3f4f6; }\n .cc-sort-btn.cc-active { background: #111827; color: #fff; }\n\n /* ── Comments List ───────────────────────────────────── */\n .cc-comments-list {\n flex: 1;\n overflow-y: auto;\n overscroll-behavior: contain;\n }\n .cc-comments-list::-webkit-scrollbar { width: 4px; }\n .cc-comments-list::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }\n\n /* ── Comment Card ────────────────────────────────────── */\n .cc-comment-card {\n padding: 16px 20px;\n background: #fff;\n border-bottom: 1px solid #f3f4f6;\n }\n .cc-comment-card.cc-reply {\n padding-left: 36px;\n background: #fafafa;\n }\n\n .cc-comment-header {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n margin-bottom: 8px;\n }\n .cc-comment-author-row { display: flex; align-items: center; gap: 10px; }\n\n .cc-avatar {\n width: 32px; height: 32px;\n border-radius: 50%;\n flex-shrink: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n color: #fff;\n font-weight: 700;\n font-size: 12px;\n overflow: hidden;\n }\n .cc-avatar img { width: 100%; height: 100%; object-fit: cover; }\n\n .cc-author-name {\n font-size: 14px;\n font-weight: 700;\n color: #111827;\n }\n .cc-comment-time {\n font-size: 11px;\n color: #9ca3af;\n margin-top: 2px;\n }\n\n .cc-comment-body {\n font-size: 14px;\n color: #374151;\n line-height: 1.6;\n margin-bottom: 12px;\n word-break: break-word;\n white-space: pre-wrap;\n }\n\n .cc-comment-actions {\n display: flex;\n align-items: center;\n gap: 12px;\n }\n .cc-action-btn {\n display: inline-flex;\n align-items: center;\n gap: 5px;\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 12px;\n font-weight: 500;\n color: #6b7280;\n padding: 3px 6px;\n border-radius: 6px;\n font-family: ${o};\n transition: background 0.15s, color 0.15s;\n }\n .cc-action-btn:hover { background: #f3f4f6; }\n .cc-action-btn.cc-liked { color: #ef4444; }\n .cc-action-btn.cc-danger:hover { color: #ef4444; background: #fef2f2; }\n .cc-action-btn.cc-owner-actions { margin-left: auto; }\n\n /* ── Reply Subthread ─────────────────────────────────── */\n .cc-subthread-label {\n font-size: 11px;\n font-weight: 600;\n color: #94a3b8;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n padding: 12px 20px 8px;\n background: #f9fafb;\n }\n\n /* ── Empty / Loading / Error ─────────────────────────── */\n .cc-empty-state, .cc-loading-state, .cc-error-state {\n text-align: center;\n padding: 60px 20px;\n color: #9ca3af;\n }\n .cc-empty-state p, .cc-loading-state p, .cc-error-state p {\n font-size: 14px;\n font-weight: 500;\n color: #9ca3af;\n margin-bottom: 6px;\n }\n .cc-empty-state span, .cc-loading-state span, .cc-error-state span {\n font-size: 13px;\n color: #d1d5db;\n }\n .cc-error-state .cc-retry-btn {\n margin-top: 16px;\n padding: 8px 16px;\n background: #111827;\n color: #fff;\n border: none;\n border-radius: 6px;\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n font-family: ${o};\n }\n .cc-error-icon { color: #ef4444; margin-bottom: 12px; }\n\n .cc-spinner-lg {\n width: 28px; height: 28px;\n border: 2px solid #e5e7eb;\n border-top-color: ${t};\n border-radius: 50%;\n animation: cc-spin 0.7s linear infinite;\n margin: 0 auto 12px;\n }\n @keyframes cc-spin { to { transform: rotate(360deg); } }\n\n /* ── Compose Box ─────────────────────────────────────── */\n .cc-compose {\n border-top: 1px solid #e5e7eb;\n padding: 12px 20px;\n background: #fff;\n flex-shrink: 0;\n position: relative;\n }\n\n .cc-compose-textarea {\n width: 100%;\n min-height: 72px;\n max-height: 180px;\n border: 1.5px solid #d1d5db;\n border-radius: 8px;\n padding: 10px 12px;\n font-size: 14px;\n font-family: ${o};\n color: #111827;\n resize: vertical;\n outline: none;\n background: #fff;\n transition: border-color 0.15s;\n line-height: 1.5;\n }\n .cc-compose-textarea:focus { border-color: ${t}; }\n .cc-compose-textarea::placeholder { color: #9ca3af; }\n\n .cc-compose-actions {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-top: 8px;\n gap: 8px;\n }\n .cc-compose-cancel {\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 13px;\n color: #6b7280;\n font-family: ${o};\n padding: 6px;\n display: none;\n }\n .cc-compose-cancel.cc-visible { display: block; }\n .cc-compose-submit {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n height: 36px;\n padding: 0 16px;\n background: ${t};\n color: #fff;\n border: none;\n border-radius: 7px;\n font-size: 13px;\n font-weight: 600;\n cursor: pointer;\n font-family: ${o};\n margin-left: auto;\n transition: opacity 0.15s;\n }\n .cc-compose-submit:disabled { opacity: 0.55; cursor: not-allowed; }\n\n .cc-spinner-sm {\n width: 14px; height: 14px;\n border: 2px solid rgba(255,255,255,0.4);\n border-top-color: #fff;\n border-radius: 50%;\n animation: cc-spin 0.7s linear infinite;\n }\n\n /* ── Login Overlay inside compose ────────────────────── */\n .cc-login-overlay {\n position: absolute;\n inset: 0;\n background: rgba(255,255,255,0.95);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 10px;\n padding: 16px;\n border-top: 1px solid #e5e7eb;\n }\n .cc-login-overlay p {\n font-size: 14px;\n color: #6b7280;\n text-align: center;\n }\n .cc-login-overlay-btn {\n height: 40px;\n padding: 0 20px;\n background: ${t};\n color: #fff;\n border: none;\n border-radius: 8px;\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n font-family: ${o};\n }\n `),c}function C(){const e=r.get();a=e?function(e){var t,o;const i=n(e);return i&&null!==(o=null!==(t=i.id)&&void 0!==t?t:i._id)&&void 0!==o?o:null}(e):null}async function E(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;y()?window.location.href=n:await x(n)&&(C(),U(),N())}async function N(){var n;const o=w(),i=o.getElementById("cc-comments-list");if(i){!function(e){e.innerHTML="";const n=g("div");n.className="cc-loading-state";const t=g("div");t.className="cc-spinner-lg",n.appendChild(t),n.appendChild(g("p","Loading comments…")),e.appendChild(n)}(i);try{const c=await t.ensureThread({pageUrl:e.articleUrl,hostname:e.hostName});if(!c._id)return void I(i,"Comments are not available for this page.");s=c._id;const r=await t.getComments({pageUrl:e.articleUrl,sortBy:d});l=null!==(n=r.comments)&&void 0!==n?n:[],r.thread&&(s=r.thread._id);const a=o.getElementById("cc-header-count");a&&f(a,String(l.length)),P(i)}catch(e){I(i,"Unable to reach the server. Check your connection.")}}}function B(e){const n=new Map,t=[];return e.forEach(e=>n.set(e._id,Object.assign(Object.assign({},e),{replies:[]}))),e.forEach(e=>{const o=n.get(e._id);if(e.parentCommentId){const t=n.get(e.parentCommentId);t&&!t.parentCommentId&&t.replies.push(o)}else t.push(o)}),t}function I(e,n){e.innerHTML="";const t=g("div");t.className="cc-error-state";const o=g("div");o.className="cc-error-icon",o.innerHTML='<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',t.appendChild(o),t.appendChild(g("p",n));const i=g("button","Try Again");i.className="cc-retry-btn",i.addEventListener("click",()=>{N()}),t.appendChild(i),e.appendChild(t)}function P(e){e.innerHTML="";const n=w(),t=n.getElementById("cc-back-btn"),o=n.getElementById("cc-panel-title");if(u?(null==t||t.classList.add("cc-visible"),o&&f(o,"Replies")):(null==t||t.classList.remove("cc-visible"),o&&f(o,"Comments")),u)!function(e,n){var t,o,i,c,r;const a=B(l).find(e=>e._id===n);if(!a)return;e.appendChild(T(a,!1));const s=g("div",`${null!==(o=null===(t=a.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0} ${1===(null!==(c=null===(i=a.replies)||void 0===i?void 0:i.length)&&void 0!==c?c:0)?"REPLY":"REPLIES"}`);if(s.className="cc-subthread-label",e.appendChild(s),null===(r=a.replies)||void 0===r?void 0:r.length)a.replies.forEach(n=>e.appendChild(T(n,!0)));else{const n=g("div");n.className="cc-empty-state",n.style.paddingTop="20px",n.appendChild(g("p","No replies yet")),e.appendChild(n)}}(e,u);else{if(0===l.length){const n=g("div");n.className="cc-empty-state",n.appendChild(g("p","No comments yet"));const t=g("span","Be the first to share your thoughts");return n.appendChild(t),void e.appendChild(n)}(function(e){const n=[...e];return"NEWEST"===d?n.sort((e,n)=>new Date(n.createdAt).getTime()-new Date(e.createdAt).getTime()):n.sort((e,n)=>{var t,o,i,c,r,a;return(null!==(o=null===(t=n.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0)-(null!==(c=null===(i=e.replies)||void 0===i?void 0:i.length)&&void 0!==c?c:0)||(null!==(r=n.likeCount)&&void 0!==r?r:0)-(null!==(a=e.likeCount)&&void 0!==a?a:0)}),n.forEach(e=>{var n;(null===(n=e.replies)||void 0===n?void 0:n.length)&&e.replies.sort((e,n)=>new Date(n.createdAt).getTime()-new Date(e.createdAt).getTime())}),n})(B(l)).forEach(n=>e.appendChild(T(n,!1)))}}function T(n,t){var o,i;const c=!(!a||n.authorId!==a),r=n.author,s=r?`${r.firstName} ${r.lastName}`.trim():"Anonymous",l=L[(s||"A").charCodeAt(0)%L.length],d=r?function(e,n){var t,o,i,c;return`${null!==(o=null===(t=null==e?void 0:e[0])||void 0===t?void 0:t.toUpperCase())&&void 0!==o?o:""}${null!==(c=null===(i=null==n?void 0:n[0])||void 0===i?void 0:i.toUpperCase())&&void 0!==c?c:""}`||"?"}(r.firstName,r.lastName):"?",u=g("div");u.className="cc-comment-card"+(t?" cc-reply":""),u.dataset.commentId=n._id;const p=g("div");p.className="cc-comment-header";const h=g("div");h.className="cc-comment-author-row";const m=g("div");if(m.className="cc-avatar",m.style.background=l,null==r?void 0:r.profilePicture){const n=function(e){try{const n=new URL(e);return"http:"!==n.protocol&&"https:"!==n.protocol?null:n.toString()}catch(e){return null}}(r.profilePicture.startsWith("http")?r.profilePicture:`${e.apiBaseUrl}${r.profilePicture}`);if(n){const e=g("img");e.setAttribute("src",n),e.setAttribute("alt",s),e.addEventListener("error",()=>{e.remove(),f(m,d)}),m.appendChild(e)}else f(m,d)}else f(m,d);const b=g("div"),y=g("div",s);y.className="cc-author-name";const v=g("div",function(e){try{const n=new Date(e);return`${n.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"})} · ${n.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}`}catch(e){return""}}(n.createdAt));v.className="cc-comment-time",b.appendChild(y),b.appendChild(v),h.appendChild(m),h.appendChild(b),p.appendChild(h),u.appendChild(p);const x=g("div");x.className="cc-comment-body",x.appendChild(function(e){const n=document.createDocumentFragment(),t=e.split("\n");return t.forEach((e,o)=>{n.appendChild(document.createTextNode(e)),o<t.length-1&&n.appendChild(document.createElement("br"))}),n}(n.content)),u.appendChild(x);const w=g("div");if(w.className="cc-comment-actions",!t){const e=g("button");e.className="cc-action-btn",e.dataset.commentId=n._id,e.dataset.action="reply",e.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="transform:scaleX(-1)"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',e.appendChild(document.createTextNode(` ${(null===(o=n.replies)||void 0===o?void 0:o.length)||"Reply"}`)),w.appendChild(e)}const C=g("button");if(C.className="cc-action-btn"+(n.hasLiked?" cc-liked":""),C.dataset.commentId=n._id,C.dataset.action="like",C.innerHTML=`<svg width="14" height="14" viewBox="0 0 24 24" fill="${n.hasLiked?"currentColor":"none"}" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>`,C.appendChild(document.createTextNode(` ${null!==(i=n.likeCount)&&void 0!==i?i:0}`)),w.appendChild(C),c){const e=g("div");e.className="cc-action-btn cc-owner-actions",e.style.cssText="margin-left:auto;display:flex;gap:4px;background:transparent;border:none;padding:0;";const t=g("button","Edit");t.className="cc-action-btn",t.dataset.commentId=n._id,t.dataset.action="edit";const o=g("button","Delete");o.className="cc-action-btn cc-danger",o.dataset.commentId=n._id,o.dataset.action="delete",e.appendChild(t),e.appendChild(o),w.appendChild(e)}return u.appendChild(w),u}function S(){const e=g("div");e.className="cc-login-overlay",e.id="cc-login-overlay",e.appendChild(g("p","Sign in to join the conversation"));const n=g("button","Login with Content Credits");return n.className="cc-login-overlay-btn",n.addEventListener("click",()=>{E()}),e.appendChild(n),e}function A(e){const n=e.target.closest("[data-action]");if(!n)return;const i=n.dataset.action,a=n.dataset.commentId;if(a)switch(i){case"reply":!function(e){if(u){p=e,b=null;const n=null==c?void 0:c.getElementById("cc-compose-textarea");n&&(n.placeholder="Write a reply…",n.focus()),M()}else{u=e;const n=null==c?void 0:c.getElementById("cc-comments-list");n&&P(n)}}(a);break;case"like":!async function(e){var n,i,a,s,d;if(!r.has())return void E();const u=l.find(n=>n._id===e);if(!u)return;const p=u.hasLiked;u.hasLiked=!p,u.likeCount=(null!==(n=u.likeCount)&&void 0!==n?n:0)+(u.hasLiked?1:-1);const h=null==c?void 0:c.getElementById("cc-comments-list");h&&P(h);try{const n=await t.toggleLike(e);n.success?("boolean"==typeof(null===(i=n.data)||void 0===i?void 0:i.hasLiked)&&(u.hasLiked=n.data.hasLiked),"number"==typeof(null===(a=n.data)||void 0===a?void 0:a.likeCount)&&(u.likeCount=n.data.likeCount),o.emit("comment:liked",{commentId:e,hasLiked:u.hasLiked})):(u.hasLiked=p,u.likeCount=(null!==(s=u.likeCount)&&void 0!==s?s:0)+(p?1:-1)),h&&P(h)}catch(e){u.hasLiked=p,u.likeCount=(null!==(d=u.likeCount)&&void 0!==d?d:0)+(p?1:-1),h&&P(h)}}(a);break;case"edit":!function(e){const n=l.find(n=>n._id===e);if(!n)return;b=e,p=null;const t=null==c?void 0:c.getElementById("cc-compose-textarea");t&&(t.value=n.content,t.placeholder="Edit your comment…",t.focus());const o=null==c?void 0:c.getElementById("cc-compose-submit");o&&f(o,"Update"),M()}(a);break;case"delete":!async function(e){if(confirm("Delete this comment?"))try{(await t.deleteComment(e))._id&&(o.emit("comment:deleted",{commentId:e}),N())}catch(e){}}(a)}}function M(){const e=null==c?void 0:c.getElementById("cc-compose-cancel");null==e||e.classList.add("cc-visible")}function $(){const e=null==c?void 0:c.getElementById("cc-compose-cancel");null==e||e.classList.remove("cc-visible")}function _(){b=null,p=null;const e=null==c?void 0:c.getElementById("cc-compose-textarea");e&&(e.value="",e.placeholder="Write a comment…");const n=null==c?void 0:c.getElementById("cc-compose-submit");n&&f(n,"Post"),$()}function U(){const e=w(),n=e.getElementById("cc-login-overlay");if(r.has()&&n)n.remove();else if(!r.has()&&!n){const n=e.getElementById("cc-compose");null==n||n.appendChild(S())}}function q(){const e=c;if(!e)return;const n=e.getElementById("cc-panel-backdrop"),t=e.getElementById("cc-comments-panel");null==n||n.classList.remove("cc-visible"),null==t||t.classList.remove("cc-open"),setTimeout(()=>{null==n||n.remove(),null==t||t.remove(),i()},280)}return{openPanel:function(){const e=w();v()&&C(),C();let n=e.getElementById("cc-panel-backdrop");if(!n){const i=g("div");i.className="cc-panel-backdrop",i.id="cc-panel-backdrop",i.addEventListener("click",q),e.appendChild(i),e.appendChild(function(){const e=g("div");e.className="cc-panel",e.id="cc-comments-panel";const n=g("div");n.className="cc-panel-header";const i=g("button");i.className="cc-back-btn",i.id="cc-back-btn",i.setAttribute("aria-label","Back"),i.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M15 18l-6-6 6-6"/></svg>',i.addEventListener("click",()=>{u=null,p=null;const e=null==c?void 0:c.getElementById("cc-comments-list");e&&P(e)});const a=g("div");a.style.cssText="flex:1;display:flex;align-items:center;gap:6px;";const l=g("span","Comments");l.className="cc-panel-title",l.id="cc-panel-title";const h=g("span","");h.className="cc-panel-count",h.id="cc-header-count",a.appendChild(l),a.appendChild(h);const m=g("button");m.className="cc-panel-close-btn",m.setAttribute("aria-label","Close comments"),m.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',m.addEventListener("click",q),n.appendChild(i),n.appendChild(a),n.appendChild(m),e.appendChild(n);const y=g("div");y.className="cc-sort-bar";const v=g("span","Sort:");v.className="cc-sort-label",y.appendChild(v),["TOP","NEWEST"].forEach(e=>{const n=g("button",e);n.className="cc-sort-btn"+(d===e?" cc-active":""),n.dataset.sort=e,n.addEventListener("click",()=>{d!==e&&(d=e,y.querySelectorAll(".cc-sort-btn").forEach(e=>e.classList.remove("cc-active")),n.classList.add("cc-active"),N())}),y.appendChild(n)}),e.appendChild(y);const x=g("div");return x.className="cc-comments-list",x.id="cc-comments-list",x.addEventListener("click",A),e.appendChild(x),e.appendChild(function(){const e=g("div");e.className="cc-compose",e.id="cc-compose";const n=g("textarea");n.className="cc-compose-textarea",n.id="cc-compose-textarea",n.setAttribute("placeholder","Write a comment…"),n.setAttribute("rows","3"),e.appendChild(n);const i=g("div");i.className="cc-compose-actions";const a=g("button","Cancel");a.className="cc-compose-cancel",a.id="cc-compose-cancel",a.addEventListener("click",_),i.appendChild(a);const l=g("button","Post");return l.className="cc-compose-submit",l.id="cc-compose-submit",l.addEventListener("click",()=>{!async function(){const e=null==c?void 0:c.getElementById("cc-compose-textarea");if(!e)return;const n=e.value.trim();if(!n)return;if(!r.has())return void E();if(!s)return;const i=null==c?void 0:c.getElementById("cc-compose-submit");i&&(i.disabled=!0,f(i,"Posting…"));try{let c;b?c=await t.editComment(b,n):(c=await t.postComment({threadId:s,content:n,parentCommentId:null!=p?p:u}),o.emit("comment:posted",{comment:c})),c._id&&(e.value="",b=null,p=null,e.placeholder=u?"Write a reply…":"Write a comment…",$(),i&&f(i,"Post"),N())}catch(e){}finally{i&&(i.disabled=!1)}}()}),i.appendChild(l),e.appendChild(i),r.has()||e.appendChild(S()),e}()),e}()),n=i}const i=n;requestAnimationFrame(()=>{var n;i.classList.add("cc-visible"),null===(n=e.getElementById("cc-comments-panel"))||void 0===n||n.classList.add("cc-open")}),U(),N()},closePanel:q,destroy:function(){h(k),c=null}}}class N{constructor(e){var n;this.config=e,this.state=function(){let e={isLoading:!1,isExtensionAvailable:!1,isLoggedIn:!1,hasAccess:!1,isLoaded:!1,user:null,creditBalance:null,requiredCredits:null};const n=[];function t(){return Object.assign({},e)}function o(o){e=Object.assign(Object.assign({},e),o),n.forEach(e=>e(t()))}return{get:t,set:o,subscribe:function(e){return n.push(e),()=>{const t=n.indexOf(e);t>=0&&n.splice(t,1)}},reset:function(){e={isLoading:!1,isExtensionAvailable:!1,isLoggedIn:!1,hasAccess:!1,isLoaded:!1,user:null,creditBalance:null,requiredCredits:null},n.forEach(e=>e(t()))},setUser:function(e){var n;o({user:e,isLoggedIn:null!==e,creditBalance:null!==(n=null==e?void 0:e.credits)&&void 0!==n?n:null})}}}(),this.emitter=function(){const e={};function n(n,t){const o=e[n];if(!o)return;const i=o.indexOf(t);i>=0&&o.splice(i,1)}return{on:function(t,o){return e[t]||(e[t]=[]),e[t].push(o),()=>n(t,o)},off:n,emit:function(n,t){const o=e[n];o&&o.forEach(e=>{try{e(t)}catch(e){console.warn(`[ContentCredits] Error in "${n}" handler:`,e)}});try{document.dispatchEvent(new CustomEvent(`contentcredits:${n}`,{detail:t,bubbles:!1}))}catch(e){}},removeAll:function(){Object.keys(e).forEach(n=>{delete e[n]})}}}(),this.paywallModule=null,this.commentsModule=null,this.client=function(e,n){async function t(o,i,c,u=0,p=!1){const h=`${e}${i}`,m=c?JSON.stringify(c):void 0,f=function(e,n,t){return`${e}:${n}:${null!=t?t:""}`}(o,h,m),g=l.get(f);if(g)return g;const b=new AbortController,y=setTimeout(()=>b.abort(),12e3),v={"Content-Type":"application/json"},x=r.get();x&&(v.Authorization=`Bearer ${x}`);const w=fetch(h,{method:o,headers:v,body:m,signal:b.signal,credentials:"omit"}).then(async h=>{var m;if(clearTimeout(y),401===h.status){if(!p&&await s(e))return l.delete(f),t(o,i,c,u,!0);throw r.clear(),a.clear(),n.emit("auth:logout",{}),new d(401,"Unauthorized — session expired")}let g;try{g=await h.json()}catch(e){throw new d(h.status,"Invalid JSON response from server")}if(!h.ok){const e=null!==(m=null==g?void 0:g.message)&&void 0!==m?m:`HTTP ${h.status}`;throw new d(h.status,e,g)}return g}).catch(async e=>{clearTimeout(y);const n=e instanceof TypeError&&e.message.includes("fetch"),r=e instanceof d&&((a=e.status)>=500||429===a);var a;if((n||r)&&u<3)return l.delete(f),await async function(e){return new Promise(n=>setTimeout(n,e))}(400*Math.pow(2,u)),t(o,i,c,u+1);throw e}).finally(()=>{l.delete(f)});return l.set(f,w),w}return{get:e=>t("GET",e),post:(e,n)=>t("POST",e,n),put:(e,n)=>t("PUT",e,n),delete:e=>t("DELETE",e)}}(e.apiBaseUrl,this.emitter),this.creditsApi=(n=this.client,{checkAccess:e=>n.post("/credits/check-article-access",{apiKey:e.apiKey,postUrl:e.postUrl,postName:e.postName,hostName:e.hostName}),purchaseArticle:e=>n.post("/credits/purchase-article",{apiKey:e.apiKey,postUrl:e.postUrl,postName:e.postName,hostName:e.hostName})}),this.commentsApi=function(e){return{ensureThread:n=>e.post("/comments/threads/ensure",{pageUrl:n.pageUrl,hostname:n.hostname}),getComments(n){const t=encodeURIComponent(n.pageUrl);return e.get(`/comments/comments/by-url?url=${t}&sortBy=${n.sortBy}`)},postComment:n=>e.post("/comments/comments",Object.assign({threadId:n.threadId,content:n.content},n.parentCommentId?{parentCommentId:n.parentCommentId}:{})),editComment:(n,t)=>e.put(`/comments/comments/${n}`,{content:t}),deleteComment:n=>e.delete(`/comments/comments/${n}`),toggleLike:n=>e.post(`/comments/comments/${n}/toggle-like`,{})}}(this.client)}static init(e){const n=function(e){var n,t,o,i,c,r,a,s,l,d,u;if(!e.apiKey||"string"!=typeof e.apiKey||""===e.apiKey.trim())throw new Error("[ContentCredits] apiKey is required. Get yours from the Content Credits admin panel.");const p=function(e){try{const n=new URL(e);return["token","cc_token","refresh_token","cc_refresh_token"].forEach(e=>{n.searchParams.delete(e)}),n.toString()}catch(n){return e}}(null!==(n=e.articleUrl)&&void 0!==n?n:window.location.href);let h;try{h=new URL(p).hostname}catch(e){throw new Error(`[ContentCredits] Invalid articleUrl: "${p}"`)}return{apiKey:e.apiKey.trim(),articleUrl:p,hostName:h,pageTitle:document.title,contentSelector:null!==(t=e.contentSelector)&&void 0!==t?t:".cc-premium-content",teaserParagraphs:null!==(o=e.teaserParagraphs)&&void 0!==o?o:2,enableComments:null===(i=e.enableComments)||void 0===i||i,extensionId:null!==(c=e.extensionId)&&void 0!==c?c:"ljehdpabbhgccmanhjdfacjnaigpgcml",debug:null!==(r=e.debug)&&void 0!==r&&r,headless:null!==(a=e.headless)&&void 0!==a&&a,apiBaseUrl:"https://api.contentcredits.com",accountsUrl:"https://accounts.contentcredits.com",paywallTemplate:e.paywallTemplate,onAccessGranted:e.onAccessGranted,onStateChange:e.onStateChange,onReady:e.onReady,onLoginRequired:e.onLoginRequired,onPurchaseRequired:e.onPurchaseRequired,onInsufficientCredits:e.onInsufficientCredits,onPurchased:e.onPurchased,onUserLogin:e.onUserLogin,onUserLogout:e.onUserLogout,onError:e.onError,theme:{primaryColor:null!==(l=null===(s=e.theme)||void 0===s?void 0:s.primaryColor)&&void 0!==l?l:"#44C678",fontFamily:null!==(u=null===(d=e.theme)||void 0===d?void 0:d.fontFamily)&&void 0!==u?u:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"}}}(e),t=new N(n);return t._start(),t}async _start(){v(),this.config.onStateChange&&this.state.subscribe(this.config.onStateChange),this.config.onReady&&this.emitter.on("ready",({state:e})=>this.config.onReady(e)),this.config.onPurchased&&this.emitter.on("article:purchased",e=>this.config.onPurchased(e)),this.config.onUserLogin&&this.emitter.on("auth:login",({user:e})=>this.config.onUserLogin(e)),this.config.onUserLogout&&this.emitter.on("auth:logout",()=>this.config.onUserLogout()),this.config.onError&&this.emitter.on("error",e=>this.config.onError(e));const e=p({selector:this.config.contentSelector,teaserParagraphs:this.config.teaserParagraphs});this.config.headless||e.hide(),r.has()||await s(this.config.apiBaseUrl),this.paywallModule=w(this.config,this.creditsApi,this.state,this.emitter,e),this.config.enableComments&&(this.commentsModule=function(e,n,t){const o=E(e,n,t,()=>i.show()),i=function(e,n){let t=null,o=null;return{mount:function(){if(document.getElementById("cc-comment-widget"))return;let i=50;try{const e=localStorage.getItem(C);e&&(i=JSON.parse(e))}catch(e){}t=document.createElement("div"),t.id="cc-comment-widget",t.style.cssText=`\n position:fixed;top:${i}%;right:0;transform:translateY(-50%);\n height:60px;background:${e};border-radius:10px 0 0 10px;\n display:flex;align-items:center;gap:8px;padding:0 8px 0 12px;\n z-index:2147483646;box-shadow:-2px 0 16px rgba(0,0,0,.12);\n cursor:pointer;user-select:none;\n font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;\n transition:filter .2s;\n `,t.setAttribute("role","button"),t.setAttribute("aria-label","Open comments"),t.tabIndex=0;const c=document.createElement("div");c.style.cssText="color:#fff;display:flex;align-items:center;flex-shrink:0;",c.innerHTML='<svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',o=document.createElement("span"),o.style.cssText=`\n background:#fff;color:${e};border-radius:12px;\n padding:2px 7px;font-size:12px;font-weight:700;min-width:20px;\n text-align:center;display:none;\n `;const r=document.createElement("div");r.style.cssText="color:rgba(255,255,255,.65);cursor:grab;display:flex;align-items:center;padding:0 2px;flex-shrink:0;",r.innerHTML='<svg width="8" height="22" viewBox="0 0 8 22" fill="none"><circle cx="4" cy="4" r="2" fill="currentColor"/><circle cx="4" cy="11" r="2" fill="currentColor"/><circle cx="4" cy="18" r="2" fill="currentColor"/></svg>',c.addEventListener("click",n),o.addEventListener("click",n);let a=!1,s=0,l=0;function d(e){a=!0,s=e,l=t.getBoundingClientRect().top,r.style.cursor="grabbing"}function u(e){if(!a||!t)return;const n=e-s,o=Math.max(0,Math.min(window.innerHeight-60,l+n))/window.innerHeight*100;t.style.top=`${o}%`}function p(){if(!a||!t)return;a=!1,r.style.cursor="grab";const e=t.getBoundingClientRect().top/window.innerHeight*100;try{localStorage.setItem(C,JSON.stringify(e))}catch(e){}}r.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),d(e.clientY)}),r.addEventListener("touchstart",e=>{e.preventDefault(),d(e.touches[0].clientY)},{passive:!1}),document.addEventListener("mousemove",e=>u(e.clientY)),document.addEventListener("touchmove",e=>u(e.touches[0].clientY),{passive:!0}),document.addEventListener("mouseup",p),document.addEventListener("touchend",p),t.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||n()}),t.appendChild(c),t.appendChild(o),t.appendChild(r),document.body.appendChild(t)},setCount:function(e){o&&(e>0?(o.textContent=e>99?"99+":String(e),o.style.display="inline-block"):o.style.display="none")},show:function(){t&&(t.style.display="flex")},hide:function(){t&&(t.style.display="none")},destroy:function(){null==t||t.remove(),t=null,o=null}}}(e.theme.primaryColor,()=>{i.hide(),o.openPanel()});return{init:function(){i.mount()},open:function(){i.hide(),o.openPanel()},close:function(){o.closePanel()},destroy:function(){o.destroy(),i.destroy()}}}(this.config,this.commentsApi,this.emitter),this.commentsModule.init()),await this.paywallModule.init(),this.emitter.emit("ready",{state:this.state.get()})}subscribe(e){return this.state.subscribe(e)}async login(){var e;await(null===(e=this.paywallModule)||void 0===e?void 0:e.login())}async purchase(){var e;await(null===(e=this.paywallModule)||void 0===e?void 0:e.purchase())}buyMoreCredits(){var e;null===(e=this.paywallModule)||void 0===e||e.buyMoreCredits()}on(e,n){return this.emitter.on(e,n)}off(e,n){this.emitter.off(e,n)}getState(){return this.state.get()}async checkAccess(){var e;await(null===(e=this.paywallModule)||void 0===e?void 0:e.checkAccess())}openComments(){var e;null===(e=this.commentsModule)||void 0===e||e.open()}closeComments(){var e;null===(e=this.commentsModule)||void 0===e||e.close()}isLoggedIn(){return r.has()}getToken(){return r.get()}async logout(){const e=a.get();if(e)try{await fetch(`${this.config.apiBaseUrl}/auth/log-out`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:e}),credentials:"omit"})}catch(e){}r.clear(),a.clear(),this.state.reset(),this.emitter.emit("auth:logout",{})}destroy(){var e,n;null===(e=this.paywallModule)||void 0===e||e.destroy(),null===(n=this.commentsModule)||void 0===n||n.destroy(),this.emitter.removeAll(),this.state.reset()}static get version(){return"2.10.0"}}!function(){var e,n,t;const o=null!==(e=document.currentScript)&&void 0!==e?e:document.querySelector("script[data-cc-api-key], script[data-api-key]");if(!o)return;const i=o.dataset,c=null!==(n=i.ccApiKey)&&void 0!==n?n:i.apiKey;if(!c)return;const r={apiKey:c,contentSelector:null!==(t=i.ccContentSelector)&&void 0!==t?t:i.contentSelector,teaserParagraphs:i.ccTeaserParagraphs?parseInt(i.ccTeaserParagraphs,10):void 0,enableComments:"false"!==i.ccEnableComments,extensionId:i.ccExtensionId,debug:"true"===i.ccDebug};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>N.init(r)):N.init(r)}(),e.ContentCredits=N});
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ContentCreditsSDK={})}(this,function(e){"use strict";function n(e){try{const n=e.split(".");if(3!==n.length)return null;const t=n[1].replace(/-/g,"+").replace(/_/g,"/"),o=t.padEnd(t.length+(4-t.length%4)%4,"="),i=decodeURIComponent(atob(o).split("").map(e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)).join(""));return JSON.parse(i)}catch(e){return null}}function t(e){const t=n(e);return!t||"number"!=typeof t.exp||Date.now()/1e3>t.exp}const o="cc_sdk_token",i="cc_rt";let c=null;const r={set(e){c=e;try{sessionStorage.setItem(o,e)}catch(e){}},get(){if(c)return t(c)?(this.clear(),null):c;try{const e=sessionStorage.getItem(o);if(e)return t(e)?(this.clear(),null):(c=e,e)}catch(e){}return null},clear(){c=null;try{sessionStorage.removeItem(o)}catch(e){}},has(){return null!==this.get()}},a={set(e){try{localStorage.setItem(i,e)}catch(e){}},get(){try{return localStorage.getItem(i)}catch(e){return null}},clear(){try{localStorage.removeItem(i)}catch(e){}},has(){return null!==this.get()}};async function s(e){const n=a.get();if(!n)return!1;const t=new AbortController,o=setTimeout(()=>t.abort(),8e3);try{const i=await fetch(`${e}/auth/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:n}),credentials:"omit",signal:t.signal});if(clearTimeout(o),!i.ok)return a.clear(),!1;const c=await i.json();return(null==c?void 0:c.accessToken)&&(null==c?void 0:c.refreshToken)?(r.set(c.accessToken),a.set(c.refreshToken),!0):(a.clear(),!1)}catch(e){return clearTimeout(o),!1}}const l=new Map;class d extends Error{constructor(e,n,t){super(n),this.status=e,this.data=t,this.name="ApiError"}}const u="data-cc-gated";function p(e){let n=!1,t=null,o=[];return{hide:function(){if(t=document.querySelector(e.selector),!t)return!1;if(t.hasAttribute(u))return!0;const i=Array.from(t.querySelectorAll("p, h2, h3, h4, blockquote, ul, ol"));if(i.length>e.teaserParagraphs){const n=i[e.teaserParagraphs],c=Array.from(t.childNodes),r=c.findIndex(e=>e===n||t.contains(e)&&e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING);o=c.slice(r<0?e.teaserParagraphs:r),o.forEach(e=>{var n,t,o,i;(e instanceof HTMLElement||e instanceof Text)&&(null===(t=null===(n=e.style)||void 0===n?void 0:n.setProperty)||void 0===t||t.call(n,"display","none"),null===(i=(o=e).setAttribute)||void 0===i||i.call(o,"data-cc-hidden","true"))})}else o=Array.from(t.childNodes),o.forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")});if(t.setAttribute(u,"true"),n=!0,!t.querySelector("[data-cc-fade]")){const e=t.style.position;e&&"static"!==e||(t.style.position="relative");const n=document.createElement("div");n.setAttribute("data-cc-fade","true"),n.style.cssText="position:absolute;bottom:0;left:0;width:100%;height:160px;background:linear-gradient(to bottom,transparent 0%,var(--cc-bg,#fff) 100%);pointer-events:none;z-index:1;",t.appendChild(n)}return!0},reveal:function(){if(!n)return;o.forEach(e=>{e instanceof HTMLElement&&(e.style.removeProperty("display"),e.removeAttribute("data-cc-hidden"))});const e=null==t?void 0:t.querySelector("[data-cc-fade]");e&&e.remove(),o=[],null==t||t.removeAttribute(u),n=!1},isGated:function(){return n}}}function h(e){const n=document.getElementById(e);n&&n.remove()}function m(e,n){const t=e.querySelector("style[data-cc-styles]");if(t)return void(t.textContent=n);const o=document.createElement("style");o.dataset.ccStyles="true",o.textContent=n,e.appendChild(o)}function f(e,n){e.textContent=n}function g(e,n,t){const o=document.createElement(e);return void 0!==n&&(o.textContent=n),o}const b="cc-paywall-host";function y(){const e=navigator.userAgent;return!!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(e)||!("function"!=typeof window.matchMedia||!window.matchMedia("(pointer: coarse)").matches||!window.matchMedia("(max-width: 768px)").matches)}function v(){var e,n;try{const t=new URL(window.location.href),o=null!==(e=t.searchParams.get("token"))&&void 0!==e?e:t.searchParams.get("cc_token"),i=null!==(n=t.searchParams.get("refresh_token"))&&void 0!==n?n:t.searchParams.get("cc_refresh_token");if(function(){try{const e=new URL(window.location.href);let n=!1;["token","cc_token","refresh_token","cc_refresh_token"].forEach(t=>{e.searchParams.has(t)&&(e.searchParams.delete(t),n=!0)}),n&&history.replaceState(null,"",e.toString())}catch(e){}}(),i&&a.set(i),o){r.set(o);const e=window.opener;if(e&&!e.closed){try{e.postMessage({type:"cc_auth_callback",token:o,refreshToken:null!=i?i:null},window.location.origin)}catch(e){}setTimeout(()=>{try{window.close()}catch(e){}},300)}return o}}catch(e){}return null}function x(e){return new Promise(n=>{let t=null,o=!1;function i(e){o||(o=!0,clearInterval(l),window.removeEventListener("message",c),n(e))}function c(e){if(e.origin!==window.location.origin)return;if("object"!=typeof(n=e.data)||null===n||"cc_auth_callback"!==n.type)return;var n;const o=e.data.token,c=e.data.refreshToken;if(o){r.set(o),c&&a.set(c);try{null==t||t.close()}catch(e){}i(o)}}window.addEventListener("message",c);try{t=window.open(e,"ccAuthPopup",`scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=600,height=650,left=${Math.round(window.screenX+(window.outerWidth-600)/2)},top=${Math.round(window.screenY+(window.outerHeight-650)/2)}`)}catch(e){return window.removeEventListener("message",c),void n(null)}if(!t||t.closed)return window.removeEventListener("message",c),void n(null);let s=0;const l=setInterval(()=>{var e,n;if(s+=200,t&&!t.closed)if(s>3e5){try{t.close()}catch(e){}i(null)}else try{const o=t.location.href;if(o.includes("/auth/callback")||o.includes("cc_token=")||o.includes("token=")){const o=new URLSearchParams(t.location.search),c=null!==(e=o.get("token"))&&void 0!==e?e:o.get("cc_token"),s=null!==(n=o.get("refresh_token"))&&void 0!==n?n:o.get("cc_refresh_token");if(c){r.set(c),s&&a.set(s);try{t.close()}catch(e){}i(c)}}}catch(e){}else i(r.get())},200)})}function w(e,n,t,o,i){const c=null!=i?i:p({selector:e.contentSelector,teaserParagraphs:e.teaserParagraphs}),a=function(e){let n=null,t=null;function o(){const o=document.querySelector(e.contentSelector);if(!o)return;const{root:i}=function(e,n){let t=document.getElementById(e);t||(t=document.createElement("div"),t.id=e,n.parentNode.insertBefore(t,n.nextSibling));const o=t._ccShadow;if(o)return{host:t,root:o};const i=t.attachShadow({mode:"open"});return t._ccShadow=i,{host:t,root:i}}(b,o);var c,r;n=i,m(n,`\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n /* Inline paywall panel — sits below the teaser content in the page flow */\n .cc-paywall-inline {\n width: 100%;\n padding: 36px 24px 32px;\n background: #fff;\n border: 1px solid #e5e7eb;\n border-top: 3px solid ${c=e.theme.primaryColor};\n border-radius: 0 0 12px 12px;\n text-align: center;\n font-family: ${r=e.theme.fontFamily};\n box-sizing: border-box;\n }\n\n .cc-paywall-inline h2 {\n font-size: 20px;\n font-weight: 700;\n color: #111827;\n margin-bottom: 8px;\n }\n\n .cc-paywall-inline p {\n font-size: 14px;\n color: #6b7280;\n margin-bottom: 24px;\n line-height: 1.6;\n }\n\n .cc-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 8px;\n height: 44px;\n padding: 0 20px;\n border: none;\n border-radius: 8px;\n font-family: ${r};\n font-size: 15px;\n font-weight: 600;\n cursor: pointer;\n transition: opacity 0.15s ease, transform 0.1s ease;\n width: 100%;\n max-width: 320px;\n }\n .cc-btn:hover:not(:disabled) { opacity: 0.88; }\n .cc-btn:active:not(:disabled) { transform: scale(0.98); }\n .cc-btn:disabled { opacity: 0.55; cursor: not-allowed; }\n\n .cc-btn-primary {\n background: ${c};\n color: #fff;\n }\n\n .cc-btn-secondary {\n background: #111827;\n color: #fff;\n margin-top: 10px;\n }\n\n .cc-btn-outline {\n background: transparent;\n color: #111827;\n border: 2px solid #111827;\n margin-top: 10px;\n }\n\n .cc-credit-badge {\n display: inline-block;\n background: #fef3c7;\n color: #92400e;\n border-radius: 20px;\n padding: 2px 10px;\n font-size: 13px;\n font-weight: 600;\n margin-bottom: 16px;\n }\n\n .cc-spinner {\n width: 18px; height: 18px;\n border: 2px solid rgba(255,255,255,0.4);\n border-top-color: #fff;\n border-radius: 50%;\n animation: cc-spin 0.7s linear infinite;\n flex-shrink: 0;\n }\n @keyframes cc-spin { to { transform: rotate(360deg); } }\n\n .cc-powered-by {\n margin-top: 20px;\n font-size: 12px;\n color: #9ca3af;\n }\n .cc-powered-by a {\n color: ${c};\n text-decoration: none;\n font-weight: 600;\n }\n .cc-powered-by a:hover { text-decoration: underline; }\n `),t=g("div"),t.className="cc-paywall-inline",n.appendChild(t)}function i(){const e=g("div");e.className="cc-powered-by",e.textContent="Powered by ";const n=g("a","Content Credits");return n.setAttribute("href","https://contentcredits.com"),n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer"),e.appendChild(n),e}function c(){h(b),n=null,t=null}return{init:o,render:function(e,n,r){var a,s,l;if("checking"!==e&&(t||o(),t)){for(;t.firstChild;)t.removeChild(t.firstChild);switch(e){case"login":!function(e,n){e.appendChild(g("h2","This article requires a subscription")),e.appendChild(g("p","Log in with your Content Credits account to unlock this article."));const t=g("button","Login & Buy with Content Credits");t.className="cc-btn cc-btn-primary",t.addEventListener("click",()=>{n.onLogin()}),e.appendChild(t),e.appendChild(i())}(t,n);break;case"purchase":!function(e,n,t){if(e.appendChild(g("h2","Unlock this article")),null!==t){const n=g("span",`${t} credit${1!==t?"s":""}`);n.className="cc-credit-badge",e.appendChild(n)}e.appendChild(g("p","Use your Content Credits balance to instantly access this premium article."));const o=g("button",null!==t?`Buy for ${t} Credit${1!==t?"s":""}`:"Buy with Content Credits");o.className="cc-btn cc-btn-primary",o.addEventListener("click",()=>{n.onPurchase()}),e.appendChild(o),e.appendChild(i())}(t,n,null!==(a=null==r?void 0:r.requiredCredits)&&void 0!==a?a:null);break;case"insufficient":!function(e,n,t,o){e.appendChild(g("h2","Not enough credits"));const c=null!==t&&null!==o?`You need ${t} credit${1!==t?"s":""} but have ${o}. Top up to unlock this article.`:"You don't have enough credits to unlock this article. Purchase more to continue.";e.appendChild(g("p",c));const r=g("button","Buy More Credits");r.className="cc-btn cc-btn-primary",r.addEventListener("click",()=>n.onBuyMoreCredits()),e.appendChild(r),e.appendChild(i())}(t,n,null!==(s=null==r?void 0:r.requiredCredits)&&void 0!==s?s:null,null!==(l=null==r?void 0:r.creditBalance)&&void 0!==l?l:null);break;case"loading":!function(e){const n=g("button");n.className="cc-btn cc-btn-primary",n.disabled=!0;const t=g("span");t.className="cc-spinner",n.appendChild(t),n.appendChild(document.createTextNode(" Processing…")),e.appendChild(n)}(t);break;case"granted":c()}}},setButtonLoading:function(e){if(!t)return;const n=t.querySelector(".cc-btn");if(n&&(n.disabled=e,e)){const e=g("span");e.className="cc-spinner",f(n,""),n.appendChild(e),n.appendChild(document.createTextNode(" Processing…"))}},destroy:c}}(e),s=function(){let e=null,n=null;function t(t){var o,i,c,r;if(!function(){const e=["https://accounts.contentcredits.com"];try{e.push(window.location.origin)}catch(e){}return e}().includes(t.origin)&&t.origin!==window.location.origin)return;const a=t.data;if(a&&"object"==typeof a&&a.type)switch(a.type){case"authorization_response":{const n=null!==(o=a.data)&&void 0!==o?o:null===(i=t.detail)||void 0===i?void 0:i.data;n&&e&&e(n);break}case"purchase_response":{const e=null!==(c=a.data)&&void 0!==c?c:null===(r=t.detail)||void 0===r?void 0:r.data;e&&n&&n(e);break}}}return{attach:function(){window.addEventListener("message",t),window.addEventListener("authorization_response",n=>{const t=n.detail;(null==t?void 0:t.data)&&e&&e(t.data)}),window.addEventListener("purchase_response",e=>{const t=e.detail;(null==t?void 0:t.data)&&n&&n(t.data)})},detach:function(){window.removeEventListener("message",t)},requestAuthorization:function(e,n){window.postMessage({type:"request_authorization",data:{articleId:e,hostName:n}},window.location.origin)},requestPurchase:function(e){window.postMessage({type:"request_purchase",data:e},window.location.origin)},requestLogin:function(e){window.postMessage({type:"request_login",data:{hostName:e}},window.location.origin)},onAuthorizationResponse:function(n){e=n},onPurchaseResponse:function(e){n=e}}}();let l=!1;function u(n=0,i=0){var r;t.set({hasAccess:!0,isLoaded:!0,isLoading:!1}),e.headless||(c.reveal(),a.render("granted",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),o.emit("paywall:hidden",{}),o.emit("article:purchased",{creditsSpent:n,remainingBalance:i}),null===(r=e.onAccessGranted)||void 0===r||r.call(e)}async function w(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;l?s.requestLogin(e.hostName):y()?window.location.href=n:(e.headless||a.render("loading",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),await x(n)?(t.set({isLoggedIn:!0}),await L()):e.headless||a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}))}async function C(){var i,c,p,h,m;if(r.has())if(l)s.requestPurchase({articleId:e.apiKey,hostName:e.hostName,location:e.articleUrl,title:e.pageTitle});else{e.headless||a.render("loading",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),t.set({isLoading:!0});try{const c=await n.purchaseArticle({apiKey:e.apiKey,postUrl:e.articleUrl,postName:e.pageTitle,hostName:e.hostName});c.success?u(0,0):(t.set({isLoading:!1}),e.headless||a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),o.emit("error",{message:null!==(i=c.message)&&void 0!==i?i:"Purchase failed"}))}catch(n){if(t.set({isLoading:!1}),n instanceof d&&402===n.status){e.headless||a.render("insufficient",{onLogin:w,onPurchase:C,onBuyMoreCredits:k},{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance});const n=null!==(c=t.get().requiredCredits)&&void 0!==c?c:0,i=null!==(p=t.get().creditBalance)&&void 0!==p?p:0;null===(h=e.onInsufficientCredits)||void 0===h||h.call(e,{required:n,available:i}),o.emit("credits:insufficient",{required:n,available:i})}else e.headless||a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),null===(m=e.onPurchaseRequired)||void 0===m||m.call(e,{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance}),o.emit("error",{message:"Purchase failed",error:n})}}else await w()}function k(){window.open("https://accounts.contentcredits.com/consumer/dashboard","_blank","noopener,noreferrer")}async function L(){var i,p,h;if(t.set({isLoading:!0}),e.headless||a.render("checking",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),l)s.requestAuthorization(e.apiKey,e.hostName);else{if(!r.has())return t.set({isLoading:!1,isLoaded:!0}),e.headless||(c.hide(),a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(i=e.onLoginRequired)||void 0===i||i.call(e),void o.emit("paywall:shown",{});try{const i=await n.checkAccess({apiKey:e.apiKey,postUrl:e.articleUrl,postName:e.pageTitle,hostName:e.hostName});t.set({isLoading:!1,isLoaded:!0,hasAccess:i.success,isLoggedIn:!0}),i.success?u(0,0):(e.headless||(c.hide(),a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(p=e.onPurchaseRequired)||void 0===p||p.call(e,{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance}),o.emit("paywall:shown",{}))}catch(n){t.set({isLoading:!1,isLoaded:!0}),e.headless||(c.hide(),a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(h=e.onLoginRequired)||void 0===h||h.call(e),n instanceof d&&401===n.status||o.emit("error",{message:"Access check failed",error:n})}}}return{init:async function(){var n;v()&&t.set({isLoggedIn:!0}),l=await(n=e.extensionId,n&&"string"==typeof n?new Promise(e=>{let t=!1;function o(n){t||(t=!0,e(n))}if(!0===window.__CC_EXTENSION_LOADED)return void o(!0);const i=new Image;i.onload=()=>o(!0),i.onerror=()=>o(!1),i.src=`chrome-extension://${n}/icons/icon16.png`,setTimeout(()=>o(!1),2e3)}):Promise.resolve(!1)),t.set({isExtensionAvailable:l}),l&&(s.attach(),s.onAuthorizationResponse(n=>{var i,r,s,l,d,p,h;t.set({isLoggedIn:n.isAuthenticated,hasAccess:n.doesHaveAccess,isLoaded:!0,isLoading:!1,creditBalance:null!==(i=n.creditBalance)&&void 0!==i?i:null,requiredCredits:null!==(r=n.requiredCredits)&&void 0!==r?r:null}),n.isAuthenticated?n.doesHaveAccess?u(0,null!==(l=n.creditBalance)&&void 0!==l?l:0):(e.headless||(c.hide(),a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k},{requiredCredits:n.requiredCredits,creditBalance:n.creditBalance})),null===(d=e.onPurchaseRequired)||void 0===d||d.call(e,{requiredCredits:null!==(p=n.requiredCredits)&&void 0!==p?p:null,creditBalance:null!==(h=n.creditBalance)&&void 0!==h?h:null}),o.emit("paywall:shown",{})):(e.headless||(c.hide(),a.render("login",{onLogin:w,onPurchase:C,onBuyMoreCredits:k})),null===(s=e.onLoginRequired)||void 0===s||s.call(e),o.emit("paywall:shown",{}))}),s.onPurchaseResponse(e=>{var n,i;t.set({isLoading:!1,isLoaded:!0,hasAccess:e.doesHaveAccess}),e.doesHaveAccess?u(null!==(n=e.creditsSpent)&&void 0!==n?n:0,null!==(i=e.creditBalance)&&void 0!==i?i:0):(a.render("purchase",{onLogin:w,onPurchase:C,onBuyMoreCredits:k}),o.emit("error",{message:"Purchase failed via extension"}))})),await L()},checkAccess:L,destroy:function(){s.detach(),e.headless||(a.destroy(),c.reveal())},login:w,purchase:C,buyMoreCredits:k}}const C="cc-widget-pos",k="cc-comments-host",L=["#6366f1","#ec4899","#8b5cf6","#14b8a6","#f59e0b","#ef4444"];function E(e,t,o,i){let c=null,a=null,s=null,l=[],d="TOP",u=null,p=null,b=null;function w(){if(c)return c;const{root:n}=function(e){let n=document.getElementById(e);n||(n=document.createElement("div"),n.id=e,n.style.cssText="position:fixed;top:0;left:0;width:0;height:0;pointer-events:none;z-index:2147483647;",document.body.appendChild(n));const t=n._ccShadow;if(t)return{host:n,root:t};const o=n.attachShadow({mode:"open"});return n._ccShadow=o,{host:n,root:o}}(k);var t,o;return c=n,m(c,`\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n /* ── Widget Button ───────────────────────────────────── */\n .cc-widget-btn {\n position: fixed;\n top: 50%;\n right: 0;\n transform: translateY(-50%);\n width: auto;\n height: 60px;\n background: ${t=e.theme.primaryColor};\n border-radius: 10px 0 0 10px;\n display: flex;\n align-items: center;\n gap: 8px;\n padding-left: 12px;\n padding-right: 6px;\n z-index: 2147483646;\n box-shadow: -2px 0 16px rgba(0,0,0,0.12);\n cursor: pointer;\n user-select: none;\n font-family: ${o=e.theme.fontFamily};\n transition: background 0.2s;\n pointer-events: all;\n }\n .cc-widget-btn:hover { filter: brightness(1.08); }\n\n .cc-widget-icon { color: #fff; display: flex; align-items: center; }\n .cc-widget-badge {\n background: #fff;\n color: ${t};\n border-radius: 12px;\n padding: 2px 7px;\n font-size: 12px;\n font-weight: 700;\n min-width: 20px;\n text-align: center;\n }\n .cc-widget-drag-handle {\n color: rgba(255,255,255,0.7);\n cursor: grab;\n display: flex;\n align-items: center;\n padding: 0 4px;\n }\n .cc-widget-drag-handle:active { cursor: grabbing; }\n\n /* ── Panel Overlay ───────────────────────────────────── */\n .cc-panel-backdrop {\n position: fixed;\n inset: 0;\n background: rgba(0,0,0,0.35);\n z-index: 2147483645;\n opacity: 0;\n transition: opacity 0.25s;\n pointer-events: all;\n }\n .cc-panel-backdrop.cc-visible { opacity: 1; }\n\n .cc-panel {\n position: fixed;\n top: 0; right: -500px;\n width: 460px;\n max-width: 95vw;\n height: 100%;\n background: #f9fafb;\n z-index: 2147483646;\n display: flex;\n flex-direction: column;\n box-shadow: -4px 0 32px rgba(0,0,0,0.12);\n transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);\n font-family: ${o};\n pointer-events: all;\n }\n .cc-panel.cc-open { right: 0; }\n\n /* ── Panel Header ────────────────────────────────────── */\n .cc-panel-header {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 16px 20px;\n border-bottom: 1px solid #e5e7eb;\n background: #fff;\n flex-shrink: 0;\n }\n .cc-panel-title {\n font-size: 16px;\n font-weight: 700;\n color: #111827;\n flex: 1;\n }\n .cc-panel-count {\n font-size: 13px;\n color: #6b7280;\n font-weight: 400;\n }\n .cc-panel-close-btn {\n background: transparent;\n border: none;\n cursor: pointer;\n color: #6b7280;\n padding: 4px;\n display: flex;\n align-items: center;\n border-radius: 6px;\n transition: background 0.15s;\n }\n .cc-panel-close-btn:hover { background: #f3f4f6; }\n\n .cc-back-btn {\n background: transparent;\n border: none;\n cursor: pointer;\n color: #6b7280;\n padding: 4px;\n display: none;\n align-items: center;\n border-radius: 6px;\n transition: background 0.15s;\n }\n .cc-back-btn.cc-visible { display: flex; }\n .cc-back-btn:hover { background: #f3f4f6; }\n\n /* ── Sort Bar ────────────────────────────────────────── */\n .cc-sort-bar {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 10px 20px;\n border-bottom: 1px solid #f3f4f6;\n background: #fff;\n flex-shrink: 0;\n }\n .cc-sort-label { font-size: 12px; color: #9ca3af; font-weight: 500; }\n .cc-sort-btn {\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 12px;\n font-weight: 600;\n color: #6b7280;\n padding: 4px 8px;\n border-radius: 6px;\n font-family: ${o};\n transition: background 0.15s, color 0.15s;\n }\n .cc-sort-btn:hover { background: #f3f4f6; }\n .cc-sort-btn.cc-active { background: #111827; color: #fff; }\n\n /* ── Comments List ───────────────────────────────────── */\n .cc-comments-list {\n flex: 1;\n overflow-y: auto;\n overscroll-behavior: contain;\n }\n .cc-comments-list::-webkit-scrollbar { width: 4px; }\n .cc-comments-list::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }\n\n /* ── Comment Card ────────────────────────────────────── */\n .cc-comment-card {\n padding: 16px 20px;\n background: #fff;\n border-bottom: 1px solid #f3f4f6;\n }\n .cc-comment-card.cc-reply {\n padding-left: 36px;\n background: #fafafa;\n }\n\n .cc-comment-header {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n margin-bottom: 8px;\n }\n .cc-comment-author-row { display: flex; align-items: center; gap: 10px; }\n\n .cc-avatar {\n width: 32px; height: 32px;\n border-radius: 50%;\n flex-shrink: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n color: #fff;\n font-weight: 700;\n font-size: 12px;\n overflow: hidden;\n }\n .cc-avatar img { width: 100%; height: 100%; object-fit: cover; }\n\n .cc-author-name {\n font-size: 14px;\n font-weight: 700;\n color: #111827;\n }\n .cc-comment-time {\n font-size: 11px;\n color: #9ca3af;\n margin-top: 2px;\n }\n\n .cc-comment-body {\n font-size: 14px;\n color: #374151;\n line-height: 1.6;\n margin-bottom: 12px;\n word-break: break-word;\n white-space: pre-wrap;\n }\n\n .cc-comment-actions {\n display: flex;\n align-items: center;\n gap: 12px;\n }\n .cc-action-btn {\n display: inline-flex;\n align-items: center;\n gap: 5px;\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 12px;\n font-weight: 500;\n color: #6b7280;\n padding: 3px 6px;\n border-radius: 6px;\n font-family: ${o};\n transition: background 0.15s, color 0.15s;\n }\n .cc-action-btn:hover { background: #f3f4f6; }\n .cc-action-btn.cc-liked { color: #ef4444; }\n .cc-action-btn.cc-danger:hover { color: #ef4444; background: #fef2f2; }\n .cc-action-btn.cc-owner-actions { margin-left: auto; }\n\n /* ── Reply Subthread ─────────────────────────────────── */\n .cc-subthread-label {\n font-size: 11px;\n font-weight: 600;\n color: #94a3b8;\n text-transform: uppercase;\n letter-spacing: 0.05em;\n padding: 12px 20px 8px;\n background: #f9fafb;\n }\n\n /* ── Empty / Loading / Error ─────────────────────────── */\n .cc-empty-state, .cc-loading-state, .cc-error-state {\n text-align: center;\n padding: 60px 20px;\n color: #9ca3af;\n }\n .cc-empty-state p, .cc-loading-state p, .cc-error-state p {\n font-size: 14px;\n font-weight: 500;\n color: #9ca3af;\n margin-bottom: 6px;\n }\n .cc-empty-state span, .cc-loading-state span, .cc-error-state span {\n font-size: 13px;\n color: #d1d5db;\n }\n .cc-error-state .cc-retry-btn {\n margin-top: 16px;\n padding: 8px 16px;\n background: #111827;\n color: #fff;\n border: none;\n border-radius: 6px;\n font-size: 13px;\n font-weight: 500;\n cursor: pointer;\n font-family: ${o};\n }\n .cc-error-icon { color: #ef4444; margin-bottom: 12px; }\n\n .cc-spinner-lg {\n width: 28px; height: 28px;\n border: 2px solid #e5e7eb;\n border-top-color: ${t};\n border-radius: 50%;\n animation: cc-spin 0.7s linear infinite;\n margin: 0 auto 12px;\n }\n @keyframes cc-spin { to { transform: rotate(360deg); } }\n\n /* ── Compose Box ─────────────────────────────────────── */\n .cc-compose {\n border-top: 1px solid #e5e7eb;\n padding: 12px 20px;\n background: #fff;\n flex-shrink: 0;\n position: relative;\n }\n\n .cc-compose-textarea {\n width: 100%;\n min-height: 72px;\n max-height: 180px;\n border: 1.5px solid #d1d5db;\n border-radius: 8px;\n padding: 10px 12px;\n font-size: 14px;\n font-family: ${o};\n color: #111827;\n resize: vertical;\n outline: none;\n background: #fff;\n transition: border-color 0.15s;\n line-height: 1.5;\n }\n .cc-compose-textarea:focus { border-color: ${t}; }\n .cc-compose-textarea::placeholder { color: #9ca3af; }\n\n .cc-compose-actions {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-top: 8px;\n gap: 8px;\n }\n .cc-compose-cancel {\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 13px;\n color: #6b7280;\n font-family: ${o};\n padding: 6px;\n display: none;\n }\n .cc-compose-cancel.cc-visible { display: block; }\n .cc-compose-submit {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n height: 36px;\n padding: 0 16px;\n background: ${t};\n color: #fff;\n border: none;\n border-radius: 7px;\n font-size: 13px;\n font-weight: 600;\n cursor: pointer;\n font-family: ${o};\n margin-left: auto;\n transition: opacity 0.15s;\n }\n .cc-compose-submit:disabled { opacity: 0.55; cursor: not-allowed; }\n\n .cc-spinner-sm {\n width: 14px; height: 14px;\n border: 2px solid rgba(255,255,255,0.4);\n border-top-color: #fff;\n border-radius: 50%;\n animation: cc-spin 0.7s linear infinite;\n }\n\n /* ── Login Overlay inside compose ────────────────────── */\n .cc-login-overlay {\n position: absolute;\n inset: 0;\n background: rgba(255,255,255,0.95);\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 10px;\n padding: 16px;\n border-top: 1px solid #e5e7eb;\n }\n .cc-login-overlay p {\n font-size: 14px;\n color: #6b7280;\n text-align: center;\n }\n .cc-login-overlay-btn {\n height: 40px;\n padding: 0 20px;\n background: ${t};\n color: #fff;\n border: none;\n border-radius: 8px;\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n font-family: ${o};\n }\n `),c}function C(){const e=r.get();a=e?function(e){var t,o;const i=n(e);return i&&null!==(o=null!==(t=i.id)&&void 0!==t?t:i._id)&&void 0!==o?o:null}(e):null}async function E(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;y()?window.location.href=n:await x(n)&&(C(),U(),N())}async function N(){var n;const o=w(),i=o.getElementById("cc-comments-list");if(i){!function(e){e.innerHTML="";const n=g("div");n.className="cc-loading-state";const t=g("div");t.className="cc-spinner-lg",n.appendChild(t),n.appendChild(g("p","Loading comments…")),e.appendChild(n)}(i);try{const c=await t.ensureThread({pageUrl:e.articleUrl,hostname:e.hostName});if(!c._id)return void I(i,"Comments are not available for this page.");s=c._id;const r=await t.getComments({pageUrl:e.articleUrl,sortBy:d});l=null!==(n=r.comments)&&void 0!==n?n:[],r.thread&&(s=r.thread._id);const a=o.getElementById("cc-header-count");a&&f(a,String(l.length)),P(i)}catch(e){I(i,"Unable to reach the server. Check your connection.")}}}function B(e){const n=new Map,t=[];return e.forEach(e=>n.set(e._id,Object.assign(Object.assign({},e),{replies:[]}))),e.forEach(e=>{const o=n.get(e._id);if(e.parentCommentId){const t=n.get(e.parentCommentId);t&&!t.parentCommentId&&t.replies.push(o)}else t.push(o)}),t}function I(e,n){e.innerHTML="";const t=g("div");t.className="cc-error-state";const o=g("div");o.className="cc-error-icon",o.innerHTML='<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',t.appendChild(o),t.appendChild(g("p",n));const i=g("button","Try Again");i.className="cc-retry-btn",i.addEventListener("click",()=>{N()}),t.appendChild(i),e.appendChild(t)}function P(e){e.innerHTML="";const n=w(),t=n.getElementById("cc-back-btn"),o=n.getElementById("cc-panel-title");if(u?(null==t||t.classList.add("cc-visible"),o&&f(o,"Replies")):(null==t||t.classList.remove("cc-visible"),o&&f(o,"Comments")),u)!function(e,n){var t,o,i,c,r;const a=B(l).find(e=>e._id===n);if(!a)return;e.appendChild(T(a,!1));const s=g("div",`${null!==(o=null===(t=a.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0} ${1===(null!==(c=null===(i=a.replies)||void 0===i?void 0:i.length)&&void 0!==c?c:0)?"REPLY":"REPLIES"}`);if(s.className="cc-subthread-label",e.appendChild(s),null===(r=a.replies)||void 0===r?void 0:r.length)a.replies.forEach(n=>e.appendChild(T(n,!0)));else{const n=g("div");n.className="cc-empty-state",n.style.paddingTop="20px",n.appendChild(g("p","No replies yet")),e.appendChild(n)}}(e,u);else{if(0===l.length){const n=g("div");n.className="cc-empty-state",n.appendChild(g("p","No comments yet"));const t=g("span","Be the first to share your thoughts");return n.appendChild(t),void e.appendChild(n)}(function(e){const n=[...e];return"NEWEST"===d?n.sort((e,n)=>new Date(n.createdAt).getTime()-new Date(e.createdAt).getTime()):n.sort((e,n)=>{var t,o,i,c,r,a;return(null!==(o=null===(t=n.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0)-(null!==(c=null===(i=e.replies)||void 0===i?void 0:i.length)&&void 0!==c?c:0)||(null!==(r=n.likeCount)&&void 0!==r?r:0)-(null!==(a=e.likeCount)&&void 0!==a?a:0)}),n.forEach(e=>{var n;(null===(n=e.replies)||void 0===n?void 0:n.length)&&e.replies.sort((e,n)=>new Date(n.createdAt).getTime()-new Date(e.createdAt).getTime())}),n})(B(l)).forEach(n=>e.appendChild(T(n,!1)))}}function T(n,t){var o,i;const c=!(!a||n.authorId!==a),r=n.author,s=r?`${r.firstName} ${r.lastName}`.trim():"Anonymous",l=L[(s||"A").charCodeAt(0)%L.length],d=r?function(e,n){var t,o,i,c;return`${null!==(o=null===(t=null==e?void 0:e[0])||void 0===t?void 0:t.toUpperCase())&&void 0!==o?o:""}${null!==(c=null===(i=null==n?void 0:n[0])||void 0===i?void 0:i.toUpperCase())&&void 0!==c?c:""}`||"?"}(r.firstName,r.lastName):"?",u=g("div");u.className="cc-comment-card"+(t?" cc-reply":""),u.dataset.commentId=n._id;const p=g("div");p.className="cc-comment-header";const h=g("div");h.className="cc-comment-author-row";const m=g("div");if(m.className="cc-avatar",m.style.background=l,null==r?void 0:r.profilePicture){const n=function(e){try{const n=new URL(e);return"http:"!==n.protocol&&"https:"!==n.protocol?null:n.toString()}catch(e){return null}}(r.profilePicture.startsWith("http")?r.profilePicture:`${e.apiBaseUrl}${r.profilePicture}`);if(n){const e=g("img");e.setAttribute("src",n),e.setAttribute("alt",s),e.addEventListener("error",()=>{e.remove(),f(m,d)}),m.appendChild(e)}else f(m,d)}else f(m,d);const b=g("div"),y=g("div",s);y.className="cc-author-name";const v=g("div",function(e){try{const n=new Date(e);return`${n.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"})} · ${n.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}`}catch(e){return""}}(n.createdAt));v.className="cc-comment-time",b.appendChild(y),b.appendChild(v),h.appendChild(m),h.appendChild(b),p.appendChild(h),u.appendChild(p);const x=g("div");x.className="cc-comment-body",x.appendChild(function(e){const n=document.createDocumentFragment(),t=e.split("\n");return t.forEach((e,o)=>{n.appendChild(document.createTextNode(e)),o<t.length-1&&n.appendChild(document.createElement("br"))}),n}(n.content)),u.appendChild(x);const w=g("div");if(w.className="cc-comment-actions",!t){const e=g("button");e.className="cc-action-btn",e.dataset.commentId=n._id,e.dataset.action="reply",e.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="transform:scaleX(-1)"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',e.appendChild(document.createTextNode(` ${(null===(o=n.replies)||void 0===o?void 0:o.length)||"Reply"}`)),w.appendChild(e)}const C=g("button");if(C.className="cc-action-btn"+(n.hasLiked?" cc-liked":""),C.dataset.commentId=n._id,C.dataset.action="like",C.innerHTML=`<svg width="14" height="14" viewBox="0 0 24 24" fill="${n.hasLiked?"currentColor":"none"}" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"/></svg>`,C.appendChild(document.createTextNode(` ${null!==(i=n.likeCount)&&void 0!==i?i:0}`)),w.appendChild(C),c){const e=g("div");e.className="cc-action-btn cc-owner-actions",e.style.cssText="margin-left:auto;display:flex;gap:4px;background:transparent;border:none;padding:0;";const t=g("button","Edit");t.className="cc-action-btn",t.dataset.commentId=n._id,t.dataset.action="edit";const o=g("button","Delete");o.className="cc-action-btn cc-danger",o.dataset.commentId=n._id,o.dataset.action="delete",e.appendChild(t),e.appendChild(o),w.appendChild(e)}return u.appendChild(w),u}function S(){const e=g("div");e.className="cc-login-overlay",e.id="cc-login-overlay",e.appendChild(g("p","Sign in to join the conversation"));const n=g("button","Login with Content Credits");return n.className="cc-login-overlay-btn",n.addEventListener("click",()=>{E()}),e.appendChild(n),e}function A(e){const n=e.target.closest("[data-action]");if(!n)return;const i=n.dataset.action,a=n.dataset.commentId;if(a)switch(i){case"reply":!function(e){if(u){p=e,b=null;const n=null==c?void 0:c.getElementById("cc-compose-textarea");n&&(n.placeholder="Write a reply…",n.focus()),M()}else{u=e;const n=null==c?void 0:c.getElementById("cc-comments-list");n&&P(n)}}(a);break;case"like":!async function(e){var n,i,a,s,d;if(!r.has())return void E();const u=l.find(n=>n._id===e);if(!u)return;const p=u.hasLiked;u.hasLiked=!p,u.likeCount=(null!==(n=u.likeCount)&&void 0!==n?n:0)+(u.hasLiked?1:-1);const h=null==c?void 0:c.getElementById("cc-comments-list");h&&P(h);try{const n=await t.toggleLike(e);n.success?("boolean"==typeof(null===(i=n.data)||void 0===i?void 0:i.hasLiked)&&(u.hasLiked=n.data.hasLiked),"number"==typeof(null===(a=n.data)||void 0===a?void 0:a.likeCount)&&(u.likeCount=n.data.likeCount),o.emit("comment:liked",{commentId:e,hasLiked:u.hasLiked})):(u.hasLiked=p,u.likeCount=(null!==(s=u.likeCount)&&void 0!==s?s:0)+(p?1:-1)),h&&P(h)}catch(e){u.hasLiked=p,u.likeCount=(null!==(d=u.likeCount)&&void 0!==d?d:0)+(p?1:-1),h&&P(h)}}(a);break;case"edit":!function(e){const n=l.find(n=>n._id===e);if(!n)return;b=e,p=null;const t=null==c?void 0:c.getElementById("cc-compose-textarea");t&&(t.value=n.content,t.placeholder="Edit your comment…",t.focus());const o=null==c?void 0:c.getElementById("cc-compose-submit");o&&f(o,"Update"),M()}(a);break;case"delete":!async function(e){if(confirm("Delete this comment?"))try{(await t.deleteComment(e))._id&&(o.emit("comment:deleted",{commentId:e}),N())}catch(e){}}(a)}}function M(){const e=null==c?void 0:c.getElementById("cc-compose-cancel");null==e||e.classList.add("cc-visible")}function $(){const e=null==c?void 0:c.getElementById("cc-compose-cancel");null==e||e.classList.remove("cc-visible")}function _(){b=null,p=null;const e=null==c?void 0:c.getElementById("cc-compose-textarea");e&&(e.value="",e.placeholder="Write a comment…");const n=null==c?void 0:c.getElementById("cc-compose-submit");n&&f(n,"Post"),$()}function U(){const e=w(),n=e.getElementById("cc-login-overlay");if(r.has()&&n)n.remove();else if(!r.has()&&!n){const n=e.getElementById("cc-compose");null==n||n.appendChild(S())}}function q(){const e=c;if(!e)return;const n=e.getElementById("cc-panel-backdrop"),t=e.getElementById("cc-comments-panel");null==n||n.classList.remove("cc-visible"),null==t||t.classList.remove("cc-open"),setTimeout(()=>{null==n||n.remove(),null==t||t.remove(),i()},280)}return{openPanel:function(){const e=w();v()&&C(),C();let n=e.getElementById("cc-panel-backdrop");if(!n){const i=g("div");i.className="cc-panel-backdrop",i.id="cc-panel-backdrop",i.addEventListener("click",q),e.appendChild(i),e.appendChild(function(){const e=g("div");e.className="cc-panel",e.id="cc-comments-panel";const n=g("div");n.className="cc-panel-header";const i=g("button");i.className="cc-back-btn",i.id="cc-back-btn",i.setAttribute("aria-label","Back"),i.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M15 18l-6-6 6-6"/></svg>',i.addEventListener("click",()=>{u=null,p=null;const e=null==c?void 0:c.getElementById("cc-comments-list");e&&P(e)});const a=g("div");a.style.cssText="flex:1;display:flex;align-items:center;gap:6px;";const l=g("span","Comments");l.className="cc-panel-title",l.id="cc-panel-title";const h=g("span","");h.className="cc-panel-count",h.id="cc-header-count",a.appendChild(l),a.appendChild(h);const m=g("button");m.className="cc-panel-close-btn",m.setAttribute("aria-label","Close comments"),m.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',m.addEventListener("click",q),n.appendChild(i),n.appendChild(a),n.appendChild(m),e.appendChild(n);const y=g("div");y.className="cc-sort-bar";const v=g("span","Sort:");v.className="cc-sort-label",y.appendChild(v),["TOP","NEWEST"].forEach(e=>{const n=g("button",e);n.className="cc-sort-btn"+(d===e?" cc-active":""),n.dataset.sort=e,n.addEventListener("click",()=>{d!==e&&(d=e,y.querySelectorAll(".cc-sort-btn").forEach(e=>e.classList.remove("cc-active")),n.classList.add("cc-active"),N())}),y.appendChild(n)}),e.appendChild(y);const x=g("div");return x.className="cc-comments-list",x.id="cc-comments-list",x.addEventListener("click",A),e.appendChild(x),e.appendChild(function(){const e=g("div");e.className="cc-compose",e.id="cc-compose";const n=g("textarea");n.className="cc-compose-textarea",n.id="cc-compose-textarea",n.setAttribute("placeholder","Write a comment…"),n.setAttribute("rows","3"),e.appendChild(n);const i=g("div");i.className="cc-compose-actions";const a=g("button","Cancel");a.className="cc-compose-cancel",a.id="cc-compose-cancel",a.addEventListener("click",_),i.appendChild(a);const l=g("button","Post");return l.className="cc-compose-submit",l.id="cc-compose-submit",l.addEventListener("click",()=>{!async function(){const e=null==c?void 0:c.getElementById("cc-compose-textarea");if(!e)return;const n=e.value.trim();if(!n)return;if(!r.has())return void E();if(!s)return;const i=null==c?void 0:c.getElementById("cc-compose-submit");i&&(i.disabled=!0,f(i,"Posting…"));try{let c;b?c=await t.editComment(b,n):(c=await t.postComment({threadId:s,content:n,parentCommentId:null!=p?p:u}),o.emit("comment:posted",{comment:c})),c._id&&(e.value="",b=null,p=null,e.placeholder=u?"Write a reply…":"Write a comment…",$(),i&&f(i,"Post"),N())}catch(e){}finally{i&&(i.disabled=!1)}}()}),i.appendChild(l),e.appendChild(i),r.has()||e.appendChild(S()),e}()),e}()),n=i}const i=n;requestAnimationFrame(()=>{var n;i.classList.add("cc-visible"),null===(n=e.getElementById("cc-comments-panel"))||void 0===n||n.classList.add("cc-open")}),U(),N()},closePanel:q,destroy:function(){h(k),c=null}}}class N{constructor(e){var n;this.config=e,this.state=function(){let e={isLoading:!1,isExtensionAvailable:!1,isLoggedIn:!1,hasAccess:!1,isLoaded:!1,user:null,creditBalance:null,requiredCredits:null};const n=[];function t(){return Object.assign({},e)}function o(o){e=Object.assign(Object.assign({},e),o),n.forEach(e=>e(t()))}return{get:t,set:o,subscribe:function(e){return n.push(e),()=>{const t=n.indexOf(e);t>=0&&n.splice(t,1)}},reset:function(){e={isLoading:!1,isExtensionAvailable:!1,isLoggedIn:!1,hasAccess:!1,isLoaded:!1,user:null,creditBalance:null,requiredCredits:null},n.forEach(e=>e(t()))},setUser:function(e){var n;o({user:e,isLoggedIn:null!==e,creditBalance:null!==(n=null==e?void 0:e.credits)&&void 0!==n?n:null})}}}(),this.emitter=function(){const e={};function n(n,t){const o=e[n];if(!o)return;const i=o.indexOf(t);i>=0&&o.splice(i,1)}return{on:function(t,o){return e[t]||(e[t]=[]),e[t].push(o),()=>n(t,o)},off:n,emit:function(n,t){const o=e[n];o&&o.forEach(e=>{try{e(t)}catch(e){console.warn(`[ContentCredits] Error in "${n}" handler:`,e)}});try{document.dispatchEvent(new CustomEvent(`contentcredits:${n}`,{detail:t,bubbles:!1}))}catch(e){}},removeAll:function(){Object.keys(e).forEach(n=>{delete e[n]})}}}(),this.paywallModule=null,this.commentsModule=null,this.client=function(e,n){async function t(o,i,c,u=0,p=!1){const h=`${e}${i}`,m=c?JSON.stringify(c):void 0,f=function(e,n,t){return`${e}:${n}:${null!=t?t:""}`}(o,h,m),g=l.get(f);if(g)return g;const b=new AbortController,y=setTimeout(()=>b.abort(),12e3),v={"Content-Type":"application/json"},x=r.get();x&&(v.Authorization=`Bearer ${x}`);const w=fetch(h,{method:o,headers:v,body:m,signal:b.signal,credentials:"omit"}).then(async h=>{var m;if(clearTimeout(y),401===h.status){if(!p&&await s(e))return l.delete(f),t(o,i,c,u,!0);throw r.clear(),a.clear(),n.emit("auth:logout",{}),new d(401,"Unauthorized — session expired")}let g;try{g=await h.json()}catch(e){throw new d(h.status,"Invalid JSON response from server")}if(!h.ok){const e=null!==(m=null==g?void 0:g.message)&&void 0!==m?m:`HTTP ${h.status}`;throw new d(h.status,e,g)}return g}).catch(async e=>{clearTimeout(y);const n=e instanceof TypeError&&e.message.includes("fetch"),r=e instanceof d&&((a=e.status)>=500||429===a);var a;if((n||r)&&u<3)return l.delete(f),await async function(e){return new Promise(n=>setTimeout(n,e))}(400*Math.pow(2,u)),t(o,i,c,u+1);throw e}).finally(()=>{l.delete(f)});return l.set(f,w),w}return{get:e=>t("GET",e),post:(e,n)=>t("POST",e,n),put:(e,n)=>t("PUT",e,n),delete:e=>t("DELETE",e)}}(e.apiBaseUrl,this.emitter),this.creditsApi=(n=this.client,{checkAccess:e=>n.post("/credits/check-article-access",{apiKey:e.apiKey,postUrl:e.postUrl,postName:e.postName,hostName:e.hostName}),purchaseArticle:e=>n.post("/credits/purchase-article",{apiKey:e.apiKey,postUrl:e.postUrl,postName:e.postName,hostName:e.hostName})}),this.commentsApi=function(e){return{ensureThread:n=>e.post("/comments/threads/ensure",{pageUrl:n.pageUrl,hostname:n.hostname}),getComments(n){const t=encodeURIComponent(n.pageUrl);return e.get(`/comments/comments/by-url?url=${t}&sortBy=${n.sortBy}`)},postComment:n=>e.post("/comments/comments",Object.assign({threadId:n.threadId,content:n.content},n.parentCommentId?{parentCommentId:n.parentCommentId}:{})),editComment:(n,t)=>e.put(`/comments/comments/${n}`,{content:t}),deleteComment:n=>e.delete(`/comments/comments/${n}`),toggleLike:n=>e.post(`/comments/comments/${n}/toggle-like`,{})}}(this.client)}static init(e){const n=function(e){var n,t,o,i,c,r,a,s,l,d,u;if(!e.apiKey||"string"!=typeof e.apiKey||""===e.apiKey.trim())throw new Error("[ContentCredits] apiKey is required. Get yours from the Content Credits admin panel.");const p=function(e){try{const n=new URL(e);return["token","cc_token","refresh_token","cc_refresh_token"].forEach(e=>{n.searchParams.delete(e)}),n.toString()}catch(n){return e}}(null!==(n=e.articleUrl)&&void 0!==n?n:window.location.href);let h;try{h=new URL(p).hostname}catch(e){throw new Error(`[ContentCredits] Invalid articleUrl: "${p}"`)}return{apiKey:e.apiKey.trim(),articleUrl:p,hostName:h,pageTitle:document.title,contentSelector:null!==(t=e.contentSelector)&&void 0!==t?t:".cc-premium-content",teaserParagraphs:null!==(o=e.teaserParagraphs)&&void 0!==o?o:2,enableComments:null===(i=e.enableComments)||void 0===i||i,extensionId:null!==(c=e.extensionId)&&void 0!==c?c:"ljehdpabbhgccmanhjdfacjnaigpgcml",debug:null!==(r=e.debug)&&void 0!==r&&r,headless:null!==(a=e.headless)&&void 0!==a&&a,apiBaseUrl:"https://api.contentcredits.com",accountsUrl:"https://accounts.contentcredits.com",paywallTemplate:e.paywallTemplate,onAccessGranted:e.onAccessGranted,onStateChange:e.onStateChange,onReady:e.onReady,onLoginRequired:e.onLoginRequired,onPurchaseRequired:e.onPurchaseRequired,onInsufficientCredits:e.onInsufficientCredits,onPurchased:e.onPurchased,onUserLogin:e.onUserLogin,onUserLogout:e.onUserLogout,onError:e.onError,theme:{primaryColor:null!==(l=null===(s=e.theme)||void 0===s?void 0:s.primaryColor)&&void 0!==l?l:"#44C678",fontFamily:null!==(u=null===(d=e.theme)||void 0===d?void 0:d.fontFamily)&&void 0!==u?u:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"}}}(e),t=new N(n);return t._start(),t}async _start(){v(),this.config.onStateChange&&this.state.subscribe(this.config.onStateChange),this.config.onReady&&this.emitter.on("ready",({state:e})=>this.config.onReady(e)),this.config.onPurchased&&this.emitter.on("article:purchased",e=>this.config.onPurchased(e)),this.config.onUserLogin&&this.emitter.on("auth:login",({user:e})=>this.config.onUserLogin(e)),this.config.onUserLogout&&this.emitter.on("auth:logout",()=>this.config.onUserLogout()),this.config.onError&&this.emitter.on("error",e=>this.config.onError(e));const e=p({selector:this.config.contentSelector,teaserParagraphs:this.config.teaserParagraphs});this.config.headless||e.hide(),r.has()||await s(this.config.apiBaseUrl),this.paywallModule=w(this.config,this.creditsApi,this.state,this.emitter,e),this.config.enableComments&&(this.commentsModule=function(e,n,t){const o=E(e,n,t,()=>i.show()),i=function(e,n){let t=null,o=null;return{mount:function(){if(document.getElementById("cc-comment-widget"))return;let i=50;try{const e=localStorage.getItem(C);e&&(i=JSON.parse(e))}catch(e){}t=document.createElement("div"),t.id="cc-comment-widget",t.style.cssText=`\n position:fixed;top:${i}%;right:0;transform:translateY(-50%);\n height:60px;background:${e};border-radius:10px 0 0 10px;\n display:flex;align-items:center;gap:8px;padding:0 8px 0 12px;\n z-index:2147483646;box-shadow:-2px 0 16px rgba(0,0,0,.12);\n cursor:pointer;user-select:none;\n font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;\n transition:filter .2s;\n `,t.setAttribute("role","button"),t.setAttribute("aria-label","Open comments"),t.tabIndex=0;const c=document.createElement("div");c.style.cssText="color:#fff;display:flex;align-items:center;flex-shrink:0;",c.innerHTML='<svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',o=document.createElement("span"),o.style.cssText=`\n background:#fff;color:${e};border-radius:12px;\n padding:2px 7px;font-size:12px;font-weight:700;min-width:20px;\n text-align:center;display:none;\n `;const r=document.createElement("div");r.style.cssText="color:rgba(255,255,255,.65);cursor:grab;display:flex;align-items:center;padding:0 2px;flex-shrink:0;",r.innerHTML='<svg width="8" height="22" viewBox="0 0 8 22" fill="none"><circle cx="4" cy="4" r="2" fill="currentColor"/><circle cx="4" cy="11" r="2" fill="currentColor"/><circle cx="4" cy="18" r="2" fill="currentColor"/></svg>',c.addEventListener("click",n),o.addEventListener("click",n);let a=!1,s=0,l=0;function d(e){a=!0,s=e,l=t.getBoundingClientRect().top,r.style.cursor="grabbing"}function u(e){if(!a||!t)return;const n=e-s,o=Math.max(0,Math.min(window.innerHeight-60,l+n))/window.innerHeight*100;t.style.top=`${o}%`}function p(){if(!a||!t)return;a=!1,r.style.cursor="grab";const e=t.getBoundingClientRect().top/window.innerHeight*100;try{localStorage.setItem(C,JSON.stringify(e))}catch(e){}}r.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),d(e.clientY)}),r.addEventListener("touchstart",e=>{e.preventDefault(),d(e.touches[0].clientY)},{passive:!1}),document.addEventListener("mousemove",e=>u(e.clientY)),document.addEventListener("touchmove",e=>u(e.touches[0].clientY),{passive:!0}),document.addEventListener("mouseup",p),document.addEventListener("touchend",p),t.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||n()}),t.appendChild(c),t.appendChild(o),t.appendChild(r),document.body.appendChild(t)},setCount:function(e){o&&(e>0?(o.textContent=e>99?"99+":String(e),o.style.display="inline-block"):o.style.display="none")},show:function(){t&&(t.style.display="flex")},hide:function(){t&&(t.style.display="none")},destroy:function(){null==t||t.remove(),t=null,o=null}}}(e.theme.primaryColor,()=>{i.hide(),o.openPanel()});return{init:function(){i.mount()},open:function(){i.hide(),o.openPanel()},close:function(){o.closePanel()},destroy:function(){o.destroy(),i.destroy()}}}(this.config,this.commentsApi,this.emitter),this.commentsModule.init()),await this.paywallModule.init(),this.emitter.emit("ready",{state:this.state.get()})}subscribe(e){return this.state.subscribe(e)}async login(){var e;await(null===(e=this.paywallModule)||void 0===e?void 0:e.login())}async purchase(){var e;await(null===(e=this.paywallModule)||void 0===e?void 0:e.purchase())}buyMoreCredits(){var e;null===(e=this.paywallModule)||void 0===e||e.buyMoreCredits()}on(e,n){return this.emitter.on(e,n)}off(e,n){this.emitter.off(e,n)}getState(){return this.state.get()}async checkAccess(){var e;await(null===(e=this.paywallModule)||void 0===e?void 0:e.checkAccess())}openComments(){var e;null===(e=this.commentsModule)||void 0===e||e.open()}closeComments(){var e;null===(e=this.commentsModule)||void 0===e||e.close()}isLoggedIn(){return r.has()}getToken(){return r.get()}async logout(){const e=a.get();if(e)try{await fetch(`${this.config.apiBaseUrl}/auth/log-out`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:e}),credentials:"omit"})}catch(e){}r.clear(),a.clear(),this.state.reset(),this.emitter.emit("auth:logout",{})}destroy(){var e,n;null===(e=this.paywallModule)||void 0===e||e.destroy(),null===(n=this.commentsModule)||void 0===n||n.destroy(),this.emitter.removeAll(),this.state.reset()}static get version(){return"2.11.0"}}!function(){var e,n,t;const o=null!==(e=document.currentScript)&&void 0!==e?e:document.querySelector("script[data-cc-api-key], script[data-api-key]");if(!o)return;const i=o.dataset,c=null!==(n=i.ccApiKey)&&void 0!==n?n:i.apiKey;if(!c)return;const r={apiKey:c,contentSelector:null!==(t=i.ccContentSelector)&&void 0!==t?t:i.contentSelector,teaserParagraphs:i.ccTeaserParagraphs?parseInt(i.ccTeaserParagraphs,10):void 0,enableComments:"false"!==i.ccEnableComments,extensionId:i.ccExtensionId,debug:"true"===i.ccDebug};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>N.init(r)):N.init(r)}(),e.ContentCredits=N});
|
|
2
2
|
//# sourceMappingURL=content-credits.umd.min.js.map
|