@contentcredits/sdk 2.16.0 → 2.17.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.
- package/dist/content-credits.cjs.js +11 -11
- package/dist/content-credits.cjs.js.map +1 -1
- package/dist/content-credits.esm.js +11 -11
- package/dist/content-credits.esm.js.map +1 -1
- package/dist/content-credits.umd.min.js +1 -1
- package/dist/content-credits.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -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 a=null;const c={set(e){a=e;try{sessionStorage.setItem(o,e)}catch(e){}},get(){if(a)return t(a)?(this.clear(),null):a;try{const e=sessionStorage.getItem(o);if(e)return t(e)?(this.clear(),null):(a=e,e)}catch(e){}return null},clear(){a=null;try{sessionStorage.removeItem(o)}catch(e){}},has(){return null!==this.get()}},r={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=r.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 r.clear(),!1;const a=await i.json();return(null==a?void 0:a.accessToken)&&(null==a?void 0:a.refreshToken)?(c.set(a.accessToken),r.set(a.refreshToken),!0):(r.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 p="data-cc-gated";function u(e){let n=!1,t=null,o=[];return{hide:function(){if(t=document.querySelector(e.selector),!t)return!1;if(t.hasAttribute(p))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],a=Array.from(t.childNodes),c=a.findIndex(e=>e===n||t.contains(e)&&e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING);o=a.slice(c<0?e.teaserParagraphs:c),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 0===e.teaserParagraphs&&(o=Array.from(t.childNodes),o.forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")}));if(t.setAttribute(p,"true"),n=!0,"inline"===e.paywallMode&&!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(p),n=!1},isGated:function(){return n}}}function h(e){let n=document.getElementById(e);n||(n=document.createElement("div"),n.id=e,n.style.cssText="position:fixed;bottom:0;left:0;width:100%;height:auto;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}}function m(e){const n=document.getElementById(e);n&&n.remove()}function f(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 g(e,n){e.textContent=n}function y(e,n,t){const o=document.createElement(e);return void 0!==n&&(o.textContent=n),o}const b="cc-paywall-host";function v(e){var n,t,o,i,a;switch(e.type){case"heading":{const t=y("span",null!==(n=e.content)&&void 0!==n?n:"");return t.className="cc-slot-heading",t}case"subheading":{const n=y("span",null!==(t=e.content)&&void 0!==t?t:"");return n.className="cc-slot-subheading",n}case"text":{const n=y("span",null!==(o=e.content)&&void 0!==o?o:"");return n.className="cc-slot-text",n}case"button":{const n=y("button",null!==(i=e.content)&&void 0!==i?i:""),t="outline"===e.variant?"cc-btn-outline":"secondary"===e.variant?"cc-btn-secondary":"cc-btn-primary";return n.className=`cc-btn ${t}`,e.onClick&&n.addEventListener("click",e.onClick),n}case"divider":{const n=y("div",null!==(a=e.content)&&void 0!==a?a:"");return n.className="cc-slot-divider",n}}}function x(){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 w(){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&&r.set(i),o){c.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 C(e){return new Promise(n=>{let t=null,o=!1;function i(e){o||(o=!0,clearInterval(l),window.removeEventListener("message",a),n(e))}function a(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,a=e.data.refreshToken;if(o){c.set(o),a&&r.set(a);try{null==t||t.close()}catch(e){}i(o)}}window.addEventListener("message",a);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",a),void n(null)}if(!t||t.closed)return window.removeEventListener("message",a),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),a=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(a){c.set(a),s&&r.set(s);try{t.close()}catch(e){}i(a)}}}catch(e){}else i(c.get())},200)})}function k(e,n,t,o,i){const a=null!=i?i:u({selector:e.contentSelector,teaserParagraphs:e.teaserParagraphs,paywallMode:e.paywallMode}),r=function(e){let n=null,t=null,o=null;function i(){const i=document.querySelector(e.contentSelector);if(!i)return;const{root:a}="overlay"===e.paywallMode?h(b):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,i);var c,r;n=a,f(n,`\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n /* ─── Inline paywall panel ──────────────────────────────────────────── */\n .cc-paywall-inline {\n width: 100%;\n padding: 32px 28px 28px;\n background: #fff;\n border: 1px solid #e2e8f0;\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 }\n .cc-paywall-inline h2 {\n font-size: 20px;\n font-weight: 700;\n color: #0f172a;\n margin-bottom: 8px;\n letter-spacing: -0.015em;\n line-height: 1.25;\n }\n .cc-paywall-inline p {\n font-size: 14px;\n color: #64748b;\n line-height: 1.6;\n margin-bottom: 20px;\n }\n\n /* ─── Overlay paywall panel ─────────────────────────────────────────── */\n /*\n * Fixed to the bottom of the viewport, full width.\n * Elevation uses layered shadows — no harsh border-top line.\n * Thin hairline at the top (1px shadow) + ambient shadow for depth.\n */\n .cc-paywall-overlay {\n position: fixed;\n bottom: 0;\n left: 0;\n width: 100%;\n background: #fff;\n box-shadow:\n 0 -1px 0 rgba(15, 23, 42, 0.07),\n 0 -4px 12px rgba(15, 23, 42, 0.04),\n 0 -24px 64px rgba(15, 23, 42, 0.07);\n font-family: ${r};\n }\n\n /*\n * Gradient that fades the article content into the panel.\n * Multi-stop with a cubic-ease-ish curve so it reads as depth,\n * not as an obvious white overlay.\n * initOverlay() overrides this via inline style with the real page bg colour.\n */\n .cc-paywall-overlay-gradient {\n position: absolute;\n top: -160px;\n left: 0;\n right: 0;\n height: 160px;\n pointer-events: none;\n background: linear-gradient(\n to bottom,\n transparent 0%,\n rgba(255,255,255,0.08) 30%,\n rgba(255,255,255,0.55) 60%,\n rgba(255,255,255,0.90) 82%,\n #ffffff 100%\n );\n }\n\n /* Top slot — publisher-supplied content */\n .cc-paywall-overlay-slot {\n padding: 18px 24px 0;\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 5px;\n }\n\n /* SDK's own action section below the slot */\n .cc-paywall-overlay-body {\n padding: 14px 24px 26px;\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n text-align: center;\n }\n\n /* ─── Slot typography ───────────────────────────────────────────────── */\n .cc-slot-heading {\n font-size: 19px;\n font-weight: 700;\n color: #0f172a;\n text-align: center;\n line-height: 1.3;\n letter-spacing: -0.015em;\n }\n .cc-slot-subheading {\n font-size: 15px;\n font-weight: 600;\n color: #1e293b;\n text-align: center;\n }\n .cc-slot-text {\n font-size: 13px;\n color: #64748b;\n text-align: center;\n line-height: 1.55;\n }\n\n /* Visual separator between slot and body */\n .cc-slot-divider {\n display: flex;\n align-items: center;\n gap: 10px;\n font-size: 12px;\n color: #94a3b8;\n }\n .cc-slot-divider::before,\n .cc-slot-divider::after {\n content: '';\n flex: 1;\n height: 1px;\n background: #e2e8f0;\n }\n\n /* ─── Buttons ───────────────────────────────────────────────────────── */\n /*\n * All primary paywall CTAs use .cc-btn-primary (filled, brand colour).\n * .cc-btn-ghost is for low-emphasis secondary links.\n * No outline variant in paywall states — one clear hierarchy.\n */\n .cc-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 7px;\n height: 46px;\n padding: 0 22px;\n border: none;\n border-radius: 10px;\n font-family: ${r};\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n transition: filter 0.15s ease, transform 0.1s ease;\n width: 100%;\n max-width: 380px;\n letter-spacing: -0.01em;\n white-space: nowrap;\n flex-shrink: 0;\n }\n .cc-btn:hover:not(:disabled) { filter: brightness(1.07); }\n .cc-btn:active:not(:disabled) { transform: scale(0.975); }\n .cc-btn:disabled { opacity: 0.55; cursor: not-allowed; }\n\n .cc-btn-primary { background: ${c}; color: #fff; }\n .cc-btn-secondary { background: #0f172a; color: #fff; }\n\n /* Ghost: text-link-style secondary action */\n .cc-btn-ghost {\n background: transparent;\n color: #64748b;\n height: 36px;\n font-size: 13px;\n font-weight: 500;\n letter-spacing: 0;\n }\n .cc-btn-ghost:hover:not(:disabled) {\n color: #0f172a;\n background: #f1f5f9;\n filter: none;\n }\n\n /* Kept for backwards-compat with paywallTopSlot button items */\n .cc-btn-outline {\n background: transparent;\n color: #0f172a;\n border: 1.5px solid #cbd5e1;\n }\n .cc-btn-outline:hover:not(:disabled) {\n border-color: #94a3b8;\n filter: none;\n background: #f8fafc;\n }\n\n /* ─── Credit badge ───────────────────────────────────────────────────── */\n .cc-credit-badge {\n display: inline-flex;\n align-items: center;\n background: #f1f5f9;\n color: #475569;\n border-radius: 20px;\n padding: 3px 10px;\n font-size: 12px;\n font-weight: 700;\n letter-spacing: 0.01em;\n }\n\n /* ─── Inline state description text ─────────────────────────────────── */\n .cc-state-detail {\n font-size: 14px;\n color: #64748b;\n line-height: 1.6;\n }\n\n /* ─── Spinner (lives inside .cc-btn-primary while loading) ──────────── */\n .cc-spinner {\n display: inline-block;\n width: 17px;\n height: 17px;\n border: 2px solid rgba(255, 255, 255, 0.3);\n border-top-color: rgba(255, 255, 255, 0.95);\n border-radius: 50%;\n animation: cc-spin 0.6s linear infinite;\n flex-shrink: 0;\n }\n @keyframes cc-spin { to { transform: rotate(360deg); } }\n\n /* ─── "Powered by" attribution ───────────────────────────────────────── */\n .cc-powered-by {\n font-size: 11px;\n color: #94a3b8;\n letter-spacing: 0.01em;\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\n /* ─── Mobile: tighter vertical padding ──────────────────────────────── */\n @media (max-width: 480px) {\n .cc-paywall-overlay-slot { padding: 14px 16px 0; gap: 4px; }\n .cc-paywall-overlay-body { padding: 12px 16px 20px; gap: 10px; }\n .cc-slot-heading { font-size: 17px; }\n }\n `),"overlay"===e.paywallMode?function(n,i){var a;const c=y("div");c.className="cc-paywall-overlay";const r=y("div");r.className="cc-paywall-overlay-gradient";const s=getComputedStyle(document.body).backgroundColor;s&&"rgba(0, 0, 0, 0)"!==s&&"transparent"!==s&&(r.style.background=["linear-gradient(to bottom,","transparent 0%,","transparent 18%,",`color-mix(in srgb, ${s} 30%, transparent) 45%,`,`color-mix(in srgb, ${s} 75%, transparent) 68%,`,`${s} 100%`,")"].join(" "),CSS.supports("color","color-mix(in srgb, red 50%, blue)")||(r.style.background=`linear-gradient(to bottom, transparent 0%, ${s} 100%)`)),c.appendChild(r),i.style.paddingBottom="200px";const l=y("div");if(l.className="cc-paywall-overlay-slot",o=null!==(a=function(e,n,t){if(n){if("object"==typeof(o=n)&&null!==o&&"$$typeof"in o&&!Array.isArray(o)&&!(o instanceof HTMLElement))return t?function(e,n,t){if("function"==typeof t.createRoot){const o=t.createRoot(e);return o.render(n),o}if("function"==typeof t.render)return t.render(n,e),{unmount(){var n;const o=t;null===(n=o.unmountComponentAtNode)||void 0===n||n.call(o,e)}};console.warn("[ContentCredits] The provided `reactDOM` has neither `createRoot` nor `render`. Pass a valid ReactDOM instance.")}(e,n,t):void console.warn("[ContentCredits] paywallTopSlot is a React element but `reactDOM` was not provided. Pass your ReactDOM instance: ContentCredits.init({ reactDOM, paywallTopSlot: <Widget /> })");var o;if("function"!=typeof n)if(n instanceof HTMLElement)e.appendChild(n);else for(const t of n)e.appendChild(v(t));else n(e)}}(l,e.paywallTopSlot,e.reactDOM))&&void 0!==a?a:null,c.appendChild(l),e.paywallTopSlot){const e=y("div");e.className="cc-slot-divider",e.style.cssText="margin: 6px 24px 0;",c.appendChild(e)}t=y("div"),t.className="cc-paywall-overlay-body",c.appendChild(t),n.appendChild(c)}(n,i):function(e){t=y("div"),t.className="cc-paywall-inline",e.appendChild(t)}(n)}function a(){const e=y("div");e.className="cc-powered-by",e.textContent="Powered by ";const n=y("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(e){if(!t)return;const n=t.querySelector(".cc-btn");if(n&&(n.disabled=e,e)){const e=y("span");e.className="cc-spinner",g(n,""),n.appendChild(e),n.appendChild(document.createTextNode(" Processing…"))}}function r(){if(null==o||o.unmount(),o=null,m(b),"overlay"===e.paywallMode){const n=document.querySelector(e.contentSelector);n&&(n.style.paddingBottom="")}n=null,t=null}return{init:i,render:function(n,o,s){var l,d,p;if("checking"!==n&&(t||i(),t))if("loading"!==n)if("granted"!==n){for(;t.firstChild;)t.removeChild(t.firstChild);switch(n){case"login":!function(n,t){if("inline"===e.paywallMode){n.appendChild(y("h2","This article requires a subscription"));const e=y("p","Sign in to your Content Credits account to unlock this article.");e.className="cc-state-detail",n.appendChild(e)}const o=y("button","Sign in to read");o.className="cc-btn cc-btn-primary",o.addEventListener("click",()=>{t.onLogin()}),n.appendChild(o),n.appendChild(a())}(t,o);break;case"purchase":!function(n,t,o){if("inline"===e.paywallMode){n.appendChild(y("h2","Unlock this article"));const e=y("p","Use your Content Credits balance to instantly access this article.");e.className="cc-state-detail",n.appendChild(e)}const i=y("button",null!==o?`Unlock · ${o} credit${1!==o?"s":""}`:"Unlock article");i.className="cc-btn cc-btn-primary",i.addEventListener("click",()=>{t.onPurchase()}),n.appendChild(i),n.appendChild(a())}(t,o,null!==(l=null==s?void 0:s.requiredCredits)&&void 0!==l?l:null);break;case"insufficient":!function(n,t,o,i){"inline"===e.paywallMode&&n.appendChild(y("h2","Not enough credits"));const c=y("p");c.className="cc-state-detail",c.textContent=null!==o&&null!==i?`This article costs ${o} credit${1!==o?"s":""} — you have ${i}.`:"You don't have enough credits to unlock this article.",n.appendChild(c);const r=y("button","Top up credits");r.className="cc-btn cc-btn-primary",r.addEventListener("click",()=>t.onBuyMoreCredits()),n.appendChild(r),n.appendChild(a())}(t,o,null!==(d=null==s?void 0:s.requiredCredits)&&void 0!==d?d:null,null!==(p=null==s?void 0:s.creditBalance)&&void 0!==p?p:null)}}else r();else c(!0)},setButtonLoading:c,destroy:r}}(e),s=function(){let e=null,n=null;function t(t){var o,i,a,c;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 r=t.data;if(r&&"object"==typeof r&&r.type)switch(r.type){case"authorization_response":{const n=null!==(o=r.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!==(a=r.data)&&void 0!==a?a:null===(c=t.detail)||void 0===c?void 0:c.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 p(n=0,i=0){var c;t.set({hasAccess:!0,isLoaded:!0,isLoading:!1}),e.headless||(a.reveal(),r.render("granted",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),o.emit("paywall:hidden",{}),o.emit("article:purchased",{creditsSpent:n,remainingBalance:i}),null===(c=e.onAccessGranted)||void 0===c||c.call(e)}async function k(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;l?s.requestLogin(e.hostName):x()?window.location.href=n:(e.headless||r.render("loading",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),await C(n)?(t.set({isLoggedIn:!0}),await N()):e.headless||r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}))}async function L(){var i,a,u,h,m;if(c.has())if(l)s.requestPurchase({articleId:e.apiKey,hostName:e.hostName,location:e.articleUrl,title:e.pageTitle});else{e.headless||r.render("loading",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),t.set({isLoading:!0});try{const a=await n.purchaseArticle({apiKey:e.apiKey,postUrl:e.articleUrl,postName:e.pageTitle,hostName:e.hostName});a.success?p(0,0):(t.set({isLoading:!1}),e.headless||r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),o.emit("error",{message:null!==(i=a.message)&&void 0!==i?i:"Purchase failed"}))}catch(n){if(t.set({isLoading:!1}),n instanceof d&&402===n.status){e.headless||r.render("insufficient",{onLogin:k,onPurchase:L,onBuyMoreCredits:E},{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance});const n=null!==(a=t.get().requiredCredits)&&void 0!==a?a:0,i=null!==(u=t.get().creditBalance)&&void 0!==u?u: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||r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),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 k()}function E(){window.open("https://accounts.contentcredits.com/consumer/dashboard","_blank","noopener,noreferrer")}async function N(){var i,u,h;if(t.set({isLoading:!0}),e.headless||r.render("checking",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),l){const n=await new Promise(n=>{const i=setTimeout(()=>{l=!1,t.set({isExtensionAvailable:!1}),n(!1)},3e3);s.onAuthorizationResponse(c=>{clearTimeout(i),function(n){var i,c,s,l,d,u,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!==(c=n.requiredCredits)&&void 0!==c?c:null}),n.isAuthenticated?n.doesHaveAccess?p(0,null!==(l=n.creditBalance)&&void 0!==l?l:0):(e.headless||(a.hide(),r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E},{requiredCredits:n.requiredCredits,creditBalance:n.creditBalance})),null===(d=e.onPurchaseRequired)||void 0===d||d.call(e,{requiredCredits:null!==(u=n.requiredCredits)&&void 0!==u?u:null,creditBalance:null!==(h=n.creditBalance)&&void 0!==h?h:null}),o.emit("paywall:shown",{})):(e.headless||(a.hide(),r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),null===(s=e.onLoginRequired)||void 0===s||s.call(e),o.emit("paywall:shown",{}))}(c),n(!0)}),s.requestAuthorization(e.apiKey,e.hostName)});if(n)return}if(!c.has())return t.set({isLoading:!1,isLoaded:!0}),e.headless||(a.hide(),r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),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?p(0,0):(e.headless||(a.hide(),r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),null===(u=e.onPurchaseRequired)||void 0===u||u.call(e,{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance}),o.emit("paywall:shown",{}))}catch(n){t.set({isLoading:!1,isLoaded:!0}),e.headless||(a.hide(),r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),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;w()&&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.onPurchaseResponse(e=>{var n,i;t.set({isLoading:!1,isLoaded:!0,hasAccess:e.doesHaveAccess}),e.doesHaveAccess?p(null!==(n=e.creditsSpent)&&void 0!==n?n:0,null!==(i=e.creditBalance)&&void 0!==i?i:0):(r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),o.emit("error",{message:"Purchase failed via extension"}))})),await N()},checkAccess:N,destroy:function(){s.detach(),e.headless||(r.destroy(),a.reveal())},login:k,purchase:L,buyMoreCredits:E}}const L="cc-widget-pos",E="cc-comments-host",N=["#6366f1","#ec4899","#8b5cf6","#14b8a6","#f59e0b","#ef4444"];function T(e,t,o,i){let a=null,r=null,s=null,l=[],d="TOP",p=null,u=null,b=null;function v(){if(a)return a;const{root:n}=h(E);var t,o;return a=n,f(a,`\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 `),a}function k(){const e=c.get();r=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 L(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;x()?window.location.href=n:await C(n)&&(k(),z(),T())}async function T(){var n;const o=v(),i=o.getElementById("cc-comments-list");if(i){!function(e){e.innerHTML="";const n=y("div");n.className="cc-loading-state";const t=y("div");t.className="cc-spinner-lg",n.appendChild(t),n.appendChild(y("p","Loading comments…")),e.appendChild(n)}(i);try{const a=await t.ensureThread({pageUrl:e.articleUrl,hostname:e.hostName});if(!a._id)return void P(i,"Comments are not available for this page.");s=a._id;const c=await t.getComments({pageUrl:e.articleUrl,sortBy:d});l=null!==(n=c.comments)&&void 0!==n?n:[],c.thread&&(s=c.thread._id);const r=o.getElementById("cc-header-count");r&&g(r,String(l.length)),M(i)}catch(e){P(i,"Unable to reach the server. Check your connection.")}}}function S(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 P(e,n){e.innerHTML="";const t=y("div");t.className="cc-error-state";const o=y("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(y("p",n));const i=y("button","Try Again");i.className="cc-retry-btn",i.addEventListener("click",()=>{T()}),t.appendChild(i),e.appendChild(t)}function M(e){e.innerHTML="";const n=v(),t=n.getElementById("cc-back-btn"),o=n.getElementById("cc-panel-title");if(p?(null==t||t.classList.add("cc-visible"),o&&g(o,"Replies")):(null==t||t.classList.remove("cc-visible"),o&&g(o,"Comments")),p)!function(e,n){var t,o,i,a,c;const r=S(l).find(e=>e._id===n);if(!r)return;e.appendChild(B(r,!1));const s=y("div",`${null!==(o=null===(t=r.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0} ${1===(null!==(a=null===(i=r.replies)||void 0===i?void 0:i.length)&&void 0!==a?a:0)?"REPLY":"REPLIES"}`);if(s.className="cc-subthread-label",e.appendChild(s),null===(c=r.replies)||void 0===c?void 0:c.length)r.replies.forEach(n=>e.appendChild(B(n,!0)));else{const n=y("div");n.className="cc-empty-state",n.style.paddingTop="20px",n.appendChild(y("p","No replies yet")),e.appendChild(n)}}(e,p);else{if(0===l.length){const n=y("div");n.className="cc-empty-state",n.appendChild(y("p","No comments yet"));const t=y("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,a,c,r;return(null!==(o=null===(t=n.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0)-(null!==(a=null===(i=e.replies)||void 0===i?void 0:i.length)&&void 0!==a?a:0)||(null!==(c=n.likeCount)&&void 0!==c?c:0)-(null!==(r=e.likeCount)&&void 0!==r?r: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})(S(l)).forEach(n=>e.appendChild(B(n,!1)))}}function B(n,t){var o,i;const a=!(!r||n.authorId!==r),c=n.author,s=c?`${c.firstName} ${c.lastName}`.trim():"Anonymous",l=N[(s||"A").charCodeAt(0)%N.length],d=c?function(e,n){var t,o,i,a;return`${null!==(o=null===(t=null==e?void 0:e[0])||void 0===t?void 0:t.toUpperCase())&&void 0!==o?o:""}${null!==(a=null===(i=null==n?void 0:n[0])||void 0===i?void 0:i.toUpperCase())&&void 0!==a?a:""}`||"?"}(c.firstName,c.lastName):"?",p=y("div");p.className="cc-comment-card"+(t?" cc-reply":""),p.dataset.commentId=n._id;const u=y("div");u.className="cc-comment-header";const h=y("div");h.className="cc-comment-author-row";const m=y("div");if(m.className="cc-avatar",m.style.background=l,null==c?void 0:c.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}}(c.profilePicture.startsWith("http")?c.profilePicture:`${e.apiBaseUrl}${c.profilePicture}`);if(n){const e=y("img");e.setAttribute("src",n),e.setAttribute("alt",s),e.addEventListener("error",()=>{e.remove(),g(m,d)}),m.appendChild(e)}else g(m,d)}else g(m,d);const f=y("div"),b=y("div",s);b.className="cc-author-name";const v=y("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",f.appendChild(b),f.appendChild(v),h.appendChild(m),h.appendChild(f),u.appendChild(h),p.appendChild(u);const x=y("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)),p.appendChild(x);const w=y("div");if(w.className="cc-comment-actions",!t){const e=y("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=y("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),a){const e=y("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=y("button","Edit");t.className="cc-action-btn",t.dataset.commentId=n._id,t.dataset.action="edit";const o=y("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 p.appendChild(w),p}function I(){const e=y("div");e.className="cc-login-overlay",e.id="cc-login-overlay",e.appendChild(y("p","Sign in to join the conversation"));const n=y("button","Login with Content Credits");return n.className="cc-login-overlay-btn",n.addEventListener("click",()=>{L()}),e.appendChild(n),e}function A(e){const n=e.target.closest("[data-action]");if(!n)return;const i=n.dataset.action,r=n.dataset.commentId;if(r)switch(i){case"reply":!function(e){if(p){u=e,b=null;const n=null==a?void 0:a.getElementById("cc-compose-textarea");n&&(n.placeholder="Write a reply…",n.focus()),$()}else{p=e;const n=null==a?void 0:a.getElementById("cc-comments-list");n&&M(n)}}(r);break;case"like":!async function(e){var n,i,r,s,d;if(!c.has())return void L();const p=l.find(n=>n._id===e);if(!p)return;const u=p.hasLiked;p.hasLiked=!u,p.likeCount=(null!==(n=p.likeCount)&&void 0!==n?n:0)+(p.hasLiked?1:-1);const h=null==a?void 0:a.getElementById("cc-comments-list");h&&M(h);try{const n=await t.toggleLike(e);n.success?("boolean"==typeof(null===(i=n.data)||void 0===i?void 0:i.hasLiked)&&(p.hasLiked=n.data.hasLiked),"number"==typeof(null===(r=n.data)||void 0===r?void 0:r.likeCount)&&(p.likeCount=n.data.likeCount),o.emit("comment:liked",{commentId:e,hasLiked:p.hasLiked})):(p.hasLiked=u,p.likeCount=(null!==(s=p.likeCount)&&void 0!==s?s:0)+(u?1:-1)),h&&M(h)}catch(e){p.hasLiked=u,p.likeCount=(null!==(d=p.likeCount)&&void 0!==d?d:0)+(u?1:-1),h&&M(h)}}(r);break;case"edit":!function(e){const n=l.find(n=>n._id===e);if(!n)return;b=e,u=null;const t=null==a?void 0:a.getElementById("cc-compose-textarea");t&&(t.value=n.content,t.placeholder="Edit your comment…",t.focus());const o=null==a?void 0:a.getElementById("cc-compose-submit");o&&g(o,"Update"),$()}(r);break;case"delete":!async function(e){if(confirm("Delete this comment?"))try{(await t.deleteComment(e))._id&&(o.emit("comment:deleted",{commentId:e}),T())}catch(e){}}(r)}}function $(){const e=null==a?void 0:a.getElementById("cc-compose-cancel");null==e||e.classList.add("cc-visible")}function _(){const e=null==a?void 0:a.getElementById("cc-compose-cancel");null==e||e.classList.remove("cc-visible")}function U(){b=null,u=null;const e=null==a?void 0:a.getElementById("cc-compose-textarea");e&&(e.value="",e.placeholder="Write a comment…");const n=null==a?void 0:a.getElementById("cc-compose-submit");n&&g(n,"Post"),_()}function z(){const e=v(),n=e.getElementById("cc-login-overlay");if(c.has()&&n)n.remove();else if(!c.has()&&!n){const n=e.getElementById("cc-compose");null==n||n.appendChild(I())}}function q(){const e=a;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=v();w()&&k(),k();let n=e.getElementById("cc-panel-backdrop");if(!n){const i=y("div");i.className="cc-panel-backdrop",i.id="cc-panel-backdrop",i.addEventListener("click",q),e.appendChild(i),e.appendChild(function(){const e=y("div");e.className="cc-panel",e.id="cc-comments-panel";const n=y("div");n.className="cc-panel-header";const i=y("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",()=>{p=null,u=null;const e=null==a?void 0:a.getElementById("cc-comments-list");e&&M(e)});const r=y("div");r.style.cssText="flex:1;display:flex;align-items:center;gap:6px;";const l=y("span","Comments");l.className="cc-panel-title",l.id="cc-panel-title";const h=y("span","");h.className="cc-panel-count",h.id="cc-header-count",r.appendChild(l),r.appendChild(h);const m=y("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(r),n.appendChild(m),e.appendChild(n);const f=y("div");f.className="cc-sort-bar";const v=y("span","Sort:");v.className="cc-sort-label",f.appendChild(v),["TOP","NEWEST"].forEach(e=>{const n=y("button",e);n.className="cc-sort-btn"+(d===e?" cc-active":""),n.dataset.sort=e,n.addEventListener("click",()=>{d!==e&&(d=e,f.querySelectorAll(".cc-sort-btn").forEach(e=>e.classList.remove("cc-active")),n.classList.add("cc-active"),T())}),f.appendChild(n)}),e.appendChild(f);const x=y("div");return x.className="cc-comments-list",x.id="cc-comments-list",x.addEventListener("click",A),e.appendChild(x),e.appendChild(function(){const e=y("div");e.className="cc-compose",e.id="cc-compose";const n=y("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=y("div");i.className="cc-compose-actions";const r=y("button","Cancel");r.className="cc-compose-cancel",r.id="cc-compose-cancel",r.addEventListener("click",U),i.appendChild(r);const l=y("button","Post");return l.className="cc-compose-submit",l.id="cc-compose-submit",l.addEventListener("click",()=>{!async function(){const e=null==a?void 0:a.getElementById("cc-compose-textarea");if(!e)return;const n=e.value.trim();if(!n)return;if(!c.has())return void L();if(!s)return;const i=null==a?void 0:a.getElementById("cc-compose-submit");i&&(i.disabled=!0,g(i,"Posting…"));try{let a;b?a=await t.editComment(b,n):(a=await t.postComment({threadId:s,content:n,parentCommentId:null!=u?u:p}),o.emit("comment:posted",{comment:a})),a._id&&(e.value="",b=null,u=null,e.placeholder=p?"Write a reply…":"Write a comment…",_(),i&&g(i,"Post"),T())}catch(e){}finally{i&&(i.disabled=!1)}}()}),i.appendChild(l),e.appendChild(i),c.has()||e.appendChild(I()),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")}),z(),T()},closePanel:q,destroy:function(){m(E),a=null}}}class S{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,a,p=0,u=!1){const h=`${e}${i}`,m=a?JSON.stringify(a):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 y=new AbortController,b=setTimeout(()=>y.abort(),12e3),v={"Content-Type":"application/json"},x=c.get();x&&(v.Authorization=`Bearer ${x}`);const w=fetch(h,{method:o,headers:v,body:m,signal:y.signal,credentials:"omit"}).then(async h=>{var m;if(clearTimeout(b),401===h.status){if(!u&&await s(e))return l.delete(f),t(o,i,a,p,!0);throw c.clear(),r.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(b);const n=e instanceof TypeError&&e.message.includes("fetch"),c=e instanceof d&&((r=e.status)>=500||429===r);var r;if((n||c)&&p<3)return l.delete(f),await async function(e){return new Promise(n=>setTimeout(n,e))}(400*Math.pow(2,p)),t(o,i,a,p+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,a,c,r,s,l,d,p,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 h=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 m;try{m=new URL(h).hostname}catch(e){throw new Error(`[ContentCredits] Invalid articleUrl: "${h}"`)}return{apiKey:e.apiKey.trim(),articleUrl:h,hostName:m,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!==(a=e.extensionId)&&void 0!==a?a:"ljehdpabbhgccmanhjdfacjnaigpgcml",debug:null!==(c=e.debug)&&void 0!==c&&c,headless:null!==(r=e.headless)&&void 0!==r&&r,paywallMode:null!==(s=e.paywallMode)&&void 0!==s?s:"overlay",paywallTopSlot:e.paywallTopSlot,reactDOM:e.reactDOM,apiBaseUrl:"https://api.contentcredits.com",accountsUrl:"https://accounts.contentcredits.com",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!==(d=null===(l=e.theme)||void 0===l?void 0:l.primaryColor)&&void 0!==d?d:"#44C678",fontFamily:null!==(u=null===(p=e.theme)||void 0===p?void 0:p.fontFamily)&&void 0!==u?u:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"}}}(e),t=new S(n);return t._start(),t}async _start(){w(),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=u({selector:this.config.contentSelector,teaserParagraphs:this.config.teaserParagraphs,paywallMode:this.config.paywallMode});this.config.headless||e.hide(),c.has()||await s(this.config.apiBaseUrl),this.paywallModule=k(this.config,this.creditsApi,this.state,this.emitter,e),this.config.enableComments&&(this.commentsModule=function(e,n,t){const o=T(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(L);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 a=document.createElement("div");a.style.cssText="color:#fff;display:flex;align-items:center;flex-shrink:0;",a.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 c=document.createElement("div");c.style.cssText="color:rgba(255,255,255,.65);cursor:grab;display:flex;align-items:center;padding:0 2px;flex-shrink:0;",c.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>',a.addEventListener("click",n),o.addEventListener("click",n);let r=!1,s=0,l=0;function d(e){r=!0,s=e,l=t.getBoundingClientRect().top,c.style.cursor="grabbing"}function p(e){if(!r||!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 u(){if(!r||!t)return;r=!1,c.style.cursor="grab";const e=t.getBoundingClientRect().top/window.innerHeight*100;try{localStorage.setItem(L,JSON.stringify(e))}catch(e){}}c.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),d(e.clientY)}),c.addEventListener("touchstart",e=>{e.preventDefault(),d(e.touches[0].clientY)},{passive:!1}),document.addEventListener("mousemove",e=>p(e.clientY)),document.addEventListener("touchmove",e=>p(e.touches[0].clientY),{passive:!0}),document.addEventListener("mouseup",u),document.addEventListener("touchend",u),t.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||n()}),t.appendChild(a),t.appendChild(o),t.appendChild(c),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 c.has()}getToken(){return c.get()}async logout(){const e=r.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){}c.clear(),r.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.16.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,a=null!==(n=i.ccApiKey)&&void 0!==n?n:i.apiKey;if(!a)return;const c={apiKey:a,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",()=>S.init(c)):S.init(c)}(),e.ContentCredits=S});
|
|
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 a=null;const c={set(e){a=e;try{sessionStorage.setItem(o,e)}catch(e){}},get(){if(a)return t(a)?(this.clear(),null):a;try{const e=sessionStorage.getItem(o);if(e)return t(e)?(this.clear(),null):(a=e,e)}catch(e){}return null},clear(){a=null;try{sessionStorage.removeItem(o)}catch(e){}},has(){return null!==this.get()}},r={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=r.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 r.clear(),!1;const a=await i.json();return(null==a?void 0:a.accessToken)&&(null==a?void 0:a.refreshToken)?(c.set(a.accessToken),r.set(a.refreshToken),!0):(r.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 p="data-cc-gated";function u(e){let n=!1,t=null,o=[];return{hide:function(){if(t=document.querySelector(e.selector),!t)return!1;if(t.hasAttribute(p))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],a=Array.from(t.childNodes),c=a.findIndex(e=>e===n||t.contains(e)&&e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING);o=a.slice(c<0?e.teaserParagraphs:c),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 0===e.teaserParagraphs&&(o=Array.from(t.childNodes),o.forEach(e=>{e instanceof HTMLElement&&(e.style.display="none")}));if(t.setAttribute(p,"true"),n=!0,"inline"===e.paywallMode&&!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(p),n=!1},isGated:function(){return n}}}function h(e){let n=document.getElementById(e);n||(n=document.createElement("div"),n.id=e,n.style.cssText="position:fixed;bottom:0;left:0;width:100%;height:auto;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}}function m(e){const n=document.getElementById(e);n&&n.remove()}function f(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 g(e,n){e.textContent=n}function y(e,n,t){const o=document.createElement(e);return void 0!==n&&(o.textContent=n),o}const b="cc-paywall-host";function v(e){var n,t,o,i,a;switch(e.type){case"heading":{const t=y("span",null!==(n=e.content)&&void 0!==n?n:"");return t.className="cc-slot-heading",t}case"subheading":{const n=y("span",null!==(t=e.content)&&void 0!==t?t:"");return n.className="cc-slot-subheading",n}case"text":{const n=y("span",null!==(o=e.content)&&void 0!==o?o:"");return n.className="cc-slot-text",n}case"button":{const n=y("button",null!==(i=e.content)&&void 0!==i?i:""),t="outline"===e.variant?"cc-btn-outline":"secondary"===e.variant?"cc-btn-secondary":"cc-btn-primary";return n.className=`cc-btn ${t}`,e.onClick&&n.addEventListener("click",e.onClick),n}case"divider":{const n=y("div",null!==(a=e.content)&&void 0!==a?a:"");return n.className="cc-slot-divider",n}}}function x(){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 w(){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&&r.set(i),o){c.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 C(e){return new Promise(n=>{let t=null,o=!1;function i(e){o||(o=!0,clearInterval(l),window.removeEventListener("message",a),n(e))}function a(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,a=e.data.refreshToken;if(o){c.set(o),a&&r.set(a);try{null==t||t.close()}catch(e){}i(o)}}window.addEventListener("message",a);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",a),void n(null)}if(!t||t.closed)return window.removeEventListener("message",a),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),a=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(a){c.set(a),s&&r.set(s);try{t.close()}catch(e){}i(a)}}}catch(e){}else i(c.get())},200)})}function k(e,n,t,o,i){const a=null!=i?i:u({selector:e.contentSelector,teaserParagraphs:e.teaserParagraphs,paywallMode:e.paywallMode}),r=function(e){let n=null,t=null,o=null;function i(){const i=document.querySelector(e.contentSelector);if(!i)return;const{root:a}="overlay"===e.paywallMode?h(b):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,i);var c,r;n=a,f(n,`\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n /* ─── Inline paywall panel ──────────────────────────────────────────── */\n .cc-paywall-inline {\n width: 100%;\n padding: 32px 28px 28px;\n background: #fff;\n border: 1px solid #e2e8f0;\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 }\n .cc-paywall-inline h2 {\n font-size: 20px;\n font-weight: 700;\n color: #0f172a;\n margin-bottom: 8px;\n letter-spacing: -0.015em;\n line-height: 1.25;\n }\n .cc-paywall-inline p {\n font-size: 14px;\n color: #64748b;\n line-height: 1.6;\n margin-bottom: 20px;\n }\n\n /* ─── Overlay paywall panel ─────────────────────────────────────────── */\n /*\n * Fixed to the bottom of the viewport, full width.\n * Elevation uses layered shadows — no harsh border-top line.\n * Thin hairline at the top (1px shadow) + ambient shadow for depth.\n */\n .cc-paywall-overlay {\n position: fixed;\n bottom: 0;\n left: 0;\n width: 100%;\n background: #fff;\n box-shadow:\n 0 -1px 0 rgba(15, 23, 42, 0.07),\n 0 -4px 12px rgba(15, 23, 42, 0.04),\n 0 -24px 64px rgba(15, 23, 42, 0.07);\n font-family: ${r};\n }\n\n /*\n * Gradient that fades the article content into the panel.\n * Multi-stop with a cubic-ease-ish curve so it reads as depth,\n * not as an obvious white overlay.\n * initOverlay() overrides this via inline style with the real page bg colour.\n */\n .cc-paywall-overlay-gradient {\n position: absolute;\n top: -180px;\n left: 0;\n right: 0;\n height: 180px;\n pointer-events: none;\n background: linear-gradient(\n to bottom,\n transparent 0%,\n rgba(255,255,255,0.08) 30%,\n rgba(255,255,255,0.55) 60%,\n rgba(255,255,255,0.90) 82%,\n #ffffff 100%\n );\n }\n\n /* Top slot — publisher-supplied content */\n .cc-paywall-overlay-slot {\n padding: 26px 32px 0;\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 8px;\n }\n\n /* SDK's own action section below the slot */\n .cc-paywall-overlay-body {\n padding: 18px 32px 36px;\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 16px;\n text-align: center;\n }\n\n /* ─── Slot typography ───────────────────────────────────────────────── */\n .cc-slot-heading {\n font-size: 19px;\n font-weight: 700;\n color: #0f172a;\n text-align: center;\n line-height: 1.3;\n letter-spacing: -0.015em;\n }\n .cc-slot-subheading {\n font-size: 15px;\n font-weight: 600;\n color: #1e293b;\n text-align: center;\n }\n .cc-slot-text {\n font-size: 13px;\n color: #64748b;\n text-align: center;\n line-height: 1.55;\n }\n\n /* Visual separator between slot and body */\n .cc-slot-divider {\n display: flex;\n align-items: center;\n gap: 10px;\n font-size: 12px;\n color: #94a3b8;\n }\n .cc-slot-divider::before,\n .cc-slot-divider::after {\n content: '';\n flex: 1;\n height: 1px;\n background: #e2e8f0;\n }\n\n /* ─── Buttons ───────────────────────────────────────────────────────── */\n /*\n * All primary paywall CTAs use .cc-btn-primary (filled, brand colour).\n * .cc-btn-ghost is for low-emphasis secondary links.\n * No outline variant in paywall states — one clear hierarchy.\n */\n .cc-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 7px;\n height: 46px;\n padding: 0 22px;\n border: none;\n border-radius: 10px;\n font-family: ${r};\n font-size: 14px;\n font-weight: 600;\n cursor: pointer;\n transition: filter 0.15s ease, transform 0.1s ease;\n width: 100%;\n max-width: 380px;\n letter-spacing: -0.01em;\n white-space: nowrap;\n flex-shrink: 0;\n }\n .cc-btn:hover:not(:disabled) { filter: brightness(1.07); }\n .cc-btn:active:not(:disabled) { transform: scale(0.975); }\n .cc-btn:disabled { opacity: 0.55; cursor: not-allowed; }\n\n .cc-btn-primary { background: ${c}; color: #fff; }\n .cc-btn-secondary { background: #0f172a; color: #fff; }\n\n /* Ghost: text-link-style secondary action */\n .cc-btn-ghost {\n background: transparent;\n color: #64748b;\n height: 36px;\n font-size: 13px;\n font-weight: 500;\n letter-spacing: 0;\n }\n .cc-btn-ghost:hover:not(:disabled) {\n color: #0f172a;\n background: #f1f5f9;\n filter: none;\n }\n\n /* Kept for backwards-compat with paywallTopSlot button items */\n .cc-btn-outline {\n background: transparent;\n color: #0f172a;\n border: 1.5px solid #cbd5e1;\n }\n .cc-btn-outline:hover:not(:disabled) {\n border-color: #94a3b8;\n filter: none;\n background: #f8fafc;\n }\n\n /* ─── Credit badge ───────────────────────────────────────────────────── */\n .cc-credit-badge {\n display: inline-flex;\n align-items: center;\n background: #f1f5f9;\n color: #475569;\n border-radius: 20px;\n padding: 3px 10px;\n font-size: 12px;\n font-weight: 700;\n letter-spacing: 0.01em;\n }\n\n /* ─── Inline state description text ─────────────────────────────────── */\n .cc-state-detail {\n font-size: 14px;\n color: #64748b;\n line-height: 1.6;\n }\n\n /* ─── Spinner (lives inside .cc-btn-primary while loading) ──────────── */\n .cc-spinner {\n display: inline-block;\n width: 17px;\n height: 17px;\n border: 2px solid rgba(255, 255, 255, 0.3);\n border-top-color: rgba(255, 255, 255, 0.95);\n border-radius: 50%;\n animation: cc-spin 0.6s linear infinite;\n flex-shrink: 0;\n }\n @keyframes cc-spin { to { transform: rotate(360deg); } }\n\n /* ─── "Powered by" attribution ───────────────────────────────────────── */\n .cc-powered-by {\n font-size: 11px;\n color: #94a3b8;\n letter-spacing: 0.01em;\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\n /* ─── Mobile: tighter vertical padding ──────────────────────────────── */\n @media (max-width: 480px) {\n .cc-paywall-overlay-slot { padding: 20px 20px 0; gap: 6px; }\n .cc-paywall-overlay-body { padding: 14px 20px 28px; gap: 14px; }\n .cc-slot-heading { font-size: 17px; }\n }\n `),"overlay"===e.paywallMode?function(n,i){var a;const c=y("div");c.className="cc-paywall-overlay";const r=y("div");r.className="cc-paywall-overlay-gradient";const s=getComputedStyle(document.body).backgroundColor;s&&"rgba(0, 0, 0, 0)"!==s&&"transparent"!==s&&(r.style.background=["linear-gradient(to bottom,","transparent 0%,","transparent 18%,",`color-mix(in srgb, ${s} 30%, transparent) 45%,`,`color-mix(in srgb, ${s} 75%, transparent) 68%,`,`${s} 100%`,")"].join(" "),CSS.supports("color","color-mix(in srgb, red 50%, blue)")||(r.style.background=`linear-gradient(to bottom, transparent 0%, ${s} 100%)`)),c.appendChild(r),i.style.paddingBottom="240px";const l=y("div");if(l.className="cc-paywall-overlay-slot",o=null!==(a=function(e,n,t){if(n){if("object"==typeof(o=n)&&null!==o&&"$$typeof"in o&&!Array.isArray(o)&&!(o instanceof HTMLElement))return t?function(e,n,t){if("function"==typeof t.createRoot){const o=t.createRoot(e);return o.render(n),o}if("function"==typeof t.render)return t.render(n,e),{unmount(){var n;const o=t;null===(n=o.unmountComponentAtNode)||void 0===n||n.call(o,e)}};console.warn("[ContentCredits] The provided `reactDOM` has neither `createRoot` nor `render`. Pass a valid ReactDOM instance.")}(e,n,t):void console.warn("[ContentCredits] paywallTopSlot is a React element but `reactDOM` was not provided. Pass your ReactDOM instance: ContentCredits.init({ reactDOM, paywallTopSlot: <Widget /> })");var o;if("function"!=typeof n)if(n instanceof HTMLElement)e.appendChild(n);else for(const t of n)e.appendChild(v(t));else n(e)}}(l,e.paywallTopSlot,e.reactDOM))&&void 0!==a?a:null,c.appendChild(l),e.paywallTopSlot){const e=y("div");e.className="cc-slot-divider",e.style.cssText="margin: 12px 32px 0;",c.appendChild(e)}t=y("div"),t.className="cc-paywall-overlay-body",c.appendChild(t),n.appendChild(c)}(n,i):function(e){t=y("div"),t.className="cc-paywall-inline",e.appendChild(t)}(n)}function a(){const e=y("div");e.className="cc-powered-by",e.textContent="Powered by ";const n=y("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(e){if(!t)return;const n=t.querySelector(".cc-btn");if(n&&(n.disabled=e,e)){const e=y("span");e.className="cc-spinner",g(n,""),n.appendChild(e),n.appendChild(document.createTextNode(" Processing…"))}}function r(){if(null==o||o.unmount(),o=null,m(b),"overlay"===e.paywallMode){const n=document.querySelector(e.contentSelector);n&&(n.style.paddingBottom="")}n=null,t=null}return{init:i,render:function(n,o,s){var l,d,p;if("checking"!==n&&(t||i(),t))if("loading"!==n)if("granted"!==n){for(;t.firstChild;)t.removeChild(t.firstChild);switch(n){case"login":!function(n,t){if("inline"===e.paywallMode){n.appendChild(y("h2","This article requires a subscription"));const e=y("p","Sign in to your Content Credits account to unlock this article.");e.className="cc-state-detail",n.appendChild(e)}const o=y("button","Sign in to read");o.className="cc-btn cc-btn-primary",o.addEventListener("click",()=>{t.onLogin()}),n.appendChild(o),n.appendChild(a())}(t,o);break;case"purchase":!function(n,t,o){if("inline"===e.paywallMode){n.appendChild(y("h2","Unlock this article"));const e=y("p","Use your Content Credits balance to instantly access this article.");e.className="cc-state-detail",n.appendChild(e)}const i=y("button",null!==o?`Unlock · ${o} credit${1!==o?"s":""}`:"Unlock article");i.className="cc-btn cc-btn-primary",i.addEventListener("click",()=>{t.onPurchase()}),n.appendChild(i),n.appendChild(a())}(t,o,null!==(l=null==s?void 0:s.requiredCredits)&&void 0!==l?l:null);break;case"insufficient":!function(n,t,o,i){"inline"===e.paywallMode&&n.appendChild(y("h2","Not enough credits"));const c=y("p");c.className="cc-state-detail",c.textContent=null!==o&&null!==i?`This article costs ${o} credit${1!==o?"s":""} — you have ${i}.`:"You don't have enough credits to unlock this article.",n.appendChild(c);const r=y("button","Top up credits");r.className="cc-btn cc-btn-primary",r.addEventListener("click",()=>t.onBuyMoreCredits()),n.appendChild(r),n.appendChild(a())}(t,o,null!==(d=null==s?void 0:s.requiredCredits)&&void 0!==d?d:null,null!==(p=null==s?void 0:s.creditBalance)&&void 0!==p?p:null)}}else r();else c(!0)},setButtonLoading:c,destroy:r}}(e),s=function(){let e=null,n=null;function t(t){var o,i,a,c;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 r=t.data;if(r&&"object"==typeof r&&r.type)switch(r.type){case"authorization_response":{const n=null!==(o=r.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!==(a=r.data)&&void 0!==a?a:null===(c=t.detail)||void 0===c?void 0:c.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 p(n=0,i=0){var c;t.set({hasAccess:!0,isLoaded:!0,isLoading:!1}),e.headless||(a.reveal(),r.render("granted",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),o.emit("paywall:hidden",{}),o.emit("article:purchased",{creditsSpent:n,remainingBalance:i}),null===(c=e.onAccessGranted)||void 0===c||c.call(e)}async function k(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;l?s.requestLogin(e.hostName):x()?window.location.href=n:(e.headless||r.render("loading",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),await C(n)?(t.set({isLoggedIn:!0}),await N()):e.headless||r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}))}async function L(){var i,a,u,h,m;if(c.has())if(l)s.requestPurchase({articleId:e.apiKey,hostName:e.hostName,location:e.articleUrl,title:e.pageTitle});else{e.headless||r.render("loading",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),t.set({isLoading:!0});try{const a=await n.purchaseArticle({apiKey:e.apiKey,postUrl:e.articleUrl,postName:e.pageTitle,hostName:e.hostName});a.success?p(0,0):(t.set({isLoading:!1}),e.headless||r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),o.emit("error",{message:null!==(i=a.message)&&void 0!==i?i:"Purchase failed"}))}catch(n){if(t.set({isLoading:!1}),n instanceof d&&402===n.status){e.headless||r.render("insufficient",{onLogin:k,onPurchase:L,onBuyMoreCredits:E},{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance});const n=null!==(a=t.get().requiredCredits)&&void 0!==a?a:0,i=null!==(u=t.get().creditBalance)&&void 0!==u?u: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||r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),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 k()}function E(){window.open("https://accounts.contentcredits.com/consumer/dashboard","_blank","noopener,noreferrer")}async function N(){var i,u,h;if(t.set({isLoading:!0}),e.headless||r.render("checking",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),l){const n=await new Promise(n=>{const i=setTimeout(()=>{l=!1,t.set({isExtensionAvailable:!1}),n(!1)},3e3);s.onAuthorizationResponse(c=>{clearTimeout(i),function(n){var i,c,s,l,d,u,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!==(c=n.requiredCredits)&&void 0!==c?c:null}),n.isAuthenticated?n.doesHaveAccess?p(0,null!==(l=n.creditBalance)&&void 0!==l?l:0):(e.headless||(a.hide(),r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E},{requiredCredits:n.requiredCredits,creditBalance:n.creditBalance})),null===(d=e.onPurchaseRequired)||void 0===d||d.call(e,{requiredCredits:null!==(u=n.requiredCredits)&&void 0!==u?u:null,creditBalance:null!==(h=n.creditBalance)&&void 0!==h?h:null}),o.emit("paywall:shown",{})):(e.headless||(a.hide(),r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),null===(s=e.onLoginRequired)||void 0===s||s.call(e),o.emit("paywall:shown",{}))}(c),n(!0)}),s.requestAuthorization(e.apiKey,e.hostName)});if(n)return}if(!c.has())return t.set({isLoading:!1,isLoaded:!0}),e.headless||(a.hide(),r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),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?p(0,0):(e.headless||(a.hide(),r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),null===(u=e.onPurchaseRequired)||void 0===u||u.call(e,{requiredCredits:t.get().requiredCredits,creditBalance:t.get().creditBalance}),o.emit("paywall:shown",{}))}catch(n){t.set({isLoading:!1,isLoaded:!0}),e.headless||(a.hide(),r.render("login",{onLogin:k,onPurchase:L,onBuyMoreCredits:E})),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;w()&&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.onPurchaseResponse(e=>{var n,i;t.set({isLoading:!1,isLoaded:!0,hasAccess:e.doesHaveAccess}),e.doesHaveAccess?p(null!==(n=e.creditsSpent)&&void 0!==n?n:0,null!==(i=e.creditBalance)&&void 0!==i?i:0):(r.render("purchase",{onLogin:k,onPurchase:L,onBuyMoreCredits:E}),o.emit("error",{message:"Purchase failed via extension"}))})),await N()},checkAccess:N,destroy:function(){s.detach(),e.headless||(r.destroy(),a.reveal())},login:k,purchase:L,buyMoreCredits:E}}const L="cc-widget-pos",E="cc-comments-host",N=["#6366f1","#ec4899","#8b5cf6","#14b8a6","#f59e0b","#ef4444"];function T(e,t,o,i){let a=null,r=null,s=null,l=[],d="TOP",p=null,u=null,b=null;function v(){if(a)return a;const{root:n}=h(E);var t,o;return a=n,f(a,`\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 `),a}function k(){const e=c.get();r=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 L(){const n=`https://accounts.contentcredits.com/authenticate/extension?redirect=${encodeURIComponent(e.articleUrl)}`;x()?window.location.href=n:await C(n)&&(k(),z(),T())}async function T(){var n;const o=v(),i=o.getElementById("cc-comments-list");if(i){!function(e){e.innerHTML="";const n=y("div");n.className="cc-loading-state";const t=y("div");t.className="cc-spinner-lg",n.appendChild(t),n.appendChild(y("p","Loading comments…")),e.appendChild(n)}(i);try{const a=await t.ensureThread({pageUrl:e.articleUrl,hostname:e.hostName});if(!a._id)return void P(i,"Comments are not available for this page.");s=a._id;const c=await t.getComments({pageUrl:e.articleUrl,sortBy:d});l=null!==(n=c.comments)&&void 0!==n?n:[],c.thread&&(s=c.thread._id);const r=o.getElementById("cc-header-count");r&&g(r,String(l.length)),M(i)}catch(e){P(i,"Unable to reach the server. Check your connection.")}}}function S(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 P(e,n){e.innerHTML="";const t=y("div");t.className="cc-error-state";const o=y("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(y("p",n));const i=y("button","Try Again");i.className="cc-retry-btn",i.addEventListener("click",()=>{T()}),t.appendChild(i),e.appendChild(t)}function M(e){e.innerHTML="";const n=v(),t=n.getElementById("cc-back-btn"),o=n.getElementById("cc-panel-title");if(p?(null==t||t.classList.add("cc-visible"),o&&g(o,"Replies")):(null==t||t.classList.remove("cc-visible"),o&&g(o,"Comments")),p)!function(e,n){var t,o,i,a,c;const r=S(l).find(e=>e._id===n);if(!r)return;e.appendChild(B(r,!1));const s=y("div",`${null!==(o=null===(t=r.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0} ${1===(null!==(a=null===(i=r.replies)||void 0===i?void 0:i.length)&&void 0!==a?a:0)?"REPLY":"REPLIES"}`);if(s.className="cc-subthread-label",e.appendChild(s),null===(c=r.replies)||void 0===c?void 0:c.length)r.replies.forEach(n=>e.appendChild(B(n,!0)));else{const n=y("div");n.className="cc-empty-state",n.style.paddingTop="20px",n.appendChild(y("p","No replies yet")),e.appendChild(n)}}(e,p);else{if(0===l.length){const n=y("div");n.className="cc-empty-state",n.appendChild(y("p","No comments yet"));const t=y("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,a,c,r;return(null!==(o=null===(t=n.replies)||void 0===t?void 0:t.length)&&void 0!==o?o:0)-(null!==(a=null===(i=e.replies)||void 0===i?void 0:i.length)&&void 0!==a?a:0)||(null!==(c=n.likeCount)&&void 0!==c?c:0)-(null!==(r=e.likeCount)&&void 0!==r?r: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})(S(l)).forEach(n=>e.appendChild(B(n,!1)))}}function B(n,t){var o,i;const a=!(!r||n.authorId!==r),c=n.author,s=c?`${c.firstName} ${c.lastName}`.trim():"Anonymous",l=N[(s||"A").charCodeAt(0)%N.length],d=c?function(e,n){var t,o,i,a;return`${null!==(o=null===(t=null==e?void 0:e[0])||void 0===t?void 0:t.toUpperCase())&&void 0!==o?o:""}${null!==(a=null===(i=null==n?void 0:n[0])||void 0===i?void 0:i.toUpperCase())&&void 0!==a?a:""}`||"?"}(c.firstName,c.lastName):"?",p=y("div");p.className="cc-comment-card"+(t?" cc-reply":""),p.dataset.commentId=n._id;const u=y("div");u.className="cc-comment-header";const h=y("div");h.className="cc-comment-author-row";const m=y("div");if(m.className="cc-avatar",m.style.background=l,null==c?void 0:c.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}}(c.profilePicture.startsWith("http")?c.profilePicture:`${e.apiBaseUrl}${c.profilePicture}`);if(n){const e=y("img");e.setAttribute("src",n),e.setAttribute("alt",s),e.addEventListener("error",()=>{e.remove(),g(m,d)}),m.appendChild(e)}else g(m,d)}else g(m,d);const f=y("div"),b=y("div",s);b.className="cc-author-name";const v=y("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",f.appendChild(b),f.appendChild(v),h.appendChild(m),h.appendChild(f),u.appendChild(h),p.appendChild(u);const x=y("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)),p.appendChild(x);const w=y("div");if(w.className="cc-comment-actions",!t){const e=y("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=y("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),a){const e=y("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=y("button","Edit");t.className="cc-action-btn",t.dataset.commentId=n._id,t.dataset.action="edit";const o=y("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 p.appendChild(w),p}function I(){const e=y("div");e.className="cc-login-overlay",e.id="cc-login-overlay",e.appendChild(y("p","Sign in to join the conversation"));const n=y("button","Login with Content Credits");return n.className="cc-login-overlay-btn",n.addEventListener("click",()=>{L()}),e.appendChild(n),e}function A(e){const n=e.target.closest("[data-action]");if(!n)return;const i=n.dataset.action,r=n.dataset.commentId;if(r)switch(i){case"reply":!function(e){if(p){u=e,b=null;const n=null==a?void 0:a.getElementById("cc-compose-textarea");n&&(n.placeholder="Write a reply…",n.focus()),$()}else{p=e;const n=null==a?void 0:a.getElementById("cc-comments-list");n&&M(n)}}(r);break;case"like":!async function(e){var n,i,r,s,d;if(!c.has())return void L();const p=l.find(n=>n._id===e);if(!p)return;const u=p.hasLiked;p.hasLiked=!u,p.likeCount=(null!==(n=p.likeCount)&&void 0!==n?n:0)+(p.hasLiked?1:-1);const h=null==a?void 0:a.getElementById("cc-comments-list");h&&M(h);try{const n=await t.toggleLike(e);n.success?("boolean"==typeof(null===(i=n.data)||void 0===i?void 0:i.hasLiked)&&(p.hasLiked=n.data.hasLiked),"number"==typeof(null===(r=n.data)||void 0===r?void 0:r.likeCount)&&(p.likeCount=n.data.likeCount),o.emit("comment:liked",{commentId:e,hasLiked:p.hasLiked})):(p.hasLiked=u,p.likeCount=(null!==(s=p.likeCount)&&void 0!==s?s:0)+(u?1:-1)),h&&M(h)}catch(e){p.hasLiked=u,p.likeCount=(null!==(d=p.likeCount)&&void 0!==d?d:0)+(u?1:-1),h&&M(h)}}(r);break;case"edit":!function(e){const n=l.find(n=>n._id===e);if(!n)return;b=e,u=null;const t=null==a?void 0:a.getElementById("cc-compose-textarea");t&&(t.value=n.content,t.placeholder="Edit your comment…",t.focus());const o=null==a?void 0:a.getElementById("cc-compose-submit");o&&g(o,"Update"),$()}(r);break;case"delete":!async function(e){if(confirm("Delete this comment?"))try{(await t.deleteComment(e))._id&&(o.emit("comment:deleted",{commentId:e}),T())}catch(e){}}(r)}}function $(){const e=null==a?void 0:a.getElementById("cc-compose-cancel");null==e||e.classList.add("cc-visible")}function _(){const e=null==a?void 0:a.getElementById("cc-compose-cancel");null==e||e.classList.remove("cc-visible")}function U(){b=null,u=null;const e=null==a?void 0:a.getElementById("cc-compose-textarea");e&&(e.value="",e.placeholder="Write a comment…");const n=null==a?void 0:a.getElementById("cc-compose-submit");n&&g(n,"Post"),_()}function z(){const e=v(),n=e.getElementById("cc-login-overlay");if(c.has()&&n)n.remove();else if(!c.has()&&!n){const n=e.getElementById("cc-compose");null==n||n.appendChild(I())}}function q(){const e=a;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=v();w()&&k(),k();let n=e.getElementById("cc-panel-backdrop");if(!n){const i=y("div");i.className="cc-panel-backdrop",i.id="cc-panel-backdrop",i.addEventListener("click",q),e.appendChild(i),e.appendChild(function(){const e=y("div");e.className="cc-panel",e.id="cc-comments-panel";const n=y("div");n.className="cc-panel-header";const i=y("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",()=>{p=null,u=null;const e=null==a?void 0:a.getElementById("cc-comments-list");e&&M(e)});const r=y("div");r.style.cssText="flex:1;display:flex;align-items:center;gap:6px;";const l=y("span","Comments");l.className="cc-panel-title",l.id="cc-panel-title";const h=y("span","");h.className="cc-panel-count",h.id="cc-header-count",r.appendChild(l),r.appendChild(h);const m=y("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(r),n.appendChild(m),e.appendChild(n);const f=y("div");f.className="cc-sort-bar";const v=y("span","Sort:");v.className="cc-sort-label",f.appendChild(v),["TOP","NEWEST"].forEach(e=>{const n=y("button",e);n.className="cc-sort-btn"+(d===e?" cc-active":""),n.dataset.sort=e,n.addEventListener("click",()=>{d!==e&&(d=e,f.querySelectorAll(".cc-sort-btn").forEach(e=>e.classList.remove("cc-active")),n.classList.add("cc-active"),T())}),f.appendChild(n)}),e.appendChild(f);const x=y("div");return x.className="cc-comments-list",x.id="cc-comments-list",x.addEventListener("click",A),e.appendChild(x),e.appendChild(function(){const e=y("div");e.className="cc-compose",e.id="cc-compose";const n=y("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=y("div");i.className="cc-compose-actions";const r=y("button","Cancel");r.className="cc-compose-cancel",r.id="cc-compose-cancel",r.addEventListener("click",U),i.appendChild(r);const l=y("button","Post");return l.className="cc-compose-submit",l.id="cc-compose-submit",l.addEventListener("click",()=>{!async function(){const e=null==a?void 0:a.getElementById("cc-compose-textarea");if(!e)return;const n=e.value.trim();if(!n)return;if(!c.has())return void L();if(!s)return;const i=null==a?void 0:a.getElementById("cc-compose-submit");i&&(i.disabled=!0,g(i,"Posting…"));try{let a;b?a=await t.editComment(b,n):(a=await t.postComment({threadId:s,content:n,parentCommentId:null!=u?u:p}),o.emit("comment:posted",{comment:a})),a._id&&(e.value="",b=null,u=null,e.placeholder=p?"Write a reply…":"Write a comment…",_(),i&&g(i,"Post"),T())}catch(e){}finally{i&&(i.disabled=!1)}}()}),i.appendChild(l),e.appendChild(i),c.has()||e.appendChild(I()),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")}),z(),T()},closePanel:q,destroy:function(){m(E),a=null}}}class S{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,a,p=0,u=!1){const h=`${e}${i}`,m=a?JSON.stringify(a):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 y=new AbortController,b=setTimeout(()=>y.abort(),12e3),v={"Content-Type":"application/json"},x=c.get();x&&(v.Authorization=`Bearer ${x}`);const w=fetch(h,{method:o,headers:v,body:m,signal:y.signal,credentials:"omit"}).then(async h=>{var m;if(clearTimeout(b),401===h.status){if(!u&&await s(e))return l.delete(f),t(o,i,a,p,!0);throw c.clear(),r.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(b);const n=e instanceof TypeError&&e.message.includes("fetch"),c=e instanceof d&&((r=e.status)>=500||429===r);var r;if((n||c)&&p<3)return l.delete(f),await async function(e){return new Promise(n=>setTimeout(n,e))}(400*Math.pow(2,p)),t(o,i,a,p+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,a,c,r,s,l,d,p,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 h=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 m;try{m=new URL(h).hostname}catch(e){throw new Error(`[ContentCredits] Invalid articleUrl: "${h}"`)}return{apiKey:e.apiKey.trim(),articleUrl:h,hostName:m,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!==(a=e.extensionId)&&void 0!==a?a:"ljehdpabbhgccmanhjdfacjnaigpgcml",debug:null!==(c=e.debug)&&void 0!==c&&c,headless:null!==(r=e.headless)&&void 0!==r&&r,paywallMode:null!==(s=e.paywallMode)&&void 0!==s?s:"overlay",paywallTopSlot:e.paywallTopSlot,reactDOM:e.reactDOM,apiBaseUrl:"https://api.contentcredits.com",accountsUrl:"https://accounts.contentcredits.com",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!==(d=null===(l=e.theme)||void 0===l?void 0:l.primaryColor)&&void 0!==d?d:"#44C678",fontFamily:null!==(u=null===(p=e.theme)||void 0===p?void 0:p.fontFamily)&&void 0!==u?u:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"}}}(e),t=new S(n);return t._start(),t}async _start(){w(),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=u({selector:this.config.contentSelector,teaserParagraphs:this.config.teaserParagraphs,paywallMode:this.config.paywallMode});this.config.headless||e.hide(),c.has()||await s(this.config.apiBaseUrl),this.paywallModule=k(this.config,this.creditsApi,this.state,this.emitter,e),this.config.enableComments&&(this.commentsModule=function(e,n,t){const o=T(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(L);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 a=document.createElement("div");a.style.cssText="color:#fff;display:flex;align-items:center;flex-shrink:0;",a.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 c=document.createElement("div");c.style.cssText="color:rgba(255,255,255,.65);cursor:grab;display:flex;align-items:center;padding:0 2px;flex-shrink:0;",c.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>',a.addEventListener("click",n),o.addEventListener("click",n);let r=!1,s=0,l=0;function d(e){r=!0,s=e,l=t.getBoundingClientRect().top,c.style.cursor="grabbing"}function p(e){if(!r||!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 u(){if(!r||!t)return;r=!1,c.style.cursor="grab";const e=t.getBoundingClientRect().top/window.innerHeight*100;try{localStorage.setItem(L,JSON.stringify(e))}catch(e){}}c.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),d(e.clientY)}),c.addEventListener("touchstart",e=>{e.preventDefault(),d(e.touches[0].clientY)},{passive:!1}),document.addEventListener("mousemove",e=>p(e.clientY)),document.addEventListener("touchmove",e=>p(e.touches[0].clientY),{passive:!0}),document.addEventListener("mouseup",u),document.addEventListener("touchend",u),t.addEventListener("keydown",e=>{"Enter"!==e.key&&" "!==e.key||n()}),t.appendChild(a),t.appendChild(o),t.appendChild(c),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 c.has()}getToken(){return c.get()}async logout(){const e=r.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){}c.clear(),r.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.17.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,a=null!==(n=i.ccApiKey)&&void 0!==n?n:i.apiKey;if(!a)return;const c={apiKey:a,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",()=>S.init(c)):S.init(c)}(),e.ContentCredits=S});
|
|
2
2
|
//# sourceMappingURL=content-credits.umd.min.js.map
|