@freshjuice/zest 2.1.0 → 2.3.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.
Files changed (57) hide show
  1. package/dist/zest.d.ts +40 -0
  2. package/dist/zest.de.js +763 -51
  3. package/dist/zest.de.js.map +1 -1
  4. package/dist/zest.de.min.js +1 -1
  5. package/dist/zest.en.js +763 -51
  6. package/dist/zest.en.js.map +1 -1
  7. package/dist/zest.en.min.js +1 -1
  8. package/dist/zest.es.js +763 -51
  9. package/dist/zest.es.js.map +1 -1
  10. package/dist/zest.es.min.js +1 -1
  11. package/dist/zest.esm.js +763 -51
  12. package/dist/zest.esm.js.map +1 -1
  13. package/dist/zest.esm.min.js +1 -1
  14. package/dist/zest.fr.js +763 -51
  15. package/dist/zest.fr.js.map +1 -1
  16. package/dist/zest.fr.min.js +1 -1
  17. package/dist/zest.headless.d.ts +40 -0
  18. package/dist/zest.headless.esm.js +717 -33
  19. package/dist/zest.headless.esm.js.map +1 -1
  20. package/dist/zest.headless.esm.min.js +1 -1
  21. package/dist/zest.it.js +763 -51
  22. package/dist/zest.it.js.map +1 -1
  23. package/dist/zest.it.min.js +1 -1
  24. package/dist/zest.ja.js +763 -51
  25. package/dist/zest.ja.js.map +1 -1
  26. package/dist/zest.ja.min.js +1 -1
  27. package/dist/zest.js +763 -51
  28. package/dist/zest.js.map +1 -1
  29. package/dist/zest.min.js +1 -1
  30. package/dist/zest.nl.js +763 -51
  31. package/dist/zest.nl.js.map +1 -1
  32. package/dist/zest.nl.min.js +1 -1
  33. package/dist/zest.pl.js +763 -51
  34. package/dist/zest.pl.js.map +1 -1
  35. package/dist/zest.pl.min.js +1 -1
  36. package/dist/zest.pt.js +763 -51
  37. package/dist/zest.pt.js.map +1 -1
  38. package/dist/zest.pt.min.js +1 -1
  39. package/dist/zest.ru.js +763 -51
  40. package/dist/zest.ru.js.map +1 -1
  41. package/dist/zest.ru.min.js +1 -1
  42. package/dist/zest.uk.js +763 -51
  43. package/dist/zest.uk.js.map +1 -1
  44. package/dist/zest.uk.min.js +1 -1
  45. package/dist/zest.zh.js +763 -51
  46. package/dist/zest.zh.js.map +1 -1
  47. package/dist/zest.zh.min.js +1 -1
  48. package/package.json +1 -1
  49. package/src/config/defaults.js +49 -0
  50. package/src/core/element-interceptor.js +374 -0
  51. package/src/core/network-interceptor.js +289 -0
  52. package/src/core/pattern-matcher.js +37 -0
  53. package/src/core-lifecycle.js +43 -5
  54. package/src/index.js +46 -18
  55. package/src/types/zest.d.ts +40 -0
  56. package/src/types/zest.headless.d.ts +40 -0
  57. package/zest.config.schema.json +26 -0
@@ -1 +1 @@
1
- var Zest=function(){"use strict";const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","`":"&#96;"};function n(n){if(null==n)return"";return("string"==typeof n?n:n+"").replace(/[&<>"'`]/g,n=>t[n])}const e=new Set(["transparent","black","white","red","green","blue","yellow","orange","purple","pink","gray","grey","brown","cyan","magenta","silver","gold","navy","teal","maroon","olive","lime","aqua","fuchsia","indigo","violet","crimson","coral","salmon","tomato"]);const o=[/(\([^)]*[+*][^)]*\)|\[[^\]]*\]|\\w|\\d|\\s)\s*[+*]/,/\(\?[=!][^)]*[+*][^)]*\)[+*]/];function a(t,n){if(t instanceof RegExp)return t;if("string"!=typeof t)return null;if(t.length>500)return null;for(const n of o)if(n.test(t))return null;try{return RegExp(t,n)}catch(t){return null}}const s=new Set(["__proto__","constructor","prototype"]);function r(t,n){if(!t||"object"!=typeof t||Array.isArray(t))return null;const e={version:"string"==typeof t.version?t.version:null,timestamp:"number"==typeof t.timestamp&&Number.isFinite(t.timestamp)?t.timestamp:null,categories:{}},o=t.categories;if(!o||"object"!=typeof o||Array.isArray(o))return null;for(const t of n)s.has(t)||Object.prototype.hasOwnProperty.call(o,t)&&(e.categories[t]=!0===o[t]);return n.includes("essential")&&(e.categories.essential=!0),e}function i(t,...n){if("function"==typeof t)try{return t(...n)}catch(t){try{console.error("[Zest] User callback threw:",t)}catch(t){}return}}const c={essential:[/^zest_/,/^csrf/i,/^xsrf/i,/^session/i,/^__host-/i,/^__secure-/i],functional:[/^lang/i,/^locale/i,/^theme/i,/^preferences/i,/^ui_/i],analytics:[/^_ga/,/^_gid/,/^_gat/,/^_utm/,/^__utm/,/^plausible/i,/^_pk_/,/^matomo/i,/^_hj/,/^ajs_/],marketing:[/^_fbp/,/^_fbc/,/^_gcl/,/^_ttp/,/^ads/i,/^doubleclick/i,/^__gads/,/^__gpi/,/^_pin_/,/^li_/]};let l={...c};function d(t){for(const[n,e]of Object.entries(l))if(e.some(n=>n.test(t)))return n;return"marketing"}let u=null;const p=[];let f=()=>!1;function g(){return u}let m=null,b=null;const h=[],y=[];let z=()=>!1;function w(t,n,e){return new Proxy(t,{get(t,e){if("setItem"===e)return(e,o)=>{const a=d(e);z(a)?t.setItem(e,o):200>n.length&&n.push({key:e,value:o,category:a,timestamp:Date.now()})};const o=t[e];return"function"==typeof o?o.bind(t):o}})}const x={analytics:["google-analytics.com","www.google-analytics.com","analytics.google.com","googletagmanager.com","www.googletagmanager.com","plausible.io","cloudflareinsights.com","static.cloudflareinsights.com"],marketing:["connect.facebook.net","www.facebook.com/tr","ads.google.com","www.googleadservices.com","googleads.g.doubleclick.net","pagead2.googlesyndication.com"]},v={analytics:[...x.analytics,"analytics.tiktok.com","matomo.","hotjar.com","static.hotjar.com","script.hotjar.com","clarity.ms","www.clarity.ms","heapanalytics.com","cdn.heapanalytics.com","mixpanel.com","cdn.mxpnl.com","segment.com","cdn.segment.com","api.segment.io","fullstory.com","rs.fullstory.com","amplitude.com","cdn.amplitude.com","mouseflow.com","cdn.mouseflow.com","luckyorange.com","cdn.luckyorange.net","crazyegg.com","script.crazyegg.com"],marketing:[...x.marketing,"snap.licdn.com","px.ads.linkedin.com","ads.linkedin.com","analytics.twitter.com","static.ads-twitter.com","t.co","analytics.tiktok.com","ads.tiktok.com","sc-static.net","tr.snapchat.com","ct.pinterest.com","pintrk.com","s.pinimg.com","widgets.pinterest.com","bat.bing.com","ads.yahoo.com","sp.analytics.yahoo.com","amazon-adsystem.com","z-na.amazon-adsystem.com","criteo.com","static.criteo.net","dis.criteo.com","taboola.com","cdn.taboola.com","trc.taboola.com","outbrain.com","widgets.outbrain.com","adroll.com","s.adroll.com"],functional:["cdn.onesignal.com","onesignal.com","pusher.com","js.pusher.com","intercom.io","widget.intercom.io","js.intercomcdn.com","crisp.chat","client.crisp.chat","cdn.livechatinc.com","livechatinc.com","tawk.to","embed.tawk.to","zendesk.com","static.zdassets.com"]};function k(t,n){let e;try{e=new URL(t)}catch(t){return!1}const o=e.hostname.toLowerCase(),a=e.pathname.toLowerCase();for(const t of n){if("string"!=typeof t)continue;const n=t.toLowerCase();if(n.endsWith(".")){const t=n.slice(0,-1);if(o.split(".").some(n=>n===t)||o.startsWith(n))return!0;continue}const e=n.indexOf("/");if(-1!==e){const t=n.slice(0,e),s=n.slice(e);if((o===t||o.endsWith("."+t))&&a.startsWith(s))return!0;continue}if(o===n||o.endsWith("."+n))return!0}return!1}function _(t,n="safe"){const e="strict"===n?v:x;for(const[n,o]of Object.entries(e))if(k(t,o))return n;return null}const A=new Set(["functional","analytics","marketing"]),C=[];let S=null,j="safe",E=[],$=()=>!1;function L(t){if(t.hasAttribute("data-zest-allow"))return null;const n=t.getAttribute("data-consent-category"),e=n&&A.has(n)?n:null,o=t.src;if(!o)return e;const a=function(t){if(!t||0===E.length)return null;try{const n=new URL(t).hostname.toLowerCase();for(const t of E){const e="string"==typeof t?t:t.domain,o="string"==typeof t?"marketing":t.category||"marketing";if(n===e||n.endsWith("."+e))return o}}catch(t){}return null}(o);let s=null;switch(j){case"manual":break;case"safe":case"strict":s=_(o,j);break;case"doomsday":(function(t){try{const n=new URL(t).hostname,e=window.location.hostname,o=t=>t.replace(/^www\./,"");return o(n)!==o(e)}catch(t){return!1}})(o)&&(s=_(o,"strict")||"marketing")}return s||a||e}function R(t){if(t.hasAttribute("data-zest-processed"))return!1;const n=L(t);if(!n)return t.setAttribute("data-zest-processed","allowed"),!1;if($(n))return t.setAttribute("data-zest-processed","allowed"),!1;const e={category:n,src:t.src||"",inline:t.textContent,type:t.type,async:t.async,defer:t.defer,element:t,timestamp:Date.now()};return t.setAttribute("data-zest-processed","blocked"),t.setAttribute("data-consent-category",n),t.type="text/plain",t.src&&t.removeAttribute("src"),500>C.length&&C.push(e),!0}function M(t){for(const n of t)for(const t of n.addedNodes)if("SCRIPT"!==t.nodeName||t.hasAttribute("data-zest-processed")||R(t),t.querySelectorAll){t.querySelectorAll("script:not([data-zest-processed])").forEach(R)}}function N(t="safe",n=[]){return j=t,E=n,document.querySelectorAll("script:not([data-zest-processed])").forEach(R),S=new MutationObserver(M),S.observe(document.documentElement,{childList:!0,subtree:!0}),!0}const D={essential:{id:"essential",label:"Essential",description:"Required for the website to function properly. Cannot be disabled.",required:!0,default:!0},functional:{id:"functional",label:"Functional",description:"Enable personalized features like language preferences and themes.",required:!1,default:!1},analytics:{id:"analytics",label:"Analytics",description:"Help us understand how visitors interact with our website.",required:!1,default:!1},marketing:{id:"marketing",label:"Marketing",description:"Used to deliver relevant advertisements and track campaign performance.",required:!1,default:!1}};function O(){return Object.keys(D)}function q(){if("undefined"==typeof navigator)return!1;const t=navigator.doNotTrack||window.doNotTrack||navigator.msDoNotTrack;return"1"===t||"yes"===t||!0===t||!0===navigator.globalPrivacyControl}function T(t,n,e){const o=e?"default":"update";n.consentModeGoogle&&function(t,n){if(window.dataLayer=window.dataLayer||[],"function"==typeof window.gtag)window.gtag("consent",t,n);else{function e(){window.dataLayer.push(arguments)}e("consent",t,n)}}(o,function(t){const n=t=>t?"granted":"denied";return{ad_storage:n(t.marketing),ad_user_data:n(t.marketing),ad_personalization:n(t.marketing),analytics_storage:n(t.analytics),functionality_storage:"granted",personalization_storage:n(t.functional)}}(t)),n.consentModeMicrosoft&&function(t,n){window.uetq=window.uetq||[],window.uetq.push("consent",t,n)}(o,function(t){return{ad_storage:t.marketing?"granted":"denied"}}(t))}const W={labels:{banner:{title:"我们重视您的隐私",description:'我们使用Cookie来改善您的浏览体验、提供个性化内容并分析我们的流量。点击"全部接受"即表示您同意我们使用Cookie。',acceptAll:"全部接受",rejectAll:"全部拒绝",settings:"设置"},modal:{title:"隐私设置",description:"管理您的Cookie偏好设置。您可以在下方启用或禁用不同类型的Cookie。",save:"保存设置",acceptAll:"全部接受",rejectAll:"全部拒绝"},widget:{label:"Cookie设置"}},categories:{essential:{label:"必要",description:"网站正常运行所必需的。无法禁用。"},functional:{label:"功能性",description:"启用个性化功能,如语言偏好和主题设置。"},analytics:{label:"分析",description:"帮助我们了解访问者如何与网站互动。"},marketing:{label:"营销",description:"用于展示相关广告并衡量营销活动效果。"}}};const I={lang:"auto",position:"bottom",theme:"auto",accentColor:"#0071e3",categories:D,labels:{banner:{title:"We value your privacy",description:'We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.',acceptAll:"Accept All",rejectAll:"Reject All",settings:"Settings"},modal:{title:"Privacy Settings",description:"Manage your cookie preferences. You can enable or disable different types of cookies below.",save:"Save Preferences",acceptAll:"Accept All",rejectAll:"Reject All"},widget:{label:"Cookie Settings"}},autoInit:!0,showWidget:!0,expiration:365,respectDNT:!0,dntBehavior:"reject",customStyles:"",consentModeGoogle:!1,consentModeMicrosoft:!1,mode:"safe",blockedDomains:[],policyUrl:null,imprintUrl:null,callbacks:{onAccept:null,onReject:null,onChange:null,onReady:null}};function Z(t){const n={...I};t||(t={});const e=["lang","position","theme","accentColor","autoInit","showWidget","expiration","policyUrl","imprintUrl","customStyles","mode","blockedDomains","respectDNT","dntBehavior","consentModeGoogle","consentModeMicrosoft"];for(const o of e)void 0!==t[o]&&(n[o]=t[o]);n.lang="zh";const o=W,a=o.labels||{},s=t.labels||{};n.labels={banner:{...I.labels.banner,...a.banner,...s.banner},modal:{...I.labels.modal,...a.modal,...s.modal},widget:{...I.labels.widget,...a.widget,...s.widget}};const r=o.categories||{},i=t.categories||{};n.categories={...I.categories};for(const t of Object.keys(I.categories))n.categories[t]={...I.categories[t],...r[t],...i[t]};return t.callbacks&&(n.callbacks={...I.callbacks,...t.callbacks}),t.patterns&&(n.patterns=t.patterns),n}function U(){const t="undefined"!=typeof window&&window.ZestConfig?window.ZestConfig:{},n=function(){const t=document.currentScript||document.querySelector("script[data-zest]")||document.querySelector('script[src*="zest"]');if(!t)return{};const n={},e=t.getAttribute("data-position");e&&(n.position=e);const o=t.getAttribute("data-theme");o&&(n.theme=o);const a=t.getAttribute("data-accent")||t.getAttribute("data-accent-color");a&&(n.accentColor=a);const s=t.getAttribute("data-policy-url")||t.getAttribute("data-privacy-url");s&&(n.policyUrl=s);const r=t.getAttribute("data-imprint-url");r&&(n.imprintUrl=r);const i=t.getAttribute("data-show-widget");null!==i&&(n.showWidget="false"!==i);const c=t.getAttribute("data-auto-init");null!==c&&(n.autoInit="false"!==c);const l=t.getAttribute("data-expiration");l&&(n.expiration=parseInt(l,10));const d=t.getAttribute("data-consent-mode-google");null!==d&&(n.consentModeGoogle="false"!==d);const u=t.getAttribute("data-consent-mode-microsoft");return null!==u&&(n.consentModeMicrosoft="false"!==u),n}();return Z({...t,...n})}let P=null;function Y(){return P||(P=U()),P}const H="zest_consent";function B(){try{return"undefined"!=typeof location&&"https:"===location.protocol?"; Secure":""}catch(t){return""}}let F=null;function G(t){const n=g();n?.set?n.set.call(document,t):document.cookie=t}function J(){const t=g();return t?.get?t.get.call(document):document.cookie}function X(){try{const t=J().match(RegExp(H+"=([^;]+)"));if(t){const n=r(JSON.parse(decodeURIComponent(t[1])),O());if(n&&n.categories)return F={essential:!0,functional:!1,analytics:!1,marketing:!1,...n.categories},{...F}}}catch(t){}return F={essential:!0,functional:!1,analytics:!1,marketing:!1},{...F}}function V(){return F||(F=X()),{...F}}function K(t,n=365){const e=F?{...F}:{essential:!0,functional:!1,analytics:!1,marketing:!1};return F={essential:!0,functional:!!t.functional,analytics:!!t.analytics,marketing:!!t.marketing},function(t=365){F||(F={essential:!0,functional:!1,analytics:!1,marketing:!1});const n={version:"1.0",timestamp:Date.now(),categories:F},e=new Date(Date.now()+24*t*60*60*1e3).toUTCString();G(`${H}=${encodeURIComponent(JSON.stringify(n))}; expires=${e}; path=/; SameSite=Lax${B()}`)}(n),{current:{...F},previous:e}}function Q(t){return F||(F=X()),!0===F[t]}function tt(t=365){return K({functional:!1,analytics:!1,marketing:!1},t)}function nt(){try{return J().includes(H)}catch(t){return!1}}const et={READY:"zest:ready",CONSENT:"zest:consent",REJECT:"zest:reject",CHANGE:"zest:change",SHOW:"zest:show",HIDE:"zest:hide"};function ot(t,n={}){const e=new CustomEvent(t,{detail:n,bubbles:!0,cancelable:!0});return document.dispatchEvent(e),e}function at(t,n){return ot(et.CONSENT,{consent:t,previous:n})}function st(t){return ot(et.REJECT,{consent:t})}function rt(t,n){return ot(et.CHANGE,{consent:t,previous:n})}function it(t="banner"){return ot(et.SHOW,{type:t})}function ct(t="banner"){return ot(et.HIDE,{type:t})}let lt=!1,dt=null;function ut(t){return Q(t)}function pt(t){!function(t){const n=[];for(const e of p)t.includes(e.category)?u?.set&&u.set.call(document,e.value):n.push(e);p.length=0,p.push(...n)}(t),function(t){const n=[];for(const e of h)t.includes(e.category)?m?.setItem(e.key,e.value):n.push(e);h.length=0,h.push(...n);const e=[];for(const n of y)t.includes(n.category)?b?.setItem(n.key,n.value):e.push(n);y.length=0,y.push(...e)}(t),function(t){const n=[];for(const e of C){if(!t.includes(e.category)){n.push(e);continue}const o=document.createElement("script");e.src?o.src=e.src:e.inline&&(o.textContent=e.inline),e.async&&(o.async=!0),e.defer&&(o.defer=!0),e.type&&"text/plain"!==e.type&&(o.type=e.type),o.setAttribute("data-zest-processed","executed"),o.setAttribute("data-consent-executed","true");const a=e.element;a&&a.isConnected&&a.parentNode?a.parentNode.replaceChild(o,a):document.head.appendChild(o)}C.length=0,C.push(...n)}(t)}function ft(t={}){if(lt)return{alreadyInitialized:!0,config:dt,consent:X(),hasDecision:nt(),dntApplied:!1};P=Z(t),dt=P,T({functional:!1,analytics:!1,marketing:!1},dt,!0),dt.patterns&&function(t){if(l={...c},t&&"object"==typeof t)for(const[n,e]of Object.entries(t)){if(!Array.isArray(e))continue;const t=[];for(const n of e){const e=a(n);if(e)t.push(e);else try{console.warn("[Zest] Rejected unsafe pattern:",n)}catch(t){}}l[n]=t}}(dt.patterns),f=ut,function(t){z=t}(ut),function(t){$=t}(ut),u=Object.getOwnPropertyDescriptor(Document.prototype,"cookie"),u?Object.defineProperty(document,"cookie",{get:()=>u.get.call(document),set(t){const n=function(t){const n=t.match(/^([^=]+)/);return n?n[1].trim():null}(t);if(!n)return;const e=d(n);f(e)?u.set.call(document,t):100>p.length&&p.push({value:t,name:n,category:e,timestamp:Date.now()})},configurable:!1}):console.warn("[Zest] Could not get cookie descriptor"),function(){try{return m=window.localStorage,b=window.sessionStorage,Object.defineProperty(window,"localStorage",{value:w(m,h),configurable:!0,writable:!1}),Object.defineProperty(window,"sessionStorage",{value:w(b,y),configurable:!0,writable:!1}),!0}catch(t){return console.warn("[Zest] Could not intercept storage APIs:",t),!1}}(),N(dt.mode,dt.blockedDomains);const n=X();lt=!0,nt()&&T(n,dt,!1);let e=!1;if(q()&&dt.respectDNT&&"ignore"!==dt.dntBehavior&&"reject"===dt.dntBehavior&&!nt()){const t=tt(dt.expiration);e=!0,T(t.current,dt,!1),st(t.current),rt(t.current,t.previous),i(dt.callbacks?.onReject),i(dt.callbacks?.onChange,t.current)}return function(t){ot(et.READY,{consent:t})}(n),i(dt.callbacks?.onReady,n),{alreadyInitialized:!1,config:dt,consent:n,hasDecision:nt(),dntApplied:e}}function gt(){if(!lt)return null;const t=function(t=365){return K({functional:!0,analytics:!0,marketing:!0},t)}(dt.expiration);return T(t.current,dt,!1),pt(O()),at(t.current,t.previous),rt(t.current,t.previous),i(dt.callbacks?.onAccept,t.current),i(dt.callbacks?.onChange,t.current),t}function mt(){G(`${H}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; SameSite=Lax${B()}`),F=null}function bt(){return lt}function ht(){return dt}const yt="#4F46E5";function zt(t){const n=function(t){if("string"!=typeof t)return null;const n=t.trim();return/^#[0-9a-fA-F]{3,8}$/.test(n)||e.has(n.toLowerCase())||/^(rgb|rgba|hsl|hsla)\(\s*[\d.,%\s/]+\s*\)$/i.test(n)?n:null}(t.accentColor)||yt,o=function(t){if("string"!=typeof t||0===t.length)return"";if(t.length>2e4)return"";let n=t.replace(/\/\*[\s\S]*?\*\//g,"");return n=n.replace(/@import\s+[^;]+;?/gi,""),n=n.replace(/@charset\s+[^;]+;?/gi,""),n=n.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi,(t,n,e)=>{const o=e.trim().toLowerCase();return o.startsWith("https:")||o.startsWith("data:image/")||o.startsWith("/")||o.startsWith("#")?t:"url(#)"}),n=n.replace(/\.zest-btn--secondary\s*\{[^}]*\}/gi,""),n=n.replace(/\[data-action\s*=\s*["']reject-all["']\]\s*\{[^}]*\}/gi,""),n=n.replace(/\[data-action\s*=\s*["']accept-all["']\]\s*\{[^}]*\}/gi,""),n=n.replace(/expression\s*\([^)]*\)/gi,""),n=n.replace(/-moz-binding\s*:[^;}]*/gi,""),n}(t.customStyles);return`\n:host {\n --zest-accent: ${n};\n --zest-accent-hover: ${function(t,n){"string"==typeof t&&/^#[0-9a-fA-F]{3,8}$/.test(t.trim())||(t=yt);let e=t.trim().replace("#","");3===e.length&&(e=e.split("").map(t=>t+t).join(""));8===e.length&&(e=e.slice(0,6));6!==e.length&&(e="4F46E5");const o=parseInt(e,16),a=Math.round(2.55*n);return"#"+(16777216+65536*Math.min(255,Math.max(0,(o>>16)+a))+256*Math.min(255,Math.max(0,(o>>8&255)+a))+Math.min(255,Math.max(0,(255&o)+a))).toString(16).slice(1)}(n,-15)};\n --zest-bg: #ffffff;\n --zest-bg-secondary: #f3f4f6;\n --zest-text: #1f2937;\n --zest-text-secondary: #6b7280;\n --zest-border: #e5e7eb;\n --zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);\n --zest-radius: 12px;\n --zest-radius-sm: 8px;\n --zest-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;\n\n font-family: var(--zest-font);\n font-size: 14px;\n line-height: 1.5;\n color: var(--zest-text);\n box-sizing: border-box;\n}\n\n:host([data-theme="dark"]) {\n --zest-bg: #1f2937;\n --zest-bg-secondary: #374151;\n --zest-text: #f9fafb;\n --zest-text-secondary: #9ca3af;\n --zest-border: #4b5563;\n --zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);\n}\n\n@media (prefers-color-scheme: dark) {\n :host([data-theme="auto"]) {\n --zest-bg: #1f2937;\n --zest-bg-secondary: #374151;\n --zest-text: #f9fafb;\n --zest-text-secondary: #9ca3af;\n --zest-border: #4b5563;\n --zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);\n }\n}\n\n*, *::before, *::after {\n box-sizing: border-box;\n}\n\n/* Banner */\n.zest-banner {\n position: fixed;\n z-index: 999999;\n max-width: 480px;\n padding: 20px;\n background: var(--zest-bg);\n border-radius: var(--zest-radius);\n box-shadow: var(--zest-shadow);\n animation: zest-slide-in 0.3s ease-out;\n}\n\n.zest-banner--bottom {\n bottom: 20px;\n left: 50%;\n transform: translateX(-50%);\n}\n\n.zest-banner--bottom-left {\n bottom: 20px;\n left: 20px;\n}\n\n.zest-banner--bottom-right {\n bottom: 20px;\n right: 20px;\n}\n\n.zest-banner--top {\n top: 20px;\n left: 50%;\n transform: translateX(-50%);\n}\n\n@keyframes zest-slide-in {\n from {\n opacity: 0;\n transform: translateX(-50%) translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateX(-50%) translateY(0);\n }\n}\n\n.zest-banner--bottom-left {\n animation-name: zest-slide-in-left;\n}\n\n@keyframes zest-slide-in-left {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n.zest-banner--bottom-right {\n animation-name: zest-slide-in-right;\n}\n\n@keyframes zest-slide-in-right {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .zest-banner,\n .zest-modal {\n animation: none;\n }\n}\n\n.zest-banner__title {\n margin: 0 0 8px 0;\n font-size: 16px;\n font-weight: 600;\n color: var(--zest-text);\n}\n\n.zest-banner__description {\n margin: 0 0 16px 0;\n font-size: 14px;\n color: var(--zest-text-secondary);\n}\n\n.zest-banner__buttons {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n}\n\n/* Buttons */\n.zest-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n padding: 10px 16px;\n font-size: 14px;\n font-weight: 500;\n font-family: inherit;\n border: none;\n border-radius: var(--zest-radius-sm);\n cursor: pointer;\n transition: background-color 0.15s ease, transform 0.1s ease;\n}\n\n.zest-btn:hover {\n transform: translateY(-1px);\n}\n\n.zest-btn:active {\n transform: translateY(0);\n}\n\n.zest-btn:focus-visible {\n outline: 2px solid var(--zest-accent);\n outline-offset: 2px;\n}\n\n.zest-btn--primary {\n background: var(--zest-accent);\n color: #ffffff;\n}\n\n.zest-btn--primary:hover {\n background: var(--zest-accent-hover);\n}\n\n.zest-btn--secondary {\n background: var(--zest-bg-secondary);\n color: var(--zest-text);\n}\n\n.zest-btn--secondary:hover {\n background: var(--zest-border);\n}\n\n.zest-btn--ghost {\n background: transparent;\n color: var(--zest-text-secondary);\n}\n\n.zest-btn--ghost:hover {\n background: var(--zest-bg-secondary);\n color: var(--zest-text);\n}\n\n/* Modal */\n.zest-modal-overlay {\n position: fixed;\n inset: 0;\n z-index: 999998;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 20px;\n background: rgba(0, 0, 0, 0.5);\n animation: zest-fade-in 0.2s ease-out;\n}\n\n@keyframes zest-fade-in {\n from { opacity: 0; }\n to { opacity: 1; }\n}\n\n.zest-modal {\n width: 100%;\n max-width: 500px;\n max-height: 90vh;\n overflow-y: auto;\n background: var(--zest-bg);\n border-radius: var(--zest-radius);\n box-shadow: var(--zest-shadow);\n animation: zest-modal-in 0.3s ease-out;\n}\n\n@keyframes zest-modal-in {\n from {\n opacity: 0;\n transform: scale(0.95);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n\n.zest-modal__header {\n padding: 20px 20px 0;\n}\n\n.zest-modal__title {\n margin: 0 0 8px 0;\n font-size: 18px;\n font-weight: 600;\n color: var(--zest-text);\n}\n\n.zest-modal__description {\n margin: 0;\n font-size: 14px;\n color: var(--zest-text-secondary);\n}\n\n.zest-modal__body {\n padding: 20px;\n}\n\n.zest-modal__footer {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n padding: 0 20px 20px;\n}\n\n/* Categories */\n.zest-category {\n padding: 16px;\n margin-bottom: 12px;\n background: var(--zest-bg-secondary);\n border-radius: var(--zest-radius-sm);\n}\n\n.zest-category:last-child {\n margin-bottom: 0;\n}\n\n.zest-category__header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n}\n\n.zest-category__info {\n flex: 1;\n}\n\n.zest-category__label {\n display: block;\n font-size: 14px;\n font-weight: 600;\n color: var(--zest-text);\n}\n\n.zest-category__description {\n margin: 4px 0 0;\n font-size: 13px;\n color: var(--zest-text-secondary);\n}\n\n/* Toggle Switch */\n.zest-toggle {\n position: relative;\n width: 44px;\n height: 24px;\n flex-shrink: 0;\n}\n\n.zest-toggle__input {\n position: absolute;\n opacity: 0;\n width: 100%;\n height: 100%;\n cursor: pointer;\n margin: 0;\n}\n\n.zest-toggle__input:disabled {\n cursor: not-allowed;\n}\n\n.zest-toggle__slider {\n position: absolute;\n inset: 0;\n background: var(--zest-border);\n border-radius: 12px;\n transition: background-color 0.2s ease;\n pointer-events: none;\n}\n\n.zest-toggle__slider::before {\n content: '';\n position: absolute;\n top: 2px;\n left: 2px;\n width: 20px;\n height: 20px;\n background: #ffffff;\n border-radius: 50%;\n transition: transform 0.2s ease;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);\n}\n\n.zest-toggle__input:checked + .zest-toggle__slider {\n background: var(--zest-accent);\n}\n\n.zest-toggle__input:checked + .zest-toggle__slider::before {\n transform: translateX(20px);\n}\n\n.zest-toggle__input:focus-visible + .zest-toggle__slider {\n outline: 2px solid var(--zest-accent);\n outline-offset: 2px;\n}\n\n.zest-toggle__input:disabled + .zest-toggle__slider {\n opacity: 0.6;\n}\n\n/* Widget */\n.zest-widget {\n position: fixed;\n z-index: 999997;\n bottom: 20px;\n left: 20px;\n}\n\n.zest-widget__btn {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 48px;\n height: 48px;\n padding: 0;\n background: var(--zest-bg);\n border: 1px solid var(--zest-border);\n border-radius: 50%;\n box-shadow: var(--zest-shadow);\n cursor: pointer;\n transition: transform 0.2s ease, box-shadow 0.2s ease;\n}\n\n.zest-widget__btn:hover {\n transform: scale(1.05);\n box-shadow: 0 12px 28px -5px rgba(0, 0, 0, 0.15);\n}\n\n.zest-widget__btn:focus-visible {\n outline: 2px solid var(--zest-accent);\n outline-offset: 2px;\n}\n\n.zest-widget__icon {\n width: 24px;\n height: 24px;\n fill: var(--zest-text);\n}\n\n/* Link */\n.zest-link {\n color: var(--zest-accent);\n text-decoration: none;\n}\n\n.zest-link:hover {\n text-decoration: underline;\n}\n\n/* Mobile */\n@media (max-width: 480px) {\n .zest-banner {\n left: 10px;\n right: 10px;\n max-width: none;\n transform: none;\n }\n\n .zest-banner--bottom,\n .zest-banner--bottom-left,\n .zest-banner--bottom-right {\n bottom: 10px;\n }\n\n .zest-banner--top {\n top: 10px;\n transform: none;\n }\n\n @keyframes zest-slide-in {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n\n .zest-banner__buttons {\n flex-direction: column;\n }\n\n .zest-btn {\n width: 100%;\n }\n\n .zest-modal-overlay {\n padding: 10px;\n }\n\n .zest-widget {\n bottom: 10px;\n left: 10px;\n }\n}\n\n/* Hidden utility */\n.zest-hidden {\n display: none !important;\n}\n${o}\n`}let wt=null,xt=null;const vt=new Set(["bottom","bottom-left","bottom-right","top"]);function kt(t={}){if(wt)return wt;const e=Y();wt=document.createElement("zest-banner"),wt.setAttribute("data-theme",e.theme||"light"),xt=wt.attachShadow({mode:"open"});const o=document.createElement("style");o.textContent=zt(e),xt.appendChild(o);const a=document.createElement("div");a.innerHTML=function(t){const e=t.labels.banner,o=t.position||"bottom";return`\n <div class="zest-banner zest-banner--${vt.has(o)?o:"bottom"}" role="dialog" aria-modal="false" aria-label="${n(e.title)}">\n <h2 class="zest-banner__title">${n(e.title)}</h2>\n <p class="zest-banner__description">${n(e.description)}</p>\n <div class="zest-banner__buttons">\n <button type="button" class="zest-btn zest-btn--primary" data-action="accept-all">\n ${n(e.acceptAll)}\n </button>\n <button type="button" class="zest-btn zest-btn--secondary" data-action="reject-all">\n ${n(e.rejectAll)}\n </button>\n <button type="button" class="zest-btn zest-btn--ghost" data-action="settings">\n ${n(e.settings)}\n </button>\n </div>\n </div>\n `}(e),xt.appendChild(a.firstElementChild);const s=xt.querySelector(".zest-banner");return s.addEventListener("click",n=>{const e=n.target.dataset.action;if(e)switch(e){case"accept-all":t.onAcceptAll?.();break;case"reject-all":t.onRejectAll?.();break;case"settings":t.onSettings?.()}}),s.addEventListener("keydown",n=>{"Escape"===n.key&&t.onSettings?.()}),document.body.appendChild(wt),requestAnimationFrame(()=>{const t=xt.querySelector("button");t?.focus()}),wt}function _t(t={}){wt?wt.classList.remove("zest-hidden"):kt(t)}function At(){wt&&(wt.remove(),wt=null,xt=null)}let Ct=null,St=null,jt={};function Et(t,e){const o=t.labels.modal,a=Object.values(t.categories||D).map(t=>function(t,e,o){const a=o?"disabled":"",s=e?"checked":"",r=n(t.id),i=n(t.label);return`\n <div class="zest-category">\n <div class="zest-category__header">\n <div class="zest-category__info">\n <span class="zest-category__label">${i}</span>\n <p class="zest-category__description">${n(t.description)}</p>\n </div>\n <label class="zest-toggle">\n <input\n type="checkbox"\n class="zest-toggle__input"\n data-category="${r}"\n ${s}\n ${a}\n aria-label="${i}"\n >\n <span class="zest-toggle__slider"></span>\n </label>\n </div>\n </div>\n `}(t,e[t.id]??t.default,t.required)).join(""),s=t.policyUrl?function(t){if("string"!=typeof t||0===t.length)return null;const n=t.trim();if(0===n.length)return null;if(/^[/?#]/.test(n))return n;const e=n.match(/^([a-z][a-z0-9+.-]*):/i);if(!e)return n;const o=e[1].toLowerCase();return"http"===o||"https"===o||"mailto"===o||"tel"===o?n:null}(t.policyUrl):null,r=s?`<a href="${n(s)}" class="zest-link" target="_blank" rel="noopener noreferrer">Privacy Policy</a>`:"";return`\n <div class="zest-modal-overlay" role="dialog" aria-modal="true" aria-label="${n(o.title)}">\n <div class="zest-modal">\n <div class="zest-modal__header">\n <h2 class="zest-modal__title">${n(o.title)}</h2>\n <p class="zest-modal__description">${n(o.description)} ${r}</p>\n </div>\n <div class="zest-modal__body">\n ${a}\n </div>\n <div class="zest-modal__footer">\n <button type="button" class="zest-btn zest-btn--primary" data-action="save">\n ${n(o.save)}\n </button>\n <button type="button" class="zest-btn zest-btn--secondary" data-action="accept-all">\n ${n(o.acceptAll)}\n </button>\n <button type="button" class="zest-btn zest-btn--ghost" data-action="reject-all">\n ${n(o.rejectAll)}\n </button>\n </div>\n </div>\n </div>\n `}function $t(){if(!St)return jt;const t=St.querySelectorAll(".zest-toggle__input"),n={essential:!0};return t.forEach(t=>{const e=t.dataset.category;e&&"essential"!==e&&(n[e]=t.checked)}),n}function Lt(){Ct&&(Ct.remove(),Ct=null,St=null)}let Rt=null,Mt=null;function Nt(t={}){if(Rt)return Rt;const e=Y();Rt=document.createElement("zest-widget"),Rt.setAttribute("data-theme",e.theme||"light"),Mt=Rt.attachShadow({mode:"open"});const o=document.createElement("style");o.textContent=zt(e),Mt.appendChild(o);const a=document.createElement("div");a.innerHTML=function(t){const e=n(t.labels.widget.label);return`\n <div class="zest-widget">\n <button type="button" class="zest-widget__btn" aria-label="${e}" title="${e}">\n <span class="zest-widget__icon"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10c0-.728-.078-1.437-.225-2.12a1 1 0 0 0-1.482-.63 3 3 0 0 1-4.086-3.72 1 1 0 0 0-.793-1.263A10.05 10.05 0 0 0 12 2zm0 2c.178 0 .354.006.528.017a5 5 0 0 0 5.955 5.955c.011.174.017.35.017.528 0 4.418-3.582 8-8 8s-8-3.582-8-8 3.582-8 8-8zm-4 6a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm5 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"/></svg></span>\n </button>\n </div>\n `}(e),Mt.appendChild(a.firstElementChild);return Mt.querySelector(".zest-widget__btn").addEventListener("click",()=>{t.onClick?.()}),document.body.appendChild(Rt),Rt}function Dt(t={}){Rt?Rt.style.display="":Nt(t)}function Ot(){Rt&&(Rt.style.display="none")}function qt(){gt();const t=ht();At(),Lt(),t?.showWidget&&Dt({onClick:It})}function Tt(){!function(){if(!lt)return null;const t=tt(dt.expiration);T(t.current,dt,!1),st(t.current),rt(t.current,t.previous),i(dt.callbacks?.onReject),i(dt.callbacks?.onChange,t.current)}();const t=ht();At(),Lt(),t?.showWidget&&Dt({onClick:It})}function Wt(t){!function(t){if(!lt)return null;const n=K(t,dt.expiration);T(n.current,dt,!1);const e=Object.keys(n.current).filter(t=>n.current[t]&&!n.previous[t]);e.length>0&&pt(e),Object.entries(t||{}).some(([t,n])=>"essential"!==t&&n)?at(n.current,n.previous):st(n.current),rt(n.current,n.previous),i(dt.callbacks?.onChange,n.current)}(t);const n=ht();Lt(),n?.showWidget&&Dt({onClick:It})}function It(){At(),Ot(),function(t={},n={}){if(Ct)return Ct;const e=Y();jt={...t},Ct=document.createElement("zest-modal"),Ct.setAttribute("data-theme",e.theme||"light"),St=Ct.attachShadow({mode:"open"});const o=document.createElement("style");o.textContent=zt(e),St.appendChild(o);const a=document.createElement("div");a.innerHTML=Et(e,t),St.appendChild(a.firstElementChild);const s=St.querySelector(".zest-modal-overlay");s.addEventListener("click",t=>{const e=t.target.dataset.action;if(e)switch(e){case"save":n.onSave?.($t());break;case"accept-all":n.onAcceptAll?.();break;case"reject-all":n.onRejectAll?.()}else t.target===s&&n.onClose?.()}),s.addEventListener("keydown",t=>{"Escape"===t.key&&n.onClose?.()}),St.querySelectorAll(".zest-toggle__input").forEach(t=>{t.addEventListener("change",()=>{jt=$t()})}),document.body.appendChild(Ct),requestAnimationFrame(()=>{const t=St.querySelector("button");t?.focus()})}(V(),{onSave:Wt,onAcceptAll:qt,onRejectAll:Tt,onClose:Zt}),it("modal")}function Zt(){Lt(),ct("modal");const t=ht();nt()&&t?.showWidget?Dt({onClick:It}):_t({onAcceptAll:qt,onRejectAll:Tt,onSettings:It})}function Ut(t={}){const{alreadyInitialized:n,hasDecision:e,dntApplied:o}=ft(t);if(n)return console.warn("[Zest] Already initialized"),Pt;const a=ht();return e||o?a?.showWidget&&Dt({onClick:It}):(_t({onAcceptAll:qt,onRejectAll:Tt,onSettings:It}),it("banner")),Pt}const Pt={init:Ut,show(){bt()?(Lt(),Ot(),_t({onAcceptAll:qt,onRejectAll:Tt,onSettings:It}),it("banner")):console.warn("[Zest] Not initialized. Call Zest.init() first.")},hide(){At(),ct("banner")},showSettings(){bt()?It():console.warn("[Zest] Not initialized. Call Zest.init() first.")},hideSettings(){Lt(),ct("modal")},getConsent:V,hasConsent:Q,hasConsentDecision:nt,getConsentProof:function(){try{const t=J().match(RegExp(H+"=([^;]+)"));if(t){return r(JSON.parse(decodeURIComponent(t[1])),O())}}catch(t){}return null},isDoNotTrackEnabled:q,getDNTDetails:function(){if("undefined"==typeof navigator)return{enabled:!1,source:null};const t=navigator.doNotTrack||window.doNotTrack||navigator.msDoNotTrack;return"1"===t||"yes"===t||!0===t?{enabled:!0,source:"dnt"}:!0===navigator.globalPrivacyControl?{enabled:!0,source:"gpc"}:{enabled:!1,source:null}},acceptAll(){bt()?qt():console.warn("[Zest] Not initialized. Call Zest.init() first.")},rejectAll(){bt()?Tt():console.warn("[Zest] Not initialized. Call Zest.init() first.")},reset(){mt(),Lt(),Rt&&(Rt.remove(),Rt=null,Mt=null),bt()&&(_t({onAcceptAll:qt,onRejectAll:Tt,onSettings:It}),it("banner"))},getConfig:Y,on:function(t,n){return document.addEventListener(t,n),()=>document.removeEventListener(t,n)},once:function(t,n){document.addEventListener(t,n,{once:!0})},EVENTS:et};if("undefined"!=typeof window){try{Object.defineProperty(window,"Zest",{value:Object.freeze(Pt),writable:!1,configurable:!1,enumerable:!0})}catch(t){window.Zest=Pt}const t=()=>{!1!==U().autoInit&&Ut(window.ZestConfig)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t()}return Pt}();
1
+ var Zest=function(){"use strict";const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","`":"&#96;"};function e(e){if(null==e)return"";return("string"==typeof e?e:e+"").replace(/[&<>"'`]/g,e=>t[e])}const n=new Set(["transparent","black","white","red","green","blue","yellow","orange","purple","pink","gray","grey","brown","cyan","magenta","silver","gold","navy","teal","maroon","olive","lime","aqua","fuchsia","indigo","violet","crimson","coral","salmon","tomato"]);const o=[/(\([^)]*[+*][^)]*\)|\[[^\]]*\]|\\w|\\d|\\s)\s*[+*]/,/\(\?[=!][^)]*[+*][^)]*\)[+*]/];function r(t,e){if(t instanceof RegExp)return t;if("string"!=typeof t)return null;if(t.length>500)return null;for(const e of o)if(e.test(t))return null;try{return RegExp(t,e)}catch(t){return null}}const s=new Set(["__proto__","constructor","prototype"]);function a(t,e){if(!t||"object"!=typeof t||Array.isArray(t))return null;const n={version:"string"==typeof t.version?t.version:null,timestamp:"number"==typeof t.timestamp&&Number.isFinite(t.timestamp)?t.timestamp:null,categories:{}},o=t.categories;if(!o||"object"!=typeof o||Array.isArray(o))return null;for(const t of e)s.has(t)||Object.prototype.hasOwnProperty.call(o,t)&&(n.categories[t]=!0===o[t]);return e.includes("essential")&&(n.categories.essential=!0),n}function i(t,...e){if("function"==typeof t)try{return t(...e)}catch(t){try{console.error("[Zest] User callback threw:",t)}catch(t){}return}}const c={essential:[/^zest_/,/^csrf/i,/^xsrf/i,/^session/i,/^__host-/i,/^__secure-/i],functional:[/^lang/i,/^locale/i,/^theme/i,/^preferences/i,/^ui_/i],analytics:[/^_ga/,/^_gid/,/^_gat/,/^_utm/,/^__utm/,/^plausible/i,/^_pk_/,/^matomo/i,/^_hj/,/^ajs_/],marketing:[/^_fbp/,/^_fbc/,/^_gcl/,/^_ttp/,/^ads/i,/^doubleclick/i,/^__gads/,/^__gpi/,/^_pin_/,/^li_/]};let l={...c};function u(t){return(t+"").replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function d(t){for(const[e,n]of Object.entries(l))if(n.some(e=>e.test(t)))return e;return"marketing"}let f=null;const p=[];let g=()=>!1;function m(){return f}let b=null,y=null;const h=[],w=[];let z=()=>!1;function v(t,e,n){return new Proxy(t,{get(t,n){if("setItem"===n)return(n,o)=>{const r=d(n);z(r)?t.setItem(n,o):200>e.length&&e.push({key:n,value:o,category:r,timestamp:Date.now()})};const o=t[n];return"function"==typeof o?o.bind(t):o}})}const x={analytics:["google-analytics.com","www.google-analytics.com","analytics.google.com","googletagmanager.com","www.googletagmanager.com","plausible.io","cloudflareinsights.com","static.cloudflareinsights.com"],marketing:["connect.facebook.net","www.facebook.com/tr","ads.google.com","www.googleadservices.com","googleads.g.doubleclick.net","pagead2.googlesyndication.com"]},k={analytics:[...x.analytics,"analytics.tiktok.com","matomo.","hotjar.com","static.hotjar.com","script.hotjar.com","clarity.ms","www.clarity.ms","heapanalytics.com","cdn.heapanalytics.com","mixpanel.com","cdn.mxpnl.com","segment.com","cdn.segment.com","api.segment.io","fullstory.com","rs.fullstory.com","amplitude.com","cdn.amplitude.com","mouseflow.com","cdn.mouseflow.com","luckyorange.com","cdn.luckyorange.net","crazyegg.com","script.crazyegg.com"],marketing:[...x.marketing,"snap.licdn.com","px.ads.linkedin.com","ads.linkedin.com","analytics.twitter.com","static.ads-twitter.com","t.co","analytics.tiktok.com","ads.tiktok.com","sc-static.net","tr.snapchat.com","ct.pinterest.com","pintrk.com","s.pinimg.com","widgets.pinterest.com","bat.bing.com","ads.yahoo.com","sp.analytics.yahoo.com","amazon-adsystem.com","z-na.amazon-adsystem.com","criteo.com","static.criteo.net","dis.criteo.com","taboola.com","cdn.taboola.com","trc.taboola.com","outbrain.com","widgets.outbrain.com","adroll.com","s.adroll.com"],functional:["cdn.onesignal.com","onesignal.com","pusher.com","js.pusher.com","intercom.io","widget.intercom.io","js.intercomcdn.com","crisp.chat","client.crisp.chat","cdn.livechatinc.com","livechatinc.com","tawk.to","embed.tawk.to","zendesk.com","static.zdassets.com"]};function _(t,e){let n;try{n=new URL(t)}catch(t){return!1}const o=n.hostname.toLowerCase(),r=n.pathname.toLowerCase();for(const t of e){if("string"!=typeof t)continue;const e=t.toLowerCase();if(e.endsWith(".")){const t=e.slice(0,-1);if(o.split(".").some(e=>e===t)||o.startsWith(e))return!0;continue}const n=e.indexOf("/");if(-1!==n){const t=e.slice(0,n),s=e.slice(n);if((o===t||o.endsWith("."+t))&&r.startsWith(s))return!0;continue}if(o===e||o.endsWith("."+e))return!0}return!1}function A(t,e="safe"){const n="strict"===e?k:x;for(const[e,o]of Object.entries(n))if(_(t,o))return e;return null}function C(t){try{const e=new URL(t).hostname,n=window.location.hostname,o=t=>t.replace(/^www\./,"");return o(e)!==o(n)}catch(t){return!1}}const E=new Set(["functional","analytics","marketing"]),S=[];let j=null,L="safe",M=[],R=()=>!1;function $(t){if(t.hasAttribute("data-zest-allow"))return null;const e=t.getAttribute("data-consent-category"),n=e&&E.has(e)?e:null,o=t.src;if(!o)return n;const r=function(t){if(!t||0===M.length)return null;try{const e=new URL(t).hostname.toLowerCase();for(const t of M){const n="string"==typeof t?t:t.domain,o="string"==typeof t?"marketing":t.category||"marketing";if(e===n||e.endsWith("."+n))return o}}catch(t){}return null}(o);let s=null;switch(L){case"manual":break;case"safe":case"strict":s=A(o,L);break;case"doomsday":C(o)&&(s=A(o,"strict")||"marketing")}return s||r||n}function O(t){if(t.hasAttribute("data-zest-processed"))return!1;const e=$(t);if(!e)return t.setAttribute("data-zest-processed","allowed"),!1;if(R(e))return t.setAttribute("data-zest-processed","allowed"),!1;const n={category:e,src:t.src||"",inline:t.textContent,type:t.type,async:t.async,defer:t.defer,element:t,timestamp:Date.now()};return t.setAttribute("data-zest-processed","blocked"),t.setAttribute("data-consent-category",e),t.type="text/plain",t.src&&t.removeAttribute("src"),500>S.length&&S.push(n),!0}function T(t){for(const e of t)for(const t of e.addedNodes)if("SCRIPT"!==t.nodeName||t.hasAttribute("data-zest-processed")||O(t),t.querySelectorAll){t.querySelectorAll("script:not([data-zest-processed])").forEach(O)}}function N(t="safe",e=[]){return L=t,M=e,document.querySelectorAll("script:not([data-zest-processed])").forEach(O),j=new MutationObserver(T),j.observe(document.documentElement,{childList:!0,subtree:!0}),!0}let P=null,D=null,q=null,I=null,W="safe",U=[],H=!1,Z=()=>!1;const B=new Set(["functional","analytics","marketing"]);function Y(t){if(!t)return null;let e;try{e=new URL(t,location.href).hostname}catch(t){return null}const n=function(t){if(!t||0===U.length)return null;const e=t.toLowerCase();for(const t of U){const n=("string"==typeof t?t:t?.domain||"").toLowerCase();if(!n)continue;const o="string"==typeof t?"marketing":B.has(t?.category)?t.category:"marketing";if(e===n||e.endsWith("."+n))return o}return null}(e);if(n)return n;switch(W){case"manual":default:return null;case"safe":case"strict":return A(t,W);case"doomsday":return C(t)?A(t,"strict")||"marketing":null}}function F(t){const e=Y(t);return e?Z(e)?null:e:null}function G(){"undefined"!=typeof window&&"function"==typeof window.fetch&&(P=window.fetch.bind(window),window.fetch=function(t,e){const n=function(t){try{if("string"==typeof t)return new URL(t,location.href).href;if(t&&"object"==typeof t){if("string"==typeof t.url)return new URL(t.url,location.href).href;if("string"==typeof t.href)return t.href}}catch(t){}return null}(t);return F(n)?Promise.resolve("function"==typeof Response?new Response(null,{status:204,statusText:"Blocked by Zest"}):{ok:!1,status:204,statusText:"Blocked by Zest",json:()=>Promise.resolve({}),text:()=>Promise.resolve(""),arrayBuffer:()=>Promise.resolve(new ArrayBuffer(0))}):P(t,e)})}const K=Symbol("zestUrl");function X(t="safe",e=[]){return W=t,U=Array.isArray(e)?e:[],H||(G(),function(){if("undefined"==typeof XMLHttpRequest)return;const t=XMLHttpRequest.prototype;D=t.open,q=t.send,t.open=function(t,e,...n){return this[K]="string"==typeof e?e:e&&e.href||"",D.call(this,t,e,...n)},t.send=function(t){if(F(this[K])){const t=this;return void queueMicrotask(()=>{try{Object.defineProperty(t,"readyState",{value:4,configurable:!0}),Object.defineProperty(t,"status",{value:0,configurable:!0})}catch(t){}try{t.dispatchEvent(new Event("error")),t.dispatchEvent(new Event("loadend"))}catch(t){}})}return q.call(this,t)}}(),"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon&&(I=navigator.sendBeacon.bind(navigator),navigator.sendBeacon=function(t,e){return!F("string"==typeof t?t:t&&t.href||"")&&I(t,e)}),H=!0),!0}const J=[];let V="safe",Q=[],tt=!1,et=()=>!1;const nt=new Set(["functional","analytics","marketing"]),ot={script:"src",link:"href",img:"src",iframe:"src"};function rt(t){if(!t)return null;let e;try{e=new URL(t,location.href).hostname}catch(t){return null}const n=function(t){if(!t||0===Q.length)return null;const e=t.toLowerCase();for(const t of Q){const n=("string"==typeof t?t:t?.domain||"").toLowerCase();if(!n)continue;const o="string"==typeof t?"marketing":nt.has(t?.category)?t.category:"marketing";if(e===n||e.endsWith("."+n))return o}return null}(e);if(n)return n;switch(V){case"manual":default:return null;case"safe":case"strict":return A(t,V);case"doomsday":return C(t)?A(t,"strict")||"marketing":null}}function st(t){const e=rt(t);return e?et(e)?null:e:null}function at(t,e){if("function"!=typeof t||!t.prototype)return null;const n=t.prototype,o=Object.getOwnPropertyDescriptor(n,e);return o&&"function"==typeof o.set?(Object.defineProperty(n,e,{configurable:!0,enumerable:o.enumerable,get:o.get,set(t){if("string"==typeof t){const n=st(t);if(n)return void(500>J.length&&J.push({element:this,setter:o.set,prop:e,value:t,category:n,method:"property"}))}return o.set.call(this,t)}}),o):null}function it(t="safe",e=[]){return V=t,Q=Array.isArray(e)?e:[],tt||("undefined"!=typeof HTMLScriptElement&&at(HTMLScriptElement,"src"),"undefined"!=typeof HTMLLinkElement&&at(HTMLLinkElement,"href"),"undefined"!=typeof HTMLImageElement&&at(HTMLImageElement,"src"),"undefined"!=typeof HTMLIFrameElement&&at(HTMLIFrameElement,"src"),function(){if("undefined"==typeof Element||!Element.prototype)return null;const t=Element.prototype.setAttribute;Element.prototype.setAttribute=function(e,n){if("string"!=typeof e||"string"!=typeof n||!this||!this.tagName)return t.call(this,e,n);const o=this.tagName.toLowerCase(),r=ot[o];if(!r)return t.call(this,e,n);if(e.toLowerCase()!==r)return t.call(this,e,n);const s=st(n);if(!s)return t.call(this,e,n);500>J.length&&J.push({element:this,setter:t,prop:e,value:n,category:s,method:"attribute"})}}(),function(){if("undefined"==typeof window||"function"!=typeof window.Image)return null;const t=window.Image;function e(e,n){return 2>arguments.length?new t:new t(e,n)}e.prototype=t.prototype;for(const n of Object.keys(t))try{e[n]=t[n]}catch(t){}try{Object.defineProperty(window,"Image",{configurable:!0,writable:!0,value:e})}catch(t){window.Image=e}}(),tt=!0),!0}const ct={essential:{id:"essential",label:"Essential",description:"Required for the website to function properly. Cannot be disabled.",required:!0,default:!0},functional:{id:"functional",label:"Functional",description:"Enable personalized features like language preferences and themes.",required:!1,default:!1},analytics:{id:"analytics",label:"Analytics",description:"Help us understand how visitors interact with our website.",required:!1,default:!1},marketing:{id:"marketing",label:"Marketing",description:"Used to deliver relevant advertisements and track campaign performance.",required:!1,default:!1}};function lt(){return Object.keys(ct)}function ut(){if("undefined"==typeof navigator)return!1;const t=navigator.doNotTrack||window.doNotTrack||navigator.msDoNotTrack;return"1"===t||"yes"===t||!0===t||!0===navigator.globalPrivacyControl}function dt(t,e,n){const o=n?"default":"update";e.consentModeGoogle&&function(t,e){if(window.dataLayer=window.dataLayer||[],"function"==typeof window.gtag)window.gtag("consent",t,e);else{function n(){window.dataLayer.push(arguments)}n("consent",t,e)}}(o,function(t){const e=t=>t?"granted":"denied";return{ad_storage:e(t.marketing),ad_user_data:e(t.marketing),ad_personalization:e(t.marketing),analytics_storage:e(t.analytics),functionality_storage:"granted",personalization_storage:e(t.functional)}}(t)),e.consentModeMicrosoft&&function(t,e){window.uetq=window.uetq||[],window.uetq.push("consent",t,e)}(o,function(t){return{ad_storage:t.marketing?"granted":"denied"}}(t))}const ft={labels:{banner:{title:"我们重视您的隐私",description:'我们使用Cookie来改善您的浏览体验、提供个性化内容并分析我们的流量。点击"全部接受"即表示您同意我们使用Cookie。',acceptAll:"全部接受",rejectAll:"全部拒绝",settings:"设置"},modal:{title:"隐私设置",description:"管理您的Cookie偏好设置。您可以在下方启用或禁用不同类型的Cookie。",save:"保存设置",acceptAll:"全部接受",rejectAll:"全部拒绝"},widget:{label:"Cookie设置"}},categories:{essential:{label:"必要",description:"网站正常运行所必需的。无法禁用。"},functional:{label:"功能性",description:"启用个性化功能,如语言偏好和主题设置。"},analytics:{label:"分析",description:"帮助我们了解访问者如何与网站互动。"},marketing:{label:"营销",description:"用于展示相关广告并衡量营销活动效果。"}}};const pt={lang:"auto",position:"bottom",theme:"auto",accentColor:"#0071e3",categories:ct,labels:{banner:{title:"We value your privacy",description:'We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.',acceptAll:"Accept All",rejectAll:"Reject All",settings:"Settings"},modal:{title:"Privacy Settings",description:"Manage your cookie preferences. You can enable or disable different types of cookies below.",save:"Save Preferences",acceptAll:"Accept All",rejectAll:"Reject All"},widget:{label:"Cookie Settings"}},autoInit:!0,showWidget:!0,expiration:365,respectDNT:!0,dntBehavior:"reject",customStyles:"",consentModeGoogle:!1,consentModeMicrosoft:!1,mode:"safe",intercept:{cookies:!0,storage:!0,scripts:!0,network:!0},essentialKeys:[],essentialPatterns:[],blockedDomains:[],policyUrl:null,imprintUrl:null,callbacks:{onAccept:null,onReject:null,onChange:null,onReady:null}};function gt(t){const e={...pt};t||(t={});const n=["lang","position","theme","accentColor","autoInit","showWidget","expiration","policyUrl","imprintUrl","customStyles","mode","blockedDomains","respectDNT","dntBehavior","consentModeGoogle","consentModeMicrosoft"];for(const o of n)void 0!==t[o]&&(e[o]=t[o]);e.lang="zh";const o=ft,r=o.labels||{},s=t.labels||{};e.labels={banner:{...pt.labels.banner,...r.banner,...s.banner},modal:{...pt.labels.modal,...r.modal,...s.modal},widget:{...pt.labels.widget,...r.widget,...s.widget}};const a=o.categories||{},i=t.categories||{};e.categories={...pt.categories};for(const t of Object.keys(pt.categories))e.categories[t]={...pt.categories[t],...a[t],...i[t]};return t.callbacks&&(e.callbacks={...pt.callbacks,...t.callbacks}),t.patterns&&(e.patterns=t.patterns),t.intercept&&"object"==typeof t.intercept&&(e.intercept={...pt.intercept,...t.intercept}),Array.isArray(t.essentialKeys)&&(e.essentialKeys=t.essentialKeys.filter(t=>"string"==typeof t&&t.length>0&&200>=t.length)),Array.isArray(t.essentialPatterns)&&(e.essentialPatterns=t.essentialPatterns.filter(t=>"string"==typeof t&&t.length>0&&500>=t.length)),e}function mt(){const t="undefined"!=typeof window&&window.ZestConfig?window.ZestConfig:{},e=function(){const t=document.currentScript||document.querySelector("script[data-zest]")||document.querySelector('script[src*="zest"]');if(!t)return{};const e={},n=t.getAttribute("data-position");n&&(e.position=n);const o=t.getAttribute("data-theme");o&&(e.theme=o);const r=t.getAttribute("data-accent")||t.getAttribute("data-accent-color");r&&(e.accentColor=r);const s=t.getAttribute("data-policy-url")||t.getAttribute("data-privacy-url");s&&(e.policyUrl=s);const a=t.getAttribute("data-imprint-url");a&&(e.imprintUrl=a);const i=t.getAttribute("data-show-widget");null!==i&&(e.showWidget="false"!==i);const c=t.getAttribute("data-auto-init");null!==c&&(e.autoInit="false"!==c);const l=t.getAttribute("data-expiration");l&&(e.expiration=parseInt(l,10));const u=t.getAttribute("data-consent-mode-google");null!==u&&(e.consentModeGoogle="false"!==u);const d=t.getAttribute("data-consent-mode-microsoft");return null!==d&&(e.consentModeMicrosoft="false"!==d),e}();return gt({...t,...e})}let bt=null;function yt(){return bt||(bt=mt()),bt}const ht="zest_consent";function wt(){try{return"undefined"!=typeof location&&"https:"===location.protocol?"; Secure":""}catch(t){return""}}let zt=null;function vt(t){const e=m();e?.set?e.set.call(document,t):document.cookie=t}function xt(){const t=m();return t?.get?t.get.call(document):document.cookie}function kt(){try{const t=xt().match(RegExp(ht+"=([^;]+)"));if(t){const e=a(JSON.parse(decodeURIComponent(t[1])),lt());if(e&&e.categories)return zt={essential:!0,functional:!1,analytics:!1,marketing:!1,...e.categories},{...zt}}}catch(t){}return zt={essential:!0,functional:!1,analytics:!1,marketing:!1},{...zt}}function _t(){return zt||(zt=kt()),{...zt}}function At(t,e=365){const n=zt?{...zt}:{essential:!0,functional:!1,analytics:!1,marketing:!1};return zt={essential:!0,functional:!!t.functional,analytics:!!t.analytics,marketing:!!t.marketing},function(t=365){zt||(zt={essential:!0,functional:!1,analytics:!1,marketing:!1});const e={version:"1.0",timestamp:Date.now(),categories:zt},n=new Date(Date.now()+24*t*60*60*1e3).toUTCString();vt(`${ht}=${encodeURIComponent(JSON.stringify(e))}; expires=${n}; path=/; SameSite=Lax${wt()}`)}(e),{current:{...zt},previous:n}}function Ct(t){return zt||(zt=kt()),!0===zt[t]}function Et(t=365){return At({functional:!1,analytics:!1,marketing:!1},t)}function St(){try{return xt().includes(ht)}catch(t){return!1}}const jt={READY:"zest:ready",CONSENT:"zest:consent",REJECT:"zest:reject",CHANGE:"zest:change",SHOW:"zest:show",HIDE:"zest:hide"};function Lt(t,e={}){const n=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return document.dispatchEvent(n),n}function Mt(t,e){return Lt(jt.CONSENT,{consent:t,previous:e})}function Rt(t){return Lt(jt.REJECT,{consent:t})}function $t(t,e){return Lt(jt.CHANGE,{consent:t,previous:e})}function Ot(t="banner"){return Lt(jt.SHOW,{type:t})}function Tt(t="banner"){return Lt(jt.HIDE,{type:t})}let Nt=!1,Pt=null;function Dt(t){return Ct(t)}function qt(t){!function(t){const e=[];for(const n of p)t.includes(n.category)?f?.set&&f.set.call(document,n.value):e.push(n);p.length=0,p.push(...e)}(t),function(t){const e=[];for(const n of h)t.includes(n.category)?b?.setItem(n.key,n.value):e.push(n);h.length=0,h.push(...e);const n=[];for(const e of w)t.includes(e.category)?y?.setItem(e.key,e.value):n.push(e);w.length=0,w.push(...n)}(t),function(t){const e=[];for(const n of S){if(!t.includes(n.category)){e.push(n);continue}const o=document.createElement("script");n.src?o.src=n.src:n.inline&&(o.textContent=n.inline),n.async&&(o.async=!0),n.defer&&(o.defer=!0),n.type&&"text/plain"!==n.type&&(o.type=n.type),o.setAttribute("data-zest-processed","executed"),o.setAttribute("data-consent-executed","true");const r=n.element;r&&r.isConnected&&r.parentNode?r.parentNode.replaceChild(o,r):document.head.appendChild(o)}S.length=0,S.push(...e)}(t),function(t){if(!Array.isArray(t)||0===J.length)return;const e=[];for(const n of J){if(!t.includes(n.category)){e.push(n);continue}const o=n.element;if(o&&o.isConnected)try{"attribute"===n.method?n.setter.call(o,n.prop,n.value):n.setter.call(o,n.value)}catch(t){}}J.length=0,J.push(...e)}(t)}function It(t={}){if(Nt)return{alreadyInitialized:!0,config:Pt,consent:kt(),hasDecision:St(),dntApplied:!1};bt=gt(t),Pt=bt,dt({functional:!1,analytics:!1,marketing:!1},Pt,!0),Pt.patterns&&function(t){if(l={...c},t&&"object"==typeof t)for(const[e,n]of Object.entries(t)){if(!Array.isArray(n))continue;const t=[];for(const e of n){const n=r(e);if(n)t.push(n);else try{console.warn("[Zest] Rejected unsafe pattern:",e)}catch(t){}}l[e]=t}}(Pt.patterns),(Array.isArray(Pt.essentialKeys)&&Pt.essentialKeys.length>0||Array.isArray(Pt.essentialPatterns)&&Pt.essentialPatterns.length>0)&&function(t,{keys:e=[],patternStrings:n=[]}={}){l[t]||(l[t]=[]);for(const n of e){if("string"!=typeof n||!n)continue;const e=r(`^${u(n)}$`);e&&l[t].push(e)}for(const e of n){if("string"!=typeof e||!e)continue;const n=r(e);n&&l[t].push(n)}}("essential",{keys:Pt.essentialKeys,patternStrings:Pt.essentialPatterns}),g=Dt,function(t){z=t}(Dt),function(t){R=t}(Dt),function(t){Z=t}(Dt),function(t){et=t}(Dt);const e=Pt.intercept||{cookies:!0,storage:!0,scripts:!0,network:!0};!1!==e.cookies&&(f=Object.getOwnPropertyDescriptor(Document.prototype,"cookie"),f?Object.defineProperty(document,"cookie",{get:()=>f.get.call(document),set(t){const e=function(t){const e=t.match(/^([^=]+)/);return e?e[1].trim():null}(t);if(!e)return;const n=d(e);g(n)?f.set.call(document,t):100>p.length&&p.push({value:t,name:e,category:n,timestamp:Date.now()})},configurable:!1}):console.warn("[Zest] Could not get cookie descriptor")),!1!==e.storage&&function(){try{return b=window.localStorage,y=window.sessionStorage,Object.defineProperty(window,"localStorage",{value:v(b,h),configurable:!0,writable:!1}),Object.defineProperty(window,"sessionStorage",{value:v(y,w),configurable:!0,writable:!1}),!0}catch(t){return console.warn("[Zest] Could not intercept storage APIs:",t),!1}}(),!1!==e.scripts&&(it(Pt.mode,Pt.blockedDomains),N(Pt.mode,Pt.blockedDomains)),!1!==e.network&&X(Pt.mode,Pt.blockedDomains);const n=kt();Nt=!0,St()&&dt(n,Pt,!1);let o=!1;if(ut()&&Pt.respectDNT&&"ignore"!==Pt.dntBehavior&&"reject"===Pt.dntBehavior&&!St()){const t=Et(Pt.expiration);o=!0,dt(t.current,Pt,!1),Rt(t.current),$t(t.current,t.previous),i(Pt.callbacks?.onReject),i(Pt.callbacks?.onChange,t.current)}return function(t){Lt(jt.READY,{consent:t})}(n),i(Pt.callbacks?.onReady,n),{alreadyInitialized:!1,config:Pt,consent:n,hasDecision:St(),dntApplied:o}}function Wt(){if(!Nt)return null;const t=function(t=365){return At({functional:!0,analytics:!0,marketing:!0},t)}(Pt.expiration);return dt(t.current,Pt,!1),qt(lt()),Mt(t.current,t.previous),$t(t.current,t.previous),i(Pt.callbacks?.onAccept,t.current),i(Pt.callbacks?.onChange,t.current),t}function Ut(){vt(`${ht}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; SameSite=Lax${wt()}`),zt=null}function Ht(){return Nt}function Zt(){return Pt}const Bt="#4F46E5";function Yt(t){const e=function(t){if("string"!=typeof t)return null;const e=t.trim();return/^#[0-9a-fA-F]{3,8}$/.test(e)||n.has(e.toLowerCase())||/^(rgb|rgba|hsl|hsla)\(\s*[\d.,%\s/]+\s*\)$/i.test(e)?e:null}(t.accentColor)||Bt,o=function(t){if("string"!=typeof t||0===t.length)return"";if(t.length>2e4)return"";let e=t.replace(/\/\*[\s\S]*?\*\//g,"");return e=e.replace(/@import\s+[^;]+;?/gi,""),e=e.replace(/@charset\s+[^;]+;?/gi,""),e=e.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi,(t,e,n)=>{const o=n.trim().toLowerCase();return o.startsWith("https:")||o.startsWith("data:image/")||o.startsWith("/")||o.startsWith("#")?t:"url(#)"}),e=e.replace(/\.zest-btn--secondary\s*\{[^}]*\}/gi,""),e=e.replace(/\[data-action\s*=\s*["']reject-all["']\]\s*\{[^}]*\}/gi,""),e=e.replace(/\[data-action\s*=\s*["']accept-all["']\]\s*\{[^}]*\}/gi,""),e=e.replace(/expression\s*\([^)]*\)/gi,""),e=e.replace(/-moz-binding\s*:[^;}]*/gi,""),e}(t.customStyles);return`\n:host {\n --zest-accent: ${e};\n --zest-accent-hover: ${function(t,e){"string"==typeof t&&/^#[0-9a-fA-F]{3,8}$/.test(t.trim())||(t=Bt);let n=t.trim().replace("#","");3===n.length&&(n=n.split("").map(t=>t+t).join(""));8===n.length&&(n=n.slice(0,6));6!==n.length&&(n="4F46E5");const o=parseInt(n,16),r=Math.round(2.55*e);return"#"+(16777216+65536*Math.min(255,Math.max(0,(o>>16)+r))+256*Math.min(255,Math.max(0,(o>>8&255)+r))+Math.min(255,Math.max(0,(255&o)+r))).toString(16).slice(1)}(e,-15)};\n --zest-bg: #ffffff;\n --zest-bg-secondary: #f3f4f6;\n --zest-text: #1f2937;\n --zest-text-secondary: #6b7280;\n --zest-border: #e5e7eb;\n --zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);\n --zest-radius: 12px;\n --zest-radius-sm: 8px;\n --zest-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;\n\n font-family: var(--zest-font);\n font-size: 14px;\n line-height: 1.5;\n color: var(--zest-text);\n box-sizing: border-box;\n}\n\n:host([data-theme="dark"]) {\n --zest-bg: #1f2937;\n --zest-bg-secondary: #374151;\n --zest-text: #f9fafb;\n --zest-text-secondary: #9ca3af;\n --zest-border: #4b5563;\n --zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);\n}\n\n@media (prefers-color-scheme: dark) {\n :host([data-theme="auto"]) {\n --zest-bg: #1f2937;\n --zest-bg-secondary: #374151;\n --zest-text: #f9fafb;\n --zest-text-secondary: #9ca3af;\n --zest-border: #4b5563;\n --zest-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);\n }\n}\n\n*, *::before, *::after {\n box-sizing: border-box;\n}\n\n/* Banner */\n.zest-banner {\n position: fixed;\n z-index: 999999;\n max-width: 480px;\n padding: 20px;\n background: var(--zest-bg);\n border-radius: var(--zest-radius);\n box-shadow: var(--zest-shadow);\n animation: zest-slide-in 0.3s ease-out;\n}\n\n.zest-banner--bottom {\n bottom: 20px;\n left: 50%;\n transform: translateX(-50%);\n}\n\n.zest-banner--bottom-left {\n bottom: 20px;\n left: 20px;\n}\n\n.zest-banner--bottom-right {\n bottom: 20px;\n right: 20px;\n}\n\n.zest-banner--top {\n top: 20px;\n left: 50%;\n transform: translateX(-50%);\n}\n\n@keyframes zest-slide-in {\n from {\n opacity: 0;\n transform: translateX(-50%) translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateX(-50%) translateY(0);\n }\n}\n\n.zest-banner--bottom-left {\n animation-name: zest-slide-in-left;\n}\n\n@keyframes zest-slide-in-left {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n.zest-banner--bottom-right {\n animation-name: zest-slide-in-right;\n}\n\n@keyframes zest-slide-in-right {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .zest-banner,\n .zest-modal {\n animation: none;\n }\n}\n\n.zest-banner__title {\n margin: 0 0 8px 0;\n font-size: 16px;\n font-weight: 600;\n color: var(--zest-text);\n}\n\n.zest-banner__description {\n margin: 0 0 16px 0;\n font-size: 14px;\n color: var(--zest-text-secondary);\n}\n\n.zest-banner__buttons {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n}\n\n/* Buttons */\n.zest-btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n padding: 10px 16px;\n font-size: 14px;\n font-weight: 500;\n font-family: inherit;\n border: none;\n border-radius: var(--zest-radius-sm);\n cursor: pointer;\n transition: background-color 0.15s ease, transform 0.1s ease;\n}\n\n.zest-btn:hover {\n transform: translateY(-1px);\n}\n\n.zest-btn:active {\n transform: translateY(0);\n}\n\n.zest-btn:focus-visible {\n outline: 2px solid var(--zest-accent);\n outline-offset: 2px;\n}\n\n.zest-btn--primary {\n background: var(--zest-accent);\n color: #ffffff;\n}\n\n.zest-btn--primary:hover {\n background: var(--zest-accent-hover);\n}\n\n.zest-btn--secondary {\n background: var(--zest-bg-secondary);\n color: var(--zest-text);\n}\n\n.zest-btn--secondary:hover {\n background: var(--zest-border);\n}\n\n.zest-btn--ghost {\n background: transparent;\n color: var(--zest-text-secondary);\n}\n\n.zest-btn--ghost:hover {\n background: var(--zest-bg-secondary);\n color: var(--zest-text);\n}\n\n/* Modal */\n.zest-modal-overlay {\n position: fixed;\n inset: 0;\n z-index: 999998;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 20px;\n background: rgba(0, 0, 0, 0.5);\n animation: zest-fade-in 0.2s ease-out;\n}\n\n@keyframes zest-fade-in {\n from { opacity: 0; }\n to { opacity: 1; }\n}\n\n.zest-modal {\n width: 100%;\n max-width: 500px;\n max-height: 90vh;\n overflow-y: auto;\n background: var(--zest-bg);\n border-radius: var(--zest-radius);\n box-shadow: var(--zest-shadow);\n animation: zest-modal-in 0.3s ease-out;\n}\n\n@keyframes zest-modal-in {\n from {\n opacity: 0;\n transform: scale(0.95);\n }\n to {\n opacity: 1;\n transform: scale(1);\n }\n}\n\n.zest-modal__header {\n padding: 20px 20px 0;\n}\n\n.zest-modal__title {\n margin: 0 0 8px 0;\n font-size: 18px;\n font-weight: 600;\n color: var(--zest-text);\n}\n\n.zest-modal__description {\n margin: 0;\n font-size: 14px;\n color: var(--zest-text-secondary);\n}\n\n.zest-modal__body {\n padding: 20px;\n}\n\n.zest-modal__footer {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n padding: 0 20px 20px;\n}\n\n/* Categories */\n.zest-category {\n padding: 16px;\n margin-bottom: 12px;\n background: var(--zest-bg-secondary);\n border-radius: var(--zest-radius-sm);\n}\n\n.zest-category:last-child {\n margin-bottom: 0;\n}\n\n.zest-category__header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n}\n\n.zest-category__info {\n flex: 1;\n}\n\n.zest-category__label {\n display: block;\n font-size: 14px;\n font-weight: 600;\n color: var(--zest-text);\n}\n\n.zest-category__description {\n margin: 4px 0 0;\n font-size: 13px;\n color: var(--zest-text-secondary);\n}\n\n/* Toggle Switch */\n.zest-toggle {\n position: relative;\n width: 44px;\n height: 24px;\n flex-shrink: 0;\n}\n\n.zest-toggle__input {\n position: absolute;\n opacity: 0;\n width: 100%;\n height: 100%;\n cursor: pointer;\n margin: 0;\n}\n\n.zest-toggle__input:disabled {\n cursor: not-allowed;\n}\n\n.zest-toggle__slider {\n position: absolute;\n inset: 0;\n background: var(--zest-border);\n border-radius: 12px;\n transition: background-color 0.2s ease;\n pointer-events: none;\n}\n\n.zest-toggle__slider::before {\n content: '';\n position: absolute;\n top: 2px;\n left: 2px;\n width: 20px;\n height: 20px;\n background: #ffffff;\n border-radius: 50%;\n transition: transform 0.2s ease;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);\n}\n\n.zest-toggle__input:checked + .zest-toggle__slider {\n background: var(--zest-accent);\n}\n\n.zest-toggle__input:checked + .zest-toggle__slider::before {\n transform: translateX(20px);\n}\n\n.zest-toggle__input:focus-visible + .zest-toggle__slider {\n outline: 2px solid var(--zest-accent);\n outline-offset: 2px;\n}\n\n.zest-toggle__input:disabled + .zest-toggle__slider {\n opacity: 0.6;\n}\n\n/* Widget */\n.zest-widget {\n position: fixed;\n z-index: 999997;\n bottom: 20px;\n left: 20px;\n}\n\n.zest-widget__btn {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 48px;\n height: 48px;\n padding: 0;\n background: var(--zest-bg);\n border: 1px solid var(--zest-border);\n border-radius: 50%;\n box-shadow: var(--zest-shadow);\n cursor: pointer;\n transition: transform 0.2s ease, box-shadow 0.2s ease;\n}\n\n.zest-widget__btn:hover {\n transform: scale(1.05);\n box-shadow: 0 12px 28px -5px rgba(0, 0, 0, 0.15);\n}\n\n.zest-widget__btn:focus-visible {\n outline: 2px solid var(--zest-accent);\n outline-offset: 2px;\n}\n\n.zest-widget__icon {\n width: 24px;\n height: 24px;\n fill: var(--zest-text);\n}\n\n/* Link */\n.zest-link {\n color: var(--zest-accent);\n text-decoration: none;\n}\n\n.zest-link:hover {\n text-decoration: underline;\n}\n\n/* Mobile */\n@media (max-width: 480px) {\n .zest-banner {\n left: 10px;\n right: 10px;\n max-width: none;\n transform: none;\n }\n\n .zest-banner--bottom,\n .zest-banner--bottom-left,\n .zest-banner--bottom-right {\n bottom: 10px;\n }\n\n .zest-banner--top {\n top: 10px;\n transform: none;\n }\n\n @keyframes zest-slide-in {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n\n .zest-banner__buttons {\n flex-direction: column;\n }\n\n .zest-btn {\n width: 100%;\n }\n\n .zest-modal-overlay {\n padding: 10px;\n }\n\n .zest-widget {\n bottom: 10px;\n left: 10px;\n }\n}\n\n/* Hidden utility */\n.zest-hidden {\n display: none !important;\n}\n${o}\n`}let Ft=null,Gt=null;const Kt=new Set(["bottom","bottom-left","bottom-right","top"]);function Xt(t={}){if(Ft)return Ft;const n=yt();Ft=document.createElement("zest-banner"),Ft.setAttribute("data-theme",n.theme||"light"),Gt=Ft.attachShadow({mode:"open"});const o=document.createElement("style");o.textContent=Yt(n),Gt.appendChild(o);const r=document.createElement("div");r.innerHTML=function(t){const n=t.labels.banner,o=t.position||"bottom";return`\n <div class="zest-banner zest-banner--${Kt.has(o)?o:"bottom"}" role="dialog" aria-modal="false" aria-label="${e(n.title)}">\n <h2 class="zest-banner__title">${e(n.title)}</h2>\n <p class="zest-banner__description">${e(n.description)}</p>\n <div class="zest-banner__buttons">\n <button type="button" class="zest-btn zest-btn--primary" data-action="accept-all">\n ${e(n.acceptAll)}\n </button>\n <button type="button" class="zest-btn zest-btn--secondary" data-action="reject-all">\n ${e(n.rejectAll)}\n </button>\n <button type="button" class="zest-btn zest-btn--ghost" data-action="settings">\n ${e(n.settings)}\n </button>\n </div>\n </div>\n `}(n),Gt.appendChild(r.firstElementChild);const s=Gt.querySelector(".zest-banner");return s.addEventListener("click",e=>{const n=e.target.dataset.action;if(n)switch(n){case"accept-all":t.onAcceptAll?.();break;case"reject-all":t.onRejectAll?.();break;case"settings":t.onSettings?.()}}),s.addEventListener("keydown",e=>{"Escape"===e.key&&t.onSettings?.()}),document.body.appendChild(Ft),requestAnimationFrame(()=>{const t=Gt.querySelector("button");t?.focus()}),Ft}function Jt(t={}){Ft?Ft.classList.remove("zest-hidden"):Xt(t)}function Vt(){Ft&&(Ft.remove(),Ft=null,Gt=null)}let Qt=null,te=null,ee={};function ne(t,n){const o=t.labels.modal,r=Object.values(t.categories||ct).map(t=>function(t,n,o){const r=o?"disabled":"",s=n?"checked":"",a=e(t.id),i=e(t.label);return`\n <div class="zest-category">\n <div class="zest-category__header">\n <div class="zest-category__info">\n <span class="zest-category__label">${i}</span>\n <p class="zest-category__description">${e(t.description)}</p>\n </div>\n <label class="zest-toggle">\n <input\n type="checkbox"\n class="zest-toggle__input"\n data-category="${a}"\n ${s}\n ${r}\n aria-label="${i}"\n >\n <span class="zest-toggle__slider"></span>\n </label>\n </div>\n </div>\n `}(t,n[t.id]??t.default,t.required)).join(""),s=t.policyUrl?function(t){if("string"!=typeof t||0===t.length)return null;const e=t.trim();if(0===e.length)return null;if(/^[/?#]/.test(e))return e;const n=e.match(/^([a-z][a-z0-9+.-]*):/i);if(!n)return e;const o=n[1].toLowerCase();return"http"===o||"https"===o||"mailto"===o||"tel"===o?e:null}(t.policyUrl):null,a=s?`<a href="${e(s)}" class="zest-link" target="_blank" rel="noopener noreferrer">Privacy Policy</a>`:"";return`\n <div class="zest-modal-overlay" role="dialog" aria-modal="true" aria-label="${e(o.title)}">\n <div class="zest-modal">\n <div class="zest-modal__header">\n <h2 class="zest-modal__title">${e(o.title)}</h2>\n <p class="zest-modal__description">${e(o.description)} ${a}</p>\n </div>\n <div class="zest-modal__body">\n ${r}\n </div>\n <div class="zest-modal__footer">\n <button type="button" class="zest-btn zest-btn--primary" data-action="save">\n ${e(o.save)}\n </button>\n <button type="button" class="zest-btn zest-btn--secondary" data-action="accept-all">\n ${e(o.acceptAll)}\n </button>\n <button type="button" class="zest-btn zest-btn--ghost" data-action="reject-all">\n ${e(o.rejectAll)}\n </button>\n </div>\n </div>\n </div>\n `}function oe(){if(!te)return ee;const t=te.querySelectorAll(".zest-toggle__input"),e={essential:!0};return t.forEach(t=>{const n=t.dataset.category;n&&"essential"!==n&&(e[n]=t.checked)}),e}function re(){Qt&&(Qt.remove(),Qt=null,te=null)}let se=null,ae=null;function ie(t={}){if(se)return se;const n=yt();se=document.createElement("zest-widget"),se.setAttribute("data-theme",n.theme||"light"),ae=se.attachShadow({mode:"open"});const o=document.createElement("style");o.textContent=Yt(n),ae.appendChild(o);const r=document.createElement("div");r.innerHTML=function(t){const n=e(t.labels.widget.label);return`\n <div class="zest-widget">\n <button type="button" class="zest-widget__btn" aria-label="${n}" title="${n}">\n <span class="zest-widget__icon"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10c0-.728-.078-1.437-.225-2.12a1 1 0 0 0-1.482-.63 3 3 0 0 1-4.086-3.72 1 1 0 0 0-.793-1.263A10.05 10.05 0 0 0 12 2zm0 2c.178 0 .354.006.528.017a5 5 0 0 0 5.955 5.955c.011.174.017.35.017.528 0 4.418-3.582 8-8 8s-8-3.582-8-8 3.582-8 8-8zm-4 6a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm5 0a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z"/></svg></span>\n </button>\n </div>\n `}(n),ae.appendChild(r.firstElementChild);return ae.querySelector(".zest-widget__btn").addEventListener("click",()=>{t.onClick?.()}),document.body.appendChild(se),se}function ce(t={}){se?se.style.display="":ie(t)}function le(){se&&(se.style.display="none")}function ue(){Wt();const t=Zt();Vt(),re(),t?.showWidget&&ce({onClick:pe})}function de(){!function(){if(!Nt)return null;const t=Et(Pt.expiration);dt(t.current,Pt,!1),Rt(t.current),$t(t.current,t.previous),i(Pt.callbacks?.onReject),i(Pt.callbacks?.onChange,t.current)}();const t=Zt();Vt(),re(),t?.showWidget&&ce({onClick:pe})}function fe(t){!function(t){if(!Nt)return null;const e=At(t,Pt.expiration);dt(e.current,Pt,!1);const n=Object.keys(e.current).filter(t=>e.current[t]&&!e.previous[t]);n.length>0&&qt(n),Object.entries(t||{}).some(([t,e])=>"essential"!==t&&e)?Mt(e.current,e.previous):Rt(e.current),$t(e.current,e.previous),i(Pt.callbacks?.onChange,e.current)}(t);const e=Zt();re(),e?.showWidget&&ce({onClick:pe})}function pe(){Vt(),le(),function(t={},e={}){if(Qt)return Qt;const n=yt();ee={...t},Qt=document.createElement("zest-modal"),Qt.setAttribute("data-theme",n.theme||"light"),te=Qt.attachShadow({mode:"open"});const o=document.createElement("style");o.textContent=Yt(n),te.appendChild(o);const r=document.createElement("div");r.innerHTML=ne(n,t),te.appendChild(r.firstElementChild);const s=te.querySelector(".zest-modal-overlay");s.addEventListener("click",t=>{const n=t.target.dataset.action;if(n)switch(n){case"save":e.onSave?.(oe());break;case"accept-all":e.onAcceptAll?.();break;case"reject-all":e.onRejectAll?.()}else t.target===s&&e.onClose?.()}),s.addEventListener("keydown",t=>{"Escape"===t.key&&e.onClose?.()}),te.querySelectorAll(".zest-toggle__input").forEach(t=>{t.addEventListener("change",()=>{ee=oe()})}),document.body.appendChild(Qt),requestAnimationFrame(()=>{const t=te.querySelector("button");t?.focus()})}(_t(),{onSave:fe,onAcceptAll:ue,onRejectAll:de,onClose:ge}),Ot("modal")}function ge(){re(),Tt("modal");const t=Zt();St()&&t?.showWidget?ce({onClick:pe}):Jt({onAcceptAll:ue,onRejectAll:de,onSettings:pe})}let me=!1;function be(){if(me)return;if(!document||!document.body)return void document.addEventListener("DOMContentLoaded",be,{once:!0});me=!0;const t=Zt();St()?t?.showWidget&&ce({onClick:pe}):(Jt({onAcceptAll:ue,onRejectAll:de,onSettings:pe}),Ot("banner"))}function ye(t={}){return It(t),be(),he}const he={init:ye,show(){Ht()?(re(),le(),Jt({onAcceptAll:ue,onRejectAll:de,onSettings:pe}),Ot("banner")):console.warn("[Zest] Not initialized. Call Zest.init() first.")},hide(){Vt(),Tt("banner")},showSettings(){Ht()?pe():console.warn("[Zest] Not initialized. Call Zest.init() first.")},hideSettings(){re(),Tt("modal")},getConsent:_t,hasConsent:Ct,hasConsentDecision:St,getConsentProof:function(){try{const t=xt().match(RegExp(ht+"=([^;]+)"));if(t){return a(JSON.parse(decodeURIComponent(t[1])),lt())}}catch(t){}return null},isDoNotTrackEnabled:ut,getDNTDetails:function(){if("undefined"==typeof navigator)return{enabled:!1,source:null};const t=navigator.doNotTrack||window.doNotTrack||navigator.msDoNotTrack;return"1"===t||"yes"===t||!0===t?{enabled:!0,source:"dnt"}:!0===navigator.globalPrivacyControl?{enabled:!0,source:"gpc"}:{enabled:!1,source:null}},acceptAll(){Ht()?ue():console.warn("[Zest] Not initialized. Call Zest.init() first.")},rejectAll(){Ht()?de():console.warn("[Zest] Not initialized. Call Zest.init() first.")},reset(){Ut(),re(),se&&(se.remove(),se=null,ae=null),Ht()&&(Jt({onAcceptAll:ue,onRejectAll:de,onSettings:pe}),Ot("banner"))},getConfig:yt,on:function(t,e){return document.addEventListener(t,e),()=>document.removeEventListener(t,e)},once:function(t,e){document.addEventListener(t,e,{once:!0})},EVENTS:jt};if("undefined"!=typeof window){try{Object.defineProperty(window,"Zest",{value:Object.freeze(he),writable:!1,configurable:!1,enumerable:!0})}catch(t){window.Zest=he}!1!==mt().autoInit&&ye(window.ZestConfig)}return he}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freshjuice/zest",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "description": "Lightweight cookie consent toolkit for GDPR/CCPA compliance",
6
6
  "main": "dist/zest.min.js",
@@ -64,6 +64,33 @@ export const DEFAULTS = {
64
64
  // Blocking mode: 'manual' | 'safe' | 'strict' | 'doomsday'
65
65
  mode: 'safe',
66
66
 
67
+ // Interceptor toggles. By default Zest installs cookie + storage
68
+ // interceptors that route writes through the consent layer. Consumers
69
+ // who manage gating themselves (typically headless mode with custom
70
+ // analytics integrations) can opt out per channel.
71
+ intercept: {
72
+ cookies: true,
73
+ storage: true,
74
+ scripts: true,
75
+ network: true
76
+ },
77
+
78
+ // Strictly-necessary declarations. Both fields *append* to whatever
79
+ // the essential category already matches via the pattern matcher
80
+ // defaults — they do not replace.
81
+ //
82
+ // - essentialKeys: array of exact storage / cookie names to treat
83
+ // as strictly-necessary. Easiest case.
84
+ // - essentialPatterns: array of regex source strings, validated via
85
+ // safeRegExp. For prefix or family matches.
86
+ //
87
+ // Use these instead of `patterns.essential` when you only want to
88
+ // ADD entries to the essential category without replacing the
89
+ // built-in patterns (zest_*, csrf*, xsrf*, session*, __host-*,
90
+ // __secure-*).
91
+ essentialKeys: [],
92
+ essentialPatterns: [],
93
+
67
94
  // Custom domains to block (in addition to mode-based blocking)
68
95
  blockedDomains: [], // days
69
96
 
@@ -146,5 +173,27 @@ export function mergeConfig(userConfig) {
146
173
  config.patterns = userConfig.patterns;
147
174
  }
148
175
 
176
+ // Interceptor toggles — shallow-merge so consumers can pass partial
177
+ // overrides like `intercept: { storage: false }` without losing the
178
+ // other defaults.
179
+ if (userConfig.intercept && typeof userConfig.intercept === 'object') {
180
+ config.intercept = {
181
+ ...DEFAULTS.intercept,
182
+ ...userConfig.intercept
183
+ };
184
+ }
185
+
186
+ // Strictly-necessary declarations
187
+ if (Array.isArray(userConfig.essentialKeys)) {
188
+ config.essentialKeys = userConfig.essentialKeys.filter(
189
+ (k) => typeof k === 'string' && k.length > 0 && k.length <= 200
190
+ );
191
+ }
192
+ if (Array.isArray(userConfig.essentialPatterns)) {
193
+ config.essentialPatterns = userConfig.essentialPatterns.filter(
194
+ (p) => typeof p === 'string' && p.length > 0 && p.length <= 500
195
+ );
196
+ }
197
+
149
198
  return config;
150
199
  }
@@ -0,0 +1,374 @@
1
+ /**
2
+ * Element Interceptor - Catches tracker elements BEFORE the browser fetches them.
3
+ *
4
+ * The script-blocker uses MutationObserver. That fires asynchronously
5
+ * (microtask after the DOM mutation), so by the time we can react the
6
+ * browser has already kicked off the network request for the src/href.
7
+ * The script may not execute (we flip type to text/plain) but the
8
+ * fetch already left the building — and to ConsentTheater / a privacy
9
+ * audit that fetch IS a pre-consent leak.
10
+ *
11
+ * This interceptor patches the prototype setters and Element.setAttribute
12
+ * synchronously, so when code does:
13
+ *
14
+ * const s = document.createElement('script');
15
+ * s.src = 'https://tracker.example/track.js'; // ← intercepted HERE
16
+ * document.head.appendChild(s); // ← src is already empty,
17
+ * // no fetch ever fired
18
+ *
19
+ * Covers four element types and both ways to set the URL:
20
+ *
21
+ * - HTMLScriptElement src
22
+ * - HTMLLinkElement href (stylesheets, prefetch, preload, dns-prefetch)
23
+ * - HTMLImageElement src (tracking pixels)
24
+ * - HTMLIFrameElement src (tracking iframes)
25
+ *
26
+ * Plus the global Image() constructor used by classic pixel trackers.
27
+ *
28
+ * What this does NOT catch: inline HTML <script src=...> / <link href=...>
29
+ * tags parsed from the original HTML response. The browser starts those
30
+ * fetches as soon as it encounters the tag during parsing, BEFORE any
31
+ * JavaScript runs. The only complete fix for that class is server-side
32
+ * CSP or template-time removal.
33
+ */
34
+
35
+ import { getCategoryForScript, isThirdParty } from './known-trackers.js';
36
+
37
+ // Upper bound on queued blocked elements. Unbounded growth would be a
38
+ // memory-exhaustion vector if a page (or a hostile script) tried to
39
+ // flood us with src writes.
40
+ const MAX_QUEUE_SIZE = 500;
41
+
42
+ // Queue of blocked element writes. Each entry remembers enough to
43
+ // re-apply the original URL via the ORIGINAL setter once consent
44
+ // arrives for its category. Without this queue, blocked scripts /
45
+ // stylesheets / images would be lost forever and require a page
46
+ // reload to come back.
47
+ const elementQueue = [];
48
+
49
+ let blockingMode = 'safe';
50
+ let customBlockedDomains = [];
51
+ let installed = false;
52
+ let checkConsent = () => false;
53
+
54
+ // Saved originals for restoration in tests / headless teardown.
55
+ const originals = {
56
+ scriptSrc: null,
57
+ linkHref: null,
58
+ imgSrc: null,
59
+ iframeSrc: null,
60
+ setAttribute: null,
61
+ Image: null
62
+ };
63
+
64
+ const BLOCKABLE_CATEGORIES = new Set(['functional', 'analytics', 'marketing']);
65
+
66
+ // Map of tag name -> attribute name that carries a URL we may want to
67
+ // block. Lowercased on both sides; setAttribute() gating uses this.
68
+ const URL_ATTRS = {
69
+ script: 'src',
70
+ link: 'href',
71
+ img: 'src',
72
+ iframe: 'src'
73
+ };
74
+
75
+ export function setConsentChecker(fn) {
76
+ checkConsent = fn;
77
+ }
78
+
79
+ export function setBlockingMode(mode) {
80
+ blockingMode = mode;
81
+ }
82
+
83
+ export function setCustomBlockedDomains(domains) {
84
+ customBlockedDomains = Array.isArray(domains) ? domains : [];
85
+ }
86
+
87
+ function matchesCustomDomains(hostname) {
88
+ if (!hostname || customBlockedDomains.length === 0) return null;
89
+ const host = hostname.toLowerCase();
90
+ for (const entry of customBlockedDomains) {
91
+ const domain = (typeof entry === 'string' ? entry : entry?.domain || '').toLowerCase();
92
+ if (!domain) continue;
93
+ const category = typeof entry === 'string'
94
+ ? 'marketing'
95
+ : (BLOCKABLE_CATEGORIES.has(entry?.category) ? entry.category : 'marketing');
96
+ if (host === domain || host.endsWith('.' + domain)) {
97
+ return category;
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+
103
+ function getBlockCategory(url) {
104
+ if (!url) return null;
105
+ let hostname;
106
+ try {
107
+ hostname = new URL(url, location.href).hostname;
108
+ } catch (e) {
109
+ return null;
110
+ }
111
+
112
+ const customCategory = matchesCustomDomains(hostname);
113
+ if (customCategory) return customCategory;
114
+
115
+ switch (blockingMode) {
116
+ case 'manual':
117
+ return null;
118
+ case 'safe':
119
+ case 'strict':
120
+ return getCategoryForScript(url, blockingMode);
121
+ case 'doomsday':
122
+ if (isThirdParty(url)) {
123
+ return getCategoryForScript(url, 'strict') || 'marketing';
124
+ }
125
+ return null;
126
+ default:
127
+ return null;
128
+ }
129
+ }
130
+
131
+ function shouldBlock(url) {
132
+ const category = getBlockCategory(url);
133
+ if (!category) return null;
134
+ if (checkConsent(category)) return null;
135
+ return category;
136
+ }
137
+
138
+ /**
139
+ * Replace the property setter for `prop` on `ProtoCtor.prototype` with
140
+ * a gated version. Returns the original descriptor so we can restore.
141
+ */
142
+ function patchUrlSetter(ProtoCtor, prop) {
143
+ if (typeof ProtoCtor !== 'function' || !ProtoCtor.prototype) return null;
144
+ const proto = ProtoCtor.prototype;
145
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
146
+ if (!desc || typeof desc.set !== 'function') return null;
147
+
148
+ Object.defineProperty(proto, prop, {
149
+ configurable: true,
150
+ enumerable: desc.enumerable,
151
+ get: desc.get,
152
+ set(value) {
153
+ if (typeof value === 'string') {
154
+ const category = shouldBlock(value);
155
+ if (category) {
156
+ // Don't pass through to the original setter — the URL never
157
+ // touches the element. Stash the element + URL + category
158
+ // + original descriptor in the queue so replayElements()
159
+ // can reinstate it once consent arrives.
160
+ if (elementQueue.length < MAX_QUEUE_SIZE) {
161
+ elementQueue.push({
162
+ element: this,
163
+ setter: desc.set,
164
+ prop,
165
+ value,
166
+ category,
167
+ method: 'property'
168
+ });
169
+ }
170
+ return;
171
+ }
172
+ }
173
+ return desc.set.call(this, value);
174
+ }
175
+ });
176
+
177
+ return desc;
178
+ }
179
+
180
+ function patchSetAttribute() {
181
+ if (typeof Element === 'undefined' || !Element.prototype) return null;
182
+ const orig = Element.prototype.setAttribute;
183
+ originals.setAttribute = orig;
184
+
185
+ Element.prototype.setAttribute = function patchedSetAttribute(name, value) {
186
+ // Fast path: bail out for anything not on our watchlist before doing
187
+ // any string work. setAttribute is hot — keep this cheap.
188
+ if (typeof name !== 'string' || typeof value !== 'string' || !this || !this.tagName) {
189
+ return orig.call(this, name, value);
190
+ }
191
+ const tag = this.tagName.toLowerCase();
192
+ const watched = URL_ATTRS[tag];
193
+ if (!watched) {
194
+ return orig.call(this, name, value);
195
+ }
196
+ const attr = name.toLowerCase();
197
+ if (attr !== watched) {
198
+ return orig.call(this, name, value);
199
+ }
200
+ const category = shouldBlock(value);
201
+ if (category) {
202
+ // Drop silently and queue for replay. The element keeps any
203
+ // other attributes you set before / after.
204
+ if (elementQueue.length < MAX_QUEUE_SIZE) {
205
+ elementQueue.push({
206
+ element: this,
207
+ setter: orig, // setAttribute itself, called like orig.call(el, name, value)
208
+ prop: name,
209
+ value,
210
+ category,
211
+ method: 'attribute'
212
+ });
213
+ }
214
+ return;
215
+ }
216
+ return orig.call(this, name, value);
217
+ };
218
+
219
+ return orig;
220
+ }
221
+
222
+ function patchImageConstructor() {
223
+ if (typeof window === 'undefined' || typeof window.Image !== 'function') return null;
224
+ const OrigImage = window.Image;
225
+ originals.Image = OrigImage;
226
+
227
+ function PatchedImage(width, height) {
228
+ const img = arguments.length >= 2
229
+ ? new OrigImage(width, height)
230
+ : new OrigImage();
231
+ // No work needed here — the .src setter patch on HTMLImageElement
232
+ // will catch any later assignment. PatchedImage exists mainly to
233
+ // expose the .src patch via this path for `new Image()` users.
234
+ return img;
235
+ }
236
+ PatchedImage.prototype = OrigImage.prototype;
237
+ // Copy any static fields just in case.
238
+ for (const key of Object.keys(OrigImage)) {
239
+ try { PatchedImage[key] = OrigImage[key]; } catch (e) { /* ignore */ }
240
+ }
241
+
242
+ try {
243
+ Object.defineProperty(window, 'Image', {
244
+ configurable: true,
245
+ writable: true,
246
+ value: PatchedImage
247
+ });
248
+ } catch (e) {
249
+ window.Image = PatchedImage;
250
+ }
251
+
252
+ return OrigImage;
253
+ }
254
+
255
+ /**
256
+ * Replay blocked element writes for newly-allowed categories.
257
+ *
258
+ * For each queued entry whose category is in `allowedCategories`:
259
+ * - If the element is still connected to the DOM, re-apply the
260
+ * URL via the ORIGINAL setter / setAttribute. The browser starts
261
+ * the fetch as if nothing had been intercepted.
262
+ * - If the element has since been removed (no `isConnected`), drop
263
+ * the entry — calling code lost its reference and we have no
264
+ * parent to attach to.
265
+ *
266
+ * Queue ordering is preserved so that scripts/stylesheets re-execute
267
+ * in the same order the page originally requested them.
268
+ */
269
+ export function replayElements(allowedCategories) {
270
+ if (!Array.isArray(allowedCategories) || elementQueue.length === 0) return;
271
+ const remaining = [];
272
+
273
+ for (const item of elementQueue) {
274
+ if (!allowedCategories.includes(item.category)) {
275
+ remaining.push(item);
276
+ continue;
277
+ }
278
+
279
+ const el = item.element;
280
+ if (!el || !el.isConnected) {
281
+ // Element is detached or gone — nothing to re-apply against.
282
+ continue;
283
+ }
284
+
285
+ try {
286
+ if (item.method === 'attribute') {
287
+ item.setter.call(el, item.prop, item.value);
288
+ } else {
289
+ item.setter.call(el, item.value);
290
+ }
291
+ } catch (e) {
292
+ // Restoration failed (rare — element might be in a weird state).
293
+ // Don't requeue; one failure is enough.
294
+ }
295
+ }
296
+
297
+ elementQueue.length = 0;
298
+ elementQueue.push(...remaining);
299
+ }
300
+
301
+ export function getElementQueue() {
302
+ return [...elementQueue];
303
+ }
304
+
305
+ export function clearElementQueue() {
306
+ elementQueue.length = 0;
307
+ }
308
+
309
+ /**
310
+ * Install all element-level interceptors. Idempotent — second call
311
+ * just refreshes mode + customDomains without rewrapping.
312
+ */
313
+ export function interceptElements(mode = 'safe', customDomains = []) {
314
+ blockingMode = mode;
315
+ customBlockedDomains = Array.isArray(customDomains) ? customDomains : [];
316
+
317
+ if (installed) return true;
318
+
319
+ if (typeof HTMLScriptElement !== 'undefined') {
320
+ originals.scriptSrc = patchUrlSetter(HTMLScriptElement, 'src');
321
+ }
322
+ if (typeof HTMLLinkElement !== 'undefined') {
323
+ originals.linkHref = patchUrlSetter(HTMLLinkElement, 'href');
324
+ }
325
+ if (typeof HTMLImageElement !== 'undefined') {
326
+ originals.imgSrc = patchUrlSetter(HTMLImageElement, 'src');
327
+ }
328
+ if (typeof HTMLIFrameElement !== 'undefined') {
329
+ originals.iframeSrc = patchUrlSetter(HTMLIFrameElement, 'src');
330
+ }
331
+ patchSetAttribute();
332
+ patchImageConstructor();
333
+
334
+ installed = true;
335
+ return true;
336
+ }
337
+
338
+ /**
339
+ * Restore the original setters / Image constructor. For tests / headless.
340
+ */
341
+ export function restoreElements() {
342
+ if (!installed) return;
343
+
344
+ const reinstall = (ProtoCtor, prop, desc) => {
345
+ if (!ProtoCtor || !desc) return;
346
+ Object.defineProperty(ProtoCtor.prototype, prop, desc);
347
+ };
348
+
349
+ reinstall(typeof HTMLScriptElement !== 'undefined' ? HTMLScriptElement : null, 'src', originals.scriptSrc);
350
+ reinstall(typeof HTMLLinkElement !== 'undefined' ? HTMLLinkElement : null, 'href', originals.linkHref);
351
+ reinstall(typeof HTMLImageElement !== 'undefined' ? HTMLImageElement : null, 'src', originals.imgSrc);
352
+ reinstall(typeof HTMLIFrameElement !== 'undefined' ? HTMLIFrameElement : null, 'src', originals.iframeSrc);
353
+
354
+ if (originals.setAttribute && typeof Element !== 'undefined') {
355
+ Element.prototype.setAttribute = originals.setAttribute;
356
+ }
357
+ if (originals.Image && typeof window !== 'undefined') {
358
+ try {
359
+ Object.defineProperty(window, 'Image', {
360
+ configurable: true,
361
+ writable: true,
362
+ value: originals.Image
363
+ });
364
+ } catch (e) {
365
+ window.Image = originals.Image;
366
+ }
367
+ }
368
+
369
+ installed = false;
370
+ }
371
+
372
+ export function isInstalled() {
373
+ return installed;
374
+ }