@titan-os/sdk 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd/sdk.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TitanSDK={})}(this,(function(e){"use strict";var t=Object.defineProperty,i=(e=>(e.PHILIPS="PHILIPS",e.PHILIPS_OLD="PHILIPS_OLD",e.VESTEL="VESTEL",e.VESTEL_LEGACY="VESTEL_LEGACY",e.JVC="JVC",e.BROWSER="BROWSER",e.UNKNOWN="UNKNOWN",e))(i||{}),n=(e=>(e.NOT_INITIALIZED="NOT_INITIALIZED",e.NOT_SUPPORTED="NOT_SUPPORTED",e.NOT_IMPLEMENTED="NOT_IMPLEMENTED",e.INVALID_ARGUMENTS="INVALID_ARGUMENTS",e.INVALID_PARAMETER="INVALID_PARAMETER",e.PLATFORM_NOT_DETECTED="PLATFORM_NOT_DETECTED",e.COMMUNICATION_ERROR="COMMUNICATION_ERROR",e.TIMEOUT="TIMEOUT",e.UNKNOWN="UNKNOWN",e))(n||{});class r extends Error{code;details;constructor(e,t="UNKNOWN",i){super(e),this.name="SDKError",this.code=t,this.details=i,Error.captureStackTrace&&Error.captureStackTrace(this,r)}toString(){return`SDKError [${this.code}]: ${this.message}`}toJSON(){return{name:this.name,code:this.code,message:this.message,details:this.details}}}function o(e,t,i,n){return[`${`[TitanSDK][${e}]`} ${t}`,...i,"\n",n]}function s(e,t){e}const a=new class{subscriptions=new Map;logBuffer=[];maxBufferSize=1e3;nextId=1;debugMode=!1;constructor(e=1e3){this.maxBufferSize=e}setDebugMode(e){this.debugMode=e}subscribe(e,t={}){const i="sub-"+this.nextId++,n={id:i,levels:t.levels||["debug","info","warn","error"],modules:t.modules,callback:e,created:Date.now()};if(this.subscriptions.set(i,n),t.includeHistory){this.getFilteredHistory(n.levels,n.modules).forEach((t=>{try{e(t)}catch(i){}}))}return i}unsubscribe(e){return this.subscriptions.delete(e)}addLogEntry(e){var t,i,n;this.logBuffer.push(e),this.logBuffer.length>this.maxBufferSize&&this.logBuffer.shift();if(("Gateway"===(null==(t=e.metadata)?void 0:t.source)||!0===(null==(i=e.metadata)?void 0:i.tunneled))&&"error"===e.level){const t=(null==(n=e.metadata)?void 0:n.caller)||"[Gateway]";s("error",o(e.module,e.message,e.args||[],t))}this.subscriptions.forEach((t=>{if(this.shouldNotifySubscription(t,e))try{t.callback(e)}catch(i){}}))}getHistory(e,t,i){return this.getFilteredHistory(e,t,i)}clear(){this.logBuffer=[]}getSubscriptionCount(){return this.subscriptions.size}getMetrics(){const e={totalEntries:this.logBuffer.length,entriesByLevel:{},entriesByModule:{},memoryUsageKB:Math.round(JSON.stringify(this.logBuffer).length/1024)};return this.logBuffer.length>0&&(e.oldestEntry=new Date(this.logBuffer[0].timestamp),e.newestEntry=new Date(this.logBuffer[this.logBuffer.length-1].timestamp)),this.logBuffer.forEach((t=>{e.entriesByLevel[t.level]=(e.entriesByLevel[t.level]||0)+1,e.entriesByModule[t.module]=(e.entriesByModule[t.module]||0)+1})),e}exportLogs(e,t){const i=this.getFilteredHistory(e,t);return JSON.stringify(i,null,2)}isDebugMode(){return this.debugMode}shouldNotifySubscription(e,t){return!!e.levels.includes(t.level)&&!(e.modules&&!e.modules.includes(t.module))}getFilteredHistory(e,t,i){let n=this.logBuffer;return e&&(n=n.filter((t=>e.includes(t.level)))),t&&(n=n.filter((e=>t.includes(e.module)))),i&&i>0&&(n=n.slice(-i)),[...n]}};function c(e){const t=(t,i,...n)=>{var r;const c=(()=>{try{const e=(new Error).stack;if(!e)return"";const t=e.split("\n");for(let i=3;i<t.length;i++){const e=t[i];if(e&&!e.includes("logger.ts")&&!e.includes("Logger")){const t=e.match(/\((.*):(\d+):(\d+)\)/)||e.match(/at (.*):(\d+):(\d+)/);if(t){const[,e,i]=t;return`${e.split("/").pop()||e}:${i}`}}}return""}catch{return""}})(),l=(e=>{var t;try{const i=null==(t=e.stack)?void 0:t.split("\n");if(!i||i.length<4)return"Unknown location";const n=i[3].replace("at","").trim()||"Unknown location",{fnName:r,fnPath:o}=(e=>{let t="",i="";return 1===e.split(" ").length?{fnName:"",fnPath:e.split(" ")[0]}:(3===e.split(" ").length?(t=e.split(" (")[0],i=e.split(" (")[1].replace(")","")):(t=e.split(" ")[0],i=e.split(" ")[1].replace(/\((.*)\)/,"$1")),{fnName:t,fnPath:i})})(n);return r?`${r}[${o}]`:`[${o}]`}catch{return"Unknown location"}})(new Error),d={id:`${e}-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,timestamp:Date.now(),level:t,module:e,message:i,args:n,metadata:{url:"undefined"!=typeof window?null==(r=window.location)?void 0:r.href:void 0,caller:c}};a.addLogEntry(d);if(a.isDebugMode()||"error"===t){o(e,i,n,l);s(t)}};return{debug:(e,...i)=>t("debug",e,...i),info:(e,...i)=>t("info",e,...i),warn:(e,...i)=>t("warn",e,...i),error:(e,...i)=>t("error",e,...i),subscribe:(e,t)=>a.subscribe(e,t),unsubscribe:e=>a.unsubscribe(e),getHistory:(e,t,i)=>a.getHistory(e,t,i),clear:()=>a.clear()}}function l(e){return c(e)}const d=(e,t)=>a.subscribe(e,t),u=e=>a.unsubscribe(e),g=(e,t,i)=>a.getHistory(e,t,i),h=()=>a.clear(),p=e=>a.addLogEntry(e),f=l("PlatformDetection");class m{strategies=[];register(e){this.strategies.push(e),this.strategies.sort(((e,t)=>t.getPriority()-e.getPriority()))}getStrategies(){return[...this.strategies]}}class v{canDetect(){return"undefined"!=typeof window&&("t9_core"in window||"vestel"===window.deviceBrand||navigator.userAgent.toLowerCase().includes("vestel"))}getPlatform(){return this.canDetect()?i.VESTEL:null}getPriority(){return 3}}class S{canDetect(){if("undefined"==typeof window)return!1;const e=navigator.userAgent,t=e.toLowerCase(),i=t.includes("vestel"),n=e.includes("MB181")||e.includes("MB180")||t.includes("mb181")||t.includes("mb180")||e.includes("Model/Vestel-MB181")||e.includes("Model/Vestel-MB180");return i&&n}getPlatform(){return this.canDetect()?i.VESTEL_LEGACY:null}getPriority(){return 20}}class y{canDetect(){if("undefined"==typeof window)return!1;if("undefined"==typeof navigator)return!1;const e=navigator.userAgent.toLowerCase();return["hkc","jvc"].some((t=>e.includes(t)))}getPlatform(){return this.canDetect()?i.JVC:null}getPriority(){return 6}}class b{canDetect(){return"undefined"!=typeof window&&("jwt"in window||"launcher_env"in window||"undefined"!=typeof navigator&&navigator.userAgent.toLowerCase().indexOf("philips")>-1)}getPlatform(){return this.canDetect()?i.PHILIPS:null}getPriority(){return 5}}class w{canDetect(){if("undefined"==typeof window)return!1;const e=(()=>{const e=navigator.userAgent.match(/Chrome\/(\d+)\./);return e?parseInt(e[1],10):null})(),t=null!==e&&e<=84;return"undefined"!=typeof navigator&&navigator.userAgent.includes("Philips")&&(document.cookie.includes("tos-session")||t)}getPlatform(){return this.canDetect()?i.PHILIPS_OLD:null}getPriority(){return 10}}class T{canDetect(){return!0}getPlatform(){return i.BROWSER}getPriority(){return 1}}const I=new class{factory;lastDetectedPlatform=null;constructor(){this.factory=new m,this.factory.register(new y),this.factory.register(new b),this.factory.register(new v),this.factory.register(new S),this.factory.register(new w),this.factory.register(new T)}registerStrategy(e){this.factory.register(e)}detectPlatform(e={}){if(e.forcePlatform)return{platform:e.forcePlatform,detectedBy:"forced",confidence:1};if(this.lastDetectedPlatform)return{...this.lastDetectedPlatform};const t=this.factory.getStrategies();for(const i of t)if(i.canDetect()){const t=i.getPlatform();if(null!==t){const n={platform:t,detectedBy:i.constructor.name,confidence:.9};return this.lastDetectedPlatform=n,e.debug&&f.info(`Platform detected as ${t}`),{...n}}}if(!1===e.fallbackToBrowser)throw new r("Could not detect platform and fallback is disabled",n.PLATFORM_NOT_DETECTED);const o={platform:i.BROWSER,detectedBy:"fallback",confidence:.1};return this.lastDetectedPlatform=o,e.debug&&f.info("Fallback to browser platform - no strategy matched"),{...o}}reset(){this.lastDetectedPlatform=null}},E={LAUNCH_APP_REQUEST:"LAUNCH_APP_REQUEST",DEVICE_INFO_REQUEST:"DEVICE_INFO_REQUEST",TTS_REQUEST_SETTINGS:"TTS_REQUEST_SETTINGS",TTS_REQUEST_START_SPEAKING:"TTS_REQUEST_START_SPEAKING",TTS_REQUEST_STOP_SPEAKING:"TTS_REQUEST_STOP_SPEAKING",ERROR_SIMULATION:"ERROR_SIMULATION",LAUNCH_APP_RESPONSE:"LAUNCH_APP_RESPONSE",DEVICE_INFO_RESPONSE:"DEVICE_INFO_RESPONSE",TTS_RESPONSE_SETTINGS:"TTS_RESPONSE_SETTINGS",TTS_RESPONSE_START_SPEAKING:"TTS_RESPONSE_START_SPEAKING",TTS_RESPONSE_STOP_SPEAKING:"TTS_RESPONSE_STOP_SPEAKING",ERROR_SIMULATION_RESPONSE:"ERROR_SIMULATION_RESPONSE",LAUNCHER_READY:"LAUNCHER_READY",BRIDGE_READY:"BRIDGE_READY",TTS_SETTINGS_CHANGE:"TTS_SETTINGS_CHANGE",TM_SETTINGS_CHANGE:"TM_SETTINGS_CHANGE",LOG_ENTRY:"LOG_ENTRY",ERROR_RESPONSE:"ERROR_RESPONSE",TRANSFER_DATA:"TRANSFER_DATA"},D={TTS_SETTINGS_CHANGE:E.TTS_SETTINGS_CHANGE,TM_SETTINGS_CHANGE:E.TM_SETTINGS_CHANGE,LOG_ENTRY:E.LOG_ENTRY},C={enabled:!1,available:!1},A={enabled:!1,available:!1},P={tts:C,tm:A},R="TIMEOUT",M="NOT_SUPPORTED",k="INVALID_REQUEST",O="COMMUNICATION_ERROR",_="LAUNCH_FAILED",N="APP_NOT_FOUND",L="APP_NOT_AVAILABLE",F="INVALID_APP_CODE";var x=(e=>(e.PHILIPS="philips",e.VESTEL="vestel",e.BROWSER="browser",e))(x||{});class U{mocks={};constructor(e){e&&(this.mocks={...e})}get(e){return e in this.mocks?this.mocks[e]:"undefined"!=typeof window&&e in window?window[e]:void 0}has(e){return e in this.mocks||"undefined"!=typeof window&&e in window}get proxy(){return new Proxy({},{get:(e,t)=>{const i=t,n=this.get(i);return"function"==typeof n?(...e)=>{try{return n(...e)}catch(t){return}}:n}})}setMocks(e){this.mocks={...this.mocks,...e}}clearMocks(){this.mocks={}}removeMock(e){const t={};for(const i in this.mocks)i!==e&&(t[i]=this.mocks[i]);this.mocks=t}getAvailableMethods(){const e=new Set;for(const t in this.mocks)Object.prototype.hasOwnProperty.call(this.mocks,t)&&e.add(t);if("undefined"!=typeof window)for(const t in window)Object.prototype.hasOwnProperty.call(window,t)&&t in window&&e.add(t);return Array.from(e)}create(e,t){"undefined"!=typeof window&&(window[e]=t)}removeGlobal(e){"undefined"!=typeof window&&e in window&&delete window[e]}}function H(e,t,i="titanos"){return new Promise(((e,n)=>{const r=new U,o="deviceInfoCallback_"+Date.now()+"_"+Math.floor(1e4*Math.random());r.create(o,(t=>{e(t),r.removeGlobal(o)}));const s=`https://${t}/potamoi/v1/device_info?callback=${o}`,a=`https://smarttv.zeasn.tv/homepage_api/device/clientInfo?callback=${o}`,c=document.createElement("script");c.src="titanos"===i?s:a,c.type="text/javascript",c.onerror=()=>{n(new Error("Failed to load device info script.")),delete r.proxy[o]},document.head.appendChild(c),setTimeout((()=>{r.has(o)&&(n(new Error("Device info request timed out.")),delete r.proxy[o]),c.parentNode&&c.parentNode.removeChild(c)}),7e3)}))}const V=()=>{const e=e=>{const t=(Math.random().toString(16)+"000000000").substring(2,10);return e?"-"+t.substring(0,4)+"-"+t.substring(4,8):t};return e(!1)+e(!0)+e(!0)+e(!1)},K=1e4,B=[{time:3e4,message:"DOM still not ready after 30 seconds"},{time:6e4,message:"DOM still not ready after 1 minute"},{time:12e4,message:"DOM still not ready after 2 minutes"},{time:18e4,message:"DOM still not ready after 3 minutes"},{time:24e4,message:"DOM still not ready after 4 minutes"},{time:3e5,message:"DOM still not ready after 5 minutes - this may indicate serious page issues"}],z=l("DOM-Utils");function $(){return"undefined"!=typeof document&&!!document.body}const G=(e="en-US")=>"undefined"!=typeof navigator&&navigator.language&&navigator.language||e;const j=l("BaseBridge");class W{src="";isInitialized=!1;iframe=null;iframeOrigin="";pendingRequests=new Map;messageTimeout=1e4;iframeTimeout=3e3;connected=!1;debug=!1;initializationPromise=null;aborted=!1;initReject;MESSAGE_TYPES=E;eventHandlers=new Map;constructor(e){this.debug=(null==e?void 0:e.debug)||!1,(null==e?void 0:e.gatewayUrl)&&(this.src=e.gatewayUrl),j.debug("bridge: constructor",this.src)}async initialize(){if(this.isInitialized)return!0;if(this.initializationPromise)return j.debug("bridge: initialization already in progress, waiting..."),this.initializationPromise;j.debug("bridge: initialization not in progress, starting new one"),this.initializationPromise=this.performInitialization();try{return await this.initializationPromise}catch(e){throw this.initializationPromise=null,e}}async performInitialization(){return new Promise(((e,t)=>{this.aborted=!1,this.initReject=t,j.debug("bridge: starting initialization process"),window.addEventListener("message",this.handleMessage.bind(this));let i=!1;const n=()=>{this.aborted||i||(i=!0,this.isInitialized=!0,j.debug("bridge initialized successfully"),e(!0))},r=()=>{this.aborted||i||(i=!0,j.error("Bridge iframe failed to load or initialize."),this.isInitialized=!1,t(new Error("Bridge iframe failed to load or initialize.")))};(async()=>{try{await this.setupIframe(n,r),i||(i=!0,j.warn("Bridge initialization timeout - setupIframe completed but LAUNCHER_READY not received"),this.isInitialized=!1,e(!1))}catch(o){if(i)return;i=!0,j.error("Failed to setup iframe:",o),this.isInitialized=!1,t(o)}})()}))}async sendMessage(e,t){this.isInitialized||await this.initialize();try{const i=this.prepareMessage(e,t);return new Promise(((e,t)=>{const o=setTimeout((()=>{this.pendingRequests.delete(i.requestId),t(new r("Bridge request timeout",n.TIMEOUT))}),this.messageTimeout);this.pendingRequests.set(i.requestId,{resolve:e,reject:t,timeout:o}),this.iframe&&this.iframe.contentWindow?(j.debug("bridge: sendMessage",i),this.iframe.contentWindow.postMessage(i,this.iframeOrigin||"*")):(clearTimeout(o),this.pendingRequests.delete(i.requestId),t(new r("Bridge iframe not available",n.COMMUNICATION_ERROR)))}))}catch(i){j.error("bridge: error sending message:",i);return(await Promise.resolve().then((()=>Re)).then((e=>e.rollbarClient))).reportError(i instanceof Error?i:new Error("Unknown error"),{component:"SDK",operation:"sendMessage",requestId:this.prepareMessage(e,t).requestId}),Promise.reject({success:!1,type:e,error:{code:n.COMMUNICATION_ERROR,message:i instanceof Error?i.message:"Unknown error"}})}}disconnect(){this.aborted=!0,this.initReject&&(this.initReject(new Error("Bridge initialization aborted")),this.initReject=void 0),this.iframe&&(window.removeEventListener("message",this.handleMessage.bind(this)),document.body.removeChild(this.iframe),this.iframe=null),this.isInitialized=!1,this.connected=!1,this.initializationPromise=null,this.pendingRequests.clear(),this.eventHandlers.clear()}isConnected(){return this.isInitialized&&this.connected}getBridgeHealth(){return{connected:this.isConnected()}}registerEventHandler(e,t){var i;this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set);const n=e=>{t(e)};return null==(i=this.eventHandlers.get(e))||i.add(n),window.addEventListener("message",(e=>n(e.data.data))),()=>{var t;window.removeEventListener("message",(e=>{var t;return n(null==(t=e.data)?void 0:t.data)})),null==(t=this.eventHandlers.get(e))||t.delete(n)}}handleMessage(e){var t;if(!this.iframeOrigin||e.origin===this.iframeOrigin)try{const i=e.data;if(this.debug&&i&&i.requestId&&j.debug("bridge handleMessage",i),i&&("BRIDGE_READY"===i.type||"LAUNCHER_READY"===i.type)&&(null==(t=this.iframe)?void 0:t.contentWindow)===e.source)return void(this.connected=!0);if(i&&i.type&&Object.values(D).includes(i.type)&&!i.requestId)return void this.handleNotification(i);if(i&&i.requestId&&this.pendingRequests.has(i.requestId)){const{resolve:e,reject:t,timeout:n}=this.pendingRequests.get(i.requestId);if(clearTimeout(n),this.pendingRequests.delete(i.requestId),!1===i.success&&i.error){const e=this.getOperationFromMessageType(i.type||"unknown");t(this.createSDKErrorFromGatewayResponse(i.error,e))}else e({success:!0,data:i.response||i.data||i.result,requestId:i.requestId,timestamp:i.timestamp||Date.now()})}}catch(i){j.error("Error handling message:",i)}}handleNotification(e){j.debug("bridge notification received:",e);const t=this.eventHandlers.get(e.type);t&&t.forEach((t=>{try{t(e.data)}catch(i){j.error(`Error in ${e.type} handler:`,i)}}))}prepareMessage(e,t){return{payload:t,type:e,requestId:this.generateRequestId(),timestamp:Date.now()}}generateRequestId(){return`bridge_${Date.now()}_${Math.random().toString(36).substring(2,9)}`}createSDKErrorFromGatewayResponse(e,t){const i=this.mapGatewayErrorCodeToSDK(e.code);return new r(e.message,i,{operation:t,gatewayErrorCode:e.code,gatewayErrorMessage:e.message})}mapGatewayErrorCodeToSDK(e){switch(e){case _:case N:case L:case F:return n.INVALID_PARAMETER;case R:return n.TIMEOUT;case M:return n.NOT_SUPPORTED;case O:return n.COMMUNICATION_ERROR;case k:return n.INVALID_ARGUMENTS;default:return n.UNKNOWN}}getOperationFromMessageType(e){switch(e){case E.LAUNCH_APP_REQUEST:return"launchApp";case E.DEVICE_INFO_REQUEST:return"getDeviceInfo";case E.TTS_REQUEST_START_SPEAKING:return"startSpeaking";case E.TTS_REQUEST_STOP_SPEAKING:return"stopSpeaking";case E.TTS_REQUEST_SETTINGS:return"getTTSSettings";default:return"sdkOperation"}}async setupIframe(e,t){if(!this.iframe&&this.src){if(await new Promise((e=>{"undefined"!=typeof document&&"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>e()),{once:!0}):e()})),this.iframe=document.createElement("iframe"),this.iframe.style.display="none",this.iframe.src=this.src,this.iframe.setAttribute("sandbox","allow-scripts"),!$())try{await function(e=1e4){return new Promise(((t,i)=>{if($())return void t();const n=Date.now();let r=0,o="initial";z.debug("Waiting for document.body:",{readyState:document.readyState,bodyExists:!!document.body,htmlExists:!!document.documentElement,headExists:!!document.head,timeout:e});let s=null,a=null,c=null;const l=[];function d(){a&&(clearInterval(a),a=null),s&&(s.disconnect(),s=null),c&&(clearTimeout(c),c=null),l.forEach(clearTimeout),l.length=0}const u=(e,t)=>{if(o!==e){const i=Date.now()-n;z.debug(`DOM strategy changed: ${o} → ${e}`,{elapsed:i,reason:t||"strategy switch",checkCount:r}),o=e}},g=(e,t="warn")=>{const i=Date.now()-n,o=Math.floor(i/6e4),s=Math.floor(i%6e4/1e3);"error"===t?z.error(`${e} after ${o}m ${s}s`,{elapsed:i,checkCount:r,readyState:document.readyState,bodyExists:!!document.body}):z.warn(`${e} after ${o}m ${s}s`,{elapsed:i,checkCount:r,readyState:document.readyState})},h=e=>{u("mutation-observer","DOMContentLoaded completed but body not ready"),s=new MutationObserver((()=>{r++;const e=Date.now()-n;$()&&(d(),z.debug("document.body ready via MutationObserver:",{elapsed:e,checkCount:r}),t())})),s.observe(document.documentElement,{childList:!0,subtree:!1}),c=setTimeout((()=>{$()||(g("DOM still not ready, switching to polling fallback"),u("polling","MutationObserver timeout"),a=setInterval((()=>{r++;const e=Date.now()-n;$()&&(d(),z.debug("document.body ready via polling fallback:",{elapsed:e,checkCount:r}),t())}),50))}),3e4)};if("loading"===document.readyState){u("dom-content-loaded","document still loading");const o=()=>{var e;clearTimeout(s);const i=Date.now()-n;$()?(d(),z.debug("document.body ready after DOMContentLoaded:",{elapsed:i}),t()):(z.warn("DOMContentLoaded fired but body still not ready:",{elapsed:i,childNodes:(null==(e=document.documentElement)?void 0:e.childNodes.length)||0}),h())},s=setTimeout((()=>{var e;document.removeEventListener("DOMContentLoaded",o),d();const t=Date.now()-n;z.error("Timeout waiting for document.body:",{elapsed:t,readyState:document.readyState,bodyExists:!!document.body,checkCount:r,html:!!document.documentElement,head:!!document.head,childNodesCount:(null==(e=document.documentElement)?void 0:e.childNodes.length)||0}),i(new Error(`Timeout waiting for document.body after ${t}ms. readyState: ${document.readyState}, checks: ${r}. Initialize SDK after DOMContentLoaded or use defer/async script.`))}),e);document.addEventListener("DOMContentLoaded",o,{once:!0})}else z.debug("DOM already loaded, using MutationObserver + polling"),h();B.forEach((({time:t,message:i})=>{if(t<e){const e=setTimeout((()=>{$()||g(i)}),t);l.push(e)}}))}))}(K)}catch(i){throw j.error("Document body unavailable:",{readyState:document.readyState,bodyExists:!!document.body,timeout:10}),new Error("Document body is not available. SDK initialized too early - ensure DOM is ready before calling getTitanSDK(). Consider initializing SDK after DOMContentLoaded event or in a defer/async script.")}document.body.appendChild(this.iframe),await new Promise((i=>{const n=setTimeout((()=>{this.aborted||(j.warn("Bridge iframe ready timeout - continuing anyway"),i())}),this.iframeTimeout),r=t=>{var o;this.aborted||t.data&&t.data.type===E.LAUNCHER_READY&&(null==(o=this.iframe)?void 0:o.contentWindow)===t.source&&(j.debug("bridge iframe ready:",t.data),window.removeEventListener("message",r),clearTimeout(n),this.connected=!0,e&&e(),i())};window.addEventListener("message",r),window.addEventListener("message",(e=>{var t;this.aborted||e.data&&e.data.type===E.TRANSFER_DATA&&(null==(t=this.iframe)?void 0:t.contentWindow)===e.source&&j.debug("bridge transferData:",e.data)})),this.iframe&&(this.iframe.onload=()=>{this.aborted||j.debug("bridge iframe loaded: ",this.src)},this.iframe.onerror=()=>{this.aborted||(j.error("bridge iframe error: ",this.src),t&&t())})}))}}promisify(e){return(...t)=>new Promise(((i,n)=>{try{i(e.apply(null,t))}catch(r){n(r)}}))}async getDeviceInfo(){this.isInitialized||await this.initialize();const e=await this.sendMessage(E.DEVICE_INFO_REQUEST,void 0);if(e.success&&"data"in e)return e.data}async launchApp(e){this.isInitialized||await this.initialize();const t={code:e.appId,query:e.deepLink||""};return(await this.sendMessage(E.LAUNCH_APP_REQUEST,t)).success}onLogEntry(e){return this.registerEventHandler(E.LOG_ENTRY,(t=>{p({...t,metadata:{...t.metadata,source:"Gateway",tunneled:!0}}),e(t)}))}}const q=l("CSPDetector");let Q=[];const Y=class{static getViolations(){return[...this.violations]}static clearViolations(){this.violations.length=0}static onViolation(e){return Q.push(e),()=>{Q=Q.filter((t=>t!==e))}}static checkWebAPISupport(){return{hasPostMessage:"undefined"!=typeof window&&"postMessage"in window,hasIframe:"undefined"!=typeof document&&"createElement"in document,hasMessageEvent:"undefined"!=typeof MessageEvent,hasDocument:"undefined"!=typeof document}}};var J;((e,i,n)=>{i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n})(Y,"symbol"!=typeof(J="violations")?J+"":J,[]),"undefined"!=typeof document&&document.addEventListener("securitypolicyviolation",(e=>{const t=`${e.violatedDirective}: ${e.blockedURI}`;Y.violations.push(t),q.warn("CSP Violation detected:",t);const i={directive:e.violatedDirective,blockedURI:e.blockedURI,originalEvent:e};Q.forEach((e=>{try{e(i)}catch(t){q.error("CSPDetector listener error",t)}}))}));let Z=Y;const X=l("EnhancedBridge");function ee(e,t){if(!["frame-src","child-src","connect-src"].includes(e.directive)||!e.blockedURI||!t)return!1;const i=e.blockedURI,n=e=>e.replace(/\/+$/,"").toLowerCase(),r=n(i),o=n(t),s=e=>{try{return new URL(e).hostname}catch{const t=e.match(/^(?:https?:\/\/)?([^\/]+)/);return t?t[1]:""}},a=s(i),c=s(t);return o.includes(r)||r.includes(o)||a&&c&&a===c||i.includes("titanos.tv")&&t.includes("titanos.tv")||i.includes("localhost")&&t.includes("localhost")}class te extends W{bridgeHealthStatus={connected:!1,cspBlocked:!1,iframeCreated:!1,communicationWorking:!1,cspViolations:[]};cspUnsubscribe;cspViolationDetected=!1;cspViolationPromise;cspViolationResolver=null;constructor(e){super(e),this.bridgeHealthStatus.gatewayUrl=this.src,this.cspViolationPromise=new Promise((e=>{this.cspViolationResolver=e})),this.setupCspViolationListener()}setupCspViolationListener(){this.cspUnsubscribe=Z.onViolation((e=>{if(X.debug("CSP violation received in EnhancedBaseBridge:",{directive:e.directive,blockedURI:e.blockedURI,gatewayUrl:this.src,isBridgeViolation:ee(e,this.src)}),ee(e,this.src)){const t=`${e.directive}: ${e.blockedURI||"unknown"}`;this.bridgeHealthStatus.cspViolations.includes(t)||this.bridgeHealthStatus.cspViolations.push(t),X.warn("CSP violation detected for bridge:",{directive:e.directive,blockedURI:e.blockedURI,gatewayUrl:this.src}),this.bridgeHealthStatus.cspBlocked=!0,this.bridgeHealthStatus.lastError=`CSP ${e.directive} blocked: ${e.blockedURI||"unknown"}`,!this.cspViolationDetected&&this.cspViolationResolver&&(this.cspViolationDetected=!0,X.debug("Resolving CSP violation Promise"),this.cspViolationResolver(),this.cspViolationResolver=null)}}))}async initialize(){try{X.debug("Starting enhanced bridge initialization");const e=await super.initialize();return this.bridgeHealthStatus.connected=!!e,!!e}catch(e){const t=e instanceof Error?e.message:"Unknown error";return this.bridgeHealthStatus.lastError=t,X.error("Enhanced bridge initialization failed:",e),!1}}getBridgeHealth(){return{...this.bridgeHealthStatus,connected:this.isConnected(),iframeCreated:null!==this.iframe}}disconnect(){this.aborted||(super.disconnect(),this.bridgeHealthStatus.connected=!1,this.bridgeHealthStatus.communicationWorking=!1,this.cspUnsubscribe&&(this.cspUnsubscribe(),this.cspUnsubscribe=void 0),this.cspViolationDetected=!1,this.cspViolationPromise=new Promise((e=>{this.cspViolationResolver=e})),this.bridgeHealthStatus={connected:!1,cspBlocked:!1,iframeCreated:!1,communicationWorking:!1,gatewayUrl:this.src,cspViolations:[]},this.aborted=!0)}async setupIframe(e,t){try{X.debug("Setting up bridge iframe"),await super.setupIframe(e,t),this.bridgeHealthStatus.iframeCreated=!0}catch(i){this.bridgeHealthStatus.iframeCreated=!1;const e=i instanceof Error?i.message:"Unknown error";throw this.bridgeHealthStatus.lastError=e,X.error("Failed to setup iframe:",{error:e,gatewayUrl:this.src,documentReady:document.readyState,bodyExists:!!document.body}),i}}async executeBridgeFunction(e,t){const i=this.getBridgeHealth();if(!i.connected){if(t)return X.debug("Bridge not connected, using fallback function"),await t();throw new r("Bridge not connected",n.COMMUNICATION_ERROR,{healthStatus:i})}return await e()}async executeWithFallback(e,t){return await this.executeBridgeFunction(e,t)}async sendMessage(e,t){return await this.executeBridgeFunction((()=>super.sendMessage(e,t)))}getConnectionResult(){const e=this.getBridgeHealth();return{success:e.connected&&!e.cspBlocked,healthStatus:e,error:e.lastError}}async waitForInitializationAttempt(){if(this.isConnected())return void X.debug("Bridge already initialized, no need to wait");const e=this;if(e.initializationPromise){X.debug("Bridge initialization in progress, waiting for completion...");try{await e.initializationPromise,X.debug("Bridge initialization attempt completed")}catch{X.debug("Bridge initialization attempt completed (with error)")}}else{X.debug("No bridge initialization in progress, starting new attempt...");try{await this.initialize(),X.debug("Bridge initialization attempt completed")}catch{X.debug("Bridge initialization attempt completed (with error)")}}this.bridgeHealthStatus.iframeCreated&&!this.isConnected()&&(this.cspViolationDetected||this.bridgeHealthStatus.cspBlocked?X.debug("CSP violation already detected, no need to wait"):(X.debug("Iframe created but connection not established, waiting for CSP violation detection..."),await this.cspViolationPromise,X.debug("CSP violation detection completed (or connection established)")))}}class ie extends te{constructor(e){if(null==e?void 0:e.gatewayUrl)super({gatewayUrl:e.gatewayUrl});else{const e=window.location.hostname.includes("dev01.devview"),t=window.location.hostname.startsWith("dev");super({gatewayUrl:`http://localhost:4660/gateway/${e||t?"dev01":"index"}.html`})}}}const ne=new U;class re extends te{constructor(e){var t,i;if(null==e?void 0:e.gatewayUrl)super({gatewayUrl:e.gatewayUrl});else{let e="app";if(ne.proxy.jwt&&!ne.proxy.jwt.includes("null")){const t=(e=>{const t=e.split(".");if(3!==t.length)throw new Error("Invalid JWT token format");try{const e=t[1].replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(e),n=decodeURIComponent(Array.from(i).map((e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2))).join(""));return JSON.parse(n)}catch(i){throw new Error("Error decoding JWT token: "+(i instanceof Error?i.message:String(i)))}})(ne.proxy.jwt);e=("production"===t.iss?"app":t.iss)||"app"}let n=`https://${e}.titanos.tv/gateway/${e.startsWith("dev")?"dev01":"index"}.html`;((null==(i=null==(t=ne.proxy.location)?void 0:t.host)?void 0:i.includes("dev01.devview"))||e.startsWith("dev"))&&(n="https://dev01.devview.titanos.tv/gateway/dev01.html"),super({gatewayUrl:n})}}async getTTSSettings(){return(await this.getA11ySettings()).tts||C}async getTMSettings(){return(await this.getA11ySettings()).tm||A}async getA11ySettings(){const e=await this.sendMessage(E.TTS_REQUEST_SETTINGS,void 0);return e.success&&"data"in e?e.data:P}async startSpeaking(e){this.isInitialized||await this.initialize();return(await this.sendMessage(E.TTS_REQUEST_START_SPEAKING,e)).success}async stopSpeaking(){return(await this.sendMessage(E.TTS_REQUEST_STOP_SPEAKING,void 0)).success}onTTSSettingsChange(e){return this.registerEventHandler(E.TTS_SETTINGS_CHANGE,(t=>{e(t)}))}onTMSettingsChange(e){return this.registerEventHandler(E.TM_SETTINGS_CHANGE,(t=>{e(t)}))}}const oe={HIGH:["button","link","heading","listitem"],MEDIUM:["textbox","combobox","checkbox","radio","slider"],LOW:["list","navigation","main","dialog","grid"]},se=l("AriaProcessor");class ae{config;implicitRoles={button:"button",a:"link",'input[type="text"]':"textbox",'input[type="email"]':"textbox",'input[type="password"]':"textbox",'input[type="search"]':"textbox",'input[type="tel"]':"textbox",'input[type="url"]':"textbox",'input[type="checkbox"]':"checkbox",'input[type="radio"]':"radio",'input[type="range"]':"slider",textarea:"textbox",select:"combobox",h1:"heading",h2:"heading",h3:"heading",h4:"heading",h5:"heading",h6:"heading",nav:"navigation",main:"main",aside:"complementary",section:"region",article:"article",ul:"list",ol:"list",li:"listitem",table:"table",tr:"row",td:"cell",th:"columnheader",img:"img",dialog:"dialog"};tvElementTypes={navigation:["nav","menu",'[role="navigation"]','[role="menubar"]'],mediaControl:['[role="button"][aria-label*="play"]','[role="button"][aria-label*="pause"]','[role="slider"][aria-label*="volume"]','[role="progressbar"]'],contentGrid:['[role="grid"]','[role="gridcell"]',".content-grid",".video-grid"],mainContent:["main",'[role="main"]',".main-content","#main"]};constructor(e){this.config={...e}}updateConfig(e){this.config={...e}}async processElement(e){try{if(this.isElementHidden(e))return null;const t=this.getElementRole(e);if(this.config.tvOptimized&&!this.isRelevantForTV(t))return null;const i=this.computeAccessibleName(e);if(!i&&this.isInteractiveElement(t))return se.warn("Interactive element without accessible name:",e),null;const n=this.getAccessibleDescription(e),r=this.computeElementState(e),o=this.computePositionInfo(e,t),s=this.getAvailableActions(e,t),a=this.config.tvOptimized?this.getTVSpecificProperties(e,t):void 0,c={element:e,role:t,name:i,description:n,state:r,position:o,actions:s,tvProperties:a};return se.debug("Processed accessibility element:",{role:t,name:i.substring(0,50),state:r,tvOptimized:!!a}),c}catch(t){return se.error("Error processing element:",t),null}}isElementHidden(e){if("true"===e.getAttribute("aria-hidden"))return!0;const t=window.getComputedStyle(e);if("none"===t.display||"hidden"===t.visibility||"0"===t.opacity)return!0;if(this.config.tvOptimized){const t=e.getBoundingClientRect();if(0===t.width&&0===t.height)return!0}return!1}getElementRole(e){const t=e.getAttribute("role");if(t)return t;const i=e.tagName.toLowerCase(),n=e.getAttribute("type");if("input"===i&&n){const e=`input[type="${n}"]`;if(this.implicitRoles[e])return this.implicitRoles[e]}return this.implicitRoles[i]||"generic"}computeAccessibleName(e){const t=e.getAttribute("aria-labelledby");if(t){const e=[];for(const i of t.split(/\s+/)){const t=document.getElementById(i);t&&e.push(this.getTextContent(t))}if(e.length>0)return e.join(" ").trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();if(this.isFormControl(e)){const t=this.getAssociatedLabels(e);if(t.length>0)return t.map((e=>this.getTextContent(e))).join(" ").trim()}if("input"===e.tagName.toLowerCase()){const t=e.getAttribute("placeholder");if(t)return t.trim()}if("img"===e.tagName.toLowerCase()){const t=e.getAttribute("alt");if(null!==t)return t.trim()}return this.getTextContent(e)}getAccessibleDescription(e){const t=e.getAttribute("aria-describedby");if(!t)return;const i=[];for(const n of t.split(/\s+/)){const e=document.getElementById(n);e&&i.push(this.getTextContent(e))}return i.length>0?i.join(" ").trim():void 0}computeElementState(e){const t={},i=e.getAttribute("aria-expanded");null!==i&&(t.expanded="true"===i);const n=e.getAttribute("aria-checked");null!==n&&(t.checked="mixed"===n?"mixed":"true"===n);const r=e.getAttribute("aria-selected");null!==r&&(t.selected="true"===r);const o=e.getAttribute("aria-disabled")||e.getAttribute("disabled");null!==o&&(t.disabled="true"===o||""===o);const s=e.getAttribute("aria-invalid");null!==s&&(t.invalid="true"===s||s);const a=e.getAttribute("aria-level");null!==a?t.level=parseInt(a,10):e.tagName.match(/^H[1-6]$/)&&(t.level=parseInt(e.tagName.charAt(1),10));const c=e.getAttribute("aria-valuenow");null!==c&&(t.valueNow=parseFloat(c));const l=e.getAttribute("aria-valuetext");return null!==l&&(t.valueText=l),t.focused=document.activeElement===e,t}computePositionInfo(e,t){return"listitem"===t?this.computeListItemPosition(e):"gridcell"===t||"cell"===t?this.computeGridCellPosition(e):void 0}computeListItemPosition(e){const t=e.getAttribute("aria-posinset"),i=e.getAttribute("aria-setsize");if(t&&i)return{position:parseInt(t,10),setSize:parseInt(i,10)};const n=e.closest('ul, ol, [role="list"]');if(n){const t=Array.from(n.querySelectorAll('li, [role="listitem"]')),i=t.indexOf(e)+1;if(i>0)return{position:i,setSize:t.length}}}computeGridCellPosition(e){const t=e.closest('[role="row"], tr'),i=e.closest('[role="grid"], table');if(t&&i){const n=Array.from(i.querySelectorAll('[role="row"], tr')),r=Array.from(t.querySelectorAll('[role="gridcell"], [role="cell"], td, th')),o=n.indexOf(t)+1,s=r.indexOf(e)+1;if(o>0&&s>0)return{position:s,setSize:r.length,row:o,column:s,totalRows:n.length,totalColumns:r.length}}}getAvailableActions(e,t){const i=[];if(this.isClickableElement(e,t)&&i.push({name:"activate",description:this.getActivationDescription(t),tvButton:"OK"}),e.hasAttribute("aria-expanded")){const t="true"===e.getAttribute("aria-expanded");i.push({name:t?"collapse":"expand",description:t?"Collapse":"Expand",tvButton:"OK"})}return"textbox"!==t&&"combobox"!==t||i.push({name:"edit",description:"Enter text",tvButton:"OK"}),i}getTVSpecificProperties(e,t){const i={};return this.matchesSelectors(e,this.tvElementTypes.navigation)&&(i.isMainNavigation=!0,i.priority="high"),this.matchesSelectors(e,this.tvElementTypes.mediaControl)&&(i.isMediaControl=!0,i.priority="high"),this.matchesSelectors(e,this.tvElementTypes.contentGrid)&&(i.isContentGrid=!0,i.priority="medium"),i.priority||(oe.HIGH.includes(t)?i.priority="high":oe.MEDIUM.includes(t)?i.priority="medium":i.priority="low"),Object.keys(i).length>0?i:void 0}isRelevantForTV(e){return[...oe.HIGH,...oe.MEDIUM,...oe.LOW].includes(e)}isInteractiveElement(e){return["button","link","textbox","combobox","checkbox","radio","slider"].includes(e)}isFormControl(e){return["input","textarea","select","button"].includes(e.tagName.toLowerCase())}isClickableElement(e,t){return["button","link","checkbox","radio","menuitem"].includes(t)||e.hasAttribute("onclick")}getActivationDescription(e){return{button:"Press button",link:"Follow link",checkbox:"Toggle checkbox",radio:"Select option",menuitem:"Select menu item"}[e]||"Activate"}getTextContent(e){let t="";for(const i of e.childNodes)if(i.nodeType===Node.TEXT_NODE)t+=i.textContent||"";else if(i.nodeType===Node.ELEMENT_NODE){const e=i;this.isElementHidden(e)||(t+=this.getTextContent(e))}return t.replace(/\s+/g," ").trim()}getAssociatedLabels(e){const t=[],i=e.getAttribute("id");if(i){const e=document.querySelectorAll(`label[for="${i}"]`);t.push(...Array.from(e))}const n=e.closest("label");return n&&t.push(n),t}matchesSelectors(e,t){return t.some((t=>{try{return e.matches(t)}catch{return!1}}))}}const ce=l("DOMMonitor");class le{config;ariaProcessor;isTracking=!1;focusHandler;liveRegionHandler;focusListener;keydownListener;mutationObserver;currentFocusedElement=null;liveRegions=new Map;previousFocusedElement=null;constructor(e,t){this.config={...e},this.focusHandler=t,this.ariaProcessor=new ae(e)}updateConfig(e){this.config={...e},this.ariaProcessor.updateConfig(e)}async startFocusTracking(){if(this.isTracking)return void ce.debug("Focus tracking already active");ce.info("Starting focus tracking"),this.focusListener=this.handleFocusEvent.bind(this),document.addEventListener("focusin",this.focusListener,!0),document.addEventListener("focusout",this.focusListener,!0),this.keydownListener=this.handleKeydownEvent.bind(this),document.addEventListener("keydown",this.keydownListener,!0);const e=document.activeElement;e&&e!==document.body&&(this.currentFocusedElement=e,await this.processFocusChange(e,"initial")),this.isTracking=!0,ce.info("Focus tracking started")}async startLiveRegionMonitoring(e){this.liveRegionHandler=e,ce.info("Starting live region monitoring"),await this.scanForLiveRegions(),this.mutationObserver=new MutationObserver(this.handleMutations.bind(this)),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["aria-live","aria-atomic","aria-relevant","aria-busy"]}),ce.info("Live region monitoring started")}async stop(){ce.info("Stopping DOM monitoring"),this.focusListener&&(document.removeEventListener("focusin",this.focusListener,!0),document.removeEventListener("focusout",this.focusListener,!0),this.focusListener=void 0),this.keydownListener&&(document.removeEventListener("keydown",this.keydownListener,!0),this.keydownListener=void 0),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=void 0),this.currentFocusedElement=null,this.previousFocusedElement=null,this.liveRegions.clear(),this.isTracking=!1,this.liveRegionHandler=void 0,ce.info("DOM monitoring stopped")}async restart(){await this.stop(),this.config.focusTracking&&await this.startFocusTracking(),this.config.liveRegions&&this.liveRegionHandler&&await this.startLiveRegionMonitoring(this.liveRegionHandler)}async handleFocusEvent(e){try{const t=e.target;"focusin"===e.type?t&&t!==this.currentFocusedElement&&(this.currentFocusedElement=t,await this.processFocusChange(t,"user")):"focusout"===e.type&&t===this.currentFocusedElement&&(this.currentFocusedElement=null)}catch(t){ce.error("Error handling focus event:",t)}}async handleKeydownEvent(e){const t={ArrowUp:"UP",ArrowDown:"DOWN",ArrowLeft:"LEFT",ArrowRight:"RIGHT",Enter:"OK",Escape:"BACK",Tab:"TAB"}[e.key];t&&this.currentFocusedElement&&ce.debug("TV remote button pressed:",t)}async processFocusChange(e,t){try{if(this.ariaProcessor.isElementHidden(e))return;const i=await this.ariaProcessor.processElement(e);if(i&&this.focusHandler){const e={previousElement:this.previousFocusedElement||void 0,currentElement:i,reason:t};await this.focusHandler(e),this.previousFocusedElement=i}}catch(i){ce.error("Error processing focus change:",i)}}async scanForLiveRegions(){const e=document.querySelectorAll("[aria-live]");for(const t of e){const e=this.createLiveRegion(t);e&&(this.liveRegions.set(t,e),ce.debug("Found live region:",{politeness:e.politeness,atomic:e.atomic}))}}createLiveRegion(e){const t=e.getAttribute("aria-live");if(!t||"off"===t)return null;const i=t,n="true"===e.getAttribute("aria-atomic"),r=(e.getAttribute("aria-relevant")||"additions text").split(" "),o="true"===e.getAttribute("aria-busy");return{element:e,politeness:i,atomic:n,relevant:r,busy:o}}async handleMutations(e){for(const i of e)try{"attributes"===i.type&&await this.handleAttributeChange(i),"childList"!==i.type&&"characterData"!==i.type||await this.handleContentChange(i)}catch(t){ce.error("Error handling mutation:",t)}}async handleAttributeChange(e){const t=e.target,i=e.attributeName;if("aria-live"===i){const e=this.createLiveRegion(t);e?this.liveRegions.set(t,e):this.liveRegions.delete(t)}else if("aria-busy"===i){const e=this.liveRegions.get(t);e&&(e.busy="true"===t.getAttribute("aria-busy"))}}async handleContentChange(e){let t=e.target;for(;t&&t!==document.body;){const i=this.liveRegions.get(t);if(i&&!i.busy&&this.liveRegionHandler){const n=i.atomic?t.textContent||"":this.extractChangedContent(e);n.trim()&&await this.liveRegionHandler(i,n);break}t=t.parentElement}}extractChangedContent(e){if("characterData"===e.type)return e.target.textContent||"";if("childList"===e.type){let t="";for(const i of e.addedNodes)(i.nodeType===Node.TEXT_NODE||i.nodeType===Node.ELEMENT_NODE)&&(t+=i.textContent||"");return t}return""}}const de=l("AnnouncementProcessor");class ue{config;ttsFunction;stopTtsFunction;lastAnnouncementTime=0;announcementQueue=[];isProcessingQueue=!1;tvTimings={minInterval:100,maxQueueSize:5,priorityDelay:50,politeDelay:200};constructor(e,t,i){this.config={...e},this.ttsFunction=t,this.stopTtsFunction=i}updateConfig(e){this.config={...e}}async announce(e,t="polite"){const i=this.processAnnouncementText(e);if(!i||0===i.length)return de.debug("No text to announce after processing"),!1;const n={text:i,priority:t,timestamp:Date.now()};return"assertive"===t?(this.announcementQueue.length=0,await this.speakNow(n)):(this.queueAnnouncement(n),this.processQueue(),!0)}async stopAnnouncement(){try{if(this.announcementQueue.length=0,this.isProcessingQueue=!1,this.stopTtsFunction){const e=await this.stopTtsFunction();return de.debug("TTS stop result:",e),e}return de.debug("No stopTtsFunction available"),!0}catch(e){return de.error("Error stopping announcement:",e),!1}}async announceFocusChange(e){const{currentElement:t}=e;if(!t)return;const i=this.buildFocusAnnouncement(t);i.length>0&&await this.announce(i,"polite")}async announceLiveRegion(e,t){if(!e.trim())return;const i=this.processLiveRegionContent(e);i&&await this.announce([i],t)}buildFocusAnnouncement(e){const t=[],i=this.getRoleAnnouncement(e.role);i&&t.push(i),e.name&&t.push(e.name);const n=this.getStateAnnouncement(e.state,e.role);n.length>0&&t.push(...n);const r=this.getPositionAnnouncement(e.position,e.role);r&&t.push(r),e.description&&this.shouldIncludeDescription()&&t.push(e.description);const o=this.getActionAnnouncement(e.actions||[]);return o&&t.push(o),this.filterAnnouncementContent(t,e.role)}shouldIncludeDescription(){return"concise"!==this.config.verbosity&&(this.config.verbosity,!0)}filterAnnouncementContent(e,t){if(!this.config.tvOptimized)return e;const i=["button","link","heading","alert","dialog"].includes(t);return"concise"===this.config.verbosity?i?e.slice(0,2):e.slice(1,2):"standard"===this.config.verbosity?e.slice(0,4):e}getRoleAnnouncement(e){const t={button:{concise:"",standard:"button",detailed:"button"},link:{concise:"",standard:"link",detailed:"link"},heading:{concise:"",standard:"heading",detailed:"heading"},listitem:{concise:"",standard:"list item",detailed:"list item"},textbox:{concise:"",standard:"text field",detailed:"text field"},combobox:{concise:"",standard:"dropdown",detailed:"combo box"},checkbox:{concise:"check box",standard:"check box",detailed:"check box"},radio:{concise:"radio",standard:"radio button",detailed:"radio button"},slider:{concise:"slider",standard:"slider",detailed:"slider"},navigation:{concise:"",standard:"navigation",detailed:"navigation menu"},main:{concise:"",standard:"main content",detailed:"main content area"},dialog:{concise:"dialog",standard:"dialog",detailed:"dialog box"},grid:{concise:"",standard:"grid",detailed:"content grid"},gridcell:{concise:"",standard:"",detailed:"grid cell"},list:{concise:"",standard:"list",detailed:"list"},menu:{concise:"menu",standard:"menu",detailed:"menu"},menuitem:{concise:"",standard:"menu item",detailed:"menu item"},tab:{concise:"tab",standard:"tab",detailed:"tab"},tabpanel:{concise:"",standard:"tab panel",detailed:"tab panel"},progressbar:{concise:"progress",standard:"progress bar",detailed:"progress indicator"},alert:{concise:"alert",standard:"alert",detailed:"alert message"},status:{concise:"",standard:"status",detailed:"status update"}}[e];if(!t)return null;return t[this.config.verbosity]||t.standard||null}getStateAnnouncement(e,t){const i=[];if(!e)return i;const n="concise"===this.config.verbosity,r="detailed"===this.config.verbosity;if(void 0!==e.expanded&&(n?i.push(e.expanded?"open":"closed"):i.push(e.expanded?"expanded":"collapsed")),void 0!==e.checked&&("mixed"===e.checked?i.push(n?"mixed":"partially checked"):n?i.push(e.checked?"on":"off"):i.push(e.checked?"checked":"not checked")),e.selected&&i.push(n?"on":"selected"),e.disabled&&i.push("disabled"),e.invalid&&(r?i.push("string"==typeof e.invalid?e.invalid:"invalid"):i.push("invalid")),"heading"===t&&e.level&&(n?i.push(`h${e.level}`):i.push(`level ${e.level}`)),e.valueText)i.push(e.valueText);else if(void 0!==e.valueNow)if("progressbar"===t){const t=e.valueMax?Math.round(e.valueNow/e.valueMax*100):e.valueNow;i.push(n?`${t}%`:`${t} percent`)}else"slider"===t?i.push(n?`${e.valueNow}`:`value ${e.valueNow}`):i.push(`${e.valueNow}`);return this.config.tvOptimized&&e.focused&&r&&i.push("focused"),i}getPositionAnnouncement(e,t){if(!e)return null;const i="concise"===this.config.verbosity,n="detailed"===this.config.verbosity;return"listitem"===t?i?null:`${e.position} of ${e.setSize}`:"gridcell"===t&&e.row&&e.column?this.config.tvOptimized?i?`${e.row},${e.column}`:n&&e.totalRows&&e.totalColumns?`row ${e.row} of ${e.totalRows}, column ${e.column} of ${e.totalColumns}`:`row ${e.row}, column ${e.column}`:`row ${e.row}, column ${e.column}`:"tab"===t&&e.position&&e.setSize?i?null:`tab ${e.position} of ${e.setSize}`:"menuitem"===t&&e.position&&e.setSize?i?null:`${e.position} of ${e.setSize}`:null}getActionAnnouncement(e){if(!e||0===e.length)return null;const t="concise"===this.config.verbosity,i="detailed"===this.config.verbosity;if(!this.config.tvOptimized){return`available actions: ${e.map((e=>e.name)).slice(0,2).join(", ")}`}const n=e[0];if(!n)return null;if(n.tvButton){if(t)return null;const e=this.getTVButtonText(n.tvButton),r=n.description||"activate";return i?`press ${e} to ${r.toLowerCase()}`:`press ${e}`}if(n.name){if(t)return null;const e=this.getCommonTVAction(n.name);if(e)return i?`available actions: ${e}`:e}return null}getTVButtonText(e){return{OK:"OK",BACK:"Back",UP:"Up",DOWN:"Down",LEFT:"Left",RIGHT:"Right",MENU:"Menu"}[e]||e}getCommonTVAction(e){return{activate:"activate",click:"select",toggle:"toggle",expand:"expand",collapse:"collapse",select:"select",play:"play",pause:"pause",stop:"stop",mute:"mute",unmute:"unmute"}[e.toLowerCase()]||null}processAnnouncementText(e){if(!e)return[];if("string"==typeof e&&(e=[e]),!Array.isArray(e))return[];let t=[...e];return this.config.tvOptimized&&(t=this.applyTVOptimizations(t)),t=this.applyVerbosityFilter(t),t=t.map((e=>e.trim())).filter((e=>e.length>0)).map((e=>this.cleanupText(e))),t}applyTVOptimizations(e){return e.map((e=>{let t=e.replace(/\bnavigation\b/gi,"nav").replace(/\bmenuitem\b/gi,"menu").replace(/\btextbox\b/gi,"text field").replace(/\bcombobox\b/gi,"dropdown").replace(/\bcheckbox\b/gi,"check box");return t=t.replace(/\bapplication\b/gi,"").replace(/\bregion\b/gi,"").replace(/\blandmark\b/gi,""),t.trim()}))}applyVerbosityFilter(e){switch(this.config.verbosity){case"concise":return e.slice(0,2);case"detailed":return e;default:return e.slice(0,4)}}cleanupText(e){return e.replace(/\s+/g," ").replace(/[_-]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim()}processLiveRegionContent(e){const t=this.cleanupText(e);return t.length<3||/^\s*[.!?]*\s*$/.test(t)?null:this.config.tvOptimized?this.applyTVOptimizations([t])[0]:t}queueAnnouncement(e){this.announcementQueue.length>=this.tvTimings.maxQueueSize&&this.announcementQueue.shift(),this.announcementQueue.push(e)}async processQueue(){if(!this.isProcessingQueue&&0!==this.announcementQueue.length){for(this.isProcessingQueue=!0;this.announcementQueue.length>0;){const e=this.announcementQueue.shift();if(e){await this.speakNow(e);const t="assertive"===e.priority?this.tvTimings.priorityDelay:this.tvTimings.politeDelay;await this.delay(t)}}this.isProcessingQueue=!1}}async speakNow(e){const t=Date.now()-this.lastAnnouncementTime;t<this.tvTimings.minInterval&&await this.delay(this.tvTimings.minInterval-t);try{const t=await this.ttsFunction(e.text);return this.lastAnnouncementTime=Date.now(),de.debug("Announced:",{text:e.text.join(" ").substring(0,100),priority:e.priority,success:t}),t}catch(i){return de.error("Error speaking announcement:",i),!1}}delay(e){return new Promise((t=>setTimeout(t,e)))}}const ge=l("AccessibilityReader");class he{config;isActive=!1;domMonitor;ariaProcessor;announcementProcessor;currentElement=null;liveRegions=new Map;constructor(e,t,i){this.config={...e},this.ariaProcessor=new ae(e),this.announcementProcessor=new ue(e,t,i),this.domMonitor=new le(e,this.handleFocusChange.bind(this))}async start(){if(this.isActive)return ge.debug("Accessibility Reader already active"),!0;try{ge.info("Starting Accessibility Reader",this.config),this.config.focusTracking&&await this.domMonitor.startFocusTracking(),this.config.liveRegions&&await this.domMonitor.startLiveRegionMonitoring(this.handleLiveRegionChange.bind(this));const e=document.activeElement;return e&&e!==document.body&&await this.announceElement(e),this.isActive=!0,ge.info("Accessibility Reader started successfully"),!0}catch(e){return ge.error("Failed to start Accessibility Reader:",e),!1}}async stop(){if(!this.isActive)return ge.debug("Accessibility Reader not active"),!0;try{return ge.info("Stopping Accessibility Reader"),await this.domMonitor.stop(),this.currentElement=null,this.liveRegions.clear(),this.isActive=!1,ge.info("Accessibility Reader stopped"),!0}catch(e){return ge.error("Failed to stop Accessibility Reader:",e),!1}}async updateConfig(e){try{const t={...this.config};if(this.config={...this.config,...e},this.ariaProcessor.updateConfig(this.config),this.announcementProcessor.updateConfig(this.config),this.domMonitor.updateConfig(this.config),this.isActive){const e=t.focusTracking!==this.config.focusTracking,i=t.liveRegions!==this.config.liveRegions;(e||i)&&await this.domMonitor.restart()}return ge.info("Accessibility Reader configuration updated",this.config),!0}catch(t){return ge.error("Failed to update Accessibility Reader config:",t),!1}}getConfig(){return{...this.config}}isReaderActive(){return this.isActive}async announce(e,t="polite"){return this.isActive?await this.announcementProcessor.announce(e,t):(ge.debug("Accessibility Reader not active, skipping announcement"),!1)}async stopAnnouncement(){return this.isActive?await this.announcementProcessor.stopAnnouncement():(ge.debug("Accessibility Reader not active, skipping stop"),!1)}getCurrentElement(){return this.currentElement}async handleFocusChange(e){var t,i;try{ge.debug("Focus changed",{from:null==(t=e.previousElement)?void 0:t.role,to:null==(i=e.currentElement)?void 0:i.role,reason:e.reason}),this.currentElement=e.currentElement||null,e.currentElement&&await this.announcementProcessor.announceFocusChange(e)}catch(n){ge.error("Error handling focus change:",n)}}async handleLiveRegionChange(e,t){try{if(ge.debug("Live region changed",{politeness:e.politeness,content:t.substring(0,100)}),e.busy)return;const i="assertive"===e.politeness?"assertive":"polite";await this.announcementProcessor.announceLiveRegion(t,i)}catch(i){ge.error("Error handling live region change:",i)}}async announceElement(e){try{const t=await this.ariaProcessor.processElement(e);if(t){const e={previousElement:this.currentElement||void 0,currentElement:t,reason:"programmatic"};await this.handleFocusChange(e)}}catch(t){ge.error("Error announcing element:",t)}}}const pe=l("AccessibilityService");class fe{bridge;reader=null;ttsSettings=C;tmSettings=A;constructor(e){this.bridge=e,this.bridge.onTTSSettingsChange((e=>{this.ttsSettings=e})),this.bridge.onTMSettingsChange((e=>{this.tmSettings=e}))}async startSpeaking(e){if("string"==typeof e&&(e=[e]),await this.isTTSEnabled())try{return await this.bridge.startSpeaking(e)}catch(t){return pe.error("Error starting speaking:",t),!1}return!0}async stopSpeaking(){if(await this.isTTSEnabled())try{return await this.bridge.stopSpeaking()}catch(e){return pe.error("Error stopping speaking:",e),!1}return!0}async enableReader(e){try{if(!(await this.isTTSSupported()))return pe.warn("Cannot enable Reader: TTS not supported"),!1;if(!(await this.isTTSEnabled()))return pe.warn("Cannot enable Reader: TTS not enabled"),!1;this.reader=new he(e,this.startSpeaking.bind(this),this.stopSpeaking.bind(this));return!!(await this.reader.start())&&(pe.info("Reader enabled"),!0)}catch(t){return pe.error("Error enabling Reader:",t),!1}}async disableReader(){try{if(this.reader){const e=await this.reader.stop();return this.reader=null,e&&pe.info("Reader disabled"),e}return pe.debug("Reader was not active"),!0}catch(e){return pe.error("Error disabling Reader:",e),!1}}getReader(){if(!this.reader)throw new Error("Reader is not active");return this.reader}async isTTSSupported(){try{return(await this.getTTSSettings()).available}catch(e){return pe.error("Error checking TTS support:",e),!1}}async isTextMagnificationSupported(){try{return(await this.getTMSettings()).available}catch(e){return pe.error("Error checking magnification support:",e),!1}}onTTSSettingsChange(e){return this.bridge.onTTSSettingsChange(e)}onTMSettingsChange(e){return this.bridge.onTMSettingsChange(e)}async getTTSSettings(){try{const e=await this.bridge.getTTSSettings();return this.ttsSettings=e,e}catch(e){return pe.error("Error getting TTS settings from bridge:",e),this.ttsSettings}}async getTMSettings(){try{const e=await this.bridge.getTMSettings();return this.tmSettings=e,e}catch(e){return pe.error("Error getting TM settings from bridge:",e),this.tmSettings}}async isTTSEnabled(){return(await this.getTTSSettings()).enabled}async isTMEnabled(){return(await this.getTMSettings()).enabled}}class me{config;waitReady=new Promise((()=>{}));waitReadyResolver;constructor(e){this.config=e,this.waitReady=new Promise((e=>{this.waitReadyResolver=e}))}logError(...e){this.config.debug}}var ve,Se={exports:{}};var ye,be,we=(ve||(ve=1,ye=Se,be=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function r(e,t){if(!n[e]){n[e]={};for(var i=0;i<e.length;i++)n[e][e.charAt(i)]=i}return n[e][t]}var o={compressToBase64:function(e){if(null==e)return"";var i=o._compress(e,6,(function(e){return t.charAt(e)}));switch(i.length%4){default:case 0:return i;case 1:return i+"===";case 2:return i+"==";case 3:return i+"="}},decompressFromBase64:function(e){return null==e?"":""==e?null:o._decompress(e.length,32,(function(i){return r(t,e.charAt(i))}))},compressToUTF16:function(t){return null==t?"":o._compress(t,15,(function(t){return e(t+32)}))+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:o._decompress(e.length,16384,(function(t){return e.charCodeAt(t)-32}))},compressToUint8Array:function(e){for(var t=o.compress(e),i=new Uint8Array(2*t.length),n=0,r=t.length;n<r;n++){var s=t.charCodeAt(n);i[2*n]=s>>>8,i[2*n+1]=s%256}return i},decompressFromUint8Array:function(t){if(null==t)return o.decompress(t);for(var i=new Array(t.length/2),n=0,r=i.length;n<r;n++)i[n]=256*t[2*n]+t[2*n+1];var s=[];return i.forEach((function(t){s.push(e(t))})),o.decompress(s.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":o._compress(e,6,(function(e){return i.charAt(e)}))},decompressFromEncodedURIComponent:function(e){return null==e?"":""==e?null:(e=e.replace(/ /g,"+"),o._decompress(e.length,32,(function(t){return r(i,e.charAt(t))})))},compress:function(t){return o._compress(t,16,(function(t){return e(t)}))},_compress:function(e,t,i){if(null==e)return"";var n,r,o,s={},a={},c="",l="",d="",u=2,g=3,h=2,p=[],f=0,m=0;for(o=0;o<e.length;o+=1)if(c=e.charAt(o),Object.prototype.hasOwnProperty.call(s,c)||(s[c]=g++,a[c]=!0),l=d+c,Object.prototype.hasOwnProperty.call(s,l))d=l;else{if(Object.prototype.hasOwnProperty.call(a,d)){if(d.charCodeAt(0)<256){for(n=0;n<h;n++)f<<=1,m==t-1?(m=0,p.push(i(f)),f=0):m++;for(r=d.charCodeAt(0),n=0;n<8;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}else{for(r=1,n=0;n<h;n++)f=f<<1|r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r=0;for(r=d.charCodeAt(0),n=0;n<16;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}0==--u&&(u=Math.pow(2,h),h++),delete a[d]}else for(r=s[d],n=0;n<h;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1;0==--u&&(u=Math.pow(2,h),h++),s[l]=g++,d=String(c)}if(""!==d){if(Object.prototype.hasOwnProperty.call(a,d)){if(d.charCodeAt(0)<256){for(n=0;n<h;n++)f<<=1,m==t-1?(m=0,p.push(i(f)),f=0):m++;for(r=d.charCodeAt(0),n=0;n<8;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}else{for(r=1,n=0;n<h;n++)f=f<<1|r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r=0;for(r=d.charCodeAt(0),n=0;n<16;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}0==--u&&(u=Math.pow(2,h),h++),delete a[d]}else for(r=s[d],n=0;n<h;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1;0==--u&&(u=Math.pow(2,h),h++)}for(r=2,n=0;n<h;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1;for(;;){if(f<<=1,m==t-1){p.push(i(f));break}m++}return p.join("")},decompress:function(e){return null==e?"":""==e?null:o._decompress(e.length,32768,(function(t){return e.charCodeAt(t)}))},_decompress:function(t,i,n){var r,o,s,a,c,l,d,u=[],g=4,h=4,p=3,f="",m=[],v={val:n(0),position:i,index:1};for(r=0;r<3;r+=1)u[r]=r;for(s=0,c=Math.pow(2,2),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;switch(s){case 0:for(s=0,c=Math.pow(2,8),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;d=e(s);break;case 1:for(s=0,c=Math.pow(2,16),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;d=e(s);break;case 2:return""}for(u[3]=d,o=d,m.push(d);;){if(v.index>t)return"";for(s=0,c=Math.pow(2,p),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;switch(d=s){case 0:for(s=0,c=Math.pow(2,8),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;u[h++]=e(s),d=h-1,g--;break;case 1:for(s=0,c=Math.pow(2,16),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;u[h++]=e(s),d=h-1,g--;break;case 2:return m.join("")}if(0==g&&(g=Math.pow(2,p),p++),u[d])f=u[d];else{if(d!==h)return null;f=o+o.charAt(0)}m.push(f),u[h++]=o+f.charAt(0),o=f,0==--g&&(g=Math.pow(2,p),p++)}}};return o}(),null!=ye?ye.exports=be:"undefined"!=typeof angular&&null!=angular&&angular.module("LZString",[]).factory("LZString",(function(){return be}))),Se.exports);const Te="1.9.0",Ie=l("RollbarClient"),Ee=["chrome://userjs/","chrome-extension://","moz-extension://","getJWTString","getjwtstring","user.js","userscript","tampermonkey","greasemonkey","can't find variable getjwtstring","referenceerror: can't find variable: getjwtstring","unexpected end of json input","jsonparse"];const De=new class{config=null;windowWrapper=new U;lastAPICallTime=0;API_THROTTLE_MS=1e3;sessionId="";isSDKError(e){return e instanceof r||e instanceof Error&&"SDKError"===e.name}initialize(e){if(this.config=e,!e.enabled)return Ie.info("Rollbar disabled - error reporting will be skipped"),void(this.sessionId=this.generateSessionId());this.sessionId=this.generateSessionId(),e.accessToken?Ie.info("Rollbar initialized - using API",{environment:e.environment||"development",sessionId:this.sessionId}):Ie.info("Rollbar initialized without token - will use API with Nginx proxy (server should add token)")}shouldIgnoreError(e){if(!e)return!0;const t="string"==typeof e?e:e.message||"",i="object"==typeof e&&e.stack||"",n=String(e).toLowerCase();return Ee.some((e=>(null==t?void 0:t.toLowerCase().includes(e.toLowerCase()))||(null==i?void 0:i.toLowerCase().includes(e.toLowerCase()))||n.includes(e.toLowerCase())))}parseStackTrace(e){var t;if(!e)return[];const i=[],n=e.split("\n").slice(1);for(const r of n){const e=r.match(/at\s+(?:(\S+)\s+\()?([^(]+):(\d+):(\d+)\)?/);e&&i.push({method:e[1]||void 0,filename:null==(t=e[2])?void 0:t.trim(),lineno:parseInt(e[3],10),colno:parseInt(e[4],10)})}return i}async sendErrorToRollbarAPI(e,t,i){var n,r,o,s,a,c;const l=Date.now();if(l-this.lastAPICallTime<this.API_THROTTLE_MS)return Ie.debug("Throttling API call",{timeSinceLastCall:l-this.lastAPICallTime}),null;this.lastAPICallTime=l,(null==(n=this.config)?void 0:n.accessToken)||Ie.debug("Sending error to Rollbar API without token - relying on server-side token via proxy");try{const n="string"==typeof e?e:e.message||"Unknown error",l="object"==typeof e?e.stack:void 0,d={data:{level:i,environment:(null==(r=this.config)?void 0:r.environment)||"development",body:{message:{body:n},...l&&{trace_chain:[{frames:this.parseStackTrace(l).reverse()}]}},custom:{component:t.component||"SDK",...t.operation&&{operation:t.operation},version:t.version||Te,userAgent:t.userAgent||("undefined"!=typeof navigator?navigator.userAgent:"unknown"),...t.url&&{url:t.url}}}};(null==(o=this.config)?void 0:o.accessToken)&&(d.access_token=this.config.accessToken);const u={"Content-Type":"application/json"};(null==(s=this.config)?void 0:s.accessToken)&&(u["X-Rollbar-Access-Token"]=this.config.accessToken);const g=await window.fetch("https://sdk.titanos.tv/logs/",{method:"POST",headers:u,body:JSON.stringify(d)});if(!g.ok)return Ie.error("Failed to send error to Rollbar API",{status:g.status,statusText:g.statusText}),null;const h=await g.json(),p=(null==(a=null==h?void 0:h.result)?void 0:a.uuid)||(null==h?void 0:h.uuid)||(null==(c=null==h?void 0:h.result)?void 0:c.id)||null;return Ie.info(("critical"===i?"Critical error":"Error")+" sent to Rollbar API",{message:n,component:t.component,rollbarId:p}),p}catch(d){return Ie.error("Failed to send error to Rollbar API",{error:d,originalError:e}),null}}async buildErrorContext(e,t){var i,n;const r=await this.getDeviceContext(),o={component:(null==t?void 0:t.component)||"SDK",operation:null==t?void 0:t.operation,requestId:null==t?void 0:t.requestId,timestamp:Date.now(),url:"undefined"!=typeof window?null==(i=window.location)?void 0:i.href:void 0,userAgent:"undefined"!=typeof navigator?navigator.userAgent:"unknown",sessionId:this.sessionId,errorStack:"object"==typeof e?e.stack:void 0,version:"undefined"!=typeof window&&(null==(n=this.windowWrapper.get("TitanSDK"))?void 0:n.VERSION)||Te,...r,...t},s=g().filter((e=>!e.module.includes("RollbarClient")&&!e.message.includes("Rollbar")&&"debug"!==e.level)).slice(-20);return o.logs=s.map((e=>`[${e.timestamp}] ${e.module}: ${e.message}${e.args&&e.args.length>0?"\n Args: "+JSON.stringify(e.args):""}`)).join("\n"),o}async reportError(e,t,i="error"){var n,r;if(!(null==(n=this.config)?void 0:n.enabled)||!e)return Promise.resolve(null);if(!this.isSDKError(e))return Promise.resolve(null);if(this.shouldIgnoreError(e))return Promise.resolve(null);try{const n=await this.buildErrorContext(e,t);return this.sendErrorToRollbarAPI(e,n,i)}catch(o){Ie.error(`Failed to build error context for ${i} error`,{error:o});const n={component:(null==t?void 0:t.component)||"SDK",operation:null==t?void 0:t.operation,version:Te,userAgent:"undefined"!=typeof navigator?navigator.userAgent:"unknown",url:"undefined"!=typeof window?null==(r=window.location)?void 0:r.href:void 0,timestamp:Date.now(),sessionId:this.sessionId,...t};return this.sendErrorToRollbarAPI(e,n,i)}}collectSDKUsage(e,t,i,n){var r,o;if(!(null==(r=this.config)?void 0:r.enabled))return;const s={type:"sdk_function_execution",functionName:e,success:i,component:n,result:i?t:void 0,error:i?void 0:t,timestamp:Date.now(),url:"undefined"!=typeof window?null==(o=window.location)?void 0:o.href:void 0};Ie.info("SDK function execution",s)}generateSessionId(){return`session_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}async getDeviceContext(){var e,t,i;try{if(null==window?void 0:window.TitanSDK)try{const n=await(null==(i=null==(t=null==(e=null==window?void 0:window.TitanSDK)?void 0:e.deviceInfo)?void 0:t.getDeviceInfo)?void 0:i.call(t));return{deviceInfo:n?JSON.stringify(n):"unavailable"}}catch(n){}return{deviceInfo:`OS: ${(null==navigator?void 0:navigator.platform)||"unknown"}, Browser: ${this.detectBrowserEngine()}, Storage: ${"localStorage"in(window||{})}`}}catch(r){return{}}}detectBrowserEngine(){if("undefined"==typeof navigator)return"unknown";const e=navigator.userAgent;return e.includes("Chrome")?"Blink":e.includes("Firefox")?"Gecko":e.includes("Safari")&&!e.includes("Chrome")?"WebKit":e.includes("Edge")?"EdgeHTML":"unknown"}destroy(){this.config=null,this.sessionId="",this.lastAPICallTime=0}isInitialized(){var e;return!0===(null==(e=this.config)?void 0:e.enabled)}},Ce={};function Ae(e){const t={},i=/jwt|token|authorization|cookie|password|secret/i;return Object.keys(e).forEach((n=>{const r=e[n];i.test(n)?t[n]="[REDACTED]":t[n]=(e=>{if("string"==typeof e)return e.length>500?`${e.slice(0,500)}…`:e;if(Array.isArray(e))return e.slice(-50).map((e=>"string"==typeof e&&e.length>500?`${e.slice(0,500)}…`:e));return e})(r)})),t}function Pe(e,t,i,o={}){try{const s=Date.now();if(s-(Ce[e]||0)<5e3)return Promise.resolve(null);Ce[e]=s;const a={userAgent:"undefined"!=typeof navigator?navigator.userAgent:"unknown",component:t,operation:i,context:o?Ae(o):void 0,version:Te};Ie.error("SDK_CRITICAL",{code:e,component:t,operation:i,...a.context?{context:a.context}:{}});const c=new r(e,n.UNKNOWN,{component:t,operation:i,...a.context?{context:a.context}:{}});return De.reportError(c,a,"critical")}catch{return Promise.resolve(null)}}const Re=Object.freeze(Object.defineProperty({__proto__:null,reportCriticalCode:Pe,rollbarClient:De},Symbol.toStringTag,{value:"Module"})),Me=l("TVPlatform");class ke extends me{DEFAULT_DEVICE_INFO={};bridge;isInitialized=!1;CACHE_KEY="titansdk";CACHE_EXPIRY=6048e5;constructor(e,t){if(super(e),null!=t)this.bridge=t;else if(null===t)this.waitReadyResolver(!0);else{const e={gatewayUrl:this.config.gatewayUrl};this.bridge=new te(e)}this.bridge&&this.initializeBridgeSafely()}async initializeBridgeSafely(){if(this.bridge){try{await this.bridge.initialize()&&(this.isInitialized=!0)}catch(e){Me.warn("Bridge initialization failed:",e)}this.waitReadyResolver(!0)}}getFromLocalStorage(){try{if("undefined"==typeof localStorage)return null;if(!localStorage.getItem)return null;const e=localStorage.getItem(this.CACHE_KEY);if(!e)return null;const t=JSON.parse(e);return Date.now()-t.timestamp>this.CACHE_EXPIRY||t.lastVersion!==Te?(localStorage.removeItem(this.CACHE_KEY),null):(Me.debug("Device info loaded from localStorage cache"),t)}catch(e){return Me.warn("Failed to load device info from localStorage:",e),null}}getFromURL(){try{const i=new URLSearchParams(window.location.search).get("titandata");if(!i)return null;let n=null;const r=new U;try{n=we.decompressFromEncodedURIComponent(i),n&&Me.debug("Device info loaded from URL parameter (lz-string)")}catch(e){Me.debug("lz-string decompression failed, trying base64")}if(!n)try{const e=r.get("atob");if(!e)return Me.warn("atob function not available"),null;n=e(decodeURIComponent(i)),Me.debug("Device info loaded from URL parameter (base64)")}catch(t){return Me.warn("Both lz-string and base64 decoding failed"),null}if(!n)return Me.warn("Failed to decode URL parameter"),null;return JSON.parse(n)}catch(i){return Me.warn("Failed to load device info from URL parameter:",i),null}}saveToLocalStorage(e){try{if("undefined"==typeof localStorage)return;if(!(e&&e.deviceId&&e.brand&&e.model))return void Me.warn("Skipping cache save - invalid or empty device info");const t={data:e,timestamp:Date.now(),lastVersion:Te};localStorage.setItem(this.CACHE_KEY,JSON.stringify(t)),Me.debug("Device info saved to localStorage cache")}catch(t){Me.warn("Failed to save device info to localStorage:",t)}}async getBaseDeviceInfo(){const e=this.getFromURL();if(e)return this.saveToLocalStorage(e),this.waitReadyResolver(!0),{deviceInfo:e,tts:C,tm:A};if(!1!==this.config.useCache){const e=this.getFromLocalStorage();if(e)return this.waitReadyResolver(!0),{deviceInfo:e.data,tts:C,tm:A}}else this.config.debug&&Me.debug("Debug mode: skipping cache, fetching fresh data from iframe");if(!this.bridge)return{deviceInfo:null,tts:C,tm:A};try{return await this.waitReady,await this.bridge.executeWithFallback((async()=>{const e=await this.bridge.getDeviceInfo();if(!e)throw new Error("Failed to get device info");return e.deviceInfo&&this.saveToLocalStorage(e.deviceInfo),e}),(async()=>{Me.warn("Bridge unavailable, returning fallback device info");const e={deviceInfo:null,tts:C,tm:A};return Pe("SDK_BRIDGE_FALLBACK","SDK","bridge.executeWithFallback",{reason:"bridge unavailable",platformId:this.getId(),isInitialized:this.isInitialized}),e}))}catch(t){return Me.warn("Failed to get device info from bridge:",t),Pe("SDK_BRIDGE_FALLBACK","SDK","bridge.executeWithFallback",{reason:"bridge exception",platformId:this.getId(),isInitialized:this.isInitialized,error:t instanceof Error?t.message:String(t)}),{deviceInfo:null,tts:C,tm:A}}}isTV(){return"undefined"!=typeof window&&(navigator.userAgent.includes("TV")||navigator.userAgent.includes("SmartTV")||navigator.userAgent.includes("SMART-TV")||window.location.href.includes("file://"))}}const Oe=new U,_e=new U;function Ne(){const e=document.createElement("video");return e.canPlayType&&"function"==typeof e.canPlayType?{supportAppleHLS:""!==e.canPlayType("application/vnd.apple.mpegURL")||""!==e.canPlayType("audio/mpegurl"),supportMSSmoothStreaming:""!==e.canPlayType("application/vnd.ms-sstr+xml"),supportMSSInitiator:""!==e.canPlayType("application/vnd.ms-playready.initiator+xml"),supportMPEG_DASH:""!==e.canPlayType("application/dash+xml")||"unknown"}:{supportAppleHLS:!1,supportMSSmoothStreaming:!1,supportMSSInitiator:!1,supportMPEG_DASH:"unknown"}}function Le(){try{if(void 0!==Oe.get("oipfObjectFactory"))return{supportOIPF:!0};const e=document.createElement("object");e.type="application/oipfdrmagent";return"function"==typeof e.sendDRMMessage?{supportOIPF:!0}:{supportOIPF:!1}}catch(e){return{supportOIPF:!1}}}function Fe(){try{const e=(new U).get("navigator"),t=void 0!==e&&"function"==typeof e.requestMediaKeySystemAccess,i=_e.has("MSMediaKeys");return{supportWebSocket:_e.has("WebSocket"),supportEME:t||i,hasStorage:_e.has("localStorage")&&_e.has("sessionStorage")}}catch(e){return{supportWebSocket:!1,supportEME:!1,hasStorage:!1}}}const xe=new U;function Ue(){let e="";e=function(){try{const e=document.createElement("object");e.type="application/oipfdrmagent";return"function"==typeof e.sendDRMMessage?"OIPF":""}catch(e){return""}}();try{const t=xe.has("MediaKeys"),i=xe.has("WebKitMediaKeys"),n=xe.has("MSMediaKeys");return e=t||i||n?"EME":e,{drmMethod:e}}catch(t){return{drmMethod:""}}}function He(){try{const e=xe.has("MediaKeys"),t=xe.has("WebKitMediaKeys"),i=xe.has("MSMediaKeys");return{supportEME:e||t||i}}catch(e){return{supportEME:!1}}}const Ve=l("PhilipsCapabilities");async function Ke(e){const t=function(){try{const e={support3d:!1,supportKeyNumeric:!1,supportKeyColor:!1,supportMultiscreen:!1,supportUHD:!1,supportFHD:!0,supportHDR_HDR10:!1,supportHDR_DV:!1,supportHDR:"unknown",supportMultiAudio:!1,supportTTMLInband:!1,supportTTMLOutofband:!1,supportAdobeHDS:!1,supportWidevineClassic:!1,supportDolbyAtmos:"unknown"},t=Be.get("ols3DSupport");t&&t()&&(e.support3d=!0);const i=Be.get("olsAtmosSupport");i&&"function"==typeof i&&i()?e.supportDolbyAtmos=!0:e.supportDolbyAtmos=!1,e.supportKeyNumeric=!0,e.supportKeyColor=!0,e.supportMultiscreen=!1,e.supportMultiAudio=!0,e.supportTTMLInband=!0,e.supportTTMLOutofband=!0,e.supportFHD=!0;const n=Be.get("olsUHD");n&&n()&&(e.supportUHD=n()),e.supportHDR_HDR10=!0;const r=Be.get("olsDVSupport");return r&&r()&&(e.supportHDR_DV=!0),e.supportHDR=e.supportHDR_HDR10||e.supportHDR_DV||!1,e}catch(e){return Ve.error("Error detecting SmartTV API capabilities:",e),{support3d:!1,supportKeyNumeric:!1,supportKeyColor:!1,supportMultiscreen:!1,supportUHD:!1,supportFHD:!0,supportHDR_HDR10:!1,supportHDR_DV:!1,supportMultiAudio:!1,supportTTMLInband:!1,supportTTMLOutofband:!1,supportAdobeHDS:!1,supportHDR:"unknown",supportWidevineClassic:!1,supportDolbyAtmos:"unknown"}}}();return{os:"Linux",browserEngine:"Blink",...t,...Fe(),...Ne(),...Ue(),...He(),...Le(),supportFairplay:!1,supportPrimetime:!1,supportClearKey:!0,supportPlayready:!0,supportWidevineModular:!0}}const Be=new U;const ze=l("PhilipsCompat");class $e extends ke{deviceInfo=null;deviceInfoPromise=null;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"TPV",brand:"Philips"},Product:{platform:"TitanOS",year:"2025",deviceID:"philips-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:V(),language:"en"}};constructor(e,t){super(e,t)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent.toLowerCase();return["philips","saphi","nettv","tpvision"].some((t=>e.includes(t)))}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product},i=this.formatBridgeResponse(e,t),n=(i.Product.platform,await Ke());return{...i,Capability:n}}catch(e){throw ze.error("Error getting device info:",e),e}}formatBridgeResponse(e,t){if(!e.deviceInfo)return t;let i=e.deviceInfo.platformName;e.deviceInfo.profileId&&(i=(e.deviceInfo.profileId.split("_")[1]||i).replace(/\d+$/,""));return t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country,t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=i,t.Product.language=e.deviceInfo.language,t.Product.mac=e.deviceInfo.mac,t.Product.mac||Pe("SDK_BRIDGE_NO_MAC","SDK","formatBridgeResponse",{deviceInfo:e.deviceInfo}),t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.year=e.deviceInfo.year||"",t.Product.firmwareComponentID=i||"",t}getPriority(){return 100}getId(){return"philips"}}const Ge=l("PhilipsDeviceInfoService");class je{platform;info;bridge;constructor(e,t){this.platform=new $e(e,t),this.bridge=t,this.info=null}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw Ge.error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}const We=l("PhilipsAppControlService");class qe{bridge;constructor(e){this.bridge=e}async launch(e,t){return await this.bridge.executeWithFallback((()=>this.bridge.launchApp({appId:e,deepLink:t})),(async()=>(We.warn("Function unavailable, app launch failed gracefully",{appId:e,deepLink:t}),!1)))}}const Qe=e=>{const{available:t,...i}=e;if("scale"in i){const{enabled:e,scale:t}=i;return{enabled:e,...void 0!==t&&{scale:t}}}const{enabled:n}=i;return{enabled:n}};class Ye{subscribe(e,t){const i=d(e,t);return()=>{u(i)}}getHistory(){return g()}clear(){h()}}class Je{bridge;accessibilityService;deviceInfoService;appControlService;constructor(e,t,i,n){this.bridge=e,this.accessibilityService=t,this.deviceInfoService=i,this.appControlService=n}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>Qe(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>Qe(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>this.accessibilityService.onTTSSettingsChange((t=>{e(Qe(t))})),onTMSettingsChange:e=>this.accessibilityService.onTMSettingsChange((t=>{e(Qe(t))}))};apps={launch:(e,t)=>this.appControlService.launch(e,t)};get logging(){return new Ye}get dev(){return{isBridgeConnected:async()=>{try{return this.bridge.isConnected()}catch(e){return!1}}}}}const Ze=l("PhilipsSDK");class Xe extends Je{constructor(e){const t=new re({gatewayUrl:null==e?void 0:e.gatewayUrl,debug:null==e?void 0:e.debug});super(t,new fe(t),new je(e,t),new qe(t))}async init(){try{return await this.deviceInfo.getDeviceInfo(),await this.bridge.waitForInitializationAttempt(),this.bridge.isConnected()||Ze.warn("Bridge initialization completed but bridge is not connected. Some features may not work correctly."),!0}catch(e){throw Ze.error("TitanSDK initialization failed:",e),e}}}const et=l("ChromeTTS");class tt{voices=[];currentVoice=null;settings={available:!0,enabled:!0,rate:1,volume:1};speechSynthesis;constructor(){const e=new U;this.speechSynthesis=e.get("speechSynthesis"),this.speechSynthesis&&(this.initVoices(),"onvoiceschanged"in this.speechSynthesis&&(this.speechSynthesis.onvoiceschanged=()=>{this.initVoices()}))}initVoices(){var e,t,i,n,r,o;if(!("speechSynthesis"in window))return;const s=null==(e=this.speechSynthesis)?void 0:e.getVoices();this.voices=null==s?void 0:s.map((e=>({voiceName:e.name,lang:e.lang,gender:e.name.toLowerCase().includes("female")?"female":"male",remote:!1===e.localService}))),this.currentVoice=(null==(t=this.voices)?void 0:t.find((e=>"en-GB"===e.lang)))||(null==(i=this.voices)?void 0:i.find((e=>e.lang.startsWith("en-"))))||(null==(n=this.voices)?void 0:n[0]),et.info(`Initialized with ${null==(r=this.voices)?void 0:r.length} voices, using ${null==(o=this.currentVoice)?void 0:o.voiceName}`)}getTTSSettings(){return this.settings}getTMSettings(){return{available:!0,enabled:!1,scale:1}}getSettings(){return{tts:this.getTTSSettings(),tm:this.getTMSettings()}}startSpeaking(e){return et.info("Starting speaking:",e),!(!("speechSynthesis"in window)||!e||0===e.length)&&(e.forEach(((e,t)=>{var i,n,r,o;if(!e)return;const s=new SpeechSynthesisUtterance(e);if(s.rate=this.settings.rate??1,s.volume=this.settings.volume??1,s.lang=(null==(i=this.currentVoice)?void 0:i.lang)??"en-GB",this.currentVoice){const e=null==(n=this.speechSynthesis)?void 0:n.getVoices().find((e=>e.name===this.currentVoice.voiceName));e&&(s.voice=e)}0===t&&(null==(r=this.speechSynthesis)||r.cancel()),null==(o=this.speechSynthesis)||o.speak(s)})),!0)}stopSpeaking(){var e;return"speechSynthesis"in window&&(null==(e=this.speechSynthesis)||e.cancel(),!0)}stopSpeakingButKeepHighlightTask(){this.stopSpeaking()}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}sendTTSMessage(e){}}const it=l("VestelTTS"),nt=e=>({available:!0,enabled:e.enabled,rate:e.rate,pitch:e.pitch,volume:e.level});class rt extends tt{vestelSettings={available:!0,enabled:!1,rate:1,volume:1};windowApi=new U;ttsCallbacks=new Set;tmCallbacks=new Set;settingsInitialized=!1;constructor(){super(),this.initializeSettings()}async initializeSettings(){var e,t;const i=this.windowApi.get("TTSHelper");if(!i)return void it.warn("TTSHelper not available during initialization");const n={onSuccess:e=>{this.vestelSettings=nt(e),this.settingsInitialized=!0},onError:e=>{it.error("Error initializing TTS settings:",e),this.settingsInitialized=!0}},r={onSuccess:e=>{this.vestelSettings=nt(e)},onError:e=>{it.error("Error getting TTS info:",e)}};null==(e=i.getTextToSpeechSettings)||e.call(i,n,!1),null==(t=i.getTTSInfo)||t.call(i,r)}getTTSSettings(){var e;if(!this.settingsInitialized){const t=this.windowApi.get("TTSHelper");if(t){const i={onSuccess:e=>{it.info("Current TTS settings:",e,e.toString()),this.vestelSettings=nt(e)},onError:e=>{it.error("Error getting current TTS settings:",e)}};null==(e=t.getTextToSpeechSettings)||e.call(t,i,!1)}}return this.vestelSettings}getTMSettings(){return{available:this.getTTSSettings().available,enabled:!1,scale:1}}getSettings(){return{tts:this.getTTSSettings(),tm:this.getTMSettings()}}stopSpeakingButKeepHighlightTask(){this.stopSpeaking()}onTTSSettingsChange(e){var t;const i=this.windowApi.get("TTSHelper");if(!i)return it.warn("TTSHelper not available"),()=>{};const n={onSuccess:t=>{it.info("TTS settings changed:",t,t.toString()),e(nt(t)),this.settingsInitialized=!0},onError:e=>{it.error("Error getting TTS settings:",e)}};return this.ttsCallbacks.add(n),null==(t=i.getTextToSpeechSettings)||t.call(i,n,!0),()=>{var e;i&&this.ttsCallbacks.has(n)&&(null==(e=i.unsubscribe)||e.call(i,n),this.ttsCallbacks.delete(n))}}onTMSettingsChange(e){this.tmCallbacks.add(e);const t=this.onTTSSettingsChange((t=>{const i={available:t.available,enabled:!1,scale:1};e(i)})),i=this.getTMSettings();return e(i),()=>{this.tmCallbacks.delete(e),t()}}destroy(){const e=this.windowApi.get("TTSHelper");e&&this.ttsCallbacks.forEach((t=>{var i;null==(i=e.unsubscribe)||i.call(e,t)})),this.ttsCallbacks.clear(),this.tmCallbacks.clear()}}const ot=l("AccessibilityService");class st{tts;reader=null;constructor(){this.tts=new rt}async startSpeaking(e){if("string"==typeof e&&(e=[e]),await this.isTTSEnabled())try{return this.tts.startSpeaking(e),!0}catch(t){return ot.error("Error starting speaking:",t),!1}return!1}async stopSpeaking(){return await this.isTTSEnabled()&&this.tts.stopSpeaking(),!0}async enableReader(e){try{if(!(await this.isTTSSupported()))return ot.warn("Cannot enable Reader: TTS not supported"),!1;if(!(await this.isTTSEnabled()))return ot.warn("Cannot enable Reader: TTS not enabled"),!1;this.reader=new he(e,this.startSpeaking.bind(this),this.stopSpeaking.bind(this));return!!(await this.reader.start())&&(ot.info("Reader enabled"),!0)}catch(t){return ot.error("Error enabling Reader:",t),!1}}async disableReader(){try{if(this.reader){const e=await this.reader.stop();return this.reader=null,e&&ot.info("Reader disabled"),e}return ot.debug("Reader was not active"),!0}catch(e){return ot.error("Error disabling Reader:",e),!1}}getReader(){if(!this.reader)throw new Error("Reader is not active");return this.reader}async isTTSSupported(){try{return(await this.getTTSSettings()).available}catch(e){return ot.error("Error checking TTS support:",e),!1}}async isTextMagnificationSupported(){try{return(await this.getTMSettings()).available}catch(e){return ot.error("Error checking magnification support:",e),!1}}onTTSSettingsChange(e){return this.tts.onTTSSettingsChange(e)}onTMSettingsChange(e){return this.tts.onTMSettingsChange(e)}async getTTSSettings(){return this.tts.getTTSSettings()}async getTMSettings(){return this.tts.getTMSettings()}async isTTSEnabled(){return(await this.getTTSSettings()).enabled}async isTMEnabled(){return(await this.getTMSettings()).enabled}}function at(e){const t=function(){var e;try{const t=document.createElement("object");t.style.display="none",t.setAttribute("id","sysinfo"),t.setAttribute("type","systeminfoobject"),document.body.appendChild(t);const i=t;return{support3d:Boolean(i.has3D),supportUHD:"3840x2160"===(null==(e=i.panelinfo)?void 0:e.toLowerCase()),supportFHD:!0}}catch(t){return{support3d:!1,supportUHD:!1,supportFHD:!0}}}(),i=Fe(),n=Ne(),r=Ue(),o=He(),s=Le(),a={os:"Linux",browserEngine:"Blink",hasStorage:!0,support3d:!1,supportUHD:!0,supportFHD:!0,supportHDR:!0,supportHDR_HDR10:!0,supportHDR_DV:!0,supportWebSocket:!0,supportPlayready:!0,supportWidevineModular:!0,supportAppleHLS:!0,supportMSSmoothStreaming:!1,supportMSSInitiator:!1,supportMPEG_DASH:!0,drmMethod:"widevine",supportOIPF:!1,supportEME:!0,supportKeyNumeric:!0,supportKeyColor:!0,supportFairplay:!1,supportAdobeHDS:!1,supportPrimetime:!1,supportClearKey:!0,supportWidevineClassic:!0,supportDolbyAtmos:!0,supportMultiscreen:!0,supportMultiAudio:!0,supportTTMLInband:!0,supportTTMLOutofband:!0};return"MB191"===e&&(a.supportHDR_DV=!1,a.supportHDR_HDR10=!0,a.supportDolbyAtmos=!1),{...a,...t,...i,...n,...r,...o,...s}}const ct=l("VestelCompat");class lt extends ke{deviceInfo=null;deviceInfoPromise=null;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"Vestel",brand:"JVC"},Product:{platform:"TitanOS",year:"2025",deviceID:"vestel-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:V(),language:"en"}};constructor(e,t){super(e,t)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent.toLowerCase();return["vestel"].some((t=>e.includes(t)))}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product},i=this.formatBridgeResponse(e,t),n=at(i.Product.platform);return{...i,Capability:n}}catch(e){ct.error("Error getting device info:",e);const t=at();return{Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product,Capability:t}}}formatBridgeResponse(e,t){return e.deviceInfo?(t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country.toUpperCase(),t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=e.deviceInfo.model,t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.mac=e.deviceInfo.mac,t.Product.year=e.deviceInfo.year||"",t):t}getPriority(){return 90}getId(){return"vestel"}}const dt=l("VestelDeviceInfoService");class ut{platform;info;bridge;constructor(e,t){this.platform=new lt(e,t),this.bridge=t,this.info=null}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw dt.error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}const gt=l("VestelAppControlService");class ht{bridge;constructor(e){this.bridge=e}async launch(e,t){return await this.bridge.executeWithFallback((()=>this.bridge.launchApp({appId:e,deepLink:t})),(async()=>(gt.warn("Function unavailable, app launch failed gracefully",{appId:e,deepLink:t}),!1)))}}const pt=l("VestelSDK");class ft extends Je{constructor(e){const t=new ie({gatewayUrl:null==e?void 0:e.gatewayUrl,debug:null==e?void 0:e.debug});super(t,new st,new ut(e,t),new ht(t))}async init(){try{return await this.deviceInfo.getDeviceInfo(),!0}catch(e){throw pt.error("TitanSDK initialization failed:",e),e}}}const mt=l("GeocodingService");class vt{static REQUEST_TIMEOUT=5e3;static MAX_RETRIES=1;static async getCountry(){try{return await this.fetchWithRetry()}catch(e){return mt.warn("Failed to get country from geocoding service:",e),"UNKNOWN"}}static async fetchWithRetry(){let e=null;for(let i=0;i<=this.MAX_RETRIES;i++)try{const e=await this.fetchFromAPI();if("UNKNOWN"!==e)return e}catch(t){e=t,i<this.MAX_RETRIES&&(mt.debug(`Geocoding attempt ${i+1} failed, retrying...`),await new Promise((e=>setTimeout(e,500))))}if(e)throw e;return"UNKNOWN"}static async fetchFromAPI(){if("undefined"==typeof window||void 0===window.fetch)throw new Error("Fetch API is not available");const e=new AbortController,t=setTimeout((()=>e.abort()),this.REQUEST_TIMEOUT);try{const i="https://geoip.app.titanos.tv/",n=await window.fetch(i,{method:"GET",signal:e.signal,headers:{Accept:"application/json"}});if(clearTimeout(t),!n.ok)throw new Error(`Geocoding API returned status ${n.status}: ${n.statusText}`);const r=await n.json();if(!r||"string"!=typeof r.market)throw new Error("Invalid geocoding response format");const o=r.market.toUpperCase();return mt.debug("Country fetched from geocoding service:",o),o}catch(i){if(clearTimeout(t),i instanceof Error){if("AbortError"===i.name)throw new Error("Geocoding request timeout");throw i}throw new Error("Unknown error during geocoding request")}}}const St=l("VestelLegacyOIPFService");class yt{cachedOIPFObject=null;getOIPFObject(){if(this.cachedOIPFObject)return this.cachedOIPFObject;if("undefined"==typeof document)return St.warn("Document not available for OIPF access"),null;try{const e=document.createElement("object");return e.type="application/oipfConfiguration",e.style.display="none",document.body.appendChild(e),this.cachedOIPFObject=e,e}catch(e){return St.warn("Failed to create OIPF object:",e),null}}async accessOIPFObject(e){try{const t=this.getOIPFObject();return t?e(t):null}catch(t){return St.warn("Failed to access OIPF object:",t),null}}cleanup(){if(this.cachedOIPFObject&&this.cachedOIPFObject.parentNode)try{document.body.removeChild(this.cachedOIPFObject)}catch(e){St.warn("Failed to cleanup OIPF object:",e)}this.cachedOIPFObject=null}async getMACAddress(){return this.accessOIPFObject((e=>{var t,i;let n=(null==(t=e.configuration)?void 0:t.macAddress)||(null==(i=e.localSystem)?void 0:i.serialNumber)||null;return n&&function(e){if(!e||"string"!=typeof e)return!1;const t=e.replace(/[:\-\.]/g,"").toUpperCase();return/^[0-9A-F]{12}$/.test(t)}(n)?(St.debug("MAC address retrieved from OIPF:",n),n):(n&&St.debug("MAC address format invalid:",n),null)}))}async getFirmwareVersion(){return this.accessOIPFObject((e=>{var t;const i=(null==(t=e.localSystem)?void 0:t.softwareVersion)||null;return i?(St.debug("Firmware version retrieved from OIPF:",i),i):null}))}async getCountryId(){return this.accessOIPFObject((e=>{var t;const i=(null==(t=e.configuration)?void 0:t.countryId)||null;return i?(St.debug("Country ID retrieved from OIPF:",i),i):null}))}}const bt=l("VestelLegacyCompat"),wt={alb:"AL",arg:"AR",arm:"AM",aut:"AT",aze:"AZ",bhs:"BS",blr:"BY",bel:"BE",bra:"BR",bgr:"BG",chl:"CL",col:"CO",cri:"CR",hrv:"HR",cze:"CZ",dnk:"DK",ecu:"EC",slv:"SV",est:"EE",fin:"FI",fra:"FR",geo:"GE",deu:"DE",grc:"GR",gtm:"GT",hnd:"HN",hun:"HU",isl:"IS",irl:"IE",isr:"IL",ita:"IT",kaz:"KZ",lva:"LV",lie:"LI",ltu:"LT",lux:"LU",mne:"ME",nld:"NL",nic:"NI",mkd:"MK",nor:"NO",pry:"PY",per:"PE",pol:"PL",prt:"PT",rou:"RO",rus:"RU",smr:"SM",srb:"RS",svk:"SK",svn:"SI",esp:"ES",swe:"SE",che:"CH",tur:"TR",ukr:"UA",gbr:"GB",ury:"UY"};class Tt extends ke{deviceInfo=null;deviceInfoPromise=null;oipfService=new yt;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"Vestel",brand:"JVC"},Product:{platform:"TitanOS",year:"2025",deviceID:"vestel-legacy-device",firmwareVersion:"0.0.0.0",firmwareComponentID:"",mac:"",WhaleAdID:V(),language:"en"}};constructor(e,t){super(e,null)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent,t=e.toLowerCase(),i=t.includes("vestel"),n=e.includes("MB181")||e.includes("MB180")||t.includes("mb181")||t.includes("mb180")||e.includes("Model/Vestel-MB181")||e.includes("Model/Vestel-MB180");return i&&n}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product};if(!e.deviceInfo){const e=await this.fetchDeviceInfoFromOIPF();if(e){this.saveToLocalStorage(e);const i=this.formatBridgeResponse({deviceInfo:e,tts:C,tm:A},t),n=i.Product.platform,r=await at(n);return{...i,Capability:r}}const i=await at();return{...t,Capability:i}}const i=this.formatBridgeResponse(e,t),n=i.Product.platform,r=await at(n);return{...i,Capability:r}}catch(e){bt.warn("Error getting device info:",e);const t=await at();return{Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product,Capability:t}}}async fetchDeviceInfoFromOIPF(){try{const e=this.parseUserAgent(),t=await this.oipfService.getMACAddress(),i=await this.oipfService.getFirmwareVersion();let n=await this.getCountryFromGeocoding();if(!n||"UNKNOWN"===n){const e=await this.oipfService.getCountryId();n=e?this.convertOIPFCountryToISO(e):"UNKNOWN"}const r=t||V(),o=i||e.firmwareVersion,s={profileId:`vestel_legacy_${e.boardName}`,deviceId:r,model:e.boardName,year:e.deviceYear,firmwareVersion:o,country:n,language:G("en"),brand:x.VESTEL,platformName:x.VESTEL,mac:t||"",ifa:"",ifaType:""};return bt.debug("Device info fetched from OIPF:",s),s}catch(e){return bt.warn("Error fetching device info from OIPF:",e),null}}parseUserAgent(){var e;const t=navigator.userAgent;let i=t.match(/Model\/Vestel-(MB\d{3})/i);i||(i=t.match(/MB\d{3}/i));const n=i?(null==(e=i[1])?void 0:e.toUpperCase())||i[0].toUpperCase():"MB181";let r=t.match(/(\d+\.\d+\.\d+\.\d+)/);r||(r=t.match(/(\d+\.\d+\.\d+)/));const o=r?r[1]:"0.0.0.0";let s=t.match(/_TV_[^_]+_(\d{4})_/);s||(s=t.match(/(20\d{2})/));return{boardName:n,firmwareVersion:o,deviceYear:s?s[1]:"2025"}}async getCountryFromGeocoding(){try{const e=await vt.getCountry();return bt.debug("Country retrieved from geocoding service:",e),e}catch(e){return bt.warn("Failed to get country from geocoding service:",e),"UNKNOWN"}}convertOIPFCountryToISO(e){if(!e||"string"!=typeof e)return"UNKNOWN";const t=e.toLowerCase().trim(),i=wt[t];return i?(bt.debug(`Converted OIPF country code '${e}' to ISO '${i}'`),i):/^[A-Z]{2}$/.test(e)?e:(bt.warn(`Unknown OIPF country code '${e}', returning as is`),e.toUpperCase())}formatBridgeResponse(e,t){return e.deviceInfo?(t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country,t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=e.deviceInfo.model,t.Product.language=e.deviceInfo.language,t.Product.mac=e.deviceInfo.mac,t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.year=e.deviceInfo.year||"",t.Product.firmwareComponentID=e.deviceInfo.profileId||"",t):t}getPriority(){return 95}getId(){return"vestel-legacy"}}class It{platform;info=null;bridge;isInitialized=!1;constructor(e,t){this.platform=e,this.bridge=t}async initialize(){try{this.getLogger().debug("Initializing Device Info Service"),await this.getDeviceInfo(),this.isInitialized=!0,this.getLogger().debug("Device Info Service initialized")}catch(e){throw this.getLogger().error("Failed to initialize Device Info Service:",e),e}}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw this.getLogger().error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}isReady(){return this.isInitialized&&null!==this.info}}const Et=l("VestelLegacyDeviceInfoService");class Dt extends It{constructor(e){super(new Tt(e))}getLogger(){return Et}}const Ct=l("VestelLegacyAccessibilityService");class At{reader=null;async startSpeaking(e){return!1}async stopSpeaking(){return!1}async enableReader(e){return Ct.warn("Cannot enable Reader: TTS not supported"),!1}async disableReader(){return!1}getReader(){return null}async isTTSSupported(){return!1}async isTextMagnificationSupported(){return!1}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}async getTTSSettings(){return C}async getTMSettings(){return A}async isTTSEnabled(){return!1}async isTMEnabled(){return!1}}const Pt=l("VestelLegacyAppControlService");class Rt{async launchApp(e,t){return Pt.warn("App launching not supported on legacy Vestel devices"),!1}}const Mt=l("VestelLegacySDK");class kt{accessibilityService;deviceInfoService;appControlService;loggingService;constructor(e){this.accessibilityService=new At,this.deviceInfoService=new Dt(e),this.appControlService=new Rt,this.loggingService=new Ye}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>Qe(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>Qe(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>()=>{},onTMSettingsChange:e=>()=>{}};apps={launch:async(e,t)=>{try{return await this.appControlService.launchApp(e,t),!0}catch(i){return Mt.error("Failed to launch app:",i),!1}}};get logging(){return this.loggingService}async init(){try{return Mt.debug("Initializing Vestel Legacy SDK"),await this.deviceInfoService.initialize(),Mt.debug("Vestel Legacy SDK initialized successfully"),!0}catch(e){return Mt.error("Failed to initialize Vestel Legacy SDK:",e),!1}}async getCapabilities(){return this.deviceInfoService.getCapabilities()}isReady(){return this.deviceInfoService.isReady()}getVersion(){return"1.0.0"}getPlatform(){return"vestel-legacy"}}const Ot="titanSDK_tts_settings",_t="titanSDK_tm_settings",Nt=l("BrowserAccessibilityService");class Lt{reader=null;chromeTTS;windowMock;mockStorage;ttsSettings;tmSettings;constructor(e,t,i=!1){this.windowMock=e,this.mockStorage=t,this.chromeTTS=new tt,this.ttsSettings=this.loadTTSSettings(),this.tmSettings=this.loadTMSettings()}loadTTSSettings(){try{const e=localStorage.getItem(Ot);if(e)return{...this.getDefaultTTSSettings(),...JSON.parse(e)}}catch(e){}return this.getDefaultTTSSettings()}loadTMSettings(){try{const e=localStorage.getItem(_t);if(e)return{...this.getDefaultTMSettings(),...JSON.parse(e)}}catch(e){}return this.getDefaultTMSettings()}getDefaultTTSSettings(){return{available:!0,enabled:!0,rate:1,volume:1}}getDefaultTMSettings(){return{available:!0,enabled:!1,scale:1}}saveTTSSettings(){try{localStorage.setItem(Ot,JSON.stringify(this.ttsSettings))}catch(e){}}saveTMSettings(){try{localStorage.setItem(_t,JSON.stringify(this.tmSettings))}catch(e){}}async startSpeaking(e){try{if(!this.ttsSettings.enabled)return Nt.info("TTS is disabled in settings"),!1;const t=Array.isArray(e)?e.join(" "):e,i=this.chromeTTS.startSpeaking([t]);return i&&Nt.info("🔊 Speaking:",t),i}catch(t){return Nt.error("Error starting speech:",t),!1}}async stopSpeaking(){try{const e=this.chromeTTS.stopSpeaking();return e&&Nt.info("🔇 Speech stopped"),e}catch(e){return Nt.error("Error stopping speech:",e),!1}}async enableReader(e){try{if(!(await this.isTTSSupported()))return Nt.warn("Cannot enable Reader: TTS not supported"),!1;this.reader=new he(e,this.startSpeaking.bind(this),this.stopSpeaking.bind(this));return!!(await this.reader.start())&&(Nt.info("Reader enabled"),!0)}catch(t){return Nt.error("Error enabling Reader:",t),!1}}async disableReader(){try{return!!this.reader&&(await this.reader.stop(),this.reader=null,Nt.info("Reader disabled"),!0)}catch(e){return Nt.error("Error disabling Reader:",e),!1}}getReader(){return this.reader}async isTTSSupported(){var e,t;return void 0!==(null==(t=null==(e=this.mockStorage)?void 0:e.features)?void 0:t.tts)?this.mockStorage.features.tts:"undefined"!=typeof window&&"speechSynthesis"in window}async isTextMagnificationSupported(){var e,t;return void 0===(null==(t=null==(e=this.mockStorage)?void 0:e.features)?void 0:t.magnification)||this.mockStorage.features.magnification}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}async getTTSSettings(){return{...this.ttsSettings}}async getTMSettings(){return{...this.tmSettings}}async isTTSEnabled(){const e=await this.getTTSSettings();return e.available&&e.enabled}async isTMEnabled(){const e=await this.getTMSettings();return e.available&&e.enabled}updateTTSSettings(e){this.ttsSettings={...this.ttsSettings,...e},this.saveTTSSettings(),Nt.info("TTS settings updated:",this.ttsSettings)}updateTMSettings(e){this.tmSettings={...this.tmSettings,...e},this.saveTMSettings(),Nt.info("TM settings updated:",this.tmSettings)}}const Ft=l("BrowserPlatform");class xt extends me{constructor(e){super(e),this.waitReady=new Promise((e=>{this.waitReadyResolver=e})),this.waitReadyResolver(!0)}async canHandle(){return!0}async getDeviceInfo(){return Ft.debug("Getting default device info for browser"),this.getDefaultDeviceInfo()}getDefaultDeviceInfo(){return{Channel:{appStore:"browser",vendor:"browser",brand:"browser"},Product:{platform:"browser",year:(new Date).getFullYear().toString(),deviceID:"browser-"+Math.random().toString(36).substring(2,10),firmwareVersion:"unknown",firmwareComponentID:"unknown",mac:"unknown"},Capability:{os:(null==navigator?void 0:navigator.platform)||"unknown",browserEngine:this.detectBrowserEngine(),hasStorage:this.hasLocalStorage(),support3d:!1,supportUHD:!1,supportHDR:!1,supportWebSocket:"WebSocket"in window,supportPlayready:!1,supportWidevineModular:!1,supportAppleHLS:!1,supportMSSmoothStreaming:!1,supportMSSInitiator:!1,supportMPEG_DASH:!1,drmMethod:"",supportOIPF:!1,supportEME:"mediaKeys"in Document.prototype,supportKeyNumeric:!1,supportKeyColor:!1,supportMultiscreen:!1,supportFHD:!1,supportMultiAudio:!1,supportTTMLInband:!1,supportTTMLOutofband:!1,supportFairplay:!1,supportAdobeHDS:!1,supportPrimetime:!1,supportClearKey:!1,supportWidevineClassic:!1,supportDolbyAtmos:!1,supportHDR_HDR10:!1,supportHDR_DV:!1}}}detectBrowserEngine(){const e=navigator.userAgent;return e.includes("Chrome")?"Blink":e.includes("Firefox")?"Gecko":e.includes("Safari")?"WebKit":e.includes("Edge")?"EdgeHTML":e.includes("Trident")?"Trident":"unknown"}hasLocalStorage(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}getPriority(){return 10}getId(){return"browser"}}const Ut=l("BrowserDeviceInfoService");class Ht{platform;info;options;constructor(e,t,i){this.options=e,this.info=null;const n={debug:null==e?void 0:e.debug,timeout:(null==e?void 0:e.legacyDeviceInfoTimeout)||5e3,gatewayUrl:null==e?void 0:e.gatewayUrl,useCache:!0};this.platform=new xt(n)}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw Ut.error("Error getting device info:",e),e}}async getCapabilities(){try{return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}catch(e){throw Ut.error("Error getting device capabilities:",e),e}}}const Vt=l("BrowserAppControlService");class Kt{windowMock;constructor(e){this.windowMock=e}async launch(e,t){Vt.debug(`Launching app: ${e} with deepLink: ${t||"none"}`);const i=this.windowMock||window;if(!i||"function"!=typeof i.open)throw new r("Cannot open new window for app launch (window.open not available)",n.NOT_SUPPORTED,{operation:"launch",appId:e,deepLink:t,platform:"browser"});try{return i.open(t||e,"_blank"),Vt.info(`Opened new tab for app: ${e}`),!0}catch(o){throw Vt.error("Error opening new window for app launch:",o),new r(`Failed to launch app: ${e}`,n.COMMUNICATION_ERROR,{operation:"launch",appId:e,deepLink:t,platform:"browser",originalError:o})}}}const Bt=l("BrowserSDK");class zt{accessibilityService;deviceInfoService;appControlService;constructor(e){this.accessibilityService=new Lt(null==e?void 0:e.windowMock,null==e?void 0:e.mockStorage,(null==e?void 0:e.dev)||!1),this.deviceInfoService=new Ht(e,null==e?void 0:e.windowMock,null==e?void 0:e.mockStorage),this.appControlService=new Kt(null==e?void 0:e.windowMock),"undefined"!=typeof window&&Object.defineProperty(window,"titanSDK",{value:this,writable:!0,configurable:!0}),(null==e?void 0:e.debug)&&Bt.debug("BrowserSDK constructor finished")}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>Qe(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>Qe(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>this.accessibilityService.onTTSSettingsChange((t=>{e(Qe(t))})),onTMSettingsChange:e=>this.accessibilityService.onTMSettingsChange((t=>{e(Qe(t))}))};apps={launch:(e,t)=>this.appControlService.launch(e,t)};get logging(){return new Ye}get dev(){const e={simulateError(e){switch(e){case"sdk":{const e=new r("Test SDK error for Rollbar integration",n.UNKNOWN,{operation:"dev-api-sdk-error",component:"SDK"});throw De.reportError(e,{operation:"dev-api-sdk-error",component:"SDK"}),e}case"bridge":{const e=new r("Test bridge communication error",n.COMMUNICATION_ERROR,{operation:"dev-api-bridge-error",component:"SDK"});return De.reportError(e,{operation:"dev-api-bridge-error",component:"SDK"}),Promise.reject(e)}case"async":return new Promise(((e,t)=>{setTimeout((()=>{const e=new r("Test async error after timeout",n.TIMEOUT,{operation:"dev-api-async-error",component:"SDK"});De.reportError(e,{operation:"dev-api-async-error",component:"SDK"}),t(e)}),100)}));default:{const t=new r(`Unknown error type: ${e}`,n.UNKNOWN,{operation:"dev-api-unknown-error",component:"SDK"});throw De.reportError(t,{operation:"dev-api-unknown-error",component:"SDK"}),t}}},async simulateGatewayError(e,t){const i=new r(`Gateway error simulation not supported in browser platform. Error type: ${e}, message: ${t||"default"}`,n.NOT_SUPPORTED,{operation:"dev-api-gateway-error",component:"SDK"});throw De.reportError(i,{operation:"dev-api-gateway-error",component:"SDK"},"critical"===e?"critical":"error"),i}};return{updateTTSSettings:e=>{this.accessibilityService.updateTTSSettings(e)},updateTMSettings:e=>{this.accessibilityService.updateTMSettings(e)},simulateError:e.simulateError,simulateGatewayError:e.simulateGatewayError}}async init(){try{return Bt.debug("BrowserSDK initialization started"),Bt.info("BrowserSDK initialized successfully"),!0}catch(e){throw Bt.error("BrowserSDK initialization failed:",e),e}}}class $t extends $e{DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"HKC",brand:"JVC"},Product:{platform:"TitanOS",year:"2026",deviceID:"jvc-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:V(),language:"en"}};constructor(e,t){super(e,t)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent.toLowerCase();return["hkc","jvc"].some((t=>e.includes(t)))}getId(){return"jvc"}}const Gt=l("JVCDeviceInfoService");class jt{platform;info;bridge;constructor(e,t){this.platform=new $t(e,t),this.bridge=t,this.info=null}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw Gt.error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}const Wt=l("JVCSDK");class qt extends Je{constructor(e){const t=new re({gatewayUrl:null==e?void 0:e.gatewayUrl,debug:null==e?void 0:e.debug});super(t,new fe(t),new jt(e,t),new qe(t))}async init(){try{return await this.deviceInfo.getDeviceInfo(),await this.bridge.waitForInitializationAttempt(),this.bridge.isConnected()||Wt.warn("Bridge initialization completed but bridge is not connected. Some features may not work correctly."),!0}catch(e){throw Wt.error("TitanSDK initialization failed:",e),e}}}const Qt=l("AccessibilityService");class Yt{reader=null;async startSpeaking(e){return!1}async stopSpeaking(){return!1}async enableReader(e){return Qt.warn("Cannot enable Reader: TTS not supported"),!1}async disableReader(){return!1}getReader(){return null}async isTTSSupported(){return!1}async isTextMagnificationSupported(){return!1}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}async getTTSSettings(){return C}async getTMSettings(){return A}async isTTSEnabled(){return!1}async isTMEnabled(){return!1}}const Jt=l("PhilipsLegacyPlatform");class Zt extends ke{deviceInfo=null;deviceInfoPromise=null;timeout=7e3;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"TPV",brand:"Philips"},Product:{platform:"TitanOS",year:"2023",deviceID:"philips-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:V(),language:"en"}};constructor(e,t){super(e,null)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent.toLowerCase();return["philips","saphi","nettv","tpvision"].some((t=>e.includes(t)))}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product};if(!e.deviceInfo){const e=await this.fetchDeviceInfo();if(e){this.saveToLocalStorage(e);const i=this.formatBridgeResponse({deviceInfo:e,tts:C,tm:A},t),n=(i.Product.platform,await Ke());return{...i,Capability:n}}const i=await Ke();return{...t,Capability:i}}const i=this.formatBridgeResponse(e,t),n=(i.Product.platform,await Ke());return{...i,Capability:n}}catch(e){throw Jt.warn("Error getting device info:",e),e}}async fetchDeviceInfo(){var e;try{const t="app.titanos.tv",i=await Promise.race([H(0,t,"zeasn"),new Promise((e=>{setTimeout((()=>{Jt.warn("Zeasn backend device info request timed out"),e(null)}),this.timeout)}))]);if(!i||!(null==(e=i.datas)?void 0:e.cookies))return null;const n=i.datas.cookies.profileid;return{profileId:n,deviceId:decodeURIComponent(i.datas.cookies.deviceid||""),model:i.datas.cookies.deviceYear||"",year:i.datas.cookies.deviceYear||"",firmwareVersion:i.datas.cookies.ufversion||"",country:i.datas.cookies.country||"",language:G("en"),brand:x.PHILIPS,platformName:x.PHILIPS,mac:decodeURIComponent(i.datas.cookies.mac||""),ifa:"",ifaType:""}}catch(t){return Jt.warn("Error fetching device info from backend",t),null}}formatBridgeResponse(e,t){let i="TitanOS",n="unknown";if(!e.deviceInfo)return t;if(e.deviceInfo.profileId&&(i=e.deviceInfo.platformName,e.deviceInfo.profileId)){var r=e.deviceInfo.profileId.split("_");i=(r[1]||i).replace(/\d+$/,""),n=r[1]?decodeURIComponent(r[1]):"unknown"}return t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country,t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=i,t.Product.language=e.deviceInfo.language,t.Product.mac=e.deviceInfo.mac,t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.year=e.deviceInfo.year||"",t.Product.firmwareComponentID=n,t}getPriority(){return 100}getId(){return"philips"}}class Xt{platform;info;constructor(e){this.platform=new Zt(e),this.info=null}async getDeviceInfo(){const e=await this.platform.getDeviceInfo();return this.info=e,this.info}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}class ei{async launch(e,t){return!1}}class ti{accessibilityService;deviceInfoService;appControlService;constructor(e){this.accessibilityService=new Yt,this.deviceInfoService=new Xt(e),this.appControlService=new ei}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>Qe(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>Qe(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>()=>{},onTMSettingsChange:e=>()=>{}};apps={launch:(e,t)=>this.appControlService.launch(e,t)};get logging(){return new Ye}async init(){return!0}}const ii=l("SmartTvA_API"),ni=(e,t)=>{var i,n,r,o;try{if(!t)return ii.warn(`Device info not available, cannot check capability: ${e}`),!1;const s=t.Product||{},a=t.Channel||{},c=t.Capability||{};switch(e){case"3d":return Boolean(c.support3d);case"uhd":return Boolean(c.supportUHD);case"dolby-vision":return Boolean(c.supportHDR&&((null==(i=s.platform)?void 0:i.toLowerCase().includes("dolby"))||(null==(n=a.brand)?void 0:n.toLowerCase().includes("dolby"))));case"atmos":return Boolean((null==(r=s.platform)?void 0:r.toLowerCase().includes("atmos"))||(null==(o=a.brand)?void 0:o.toLowerCase().includes("dolby")));default:return ii.warn(`Unknown device capability: ${e}`),!1}}catch(s){return ii.error(`Error checking device capability ${e}:`,s),!1}},ri=async e=>{if("undefined"==typeof window)return void ii.warn("Window object not available, cannot attach SmartTvA_API");if("object"==typeof window.SmartTvA_API)return void ii.info("SmartTvA_API already exists on window, skipping initialization");const t=await(async e=>{ii.info("Initializing SmartTvA_API with TitanSDK");let t=null;try{ii.info("Waiting for device info to be ready..."),t=await e.deviceInfo.getDeviceInfo(),ii.info("Device info is ready, proceeding with SmartTvA_API initialization")}catch(i){ii.warn("Failed to get device info during SmartTvA_API initialization:",i)}return{exit:()=>{ii.info("SmartTvA_API.exit() called"),window.close()},hasCapability:(e,...i)=>{switch(ii.debug(`SmartTvA_API.hasCapability('${e}', ${i.join(", ")})`),e){case"3DSupport":return ni("3d",t);case"MultiScreen":return 1===i.length&&i[0],!1;case"DRM":if(2===i.length){const[e,t]=i;if("PlayReady"===e&&"DASH"===t)return!0;if("Widevine"===e&&"AdaptiveStreaming"===t)return!1}return!1;case"Key":if(1===i.length)switch(i[0]){case"numerickeys":case"colorkeys":case"prev_next":return!0;default:return!1}return!1;case"UHD":return ni("uhd",t);case"FHD":case"Multiaudio":return!0;case"TTML":if(1===i.length)switch(i[0]){case"inband":case"outofband":case"EBU-TT-D":case"CFF-TT":return!0;default:return!1}return!1;case"HLS":return 1===i.length&&"DISCONTINUITY"===i[0];case"HDR":if(1===i.length){const e=i[0];if(!ni("uhd",t))return!1;switch(e){case"HDR10":case"DA":case"HDR10+":return!0;case"DV":return ni("dolby-vision",t);default:return!1}}return!1;case"8K":case"WidevineClassic":case"AdobeHDS":return!1;case"ATMOS":return ni("atmos",t);default:return ii.warn(`Unknown capability requested: ${e}`),!1}}}})(e);Object.defineProperty(window,"SmartTvA_API",{value:t,writable:!1,configurable:!0}),ii.info("SmartTvA_API successfully attached to window object")},oi=l("WrapperUtils");function si(e){return{getTTSSettings:async()=>(await e()).accessibility.getTTSSettings(),getTMSettings:async()=>(await e()).accessibility.getTMSettings(),isTTSSupported:async()=>(await e()).accessibility.isTTSSupported(),isTTSEnabled:async()=>(await e()).accessibility.isTTSEnabled(),isTMEnabled:async()=>(await e()).accessibility.isTMEnabled(),isTextMagnificationSupported:async()=>(await e()).accessibility.isTextMagnificationSupported(),startSpeaking:async t=>(await e()).accessibility.startSpeaking(t),stopSpeaking:async()=>(await e()).accessibility.stopSpeaking(),enableReader:async t=>(await e()).accessibility.enableReader(t),disableReader:async()=>(await e()).accessibility.disableReader(),onTTSSettingsChange:t=>{let i=null;return e().then((e=>{i=e.accessibility.onTTSSettingsChange(t)})).catch((e=>{oi.error("Failed to set up TTS settings change handler:",e)})),()=>{i&&i()}},onTMSettingsChange:t=>{let i=null;return e().then((e=>{i=e.accessibility.onTMSettingsChange(t)})).catch((e=>{oi.error("Failed to set up TM settings change handler:",e)})),()=>{i&&i()}}}}function ai(e){return{launch:async(t,i)=>(await e()).apps.launch(t,i)}}const ci=l("AnalyticsService");class li{sdkVersion;constructor(e){this.sdkVersion=e}getEventUrl(){return"https://sdk.titanos.tv/events"}async track(e){if("undefined"==typeof window||void 0===window.fetch)return Promise.resolve();try{const t={event_name:e.eventName,event_type:e.eventType,event_params:e.eventParams,event_timestamp:(new Date).toISOString().replace("T"," ").slice(0,-1)};await window.fetch(this.getEventUrl(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(t){ci.warn("TitanSDK: Usage tracking event failed to send.",t)}}trackUsage(){const e={eventName:"sdk",eventType:"sdk-initialized",eventParams:{appHostname:window.location.hostname,sdkVersion:this.sdkVersion}};return this.track(e)}}const di=l("SDK"),ui={debug:!1,useLegacyDeviceInfo:!1,legacyDeviceInfoTimeout:5e3,fallbackToBrowser:!0},gi="TITAN_SDK_USAGE_SENT";let hi=null,pi=null,fi=null,mi=null,vi=!1;const Si=async()=>{if(!hi)throw new r("SDK not created. Call getTitanSDK() first.",n.NOT_INITIALIZED);if(!fi)throw di.error("SDK initialization not started"),new r("SDK initialization not started.",n.NOT_INITIALIZED);if(!(await fi))throw new r("SDK initialization failed.",n.UNKNOWN);return hi},yi=e=>{if(pi)return pi;const t={...ui,...e};if(a.setDebugMode(t.debug??!1),!vi){const e="",t=!1;De.initialize({accessToken:e,enabled:t}),vi=!0}const o=I.detectPlatform(t).platform;di.info("Platform detected:",o);try{switch(o){case i.JVC:hi=new qt(t);break;case i.PHILIPS:hi=new Xe(t);break;case i.PHILIPS_OLD:hi=new ti(t);break;case i.VESTEL:hi=new ft(t);break;case i.VESTEL_LEGACY:hi=new kt(t);break;case i.BROWSER:default:o!==i.BROWSER&&t.debug&&di.warn(`Platform ${o} detected but no specific SDK found, using BrowserSDK as fallback.`),hi=new zt(t)}if(!hi)throw new r("Failed to create SDK instance after platform detection",n.UNKNOWN)}catch(d){throw di.error("Error creating SDK instance:",d),new r(`Failed to create SDK instance after platform detection: ${d}`,n.UNKNOWN)}fi=hi.init(),di.info("SDK Version:",Te);const s={VERSION:Te,isReady:fi,deviceInfo:(c=Si,l=e=>{mi=e},{getDeviceInfo:async()=>{const e=await c(),t=await e.deviceInfo.getDeviceInfo();return null==l||l(t),t}}),accessibility:si(Si),apps:ai(Si)};var c,l;return t.debug&&(di.info("🔧 [DEBUG MODE] TitanSDK debug access enabled"),s.logging=function(e){let t=null;return{subscribe:(i,n)=>{let r=null;return e().then((e=>{t=e,e.logging&&(r=e.logging.subscribe(i,n))})).catch((e=>{oi.error("Failed to set up logging subscription:",e)})),()=>{r&&r()}},getHistory:()=>(null==t?void 0:t.logging)?t.logging.getHistory():[],clear:()=>{(null==t?void 0:t.logging)&&t.logging.clear()}}}(Si)),t.dev&&(t.debug&&di.info("🔧 [DEV MODE] TitanSDK dev access enabled"),o===i.BROWSER&&t.dev&&(di.info("Available dev methods:"),di.info(" sdk.dev.updateTTSSettings({ enabled: true, rate: 1.5 })"),di.info(" sdk.dev.updateTMSettings({ enabled: true, scale: 1.8 })")),s.dev=function(e){return{updateTTSSettings:async t=>{var i,n;return null==(n=null==(i=(await e()).dev)?void 0:i.updateTTSSettings)?void 0:n.call(i,t)},updateTMSettings:async t=>{var i,n;return null==(n=null==(i=(await e()).dev)?void 0:i.updateTMSettings)?void 0:n.call(i,t)},simulateError:async t=>{var i,n;return null==(n=null==(i=(await e()).dev)?void 0:i.simulateError)?void 0:n.call(i,t)},simulateGatewayError:async(t,i)=>{var n,r;return null==(r=null==(n=(await e()).dev)?void 0:n.simulateGatewayError)?void 0:r.call(n,t,i)},isBridgeConnected:async()=>{var t,i;return(null==(i=null==(t=(await e()).dev)?void 0:t.isBridgeConnected)?void 0:i.call(t))??!1}}}(Si)),pi=s,fi.then((async()=>{try{mi=await hi.deviceInfo.getDeviceInfo();const e=new li(Te);if(!(()=>{try{return!("undefined"==typeof window||!window.localStorage)&&"1"===window.localStorage.getItem(gi)}catch{return!1}})())try{await e.trackUsage(),(()=>{try{if("undefined"==typeof window||!window.localStorage)return;window.localStorage.setItem(gi,"1")}catch{}})()}catch{}}catch(d){t.debug&&di.warn("Failed to pre-cache device info:",d)}})).catch((e=>{di.error(`Initialization failed for platform ${o}:`,e)})),pi},bi=async()=>{const e=await Si(),t=await e.deviceInfo.getDeviceInfo();return mi=t,t};if("undefined"!=typeof document&&document.addEventListener("securitypolicyviolation",(e=>{Z.getViolations()})),"undefined"!=typeof window)if(window.TitanSDK&&window.TitanSDK.deviceInfo)di.info("TitanSDK already exists on window, skipping initialization"),di.info("You can still create a new SDK instance using window.getTitanSDK(options)"),window.getTitanSDK=yi;else{const e=()=>{window.onDeviceInfoReady=function(e){bi().then((t=>e(t))).catch((t=>e({},String(t))))},Object.defineProperty(window,"DeviceInfo",{get:()=>{if(mi)return mi;if(hi&&pi)try{return hi.deviceInfo.getDeviceInfo()}catch{return null}return null},configurable:!0}),void 0===window.SmartTvA_API&&Object.defineProperty(window,"SmartTvA_API",{value:{exit:()=>window.close()},writable:!1,configurable:!0})},t=e=>{try{const t=null==localStorage?void 0:localStorage.getItem(e);return t?JSON.parse(t):{}}catch(t){return a.isDebugMode()&&di.error(`Failed to parse localStorage key ${e}:`,t),{}}},i=(new U).get("TITAN_SDK_PARAMS")||t("TITAN_SDK_PARAMS");i&&di.info("Initializing TitanSDK with params:",i),window.TitanSDK=yi(i),e(),ri(window.TitanSDK).catch((e=>{di.error("Failed to initialize SmartTvA_API:",e)}))}e.VERSION=Te,e.getDeviceInfo=bi,e.getTitanSDK=yi,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TitanSDK={})}(this,function(e){"use strict";var t=Object.defineProperty,i=(e=>(e.PHILIPS="PHILIPS",e.PHILIPS_OLD="PHILIPS_OLD",e.JVC_VESTEL="JVC_VESTEL",e.JVC_VESTEL_LEGACY="JVC_VESTEL_LEGACY",e.JVC_HKC="JVC_HKC",e.AOC="AOC",e.BROWSER="BROWSER",e.UNKNOWN="UNKNOWN",e))(i||{});function n(e,t,i,n){return[`${`[TitanSDK][${e}]`} ${t}`,...i,"\n",n]}function r(e,t){e}const o=new class{subscriptions=new Map;logBuffer=[];maxBufferSize=1e3;nextId=1;debugMode=!1;constructor(e=1e3){this.maxBufferSize=e}setDebugMode(e){this.debugMode=e}subscribe(e,t={}){const i="sub-"+this.nextId++,n={id:i,levels:t.levels||["debug","info","warn","error"],modules:t.modules,callback:e,created:Date.now()};if(this.subscriptions.set(i,n),t.includeHistory){this.getFilteredHistory(n.levels,n.modules).forEach(t=>{try{e(t)}catch(i){}})}return i}unsubscribe(e){return this.subscriptions.delete(e)}addLogEntry(e){var t,i,o;this.logBuffer.push(e),this.logBuffer.length>this.maxBufferSize&&this.logBuffer.shift();if(("Gateway"===(null==(t=e.metadata)?void 0:t.source)||!0===(null==(i=e.metadata)?void 0:i.tunneled))&&"error"===e.level){const t=(null==(o=e.metadata)?void 0:o.caller)||"[Gateway]";r("error",n(e.module,e.message,e.args||[],t))}this.subscriptions.forEach(t=>{if(this.shouldNotifySubscription(t,e))try{t.callback(e)}catch(i){}})}getHistory(e,t,i){return this.getFilteredHistory(e,t,i)}clear(){this.logBuffer=[]}getSubscriptionCount(){return this.subscriptions.size}getMetrics(){const e={totalEntries:this.logBuffer.length,entriesByLevel:{},entriesByModule:{},memoryUsageKB:Math.round(JSON.stringify(this.logBuffer).length/1024)};return this.logBuffer.length>0&&(e.oldestEntry=new Date(this.logBuffer[0].timestamp),e.newestEntry=new Date(this.logBuffer[this.logBuffer.length-1].timestamp)),this.logBuffer.forEach(t=>{e.entriesByLevel[t.level]=(e.entriesByLevel[t.level]||0)+1,e.entriesByModule[t.module]=(e.entriesByModule[t.module]||0)+1}),e}exportLogs(e,t){const i=this.getFilteredHistory(e,t);return JSON.stringify(i,null,2)}isDebugMode(){return this.debugMode}shouldNotifySubscription(e,t){return!!e.levels.includes(t.level)&&!(e.modules&&!e.modules.includes(t.module))}getFilteredHistory(e,t,i){let n=this.logBuffer;return e&&(n=n.filter(t=>e.includes(t.level))),t&&(n=n.filter(e=>t.includes(e.module))),i&&i>0&&(n=n.slice(-i)),[...n]}};function s(e){const t=(t,i,...s)=>{var a;const c=(()=>{try{const e=(new Error).stack;if(!e)return"";const t=e.split("\n");for(let i=3;i<t.length;i++){const e=t[i];if(e&&!e.includes("logger.ts")&&!e.includes("Logger")){const t=e.match(/\((.*):(\d+):(\d+)\)/)||e.match(/at (.*):(\d+):(\d+)/);if(t){const[,e,i]=t;return`${e.split("/").pop()||e}:${i}`}}}return""}catch{return""}})(),l=(e=>{var t;try{const i=null==(t=e.stack)?void 0:t.split("\n");if(!i||i.length<4)return"Unknown location";const n=i[3].replace("at","").trim()||"Unknown location",{fnName:r,fnPath:o}=(e=>{let t="",i="";return 1===e.split(" ").length?{fnName:"",fnPath:e.split(" ")[0]}:(3===e.split(" ").length?(t=e.split(" (")[0],i=e.split(" (")[1].replace(")","")):(t=e.split(" ")[0],i=e.split(" ")[1].replace(/\((.*)\)/,"$1")),{fnName:t,fnPath:i})})(n);return r?`${r}[${o}]`:`[${o}]`}catch{return"Unknown location"}})(new Error),d={id:`${e}-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,timestamp:Date.now(),level:t,module:e,message:i,args:s,metadata:{url:"undefined"!=typeof window?null==(a=window.location)?void 0:a.href:void 0,caller:c}};o.addLogEntry(d);if(o.isDebugMode()||"error"===t){n(e,i,s,l);r(t)}};return{debug:(e,...i)=>t("debug",e,...i),info:(e,...i)=>t("info",e,...i),warn:(e,...i)=>t("warn",e,...i),error:(e,...i)=>t("error",e,...i),subscribe:(e,t)=>o.subscribe(e,t),unsubscribe:e=>o.unsubscribe(e),getHistory:(e,t,i)=>o.getHistory(e,t,i),clear:()=>o.clear()}}function a(e){return s(e)}const c=(e,t)=>o.subscribe(e,t),l=e=>o.unsubscribe(e),d=(e,t,i)=>o.getHistory(e,t,i),u=()=>o.clear(),g=e=>o.addLogEntry(e);class h{mocks={};constructor(e){e&&(this.mocks={...e})}get(e){return e in this.mocks?this.mocks[e]:"undefined"!=typeof window&&e in window?window[e]:void 0}has(e){return e in this.mocks||"undefined"!=typeof window&&e in window}get proxy(){return new Proxy({},{get:(e,t)=>{const i=t,n=this.get(i);return"function"==typeof n?(...e)=>{try{return n(...e)}catch(t){return}}:n}})}setMocks(e){this.mocks={...this.mocks,...e}}clearMocks(){this.mocks={}}removeMock(e){const t={};for(const i in this.mocks)i!==e&&(t[i]=this.mocks[i]);this.mocks=t}getAvailableMethods(){const e=new Set;for(const t in this.mocks)Object.prototype.hasOwnProperty.call(this.mocks,t)&&e.add(t);if("undefined"!=typeof window)for(const t in window)Object.prototype.hasOwnProperty.call(window,t)&&t in window&&e.add(t);return Array.from(e)}create(e,t){"undefined"!=typeof window&&(window[e]=t)}removeGlobal(e){"undefined"!=typeof window&&e in window&&delete window[e]}}function p(e,t,i="titanos"){return new Promise((e,n)=>{const r=new h,o="deviceInfoCallback_"+Date.now()+"_"+Math.floor(1e4*Math.random());r.create(o,t=>{e(t),r.removeGlobal(o)});const s=`https://${t}/potamoi/v1/device_info?callback=${o}`,a=`https://smarttv.zeasn.tv/homepage_api/device/clientInfo?callback=${o}`,c=document.createElement("script");c.src="titanos"===i?s:a,c.type="text/javascript",c.onerror=()=>{n(new Error("Failed to load device info script.")),delete r.proxy[o]},document.head.appendChild(c),setTimeout(()=>{r.has(o)&&(n(new Error("Device info request timed out.")),delete r.proxy[o]),c.parentNode&&c.parentNode.removeChild(c)},7e3)})}const f=()=>{const e=e=>{const t=(Math.random().toString(16)+"000000000").substring(2,10);return e?"-"+t.substring(0,4)+"-"+t.substring(4,8):t};return e(!1)+e(!0)+e(!0)+e(!1)},m=1e4,v=[{time:3e4,message:"DOM still not ready after 30 seconds"},{time:6e4,message:"DOM still not ready after 1 minute"},{time:12e4,message:"DOM still not ready after 2 minutes"},{time:18e4,message:"DOM still not ready after 3 minutes"},{time:24e4,message:"DOM still not ready after 4 minutes"},{time:3e5,message:"DOM still not ready after 5 minutes - this may indicate serious page issues"}],S=a("DOM-Utils");function y(){return"undefined"!=typeof document&&!!document.body}const b=(e="en-US")=>"undefined"!=typeof navigator&&navigator.language&&navigator.language||e;function w(e){return e.includes("MB190")||e.includes("MB191")||/MB19[01]/.test(e)}function T(e){return e.toLowerCase().includes("jvc")||/\(JVC[,\s)]/.test(e)||/JVC[-_]/.test(e)}const I="1.10.0";var E=(e=>(e.NOT_INITIALIZED="NOT_INITIALIZED",e.NOT_SUPPORTED="NOT_SUPPORTED",e.NOT_IMPLEMENTED="NOT_IMPLEMENTED",e.INVALID_ARGUMENTS="INVALID_ARGUMENTS",e.INVALID_PARAMETER="INVALID_PARAMETER",e.PLATFORM_NOT_DETECTED="PLATFORM_NOT_DETECTED",e.COMMUNICATION_ERROR="COMMUNICATION_ERROR",e.TIMEOUT="TIMEOUT",e.UNKNOWN="UNKNOWN",e))(E||{});class D extends Error{code;details;constructor(e,t="UNKNOWN",i){super(e),this.name="SDKError",this.code=t,this.details=i,Error.captureStackTrace&&Error.captureStackTrace(this,D)}toString(){return`SDKError [${this.code}]: ${this.message}`}toJSON(){return{name:this.name,code:this.code,message:this.message,details:this.details}}}const C=a("RollbarClient"),A=["chrome://userjs/","chrome-extension://","moz-extension://","getJWTString","getjwtstring","user.js","userscript","tampermonkey","greasemonkey","can't find variable getjwtstring","referenceerror: can't find variable: getjwtstring","unexpected end of json input","jsonparse"];const R=new class{config=null;windowWrapper=new h;lastAPICallTime=0;API_THROTTLE_MS=1e3;sessionId="";isSDKError(e){return e instanceof D||e instanceof Error&&"SDKError"===e.name}initialize(e){if(this.config=e,!e.enabled)return C.info("Rollbar disabled - error reporting will be skipped"),void(this.sessionId=this.generateSessionId());this.sessionId=this.generateSessionId(),e.accessToken?C.info("Rollbar initialized - using API",{environment:e.environment||"development",sessionId:this.sessionId}):C.info("Rollbar initialized without token - will use API with Nginx proxy (server should add token)")}shouldIgnoreError(e){if(!e)return!0;const t="string"==typeof e?e:e.message||"",i="object"==typeof e&&e.stack||"",n=String(e).toLowerCase();return A.some(e=>(null==t?void 0:t.toLowerCase().includes(e.toLowerCase()))||(null==i?void 0:i.toLowerCase().includes(e.toLowerCase()))||n.includes(e.toLowerCase()))}parseStackTrace(e){var t;if(!e)return[];const i=[],n=e.split("\n").slice(1);for(const r of n){const e=r.match(/at\s+(?:(\S+)\s+\()?([^(]+):(\d+):(\d+)\)?/);e&&i.push({method:e[1]||void 0,filename:null==(t=e[2])?void 0:t.trim(),lineno:parseInt(e[3],10),colno:parseInt(e[4],10)})}return i}async sendErrorToRollbarAPI(e,t,i){var n,r,o,s,a,c;const l=Date.now();if(l-this.lastAPICallTime<this.API_THROTTLE_MS)return C.debug("Throttling API call",{timeSinceLastCall:l-this.lastAPICallTime}),null;this.lastAPICallTime=l,(null==(n=this.config)?void 0:n.accessToken)||C.debug("Sending error to Rollbar API without token - relying on server-side token via proxy");try{const n="string"==typeof e?e:e.message||"Unknown error",l="object"==typeof e?e.stack:void 0,d={data:{level:i,environment:(null==(r=this.config)?void 0:r.environment)||"development",body:{message:{body:n},...l&&{trace_chain:[{frames:this.parseStackTrace(l).reverse()}]}},custom:{component:t.component||"SDK",...t.operation&&{operation:t.operation},version:t.version||I,userAgent:t.userAgent||("undefined"!=typeof navigator?navigator.userAgent:"unknown"),...t.url&&{url:t.url}}}};(null==(o=this.config)?void 0:o.accessToken)&&(d.access_token=this.config.accessToken);const u={"Content-Type":"application/json"};(null==(s=this.config)?void 0:s.accessToken)&&(u["X-Rollbar-Access-Token"]=this.config.accessToken);const g=await window.fetch("https://sdk.titanos.tv/logs/",{method:"POST",headers:u,body:JSON.stringify(d)});if(!g.ok)return C.error("Failed to send error to Rollbar API",{status:g.status,statusText:g.statusText}),null;const h=await g.json(),p=(null==(a=null==h?void 0:h.result)?void 0:a.uuid)||(null==h?void 0:h.uuid)||(null==(c=null==h?void 0:h.result)?void 0:c.id)||null;return C.info(("critical"===i?"Critical error":"Error")+" sent to Rollbar API",{message:n,component:t.component,rollbarId:p}),p}catch(d){return C.error("Failed to send error to Rollbar API",{error:d,originalError:e}),null}}async buildErrorContext(e,t){var i,n;const r=await this.getDeviceContext(),o={component:(null==t?void 0:t.component)||"SDK",operation:null==t?void 0:t.operation,requestId:null==t?void 0:t.requestId,timestamp:Date.now(),url:"undefined"!=typeof window?null==(i=window.location)?void 0:i.href:void 0,userAgent:"undefined"!=typeof navigator?navigator.userAgent:"unknown",sessionId:this.sessionId,errorStack:"object"==typeof e?e.stack:void 0,version:"undefined"!=typeof window&&(null==(n=this.windowWrapper.get("TitanSDK"))?void 0:n.VERSION)||I,...r,...t},s=d().filter(e=>!e.module.includes("RollbarClient")&&!e.message.includes("Rollbar")&&"debug"!==e.level).slice(-20);return o.logs=s.map(e=>`[${e.timestamp}] ${e.module}: ${e.message}${e.args&&e.args.length>0?"\n Args: "+JSON.stringify(e.args):""}`).join("\n"),o}async reportError(e,t,i="error"){var n,r;if(!(null==(n=this.config)?void 0:n.enabled)||!e)return Promise.resolve(null);if(!this.isSDKError(e))return Promise.resolve(null);if(this.shouldIgnoreError(e))return Promise.resolve(null);try{const n=await this.buildErrorContext(e,t);return this.sendErrorToRollbarAPI(e,n,i)}catch(o){C.error(`Failed to build error context for ${i} error`,{error:o});const n={component:(null==t?void 0:t.component)||"SDK",operation:null==t?void 0:t.operation,version:I,userAgent:"undefined"!=typeof navigator?navigator.userAgent:"unknown",url:"undefined"!=typeof window?null==(r=window.location)?void 0:r.href:void 0,timestamp:Date.now(),sessionId:this.sessionId,...t};return this.sendErrorToRollbarAPI(e,n,i)}}collectSDKUsage(e,t,i,n){var r,o;if(!(null==(r=this.config)?void 0:r.enabled))return;const s={type:"sdk_function_execution",functionName:e,success:i,component:n,result:i?t:void 0,error:i?void 0:t,timestamp:Date.now(),url:"undefined"!=typeof window?null==(o=window.location)?void 0:o.href:void 0};C.info("SDK function execution",s)}generateSessionId(){return`session_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}async getDeviceContext(){var e,t,i;try{if(null==window?void 0:window.TitanSDK)try{const n=await(null==(i=null==(t=null==(e=null==window?void 0:window.TitanSDK)?void 0:e.deviceInfo)?void 0:t.getDeviceInfo)?void 0:i.call(t));return{deviceInfo:n?JSON.stringify(n):"unavailable"}}catch(n){}return{deviceInfo:`OS: ${(null==navigator?void 0:navigator.platform)||"unknown"}, Browser: ${this.detectBrowserEngine()}, Storage: ${"localStorage"in(window||{})}`}}catch(r){return{}}}detectBrowserEngine(){if("undefined"==typeof navigator)return"unknown";const e=navigator.userAgent;return e.includes("Chrome")?"Blink":e.includes("Firefox")?"Gecko":e.includes("Safari")&&!e.includes("Chrome")?"WebKit":e.includes("Edge")?"EdgeHTML":"unknown"}destroy(){this.config=null,this.sessionId="",this.lastAPICallTime=0}isInitialized(){var e;return!0===(null==(e=this.config)?void 0:e.enabled)}},P={};function M(e){const t={},i=/jwt|token|authorization|cookie|password|secret/i;return Object.keys(e).forEach(n=>{const r=e[n];i.test(n)?t[n]="[REDACTED]":t[n]=(e=>{if("string"==typeof e)return e.length>500?`${e.slice(0,500)}…`:e;if(Array.isArray(e))return e.slice(-50).map(e=>"string"==typeof e&&e.length>500?`${e.slice(0,500)}…`:e);return e})(r)}),t}function k(e,t,i,n={}){try{const r=Date.now();if(r-(P[e]||0)<5e3)return Promise.resolve(null);P[e]=r;const o={userAgent:"undefined"!=typeof navigator?navigator.userAgent:"unknown",component:t,operation:i,context:n?M(n):void 0,version:I};C.error("SDK_CRITICAL",{code:e,component:t,operation:i,...o.context?{context:o.context}:{}});const s=new D(e,E.UNKNOWN,{component:t,operation:i,...o.context?{context:o.context}:{}});return R.reportError(s,o,"critical")}catch{return Promise.resolve(null)}}const O=Object.freeze(Object.defineProperty({__proto__:null,reportCriticalCode:k,rollbarClient:R},Symbol.toStringTag,{value:"Module"})),_=a("CSPDetector");let N=[];const L=class{static getViolations(){return[...this.violations]}static clearViolations(){this.violations.length=0}static onViolation(e){return N.push(e),()=>{N=N.filter(t=>t!==e)}}static checkWebAPISupport(){return{hasPostMessage:"undefined"!=typeof window&&"postMessage"in window,hasIframe:"undefined"!=typeof document&&"createElement"in document,hasMessageEvent:"undefined"!=typeof MessageEvent,hasDocument:"undefined"!=typeof document}}};var F;((e,i,n)=>{i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n})(L,"symbol"!=typeof(F="violations")?F+"":F,[]),"undefined"!=typeof document&&document.addEventListener("securitypolicyviolation",e=>{const t=`${e.violatedDirective}: ${e.blockedURI}`;L.violations.push(t),_.warn("CSP Violation detected:",t);const i={directive:e.violatedDirective,blockedURI:e.blockedURI,originalEvent:e};N.forEach(e=>{try{e(i)}catch(t){_.error("CSPDetector listener error",t)}})});let H=L;const x=a("PlatformDetection");class U{strategies=[];register(e){this.strategies.push(e),this.strategies.sort((e,t)=>t.getPriority()-e.getPriority())}getStrategies(){return[...this.strategies]}}class V{canDetect(){return"undefined"!=typeof window&&("t9_core"in window||"vestel"===window.deviceBrand||navigator.userAgent.toLowerCase().includes("vestel"))}getPlatform(){return this.canDetect()?i.JVC_VESTEL:null}getPriority(){return 3}}class K{canDetect(){if("undefined"==typeof window)return!1;const e=navigator.userAgent,t=e.toLowerCase(),i=t.includes("vestel"),n=e.includes("MB181")||e.includes("MB180")||t.includes("mb181")||t.includes("mb180")||e.includes("Model/Vestel-MB181")||e.includes("Model/Vestel-MB180");return i&&n}getPlatform(){return this.canDetect()?i.JVC_VESTEL_LEGACY:null}getPriority(){return 20}}class B{canDetect(){if("undefined"==typeof window)return!1;if("undefined"==typeof navigator)return!1;const e=navigator.userAgent,t=T(e),i=w(e);return t&&!i}getPlatform(){return this.canDetect()?i.JVC_HKC:null}getPriority(){return 8}}class z{canDetect(){if("undefined"==typeof window)return!1;if("undefined"==typeof navigator)return!1;const e=navigator.userAgent.toLowerCase();return/\(aoc,\s*[^)]+\)/i.test(e)}getPlatform(){return this.canDetect()?i.AOC:null}getPriority(){return 6}}class ${canDetect(){return"undefined"!=typeof window&&("jwt"in window||"launcher_env"in window||"undefined"!=typeof navigator&&navigator.userAgent.toLowerCase().indexOf("philips")>-1)}getPlatform(){return this.canDetect()?i.PHILIPS:null}getPriority(){return 5}}class G{canDetect(){if("undefined"==typeof window)return!1;const e=(()=>{const e=navigator.userAgent.match(/Chrome\/(\d+)\./);return e?parseInt(e[1],10):null})(),t=null!==e&&e<=84;return"undefined"!=typeof navigator&&navigator.userAgent.includes("Philips")&&(document.cookie.includes("tos-session")||t)}getPlatform(){return this.canDetect()?i.PHILIPS_OLD:null}getPriority(){return 10}}class j{canDetect(){return!0}getPlatform(){return i.BROWSER}getPriority(){return 1}}const W=new class{factory;lastDetectedPlatform=null;constructor(){this.factory=new U,this.factory.register(new B),this.factory.register(new z),this.factory.register(new $),this.factory.register(new V),this.factory.register(new K),this.factory.register(new G),this.factory.register(new j)}registerStrategy(e){this.factory.register(e)}detectPlatform(e={}){if(e.forcePlatform)return{platform:e.forcePlatform,detectedBy:"forced",confidence:1};if(this.lastDetectedPlatform)return{...this.lastDetectedPlatform};const t=this.factory.getStrategies();for(const i of t)if(i.canDetect()){const t=i.getPlatform();if(null!==t){const n={platform:t,detectedBy:i.constructor.name,confidence:.9};return this.lastDetectedPlatform=n,e.debug&&x.info(`Platform detected as ${t}`),{...n}}}if(!1===e.fallbackToBrowser)throw new D("Could not detect platform and fallback is disabled",E.PLATFORM_NOT_DETECTED);const n={platform:i.BROWSER,detectedBy:"fallback",confidence:.1};return this.lastDetectedPlatform=n,e.debug&&x.info("Fallback to browser platform - no strategy matched"),{...n}}reset(){this.lastDetectedPlatform=null}},q=a("SmartTvA_API"),Q=(e,t)=>{var i,n,r,o;try{if(!t)return q.warn(`Device info not available, cannot check capability: ${e}`),!1;const s=t.Product||{},a=t.Channel||{},c=t.Capability||{};switch(e){case"3d":return Boolean(c.support3d);case"uhd":return Boolean(c.supportUHD);case"hdr10":return Boolean(c.supportHDR_HDR10);case"hdr10plus":return Boolean(c.supportHDR_HDR10Plus);case"hlg":return Boolean(c.supportHDR_HLG);case"dolby-vision":return Boolean(c.supportHDR&&((null==(i=s.platform)?void 0:i.toLowerCase().includes("dolby"))||(null==(n=a.brand)?void 0:n.toLowerCase().includes("dolby"))));case"atmos":return Boolean((null==(r=s.platform)?void 0:r.toLowerCase().includes("atmos"))||(null==(o=a.brand)?void 0:o.toLowerCase().includes("dolby")));default:return q.warn(`Unknown device capability: ${e}`),!1}}catch(s){return q.error(`Error checking device capability ${e}:`,s),!1}},J=async e=>{if("undefined"==typeof window)return void q.warn("Window object not available, cannot attach SmartTvA_API");if("object"==typeof window.SmartTvA_API)return void q.info("SmartTvA_API already exists on window, skipping initialization");const t=await(async e=>{q.info("Initializing SmartTvA_API with TitanSDK");let t=null;try{q.info("Waiting for device info to be ready..."),t=await e.deviceInfo.getDeviceInfo(),q.info("Device info is ready, proceeding with SmartTvA_API initialization")}catch(i){q.warn("Failed to get device info during SmartTvA_API initialization:",i)}return{exit:()=>{q.info("SmartTvA_API.exit() called"),window.close()},hasCapability:(e,...i)=>{switch(q.debug(`SmartTvA_API.hasCapability('${e}', ${i.join(", ")})`),e){case"3DSupport":return Q("3d",t);case"MultiScreen":return 1===i.length&&i[0],!1;case"DRM":if(2===i.length){const[e,t]=i;if("PlayReady"===e&&"DASH"===t)return!0;if("Widevine"===e&&"AdaptiveStreaming"===t)return!1}return!1;case"Key":if(1===i.length)switch(i[0]){case"numerickeys":case"colorkeys":case"prev_next":return!0;default:return!1}return!1;case"UHD":return Q("uhd",t);case"FHD":case"Multiaudio":return!0;case"TTML":if(1===i.length)switch(i[0]){case"inband":case"outofband":case"EBU-TT-D":case"CFF-TT":return!0;default:return!1}return!1;case"HLS":return 1===i.length&&"DISCONTINUITY"===i[0];case"HDR":if(1===i.length){const e=i[0];if(!Q("uhd",t))return!1;switch(e){case"HDR10":return Q("hdr10",t);case"HDR10+":return Q("hdr10plus",t);case"HLG":return Q("hlg",t);case"DV":return Q("dolby-vision",t);default:return!1}}return!1;case"8K":case"WidevineClassic":case"AdobeHDS":return!1;case"ATMOS":return Q("atmos",t);default:return q.warn(`Unknown capability requested: ${e}`),!1}}}})(e);Object.defineProperty(window,"SmartTvA_API",{value:t,writable:!1,configurable:!0}),q.info("SmartTvA_API successfully attached to window object")};class Y{config;waitReady=new Promise(()=>{});waitReadyResolver;constructor(e){this.config=e,this.waitReady=new Promise(e=>{this.waitReadyResolver=e})}logError(...e){this.config.debug}}const Z={LAUNCH_APP_REQUEST:"LAUNCH_APP_REQUEST",DEVICE_INFO_REQUEST:"DEVICE_INFO_REQUEST",TTS_REQUEST_SETTINGS:"TTS_REQUEST_SETTINGS",TTS_REQUEST_START_SPEAKING:"TTS_REQUEST_START_SPEAKING",TTS_REQUEST_STOP_SPEAKING:"TTS_REQUEST_STOP_SPEAKING",ERROR_SIMULATION:"ERROR_SIMULATION",LAUNCH_APP_RESPONSE:"LAUNCH_APP_RESPONSE",DEVICE_INFO_RESPONSE:"DEVICE_INFO_RESPONSE",TTS_RESPONSE_SETTINGS:"TTS_RESPONSE_SETTINGS",TTS_RESPONSE_START_SPEAKING:"TTS_RESPONSE_START_SPEAKING",TTS_RESPONSE_STOP_SPEAKING:"TTS_RESPONSE_STOP_SPEAKING",ERROR_SIMULATION_RESPONSE:"ERROR_SIMULATION_RESPONSE",LAUNCHER_READY:"LAUNCHER_READY",BRIDGE_READY:"BRIDGE_READY",TTS_SETTINGS_CHANGE:"TTS_SETTINGS_CHANGE",TM_SETTINGS_CHANGE:"TM_SETTINGS_CHANGE",LOG_ENTRY:"LOG_ENTRY",ERROR_RESPONSE:"ERROR_RESPONSE",TRANSFER_DATA:"TRANSFER_DATA"},X={TTS_SETTINGS_CHANGE:Z.TTS_SETTINGS_CHANGE,TM_SETTINGS_CHANGE:Z.TM_SETTINGS_CHANGE,LOG_ENTRY:Z.LOG_ENTRY},ee={enabled:!1,available:!1},te={enabled:!1,available:!1},ie={tts:ee,tm:te},ne="TIMEOUT",re="NOT_SUPPORTED",oe="INVALID_REQUEST",se="COMMUNICATION_ERROR",ae="LAUNCH_FAILED",ce="APP_NOT_FOUND",le="APP_NOT_AVAILABLE",de="INVALID_APP_CODE";var ue=(e=>(e.PHILIPS="philips",e.VESTEL="vestel",e.BROWSER="browser",e))(ue||{});const ge=a("BaseBridge");class he{src="";isInitialized=!1;iframe=null;iframeOrigin="";pendingRequests=new Map;messageTimeout=1e4;iframeTimeout=3e3;connected=!1;debug=!1;initializationPromise=null;aborted=!1;initReject;MESSAGE_TYPES=Z;eventHandlers=new Map;constructor(e){this.debug=(null==e?void 0:e.debug)||!1,(null==e?void 0:e.gatewayUrl)&&(this.src=e.gatewayUrl),ge.debug("bridge: constructor",this.src)}async initialize(){if(this.isInitialized)return!0;if(this.initializationPromise)return ge.debug("bridge: initialization already in progress, waiting..."),this.initializationPromise;ge.debug("bridge: initialization not in progress, starting new one"),this.initializationPromise=this.performInitialization();try{return await this.initializationPromise}catch(e){throw this.initializationPromise=null,e}}async performInitialization(){return new Promise((e,t)=>{this.aborted=!1,this.initReject=t,ge.debug("bridge: starting initialization process"),window.addEventListener("message",this.handleMessage.bind(this));let i=!1;const n=()=>{this.aborted||i||(i=!0,this.isInitialized=!0,ge.debug("bridge initialized successfully"),e(!0))},r=()=>{this.aborted||i||(i=!0,ge.error("Bridge iframe failed to load or initialize."),this.isInitialized=!1,t(new Error("Bridge iframe failed to load or initialize.")))};(async()=>{try{await this.setupIframe(n,r),i||(i=!0,ge.warn("Bridge initialization timeout - setupIframe completed but LAUNCHER_READY not received"),this.isInitialized=!1,e(!1))}catch(o){if(i)return;i=!0,ge.error("Failed to setup iframe:",o),this.isInitialized=!1,t(o)}})()})}async sendMessage(e,t){this.isInitialized||await this.initialize();try{const i=this.prepareMessage(e,t);return new Promise((e,t)=>{const n=setTimeout(()=>{this.pendingRequests.delete(i.requestId),t(new D("Bridge request timeout",E.TIMEOUT))},this.messageTimeout);this.pendingRequests.set(i.requestId,{resolve:e,reject:t,timeout:n}),this.iframe&&this.iframe.contentWindow?(ge.debug("bridge: sendMessage",i),this.iframe.contentWindow.postMessage(i,this.iframeOrigin||"*")):(clearTimeout(n),this.pendingRequests.delete(i.requestId),t(new D("Bridge iframe not available",E.COMMUNICATION_ERROR)))})}catch(i){ge.error("bridge: error sending message:",i);return(await Promise.resolve().then(()=>O).then(e=>e.rollbarClient)).reportError(i instanceof Error?i:new Error("Unknown error"),{component:"SDK",operation:"sendMessage",requestId:this.prepareMessage(e,t).requestId}),Promise.reject({success:!1,type:e,error:{code:E.COMMUNICATION_ERROR,message:i instanceof Error?i.message:"Unknown error"}})}}disconnect(){this.aborted=!0,this.initReject&&(this.initReject(new Error("Bridge initialization aborted")),this.initReject=void 0),this.iframe&&(window.removeEventListener("message",this.handleMessage.bind(this)),document.body.removeChild(this.iframe),this.iframe=null),this.isInitialized=!1,this.connected=!1,this.initializationPromise=null,this.pendingRequests.clear(),this.eventHandlers.clear()}isConnected(){return this.isInitialized&&this.connected}getBridgeHealth(){return{connected:this.isConnected()}}registerEventHandler(e,t){var i;this.eventHandlers.has(e)||this.eventHandlers.set(e,new Set);const n=e=>{t(e)};return null==(i=this.eventHandlers.get(e))||i.add(n),window.addEventListener("message",e=>n(e.data.data)),()=>{var t;window.removeEventListener("message",e=>{var t;return n(null==(t=e.data)?void 0:t.data)}),null==(t=this.eventHandlers.get(e))||t.delete(n)}}handleMessage(e){var t;if(!this.iframeOrigin||e.origin===this.iframeOrigin)try{const i=e.data;if(this.debug&&i&&i.requestId&&ge.debug("bridge handleMessage",i),i&&("BRIDGE_READY"===i.type||"LAUNCHER_READY"===i.type)&&(null==(t=this.iframe)?void 0:t.contentWindow)===e.source)return void(this.connected=!0);if(i&&i.type&&Object.values(X).includes(i.type)&&!i.requestId)return void this.handleNotification(i);if(i&&i.requestId&&this.pendingRequests.has(i.requestId)){const{resolve:e,reject:t,timeout:n}=this.pendingRequests.get(i.requestId);if(clearTimeout(n),this.pendingRequests.delete(i.requestId),!1===i.success&&i.error){const e=this.getOperationFromMessageType(i.type||"unknown");t(this.createSDKErrorFromGatewayResponse(i.error,e))}else e({success:!0,data:i.response||i.data||i.result,requestId:i.requestId,timestamp:i.timestamp||Date.now()})}}catch(i){ge.error("Error handling message:",i)}}handleNotification(e){ge.debug("bridge notification received:",e);const t=this.eventHandlers.get(e.type);t&&t.forEach(t=>{try{t(e.data)}catch(i){ge.error(`Error in ${e.type} handler:`,i)}})}prepareMessage(e,t){return{payload:t,type:e,requestId:this.generateRequestId(),timestamp:Date.now()}}generateRequestId(){return`bridge_${Date.now()}_${Math.random().toString(36).substring(2,9)}`}createSDKErrorFromGatewayResponse(e,t){const i=this.mapGatewayErrorCodeToSDK(e.code);return new D(e.message,i,{operation:t,gatewayErrorCode:e.code,gatewayErrorMessage:e.message})}mapGatewayErrorCodeToSDK(e){switch(e){case ae:case ce:case le:case de:return E.INVALID_PARAMETER;case ne:return E.TIMEOUT;case re:return E.NOT_SUPPORTED;case se:return E.COMMUNICATION_ERROR;case oe:return E.INVALID_ARGUMENTS;default:return E.UNKNOWN}}getOperationFromMessageType(e){switch(e){case Z.LAUNCH_APP_REQUEST:return"launchApp";case Z.DEVICE_INFO_REQUEST:return"getDeviceInfo";case Z.TTS_REQUEST_START_SPEAKING:return"startSpeaking";case Z.TTS_REQUEST_STOP_SPEAKING:return"stopSpeaking";case Z.TTS_REQUEST_SETTINGS:return"getTTSSettings";default:return"sdkOperation"}}async setupIframe(e,t){if(!this.iframe&&this.src){if(await new Promise(e=>{"undefined"!=typeof document&&"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>e(),{once:!0}):e()}),this.iframe=document.createElement("iframe"),this.iframe.style.display="none",this.iframe.src=this.src,this.iframe.setAttribute("sandbox","allow-scripts"),!y())try{await function(e=1e4){return new Promise((t,i)=>{if(y())return void t();const n=Date.now();let r=0,o="initial";S.debug("Waiting for document.body:",{readyState:document.readyState,bodyExists:!!document.body,htmlExists:!!document.documentElement,headExists:!!document.head,timeout:e});let s=null,a=null,c=null;const l=[];function d(){a&&(clearInterval(a),a=null),s&&(s.disconnect(),s=null),c&&(clearTimeout(c),c=null),l.forEach(clearTimeout),l.length=0}const u=(e,t)=>{if(o!==e){const i=Date.now()-n;S.debug(`DOM strategy changed: ${o} → ${e}`,{elapsed:i,reason:t||"strategy switch",checkCount:r}),o=e}},g=(e,t="warn")=>{const i=Date.now()-n,o=Math.floor(i/6e4),s=Math.floor(i%6e4/1e3);"error"===t?S.error(`${e} after ${o}m ${s}s`,{elapsed:i,checkCount:r,readyState:document.readyState,bodyExists:!!document.body}):S.warn(`${e} after ${o}m ${s}s`,{elapsed:i,checkCount:r,readyState:document.readyState})},h=e=>{u("mutation-observer","DOMContentLoaded completed but body not ready"),s=new MutationObserver(()=>{r++;const e=Date.now()-n;y()&&(d(),S.debug("document.body ready via MutationObserver:",{elapsed:e,checkCount:r}),t())}),s.observe(document.documentElement,{childList:!0,subtree:!1}),c=setTimeout(()=>{y()||(g("DOM still not ready, switching to polling fallback"),u("polling","MutationObserver timeout"),a=setInterval(()=>{r++;const e=Date.now()-n;y()&&(d(),S.debug("document.body ready via polling fallback:",{elapsed:e,checkCount:r}),t())},50))},3e4)};if("loading"===document.readyState){u("dom-content-loaded","document still loading");const o=()=>{var e;clearTimeout(s);const i=Date.now()-n;y()?(d(),S.debug("document.body ready after DOMContentLoaded:",{elapsed:i}),t()):(S.warn("DOMContentLoaded fired but body still not ready:",{elapsed:i,childNodes:(null==(e=document.documentElement)?void 0:e.childNodes.length)||0}),h())},s=setTimeout(()=>{var e;document.removeEventListener("DOMContentLoaded",o),d();const t=Date.now()-n;S.error("Timeout waiting for document.body:",{elapsed:t,readyState:document.readyState,bodyExists:!!document.body,checkCount:r,html:!!document.documentElement,head:!!document.head,childNodesCount:(null==(e=document.documentElement)?void 0:e.childNodes.length)||0}),i(new Error(`Timeout waiting for document.body after ${t}ms. readyState: ${document.readyState}, checks: ${r}. Initialize SDK after DOMContentLoaded or use defer/async script.`))},e);document.addEventListener("DOMContentLoaded",o,{once:!0})}else S.debug("DOM already loaded, using MutationObserver + polling"),h();v.forEach(({time:t,message:i})=>{if(t<e){const e=setTimeout(()=>{y()||g(i)},t);l.push(e)}})})}(m)}catch(i){throw ge.error("Document body unavailable:",{readyState:document.readyState,bodyExists:!!document.body,timeout:10}),new Error("Document body is not available. SDK initialized too early - ensure DOM is ready before calling getTitanSDK(). Consider initializing SDK after DOMContentLoaded event or in a defer/async script.")}document.body.appendChild(this.iframe),await new Promise(i=>{const n=setTimeout(()=>{this.aborted||(ge.warn("Bridge iframe ready timeout - continuing anyway"),i())},this.iframeTimeout),r=t=>{var o;this.aborted||t.data&&t.data.type===Z.LAUNCHER_READY&&(null==(o=this.iframe)?void 0:o.contentWindow)===t.source&&(ge.debug("bridge iframe ready:",t.data),window.removeEventListener("message",r),clearTimeout(n),this.connected=!0,e&&e(),i())};window.addEventListener("message",r),window.addEventListener("message",e=>{var t;this.aborted||e.data&&e.data.type===Z.TRANSFER_DATA&&(null==(t=this.iframe)?void 0:t.contentWindow)===e.source&&ge.debug("bridge transferData:",e.data)}),this.iframe&&(this.iframe.onload=()=>{this.aborted||ge.debug("bridge iframe loaded: ",this.src)},this.iframe.onerror=()=>{this.aborted||(ge.error("bridge iframe error: ",this.src),t&&t())})})}}promisify(e){return(...t)=>new Promise((i,n)=>{try{i(e.apply(null,t))}catch(r){n(r)}})}async getDeviceInfo(){this.isInitialized||await this.initialize();const e=await this.sendMessage(Z.DEVICE_INFO_REQUEST,void 0);if(e.success&&"data"in e)return e.data}async launchApp(e){this.isInitialized||await this.initialize();const t={code:e.appId,query:e.deepLink||""};return(await this.sendMessage(Z.LAUNCH_APP_REQUEST,t)).success}onLogEntry(e){return this.registerEventHandler(Z.LOG_ENTRY,t=>{g({...t,metadata:{...t.metadata,source:"Gateway",tunneled:!0}}),e(t)})}}const pe=a("EnhancedBridge");function fe(e,t){if(!["frame-src","child-src","connect-src"].includes(e.directive)||!e.blockedURI||!t)return!1;const i=e.blockedURI,n=e=>e.replace(/\/+$/,"").toLowerCase(),r=n(i),o=n(t),s=e=>{try{return new URL(e).hostname}catch{const t=e.match(/^(?:https?:\/\/)?([^\/]+)/);return t?t[1]:""}},a=s(i),c=s(t);return o.includes(r)||r.includes(o)||a&&c&&a===c||i.includes("titanos.tv")&&t.includes("titanos.tv")||i.includes("localhost")&&t.includes("localhost")}class me extends he{bridgeHealthStatus={connected:!1,cspBlocked:!1,iframeCreated:!1,communicationWorking:!1,cspViolations:[]};cspUnsubscribe;cspViolationDetected=!1;cspViolationPromise;cspViolationResolver=null;constructor(e){super(e),this.bridgeHealthStatus.gatewayUrl=this.src,this.cspViolationPromise=new Promise(e=>{this.cspViolationResolver=e}),this.setupCspViolationListener()}setupCspViolationListener(){this.cspUnsubscribe=H.onViolation(e=>{if(pe.debug("CSP violation received in EnhancedBaseBridge:",{directive:e.directive,blockedURI:e.blockedURI,gatewayUrl:this.src,isBridgeViolation:fe(e,this.src)}),fe(e,this.src)){const t=`${e.directive}: ${e.blockedURI||"unknown"}`;this.bridgeHealthStatus.cspViolations.includes(t)||this.bridgeHealthStatus.cspViolations.push(t),pe.warn("CSP violation detected for bridge:",{directive:e.directive,blockedURI:e.blockedURI,gatewayUrl:this.src}),this.bridgeHealthStatus.cspBlocked=!0,this.bridgeHealthStatus.lastError=`CSP ${e.directive} blocked: ${e.blockedURI||"unknown"}`,!this.cspViolationDetected&&this.cspViolationResolver&&(this.cspViolationDetected=!0,pe.debug("Resolving CSP violation Promise"),this.cspViolationResolver(),this.cspViolationResolver=null)}})}async initialize(){try{pe.debug("Starting enhanced bridge initialization");const e=await super.initialize();return this.bridgeHealthStatus.connected=!!e,!!e}catch(e){const t=e instanceof Error?e.message:"Unknown error";return this.bridgeHealthStatus.lastError=t,pe.error("Enhanced bridge initialization failed:",e),!1}}getBridgeHealth(){return{...this.bridgeHealthStatus,connected:this.isConnected(),iframeCreated:null!==this.iframe}}disconnect(){this.aborted||(super.disconnect(),this.bridgeHealthStatus.connected=!1,this.bridgeHealthStatus.communicationWorking=!1,this.cspUnsubscribe&&(this.cspUnsubscribe(),this.cspUnsubscribe=void 0),this.cspViolationDetected=!1,this.cspViolationPromise=new Promise(e=>{this.cspViolationResolver=e}),this.bridgeHealthStatus={connected:!1,cspBlocked:!1,iframeCreated:!1,communicationWorking:!1,gatewayUrl:this.src,cspViolations:[]},this.aborted=!0)}async setupIframe(e,t){try{pe.debug("Setting up bridge iframe"),await super.setupIframe(e,t),this.bridgeHealthStatus.iframeCreated=!0}catch(i){this.bridgeHealthStatus.iframeCreated=!1;const e=i instanceof Error?i.message:"Unknown error";throw this.bridgeHealthStatus.lastError=e,pe.error("Failed to setup iframe:",{error:e,gatewayUrl:this.src,documentReady:document.readyState,bodyExists:!!document.body}),i}}async executeBridgeFunction(e,t){const i=this.getBridgeHealth();if(!i.connected){if(t)return pe.debug("Bridge not connected, using fallback function"),await t();throw new D("Bridge not connected",E.COMMUNICATION_ERROR,{healthStatus:i})}return await e()}async executeWithFallback(e,t){return await this.executeBridgeFunction(e,t)}async sendMessage(e,t){return await this.executeBridgeFunction(()=>super.sendMessage(e,t))}getConnectionResult(){const e=this.getBridgeHealth();return{success:e.connected&&!e.cspBlocked,healthStatus:e,error:e.lastError}}async waitForInitializationAttempt(){if(this.isConnected())return void pe.debug("Bridge already initialized, no need to wait");const e=this;if(e.initializationPromise){pe.debug("Bridge initialization in progress, waiting for completion...");try{await e.initializationPromise,pe.debug("Bridge initialization attempt completed")}catch{pe.debug("Bridge initialization attempt completed (with error)")}}else{pe.debug("No bridge initialization in progress, starting new attempt...");try{await this.initialize(),pe.debug("Bridge initialization attempt completed")}catch{pe.debug("Bridge initialization attempt completed (with error)")}}this.bridgeHealthStatus.iframeCreated&&!this.isConnected()&&(this.cspViolationDetected||this.bridgeHealthStatus.cspBlocked?pe.debug("CSP violation already detected, no need to wait"):(pe.debug("Iframe created but connection not established, waiting for CSP violation detection..."),await this.cspViolationPromise,pe.debug("CSP violation detection completed (or connection established)")))}}var ve,Se={exports:{}};var ye,be,we=(ve||(ve=1,ye=Se,be=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function r(e,t){if(!n[e]){n[e]={};for(var i=0;i<e.length;i++)n[e][e.charAt(i)]=i}return n[e][t]}var o={compressToBase64:function(e){if(null==e)return"";var i=o._compress(e,6,function(e){return t.charAt(e)});switch(i.length%4){default:case 0:return i;case 1:return i+"===";case 2:return i+"==";case 3:return i+"="}},decompressFromBase64:function(e){return null==e?"":""==e?null:o._decompress(e.length,32,function(i){return r(t,e.charAt(i))})},compressToUTF16:function(t){return null==t?"":o._compress(t,15,function(t){return e(t+32)})+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:o._decompress(e.length,16384,function(t){return e.charCodeAt(t)-32})},compressToUint8Array:function(e){for(var t=o.compress(e),i=new Uint8Array(2*t.length),n=0,r=t.length;n<r;n++){var s=t.charCodeAt(n);i[2*n]=s>>>8,i[2*n+1]=s%256}return i},decompressFromUint8Array:function(t){if(null==t)return o.decompress(t);for(var i=new Array(t.length/2),n=0,r=i.length;n<r;n++)i[n]=256*t[2*n]+t[2*n+1];var s=[];return i.forEach(function(t){s.push(e(t))}),o.decompress(s.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":o._compress(e,6,function(e){return i.charAt(e)})},decompressFromEncodedURIComponent:function(e){return null==e?"":""==e?null:(e=e.replace(/ /g,"+"),o._decompress(e.length,32,function(t){return r(i,e.charAt(t))}))},compress:function(t){return o._compress(t,16,function(t){return e(t)})},_compress:function(e,t,i){if(null==e)return"";var n,r,o,s={},a={},c="",l="",d="",u=2,g=3,h=2,p=[],f=0,m=0;for(o=0;o<e.length;o+=1)if(c=e.charAt(o),Object.prototype.hasOwnProperty.call(s,c)||(s[c]=g++,a[c]=!0),l=d+c,Object.prototype.hasOwnProperty.call(s,l))d=l;else{if(Object.prototype.hasOwnProperty.call(a,d)){if(d.charCodeAt(0)<256){for(n=0;n<h;n++)f<<=1,m==t-1?(m=0,p.push(i(f)),f=0):m++;for(r=d.charCodeAt(0),n=0;n<8;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}else{for(r=1,n=0;n<h;n++)f=f<<1|r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r=0;for(r=d.charCodeAt(0),n=0;n<16;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}0==--u&&(u=Math.pow(2,h),h++),delete a[d]}else for(r=s[d],n=0;n<h;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1;0==--u&&(u=Math.pow(2,h),h++),s[l]=g++,d=String(c)}if(""!==d){if(Object.prototype.hasOwnProperty.call(a,d)){if(d.charCodeAt(0)<256){for(n=0;n<h;n++)f<<=1,m==t-1?(m=0,p.push(i(f)),f=0):m++;for(r=d.charCodeAt(0),n=0;n<8;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}else{for(r=1,n=0;n<h;n++)f=f<<1|r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r=0;for(r=d.charCodeAt(0),n=0;n<16;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1}0==--u&&(u=Math.pow(2,h),h++),delete a[d]}else for(r=s[d],n=0;n<h;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1;0==--u&&(u=Math.pow(2,h),h++)}for(r=2,n=0;n<h;n++)f=f<<1|1&r,m==t-1?(m=0,p.push(i(f)),f=0):m++,r>>=1;for(;;){if(f<<=1,m==t-1){p.push(i(f));break}m++}return p.join("")},decompress:function(e){return null==e?"":""==e?null:o._decompress(e.length,32768,function(t){return e.charCodeAt(t)})},_decompress:function(t,i,n){var r,o,s,a,c,l,d,u=[],g=4,h=4,p=3,f="",m=[],v={val:n(0),position:i,index:1};for(r=0;r<3;r+=1)u[r]=r;for(s=0,c=Math.pow(2,2),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;switch(s){case 0:for(s=0,c=Math.pow(2,8),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;d=e(s);break;case 1:for(s=0,c=Math.pow(2,16),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;d=e(s);break;case 2:return""}for(u[3]=d,o=d,m.push(d);;){if(v.index>t)return"";for(s=0,c=Math.pow(2,p),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;switch(d=s){case 0:for(s=0,c=Math.pow(2,8),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;u[h++]=e(s),d=h-1,g--;break;case 1:for(s=0,c=Math.pow(2,16),l=1;l!=c;)a=v.val&v.position,v.position>>=1,0==v.position&&(v.position=i,v.val=n(v.index++)),s|=(a>0?1:0)*l,l<<=1;u[h++]=e(s),d=h-1,g--;break;case 2:return m.join("")}if(0==g&&(g=Math.pow(2,p),p++),u[d])f=u[d];else{if(d!==h)return null;f=o+o.charAt(0)}m.push(f),u[h++]=o+f.charAt(0),o=f,0==--g&&(g=Math.pow(2,p),p++)}}};return o}(),null!=ye?ye.exports=be:"undefined"!=typeof angular&&null!=angular&&angular.module("LZString",[]).factory("LZString",function(){return be})),Se.exports);const Te=a("TVPlatform");class Ie extends Y{DEFAULT_DEVICE_INFO={};bridge;isInitialized=!1;CACHE_KEY="titansdk";CACHE_EXPIRY=6048e5;constructor(e,t){if(super(e),null!=t)this.bridge=t;else if(null===t)this.waitReadyResolver(!0);else{const e={gatewayUrl:this.config.gatewayUrl};this.bridge=new me(e)}this.bridge&&this.initializeBridgeSafely()}async initializeBridgeSafely(){if(this.bridge){try{await this.bridge.initialize()&&(this.isInitialized=!0)}catch(e){Te.warn("Bridge initialization failed:",e)}this.waitReadyResolver(!0)}}getFromLocalStorage(){try{if("undefined"==typeof localStorage)return null;if(!localStorage.getItem)return null;const e=localStorage.getItem(this.CACHE_KEY);if(!e)return null;const t=JSON.parse(e);return Date.now()-t.timestamp>this.CACHE_EXPIRY||t.lastVersion!==I?(localStorage.removeItem(this.CACHE_KEY),null):(Te.debug("Device info loaded from localStorage cache"),t)}catch(e){return Te.warn("Failed to load device info from localStorage:",e),null}}getFromURL(){try{const i=new URLSearchParams(window.location.search).get("titandata");if(!i)return null;let n=null;const r=new h;try{n=we.decompressFromEncodedURIComponent(i),n&&Te.debug("Device info loaded from URL parameter (lz-string)")}catch(e){Te.debug("lz-string decompression failed, trying base64")}if(!n)try{const e=r.get("atob");if(!e)return Te.warn("atob function not available"),null;n=e(decodeURIComponent(i)),Te.debug("Device info loaded from URL parameter (base64)")}catch(t){return Te.warn("Both lz-string and base64 decoding failed"),null}if(!n)return Te.warn("Failed to decode URL parameter"),null;return JSON.parse(n)}catch(i){return Te.warn("Failed to load device info from URL parameter:",i),null}}saveToLocalStorage(e){try{if("undefined"==typeof localStorage)return;if(!(e&&e.deviceId&&e.brand&&e.model))return void Te.warn("Skipping cache save - invalid or empty device info");const t={data:e,timestamp:Date.now(),lastVersion:I};localStorage.setItem(this.CACHE_KEY,JSON.stringify(t)),Te.debug("Device info saved to localStorage cache")}catch(t){Te.warn("Failed to save device info to localStorage:",t)}}async getBaseDeviceInfo(){const e=this.getFromURL();if(e)return this.saveToLocalStorage(e),this.waitReadyResolver(!0),{deviceInfo:e,tts:ee,tm:te};if(!1!==this.config.useCache){const e=this.getFromLocalStorage();if(e)return this.waitReadyResolver(!0),{deviceInfo:e.data,tts:ee,tm:te}}else this.config.debug&&Te.debug("Debug mode: skipping cache, fetching fresh data from iframe");if(!this.bridge)return{deviceInfo:null,tts:ee,tm:te};try{return await this.waitReady,await this.bridge.executeWithFallback(async()=>{const e=await this.bridge.getDeviceInfo();if(!e)throw new Error("Failed to get device info");return e.deviceInfo&&this.saveToLocalStorage(e.deviceInfo),e},async()=>{Te.warn("Bridge unavailable, returning fallback device info");const e={deviceInfo:null,tts:ee,tm:te};return k("SDK_BRIDGE_FALLBACK","SDK","bridge.executeWithFallback",{reason:"bridge unavailable",platformId:this.getId(),isInitialized:this.isInitialized}),e})}catch(t){return Te.warn("Failed to get device info from bridge:",t),k("SDK_BRIDGE_FALLBACK","SDK","bridge.executeWithFallback",{reason:"bridge exception",platformId:this.getId(),isInitialized:this.isInitialized,error:t instanceof Error?t.message:String(t)}),{deviceInfo:null,tts:ee,tm:te}}}isTV(){return"undefined"!=typeof window&&(navigator.userAgent.includes("TV")||navigator.userAgent.includes("SmartTV")||navigator.userAgent.includes("SMART-TV")||window.location.href.includes("file://"))}}const Ee=new h,De=new h;function Ce(){const e=document.createElement("video");return e.canPlayType&&"function"==typeof e.canPlayType?{supportAppleHLS:""!==e.canPlayType("application/vnd.apple.mpegURL")||""!==e.canPlayType("audio/mpegurl"),supportMSSmoothStreaming:""!==e.canPlayType("application/vnd.ms-sstr+xml"),supportMSSInitiator:""!==e.canPlayType("application/vnd.ms-playready.initiator+xml"),supportMPEG_DASH:""!==e.canPlayType("application/dash+xml")||"unknown"}:{supportAppleHLS:!1,supportMSSmoothStreaming:!1,supportMSSInitiator:!1,supportMPEG_DASH:"unknown"}}function Ae(){try{if(void 0!==Ee.get("oipfObjectFactory"))return{supportOIPF:!0};const e=document.createElement("object");e.type="application/oipfdrmagent";return"function"==typeof e.sendDRMMessage?{supportOIPF:!0}:{supportOIPF:!1}}catch(e){return{supportOIPF:!1}}}function Re(){try{const e=(new h).get("navigator"),t=void 0!==e&&"function"==typeof e.requestMediaKeySystemAccess,i=De.has("MSMediaKeys");return{supportWebSocket:De.has("WebSocket"),supportEME:t||i,hasStorage:De.has("localStorage")&&De.has("sessionStorage")}}catch(e){return{supportWebSocket:!1,supportEME:!1,hasStorage:!1}}}const Pe=new h;function Me(){let e="";e=function(){try{const e=document.createElement("object");e.type="application/oipfdrmagent";return"function"==typeof e.sendDRMMessage?"OIPF":""}catch(e){return""}}();try{const t=Pe.has("MediaKeys"),i=Pe.has("WebKitMediaKeys"),n=Pe.has("MSMediaKeys");return e=t||i||n?"EME":e,{drmMethod:e}}catch(t){return{drmMethod:""}}}function ke(){try{const e=Pe.has("MediaKeys"),t=Pe.has("WebKitMediaKeys"),i=Pe.has("MSMediaKeys");return{supportEME:e||t||i}}catch(e){return{supportEME:!1}}}const Oe=a("PhilipsCapabilities");async function _e(e){const t=function(){try{const e={support3d:!1,supportKeyNumeric:!1,supportKeyColor:!1,supportMultiscreen:!1,supportUHD:!1,supportFHD:!0,supportHDR_HDR10:!1,supportHDR_DV:!1,supportHDR_HLG:!1,supportHDR_HDR10Plus:!1,supportHDR:"unknown",supportMultiAudio:!1,supportTTMLInband:!1,supportTTMLOutofband:!1,supportAdobeHDS:!1,supportWidevineClassic:!1,supportDolbyAtmos:"unknown"},t=Ne.get("ols3DSupport");t&&t()&&(e.support3d=!0);const i=Ne.get("olsAtmosSupport");i&&"function"==typeof i&&i()?e.supportDolbyAtmos=!0:e.supportDolbyAtmos=!1,e.supportKeyNumeric=!0,e.supportKeyColor=!0,e.supportMultiscreen=!1,e.supportMultiAudio=!0,e.supportTTMLInband=!0,e.supportTTMLOutofband=!0,e.supportFHD=!0;const n=Ne.get("olsUHD");n&&n()&&(e.supportUHD=n(),e.supportHDR_HDR10Plus=!0),e.supportHDR_HDR10=!0,e.supportHDR_HLG=!0;const r=Ne.get("olsDVSupport");return r&&r()&&(e.supportHDR_DV=!0),e.supportHDR=e.supportHDR_HDR10||e.supportHDR_DV||e.supportHDR_HLG||e.supportHDR_HDR10Plus||!1,e}catch(e){return Oe.error("Error detecting SmartTV API capabilities:",e),{support3d:!1,supportKeyNumeric:!1,supportKeyColor:!1,supportMultiscreen:!1,supportUHD:!1,supportFHD:!0,supportHDR_HDR10:!1,supportHDR_DV:!1,supportHDR_HLG:!1,supportHDR_HDR10Plus:!1,supportMultiAudio:!1,supportTTMLInband:!1,supportTTMLOutofband:!1,supportAdobeHDS:!1,supportHDR:"unknown",supportWidevineClassic:!1,supportDolbyAtmos:"unknown"}}}();return{os:"Linux",browserEngine:"Blink",...t,...Re(),...Ce(),...Me(),...ke(),...Ae(),supportFairplay:!1,supportPrimetime:!1,supportClearKey:!0,supportPlayready:!0,supportWidevineModular:!0,supportWidevineClassic:!0}}const Ne=new h;const Le=a("PhilipsCompat");class Fe extends Ie{deviceInfo=null;deviceInfoPromise=null;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"TPV",brand:"Philips"},Product:{platform:"TitanOS",year:"2025",deviceID:"philips-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:f(),language:"en"}};constructor(e,t){super(e,t)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent.toLowerCase();return["philips","saphi","nettv","tpvision"].some(t=>e.includes(t))}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product},i=this.formatBridgeResponse(e,t),n=(i.Product.platform,await _e());return{...i,Capability:n}}catch(e){throw Le.error("Error getting device info:",e),e}}formatBridgeResponse(e,t){if(!e.deviceInfo)return t;let i=e.deviceInfo.platformName;e.deviceInfo.profileId&&(i=(e.deviceInfo.profileId.split("_")[1]||i).replace(/\d+$/,""));return t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country,t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=i,t.Product.language=e.deviceInfo.language,t.Product.mac=e.deviceInfo.mac,t.Product.mac||k("SDK_BRIDGE_NO_MAC","SDK","formatBridgeResponse",{deviceInfo:e.deviceInfo}),t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.year=e.deviceInfo.year||"",t.Product.firmwareComponentID=i||"",t}getPriority(){return 100}getId(){return"philips"}}class He extends Fe{DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"TPV",brand:"AOC"},Product:{platform:"TitanOS",year:"2026",deviceID:"aoc-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:f(),language:"en"}};constructor(e,t){super(e,t)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent.toLowerCase();return/\(aoc,\s*[^)]+\)/i.test(e)}getId(){return"aoc"}}const xe=new h;class Ue extends me{constructor(e){var t,i;if(null==e?void 0:e.gatewayUrl)super({gatewayUrl:e.gatewayUrl});else{let e="app";if(xe.proxy.jwt&&!xe.proxy.jwt.includes("null")){const t=(e=>{const t=e.split(".");if(3!==t.length)throw new Error("Invalid JWT token format");try{const e=t[1].replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(e),n=decodeURIComponent(Array.from(i).map(e=>"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)).join(""));return JSON.parse(n)}catch(i){throw new Error("Error decoding JWT token: "+(i instanceof Error?i.message:String(i)))}})(xe.proxy.jwt);e=("production"===t.iss?"app":t.iss)||"app"}let n=`https://${e}.titanos.tv/gateway/${e.startsWith("dev")?"dev01":"index"}.html`;((null==(i=null==(t=xe.proxy.location)?void 0:t.host)?void 0:i.includes("dev01.devview"))||e.startsWith("dev"))&&(n="https://dev01.devview.titanos.tv/gateway/dev01.html"),super({gatewayUrl:n})}}async getTTSSettings(){return(await this.getA11ySettings()).tts||ee}async getTMSettings(){return(await this.getA11ySettings()).tm||te}async getA11ySettings(){const e=await this.sendMessage(Z.TTS_REQUEST_SETTINGS,void 0);return e.success&&"data"in e?e.data:ie}async startSpeaking(e){this.isInitialized||await this.initialize();return(await this.sendMessage(Z.TTS_REQUEST_START_SPEAKING,e)).success}async stopSpeaking(){return(await this.sendMessage(Z.TTS_REQUEST_STOP_SPEAKING,void 0)).success}onTTSSettingsChange(e){return this.registerEventHandler(Z.TTS_SETTINGS_CHANGE,t=>{e(t)})}onTMSettingsChange(e){return this.registerEventHandler(Z.TM_SETTINGS_CHANGE,t=>{e(t)})}}const Ve={HIGH:["button","link","heading","listitem"],MEDIUM:["textbox","combobox","checkbox","radio","slider"],LOW:["list","navigation","main","dialog","grid"]},Ke=a("AriaProcessor");class Be{config;implicitRoles={button:"button",a:"link",'input[type="text"]':"textbox",'input[type="email"]':"textbox",'input[type="password"]':"textbox",'input[type="search"]':"textbox",'input[type="tel"]':"textbox",'input[type="url"]':"textbox",'input[type="checkbox"]':"checkbox",'input[type="radio"]':"radio",'input[type="range"]':"slider",textarea:"textbox",select:"combobox",h1:"heading",h2:"heading",h3:"heading",h4:"heading",h5:"heading",h6:"heading",nav:"navigation",main:"main",aside:"complementary",section:"region",article:"article",ul:"list",ol:"list",li:"listitem",table:"table",tr:"row",td:"cell",th:"columnheader",img:"img",dialog:"dialog"};tvElementTypes={navigation:["nav","menu",'[role="navigation"]','[role="menubar"]'],mediaControl:['[role="button"][aria-label*="play"]','[role="button"][aria-label*="pause"]','[role="slider"][aria-label*="volume"]','[role="progressbar"]'],contentGrid:['[role="grid"]','[role="gridcell"]',".content-grid",".video-grid"],mainContent:["main",'[role="main"]',".main-content","#main"]};constructor(e){this.config={...e}}updateConfig(e){this.config={...e}}async processElement(e){try{if(this.isElementHidden(e))return null;const t=this.getElementRole(e);if(this.config.tvOptimized&&!this.isRelevantForTV(t))return null;const i=this.computeAccessibleName(e);if(!i&&this.isInteractiveElement(t))return Ke.warn("Interactive element without accessible name:",e),null;const n=this.getAccessibleDescription(e),r=this.computeElementState(e),o=this.computePositionInfo(e,t),s=this.getAvailableActions(e,t),a=this.config.tvOptimized?this.getTVSpecificProperties(e,t):void 0,c={element:e,role:t,name:i,description:n,state:r,position:o,actions:s,tvProperties:a};return Ke.debug("Processed accessibility element:",{role:t,name:i.substring(0,50),state:r,tvOptimized:!!a}),c}catch(t){return Ke.error("Error processing element:",t),null}}isElementHidden(e){if("true"===e.getAttribute("aria-hidden"))return!0;const t=window.getComputedStyle(e);if("none"===t.display||"hidden"===t.visibility||"0"===t.opacity)return!0;if(this.config.tvOptimized){const t=e.getBoundingClientRect();if(0===t.width&&0===t.height)return!0}return!1}getElementRole(e){const t=e.getAttribute("role");if(t)return t;const i=e.tagName.toLowerCase(),n=e.getAttribute("type");if("input"===i&&n){const e=`input[type="${n}"]`;if(this.implicitRoles[e])return this.implicitRoles[e]}return this.implicitRoles[i]||"generic"}computeAccessibleName(e){const t=e.getAttribute("aria-labelledby");if(t){const e=[];for(const i of t.split(/\s+/)){const t=document.getElementById(i);t&&e.push(this.getTextContent(t))}if(e.length>0)return e.join(" ").trim()}const i=e.getAttribute("aria-label");if(i)return i.trim();if(this.isFormControl(e)){const t=this.getAssociatedLabels(e);if(t.length>0)return t.map(e=>this.getTextContent(e)).join(" ").trim()}if("input"===e.tagName.toLowerCase()){const t=e.getAttribute("placeholder");if(t)return t.trim()}if("img"===e.tagName.toLowerCase()){const t=e.getAttribute("alt");if(null!==t)return t.trim()}return this.getTextContent(e)}getAccessibleDescription(e){const t=e.getAttribute("aria-describedby");if(!t)return;const i=[];for(const n of t.split(/\s+/)){const e=document.getElementById(n);e&&i.push(this.getTextContent(e))}return i.length>0?i.join(" ").trim():void 0}computeElementState(e){const t={},i=e.getAttribute("aria-expanded");null!==i&&(t.expanded="true"===i);const n=e.getAttribute("aria-checked");null!==n&&(t.checked="mixed"===n?"mixed":"true"===n);const r=e.getAttribute("aria-selected");null!==r&&(t.selected="true"===r);const o=e.getAttribute("aria-disabled")||e.getAttribute("disabled");null!==o&&(t.disabled="true"===o||""===o);const s=e.getAttribute("aria-invalid");null!==s&&(t.invalid="true"===s||s);const a=e.getAttribute("aria-level");null!==a?t.level=parseInt(a,10):e.tagName.match(/^H[1-6]$/)&&(t.level=parseInt(e.tagName.charAt(1),10));const c=e.getAttribute("aria-valuenow");null!==c&&(t.valueNow=parseFloat(c));const l=e.getAttribute("aria-valuetext");return null!==l&&(t.valueText=l),t.focused=document.activeElement===e,t}computePositionInfo(e,t){return"listitem"===t?this.computeListItemPosition(e):"gridcell"===t||"cell"===t?this.computeGridCellPosition(e):void 0}computeListItemPosition(e){const t=e.getAttribute("aria-posinset"),i=e.getAttribute("aria-setsize");if(t&&i)return{position:parseInt(t,10),setSize:parseInt(i,10)};const n=e.closest('ul, ol, [role="list"]');if(n){const t=Array.from(n.querySelectorAll('li, [role="listitem"]')),i=t.indexOf(e)+1;if(i>0)return{position:i,setSize:t.length}}}computeGridCellPosition(e){const t=e.closest('[role="row"], tr'),i=e.closest('[role="grid"], table');if(t&&i){const n=Array.from(i.querySelectorAll('[role="row"], tr')),r=Array.from(t.querySelectorAll('[role="gridcell"], [role="cell"], td, th')),o=n.indexOf(t)+1,s=r.indexOf(e)+1;if(o>0&&s>0)return{position:s,setSize:r.length,row:o,column:s,totalRows:n.length,totalColumns:r.length}}}getAvailableActions(e,t){const i=[];if(this.isClickableElement(e,t)&&i.push({name:"activate",description:this.getActivationDescription(t),tvButton:"OK"}),e.hasAttribute("aria-expanded")){const t="true"===e.getAttribute("aria-expanded");i.push({name:t?"collapse":"expand",description:t?"Collapse":"Expand",tvButton:"OK"})}return"textbox"!==t&&"combobox"!==t||i.push({name:"edit",description:"Enter text",tvButton:"OK"}),i}getTVSpecificProperties(e,t){const i={};return this.matchesSelectors(e,this.tvElementTypes.navigation)&&(i.isMainNavigation=!0,i.priority="high"),this.matchesSelectors(e,this.tvElementTypes.mediaControl)&&(i.isMediaControl=!0,i.priority="high"),this.matchesSelectors(e,this.tvElementTypes.contentGrid)&&(i.isContentGrid=!0,i.priority="medium"),i.priority||(Ve.HIGH.includes(t)?i.priority="high":Ve.MEDIUM.includes(t)?i.priority="medium":i.priority="low"),Object.keys(i).length>0?i:void 0}isRelevantForTV(e){return[...Ve.HIGH,...Ve.MEDIUM,...Ve.LOW].includes(e)}isInteractiveElement(e){return["button","link","textbox","combobox","checkbox","radio","slider"].includes(e)}isFormControl(e){return["input","textarea","select","button"].includes(e.tagName.toLowerCase())}isClickableElement(e,t){return["button","link","checkbox","radio","menuitem"].includes(t)||e.hasAttribute("onclick")}getActivationDescription(e){return{button:"Press button",link:"Follow link",checkbox:"Toggle checkbox",radio:"Select option",menuitem:"Select menu item"}[e]||"Activate"}getTextContent(e){let t="";for(const i of e.childNodes)if(i.nodeType===Node.TEXT_NODE)t+=i.textContent||"";else if(i.nodeType===Node.ELEMENT_NODE){const e=i;this.isElementHidden(e)||(t+=this.getTextContent(e))}return t.replace(/\s+/g," ").trim()}getAssociatedLabels(e){const t=[],i=e.getAttribute("id");if(i){const e=document.querySelectorAll(`label[for="${i}"]`);t.push(...Array.from(e))}const n=e.closest("label");return n&&t.push(n),t}matchesSelectors(e,t){return t.some(t=>{try{return e.matches(t)}catch{return!1}})}}const ze=a("DOMMonitor");class $e{config;ariaProcessor;isTracking=!1;focusHandler;liveRegionHandler;focusListener;keydownListener;mutationObserver;currentFocusedElement=null;liveRegions=new Map;previousFocusedElement=null;constructor(e,t){this.config={...e},this.focusHandler=t,this.ariaProcessor=new Be(e)}updateConfig(e){this.config={...e},this.ariaProcessor.updateConfig(e)}async startFocusTracking(){if(this.isTracking)return void ze.debug("Focus tracking already active");ze.info("Starting focus tracking"),this.focusListener=this.handleFocusEvent.bind(this),document.addEventListener("focusin",this.focusListener,!0),document.addEventListener("focusout",this.focusListener,!0),this.keydownListener=this.handleKeydownEvent.bind(this),document.addEventListener("keydown",this.keydownListener,!0);const e=document.activeElement;e&&e!==document.body&&(this.currentFocusedElement=e,await this.processFocusChange(e,"initial")),this.isTracking=!0,ze.info("Focus tracking started")}async startLiveRegionMonitoring(e){this.liveRegionHandler=e,ze.info("Starting live region monitoring"),await this.scanForLiveRegions(),this.mutationObserver=new MutationObserver(this.handleMutations.bind(this)),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["aria-live","aria-atomic","aria-relevant","aria-busy"]}),ze.info("Live region monitoring started")}async stop(){ze.info("Stopping DOM monitoring"),this.focusListener&&(document.removeEventListener("focusin",this.focusListener,!0),document.removeEventListener("focusout",this.focusListener,!0),this.focusListener=void 0),this.keydownListener&&(document.removeEventListener("keydown",this.keydownListener,!0),this.keydownListener=void 0),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=void 0),this.currentFocusedElement=null,this.previousFocusedElement=null,this.liveRegions.clear(),this.isTracking=!1,this.liveRegionHandler=void 0,ze.info("DOM monitoring stopped")}async restart(){await this.stop(),this.config.focusTracking&&await this.startFocusTracking(),this.config.liveRegions&&this.liveRegionHandler&&await this.startLiveRegionMonitoring(this.liveRegionHandler)}async handleFocusEvent(e){try{const t=e.target;"focusin"===e.type?t&&t!==this.currentFocusedElement&&(this.currentFocusedElement=t,await this.processFocusChange(t,"user")):"focusout"===e.type&&t===this.currentFocusedElement&&(this.currentFocusedElement=null)}catch(t){ze.error("Error handling focus event:",t)}}async handleKeydownEvent(e){const t={ArrowUp:"UP",ArrowDown:"DOWN",ArrowLeft:"LEFT",ArrowRight:"RIGHT",Enter:"OK",Escape:"BACK",Tab:"TAB"}[e.key];t&&this.currentFocusedElement&&ze.debug("TV remote button pressed:",t)}async processFocusChange(e,t){try{if(this.ariaProcessor.isElementHidden(e))return;const i=await this.ariaProcessor.processElement(e);if(i&&this.focusHandler){const e={previousElement:this.previousFocusedElement||void 0,currentElement:i,reason:t};await this.focusHandler(e),this.previousFocusedElement=i}}catch(i){ze.error("Error processing focus change:",i)}}async scanForLiveRegions(){const e=document.querySelectorAll("[aria-live]");for(const t of e){const e=this.createLiveRegion(t);e&&(this.liveRegions.set(t,e),ze.debug("Found live region:",{politeness:e.politeness,atomic:e.atomic}))}}createLiveRegion(e){const t=e.getAttribute("aria-live");if(!t||"off"===t)return null;const i=t,n="true"===e.getAttribute("aria-atomic"),r=(e.getAttribute("aria-relevant")||"additions text").split(" "),o="true"===e.getAttribute("aria-busy");return{element:e,politeness:i,atomic:n,relevant:r,busy:o}}async handleMutations(e){for(const i of e)try{"attributes"===i.type&&await this.handleAttributeChange(i),"childList"!==i.type&&"characterData"!==i.type||await this.handleContentChange(i)}catch(t){ze.error("Error handling mutation:",t)}}async handleAttributeChange(e){const t=e.target,i=e.attributeName;if("aria-live"===i){const e=this.createLiveRegion(t);e?this.liveRegions.set(t,e):this.liveRegions.delete(t)}else if("aria-busy"===i){const e=this.liveRegions.get(t);e&&(e.busy="true"===t.getAttribute("aria-busy"))}}async handleContentChange(e){let t=e.target;for(;t&&t!==document.body;){const i=this.liveRegions.get(t);if(i&&!i.busy&&this.liveRegionHandler){const n=i.atomic?t.textContent||"":this.extractChangedContent(e);n.trim()&&await this.liveRegionHandler(i,n);break}t=t.parentElement}}extractChangedContent(e){if("characterData"===e.type)return e.target.textContent||"";if("childList"===e.type){let t="";for(const i of e.addedNodes)(i.nodeType===Node.TEXT_NODE||i.nodeType===Node.ELEMENT_NODE)&&(t+=i.textContent||"");return t}return""}}const Ge=a("AnnouncementProcessor");class je{config;ttsFunction;stopTtsFunction;lastAnnouncementTime=0;announcementQueue=[];isProcessingQueue=!1;tvTimings={minInterval:100,maxQueueSize:5,priorityDelay:50,politeDelay:200};constructor(e,t,i){this.config={...e},this.ttsFunction=t,this.stopTtsFunction=i}updateConfig(e){this.config={...e}}async announce(e,t="polite"){const i=this.processAnnouncementText(e);if(!i||0===i.length)return Ge.debug("No text to announce after processing"),!1;const n={text:i,priority:t,timestamp:Date.now()};return"assertive"===t?(this.announcementQueue.length=0,await this.speakNow(n)):(this.queueAnnouncement(n),this.processQueue(),!0)}async stopAnnouncement(){try{if(this.announcementQueue.length=0,this.isProcessingQueue=!1,this.stopTtsFunction){const e=await this.stopTtsFunction();return Ge.debug("TTS stop result:",e),e}return Ge.debug("No stopTtsFunction available"),!0}catch(e){return Ge.error("Error stopping announcement:",e),!1}}async announceFocusChange(e){const{currentElement:t}=e;if(!t)return;const i=this.buildFocusAnnouncement(t);i.length>0&&await this.announce(i,"polite")}async announceLiveRegion(e,t){if(!e.trim())return;const i=this.processLiveRegionContent(e);i&&await this.announce([i],t)}buildFocusAnnouncement(e){const t=[],i=this.getRoleAnnouncement(e.role);i&&t.push(i),e.name&&t.push(e.name);const n=this.getStateAnnouncement(e.state,e.role);n.length>0&&t.push(...n);const r=this.getPositionAnnouncement(e.position,e.role);r&&t.push(r),e.description&&this.shouldIncludeDescription()&&t.push(e.description);const o=this.getActionAnnouncement(e.actions||[]);return o&&t.push(o),this.filterAnnouncementContent(t,e.role)}shouldIncludeDescription(){return"concise"!==this.config.verbosity&&(this.config.verbosity,!0)}filterAnnouncementContent(e,t){if(!this.config.tvOptimized)return e;const i=["button","link","heading","alert","dialog"].includes(t);return"concise"===this.config.verbosity?i?e.slice(0,2):e.slice(1,2):"standard"===this.config.verbosity?e.slice(0,4):e}getRoleAnnouncement(e){const t={button:{concise:"",standard:"button",detailed:"button"},link:{concise:"",standard:"link",detailed:"link"},heading:{concise:"",standard:"heading",detailed:"heading"},listitem:{concise:"",standard:"list item",detailed:"list item"},textbox:{concise:"",standard:"text field",detailed:"text field"},combobox:{concise:"",standard:"dropdown",detailed:"combo box"},checkbox:{concise:"check box",standard:"check box",detailed:"check box"},radio:{concise:"radio",standard:"radio button",detailed:"radio button"},slider:{concise:"slider",standard:"slider",detailed:"slider"},navigation:{concise:"",standard:"navigation",detailed:"navigation menu"},main:{concise:"",standard:"main content",detailed:"main content area"},dialog:{concise:"dialog",standard:"dialog",detailed:"dialog box"},grid:{concise:"",standard:"grid",detailed:"content grid"},gridcell:{concise:"",standard:"",detailed:"grid cell"},list:{concise:"",standard:"list",detailed:"list"},menu:{concise:"menu",standard:"menu",detailed:"menu"},menuitem:{concise:"",standard:"menu item",detailed:"menu item"},tab:{concise:"tab",standard:"tab",detailed:"tab"},tabpanel:{concise:"",standard:"tab panel",detailed:"tab panel"},progressbar:{concise:"progress",standard:"progress bar",detailed:"progress indicator"},alert:{concise:"alert",standard:"alert",detailed:"alert message"},status:{concise:"",standard:"status",detailed:"status update"}}[e];if(!t)return null;return t[this.config.verbosity]||t.standard||null}getStateAnnouncement(e,t){const i=[];if(!e)return i;const n="concise"===this.config.verbosity,r="detailed"===this.config.verbosity;if(void 0!==e.expanded&&(n?i.push(e.expanded?"open":"closed"):i.push(e.expanded?"expanded":"collapsed")),void 0!==e.checked&&("mixed"===e.checked?i.push(n?"mixed":"partially checked"):n?i.push(e.checked?"on":"off"):i.push(e.checked?"checked":"not checked")),e.selected&&i.push(n?"on":"selected"),e.disabled&&i.push("disabled"),e.invalid&&(r?i.push("string"==typeof e.invalid?e.invalid:"invalid"):i.push("invalid")),"heading"===t&&e.level&&(n?i.push(`h${e.level}`):i.push(`level ${e.level}`)),e.valueText)i.push(e.valueText);else if(void 0!==e.valueNow)if("progressbar"===t){const t=e.valueMax?Math.round(e.valueNow/e.valueMax*100):e.valueNow;i.push(n?`${t}%`:`${t} percent`)}else"slider"===t?i.push(n?`${e.valueNow}`:`value ${e.valueNow}`):i.push(`${e.valueNow}`);return this.config.tvOptimized&&e.focused&&r&&i.push("focused"),i}getPositionAnnouncement(e,t){if(!e)return null;const i="concise"===this.config.verbosity,n="detailed"===this.config.verbosity;return"listitem"===t?i?null:`${e.position} of ${e.setSize}`:"gridcell"===t&&e.row&&e.column?this.config.tvOptimized?i?`${e.row},${e.column}`:n&&e.totalRows&&e.totalColumns?`row ${e.row} of ${e.totalRows}, column ${e.column} of ${e.totalColumns}`:`row ${e.row}, column ${e.column}`:`row ${e.row}, column ${e.column}`:"tab"===t&&e.position&&e.setSize?i?null:`tab ${e.position} of ${e.setSize}`:"menuitem"===t&&e.position&&e.setSize?i?null:`${e.position} of ${e.setSize}`:null}getActionAnnouncement(e){if(!e||0===e.length)return null;const t="concise"===this.config.verbosity,i="detailed"===this.config.verbosity;if(!this.config.tvOptimized){return`available actions: ${e.map(e=>e.name).slice(0,2).join(", ")}`}const n=e[0];if(!n)return null;if(n.tvButton){if(t)return null;const e=this.getTVButtonText(n.tvButton),r=n.description||"activate";return i?`press ${e} to ${r.toLowerCase()}`:`press ${e}`}if(n.name){if(t)return null;const e=this.getCommonTVAction(n.name);if(e)return i?`available actions: ${e}`:e}return null}getTVButtonText(e){return{OK:"OK",BACK:"Back",UP:"Up",DOWN:"Down",LEFT:"Left",RIGHT:"Right",MENU:"Menu"}[e]||e}getCommonTVAction(e){return{activate:"activate",click:"select",toggle:"toggle",expand:"expand",collapse:"collapse",select:"select",play:"play",pause:"pause",stop:"stop",mute:"mute",unmute:"unmute"}[e.toLowerCase()]||null}processAnnouncementText(e){if(!e)return[];if("string"==typeof e&&(e=[e]),!Array.isArray(e))return[];let t=[...e];return this.config.tvOptimized&&(t=this.applyTVOptimizations(t)),t=this.applyVerbosityFilter(t),t=t.map(e=>e.trim()).filter(e=>e.length>0).map(e=>this.cleanupText(e)),t}applyTVOptimizations(e){return e.map(e=>{let t=e.replace(/\bnavigation\b/gi,"nav").replace(/\bmenuitem\b/gi,"menu").replace(/\btextbox\b/gi,"text field").replace(/\bcombobox\b/gi,"dropdown").replace(/\bcheckbox\b/gi,"check box");return t=t.replace(/\bapplication\b/gi,"").replace(/\bregion\b/gi,"").replace(/\blandmark\b/gi,""),t.trim()})}applyVerbosityFilter(e){switch(this.config.verbosity){case"concise":return e.slice(0,2);case"detailed":return e;default:return e.slice(0,4)}}cleanupText(e){return e.replace(/\s+/g," ").replace(/[_-]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").trim()}processLiveRegionContent(e){const t=this.cleanupText(e);return t.length<3||/^\s*[.!?]*\s*$/.test(t)?null:this.config.tvOptimized?this.applyTVOptimizations([t])[0]:t}queueAnnouncement(e){this.announcementQueue.length>=this.tvTimings.maxQueueSize&&this.announcementQueue.shift(),this.announcementQueue.push(e)}async processQueue(){if(!this.isProcessingQueue&&0!==this.announcementQueue.length){for(this.isProcessingQueue=!0;this.announcementQueue.length>0;){const e=this.announcementQueue.shift();if(e){await this.speakNow(e);const t="assertive"===e.priority?this.tvTimings.priorityDelay:this.tvTimings.politeDelay;await this.delay(t)}}this.isProcessingQueue=!1}}async speakNow(e){const t=Date.now()-this.lastAnnouncementTime;t<this.tvTimings.minInterval&&await this.delay(this.tvTimings.minInterval-t);try{const t=await this.ttsFunction(e.text);return this.lastAnnouncementTime=Date.now(),Ge.debug("Announced:",{text:e.text.join(" ").substring(0,100),priority:e.priority,success:t}),t}catch(i){return Ge.error("Error speaking announcement:",i),!1}}delay(e){return new Promise(t=>setTimeout(t,e))}}const We=a("AccessibilityReader");class qe{config;isActive=!1;domMonitor;ariaProcessor;announcementProcessor;currentElement=null;liveRegions=new Map;constructor(e,t,i){this.config={...e},this.ariaProcessor=new Be(e),this.announcementProcessor=new je(e,t,i),this.domMonitor=new $e(e,this.handleFocusChange.bind(this))}async start(){if(this.isActive)return We.debug("Accessibility Reader already active"),!0;try{We.info("Starting Accessibility Reader",this.config),this.config.focusTracking&&await this.domMonitor.startFocusTracking(),this.config.liveRegions&&await this.domMonitor.startLiveRegionMonitoring(this.handleLiveRegionChange.bind(this));const e=document.activeElement;return e&&e!==document.body&&await this.announceElement(e),this.isActive=!0,We.info("Accessibility Reader started successfully"),!0}catch(e){return We.error("Failed to start Accessibility Reader:",e),!1}}async stop(){if(!this.isActive)return We.debug("Accessibility Reader not active"),!0;try{return We.info("Stopping Accessibility Reader"),await this.domMonitor.stop(),this.currentElement=null,this.liveRegions.clear(),this.isActive=!1,We.info("Accessibility Reader stopped"),!0}catch(e){return We.error("Failed to stop Accessibility Reader:",e),!1}}async updateConfig(e){try{const t={...this.config};if(this.config={...this.config,...e},this.ariaProcessor.updateConfig(this.config),this.announcementProcessor.updateConfig(this.config),this.domMonitor.updateConfig(this.config),this.isActive){const e=t.focusTracking!==this.config.focusTracking,i=t.liveRegions!==this.config.liveRegions;(e||i)&&await this.domMonitor.restart()}return We.info("Accessibility Reader configuration updated",this.config),!0}catch(t){return We.error("Failed to update Accessibility Reader config:",t),!1}}getConfig(){return{...this.config}}isReaderActive(){return this.isActive}async announce(e,t="polite"){return this.isActive?await this.announcementProcessor.announce(e,t):(We.debug("Accessibility Reader not active, skipping announcement"),!1)}async stopAnnouncement(){return this.isActive?await this.announcementProcessor.stopAnnouncement():(We.debug("Accessibility Reader not active, skipping stop"),!1)}getCurrentElement(){return this.currentElement}async handleFocusChange(e){var t,i;try{We.debug("Focus changed",{from:null==(t=e.previousElement)?void 0:t.role,to:null==(i=e.currentElement)?void 0:i.role,reason:e.reason}),this.currentElement=e.currentElement||null,e.currentElement&&await this.announcementProcessor.announceFocusChange(e)}catch(n){We.error("Error handling focus change:",n)}}async handleLiveRegionChange(e,t){try{if(We.debug("Live region changed",{politeness:e.politeness,content:t.substring(0,100)}),e.busy)return;const i="assertive"===e.politeness?"assertive":"polite";await this.announcementProcessor.announceLiveRegion(t,i)}catch(i){We.error("Error handling live region change:",i)}}async announceElement(e){try{const t=await this.ariaProcessor.processElement(e);if(t){const e={previousElement:this.currentElement||void 0,currentElement:t,reason:"programmatic"};await this.handleFocusChange(e)}}catch(t){We.error("Error announcing element:",t)}}}const Qe=a("AccessibilityService");class Je{bridge;reader=null;ttsSettings=ee;tmSettings=te;constructor(e){this.bridge=e,this.bridge.onTTSSettingsChange(e=>{this.ttsSettings=e}),this.bridge.onTMSettingsChange(e=>{this.tmSettings=e})}async startSpeaking(e){if("string"==typeof e&&(e=[e]),await this.isTTSEnabled())try{return await this.bridge.startSpeaking(e)}catch(t){return Qe.error("Error starting speaking:",t),!1}return!0}async stopSpeaking(){if(await this.isTTSEnabled())try{return await this.bridge.stopSpeaking()}catch(e){return Qe.error("Error stopping speaking:",e),!1}return!0}async enableReader(e){try{if(!(await this.isTTSSupported()))return Qe.warn("Cannot enable Reader: TTS not supported"),!1;if(!(await this.isTTSEnabled()))return Qe.warn("Cannot enable Reader: TTS not enabled"),!1;this.reader=new qe(e,this.startSpeaking.bind(this),this.stopSpeaking.bind(this));return!!(await this.reader.start())&&(Qe.info("Reader enabled"),!0)}catch(t){return Qe.error("Error enabling Reader:",t),!1}}async disableReader(){try{if(this.reader){const e=await this.reader.stop();return this.reader=null,e&&Qe.info("Reader disabled"),e}return Qe.debug("Reader was not active"),!0}catch(e){return Qe.error("Error disabling Reader:",e),!1}}getReader(){if(!this.reader)throw new Error("Reader is not active");return this.reader}async isTTSSupported(){try{return(await this.getTTSSettings()).available}catch(e){return Qe.error("Error checking TTS support:",e),!1}}async isTextMagnificationSupported(){try{return(await this.getTMSettings()).available}catch(e){return Qe.error("Error checking magnification support:",e),!1}}onTTSSettingsChange(e){return this.bridge.onTTSSettingsChange(e)}onTMSettingsChange(e){return this.bridge.onTMSettingsChange(e)}async getTTSSettings(){try{const e=await this.bridge.getTTSSettings();return this.ttsSettings=e,e}catch(e){return Qe.error("Error getting TTS settings from bridge:",e),this.ttsSettings}}async getTMSettings(){try{const e=await this.bridge.getTMSettings();return this.tmSettings=e,e}catch(e){return Qe.error("Error getting TM settings from bridge:",e),this.tmSettings}}async isTTSEnabled(){return(await this.getTTSSettings()).enabled}async isTMEnabled(){return(await this.getTMSettings()).enabled}}const Ye=a("AOCDeviceInfoService");class Ze{platform;info;bridge;constructor(e,t){this.platform=new He(e,t),this.bridge=t,this.info=null}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw Ye.error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}const Xe=a("PhilipsAppControlService");class et{bridge;constructor(e){this.bridge=e}async launch(e,t){return await this.bridge.executeWithFallback(()=>this.bridge.launchApp({appId:e,deepLink:t}),async()=>(Xe.warn("Function unavailable, app launch failed gracefully",{appId:e,deepLink:t}),!1))}}const tt=e=>{const{available:t,...i}=e;if("scale"in i){const{enabled:e,scale:t}=i;return{enabled:e,...void 0!==t&&{scale:t}}}const{enabled:n}=i;return{enabled:n}};class it{subscribe(e,t){const i=c(e,t);return()=>{l(i)}}getHistory(){return d()}clear(){u()}}class nt{bridge;accessibilityService;deviceInfoService;appControlService;constructor(e,t,i,n){this.bridge=e,this.accessibilityService=t,this.deviceInfoService=i,this.appControlService=n}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>tt(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>tt(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>this.accessibilityService.onTTSSettingsChange(t=>{e(tt(t))}),onTMSettingsChange:e=>this.accessibilityService.onTMSettingsChange(t=>{e(tt(t))})};apps={launch:(e,t)=>this.appControlService.launch(e,t)};get logging(){return new it}get dev(){return{isBridgeConnected:async()=>{try{return this.bridge.isConnected()}catch(e){return!1}}}}}const rt=a("AOCSDK");class ot extends nt{constructor(e){const t=new Ue({gatewayUrl:null==e?void 0:e.gatewayUrl,debug:null==e?void 0:e.debug});super(t,new Je(t),new Ze(e,t),new et(t))}async init(){try{return await this.deviceInfo.getDeviceInfo(),await this.bridge.waitForInitializationAttempt(),this.bridge.isConnected()||rt.warn("Bridge initialization completed but bridge is not connected. Some features may not work correctly."),!0}catch(e){throw rt.error("TitanSDK initialization failed:",e),e}}}const st=a("ChromeTTS");class at{voices=[];currentVoice=null;settings={available:!0,enabled:!0,rate:1,volume:1};speechSynthesis;constructor(){const e=new h;this.speechSynthesis=e.get("speechSynthesis"),this.speechSynthesis&&(this.initVoices(),"onvoiceschanged"in this.speechSynthesis&&(this.speechSynthesis.onvoiceschanged=()=>{this.initVoices()}))}initVoices(){var e,t,i,n,r,o;if(!("speechSynthesis"in window))return;const s=null==(e=this.speechSynthesis)?void 0:e.getVoices();this.voices=null==s?void 0:s.map(e=>({voiceName:e.name,lang:e.lang,gender:e.name.toLowerCase().includes("female")?"female":"male",remote:!1===e.localService})),this.currentVoice=(null==(t=this.voices)?void 0:t.find(e=>"en-GB"===e.lang))||(null==(i=this.voices)?void 0:i.find(e=>e.lang.startsWith("en-")))||(null==(n=this.voices)?void 0:n[0]),st.info(`Initialized with ${null==(r=this.voices)?void 0:r.length} voices, using ${null==(o=this.currentVoice)?void 0:o.voiceName}`)}getTTSSettings(){return this.settings}getTMSettings(){return{available:!0,enabled:!1,scale:1}}getSettings(){return{tts:this.getTTSSettings(),tm:this.getTMSettings()}}startSpeaking(e){return st.info("Starting speaking:",e),!(!("speechSynthesis"in window)||!e||0===e.length)&&(e.forEach((e,t)=>{var i,n,r,o;if(!e)return;const s=new SpeechSynthesisUtterance(e);if(s.rate=this.settings.rate??1,s.volume=this.settings.volume??1,s.lang=(null==(i=this.currentVoice)?void 0:i.lang)??"en-GB",this.currentVoice){const e=null==(n=this.speechSynthesis)?void 0:n.getVoices().find(e=>e.name===this.currentVoice.voiceName);e&&(s.voice=e)}0===t&&(null==(r=this.speechSynthesis)||r.cancel()),null==(o=this.speechSynthesis)||o.speak(s)}),!0)}stopSpeaking(){var e;return"speechSynthesis"in window&&(null==(e=this.speechSynthesis)||e.cancel(),!0)}stopSpeakingButKeepHighlightTask(){this.stopSpeaking()}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}sendTTSMessage(e){}}const ct="titanSDK_tts_settings",lt="titanSDK_tm_settings",dt=a("BrowserAccessibilityService");class ut{reader=null;chromeTTS;windowMock;mockStorage;ttsSettings;tmSettings;constructor(e,t,i=!1){this.windowMock=e,this.mockStorage=t,this.chromeTTS=new at,this.ttsSettings=this.loadTTSSettings(),this.tmSettings=this.loadTMSettings()}loadTTSSettings(){try{const e=localStorage.getItem(ct);if(e)return{...this.getDefaultTTSSettings(),...JSON.parse(e)}}catch(e){}return this.getDefaultTTSSettings()}loadTMSettings(){try{const e=localStorage.getItem(lt);if(e)return{...this.getDefaultTMSettings(),...JSON.parse(e)}}catch(e){}return this.getDefaultTMSettings()}getDefaultTTSSettings(){return{available:!0,enabled:!0,rate:1,volume:1}}getDefaultTMSettings(){return{available:!0,enabled:!1,scale:1}}saveTTSSettings(){try{localStorage.setItem(ct,JSON.stringify(this.ttsSettings))}catch(e){}}saveTMSettings(){try{localStorage.setItem(lt,JSON.stringify(this.tmSettings))}catch(e){}}async startSpeaking(e){try{if(!this.ttsSettings.enabled)return dt.info("TTS is disabled in settings"),!1;const t=Array.isArray(e)?e.join(" "):e,i=this.chromeTTS.startSpeaking([t]);return i&&dt.info("🔊 Speaking:",t),i}catch(t){return dt.error("Error starting speech:",t),!1}}async stopSpeaking(){try{const e=this.chromeTTS.stopSpeaking();return e&&dt.info("🔇 Speech stopped"),e}catch(e){return dt.error("Error stopping speech:",e),!1}}async enableReader(e){try{if(!(await this.isTTSSupported()))return dt.warn("Cannot enable Reader: TTS not supported"),!1;this.reader=new qe(e,this.startSpeaking.bind(this),this.stopSpeaking.bind(this));return!!(await this.reader.start())&&(dt.info("Reader enabled"),!0)}catch(t){return dt.error("Error enabling Reader:",t),!1}}async disableReader(){try{return!!this.reader&&(await this.reader.stop(),this.reader=null,dt.info("Reader disabled"),!0)}catch(e){return dt.error("Error disabling Reader:",e),!1}}getReader(){return this.reader}async isTTSSupported(){var e,t;return void 0!==(null==(t=null==(e=this.mockStorage)?void 0:e.features)?void 0:t.tts)?this.mockStorage.features.tts:"undefined"!=typeof window&&"speechSynthesis"in window}async isTextMagnificationSupported(){var e,t;return void 0===(null==(t=null==(e=this.mockStorage)?void 0:e.features)?void 0:t.magnification)||this.mockStorage.features.magnification}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}async getTTSSettings(){return{...this.ttsSettings}}async getTMSettings(){return{...this.tmSettings}}async isTTSEnabled(){const e=await this.getTTSSettings();return e.available&&e.enabled}async isTMEnabled(){const e=await this.getTMSettings();return e.available&&e.enabled}updateTTSSettings(e){this.ttsSettings={...this.ttsSettings,...e},this.saveTTSSettings(),dt.info("TTS settings updated:",this.ttsSettings)}updateTMSettings(e){this.tmSettings={...this.tmSettings,...e},this.saveTMSettings(),dt.info("TM settings updated:",this.tmSettings)}}const gt=a("BrowserPlatform");class ht extends Y{constructor(e){super(e),this.waitReady=new Promise(e=>{this.waitReadyResolver=e}),this.waitReadyResolver(!0)}async canHandle(){return!0}async getDeviceInfo(){return gt.debug("Getting default device info for browser"),this.getDefaultDeviceInfo()}getDefaultDeviceInfo(){return{Channel:{appStore:"browser",vendor:"browser",brand:"browser"},Product:{platform:"browser",year:(new Date).getFullYear().toString(),deviceID:"browser-"+Math.random().toString(36).substring(2,10),firmwareVersion:"unknown",firmwareComponentID:"unknown",mac:"unknown"},Capability:{os:(null==navigator?void 0:navigator.platform)||"unknown",browserEngine:this.detectBrowserEngine(),hasStorage:this.hasLocalStorage(),support3d:!1,supportUHD:!1,supportHDR:!1,supportWebSocket:"WebSocket"in window,supportPlayready:!1,supportWidevineModular:!1,supportAppleHLS:!1,supportMSSmoothStreaming:!1,supportMSSInitiator:!1,supportMPEG_DASH:!1,drmMethod:"",supportOIPF:!1,supportEME:"mediaKeys"in Document.prototype,supportKeyNumeric:!1,supportKeyColor:!1,supportMultiscreen:!1,supportFHD:!1,supportMultiAudio:!1,supportTTMLInband:!1,supportTTMLOutofband:!1,supportFairplay:!1,supportAdobeHDS:!1,supportPrimetime:!1,supportClearKey:!1,supportWidevineClassic:!1,supportDolbyAtmos:!1,supportHDR_HDR10:!1,supportHDR_DV:!1,supportHDR_HLG:!1,supportHDR_HDR10Plus:!1}}}detectBrowserEngine(){const e=navigator.userAgent;return e.includes("Chrome")?"Blink":e.includes("Firefox")?"Gecko":e.includes("Safari")?"WebKit":e.includes("Edge")?"EdgeHTML":e.includes("Trident")?"Trident":"unknown"}hasLocalStorage(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}getPriority(){return 10}getId(){return"browser"}}const pt=a("BrowserDeviceInfoService");class ft{platform;info;options;constructor(e,t,i){this.options=e,this.info=null;const n={debug:null==e?void 0:e.debug,timeout:(null==e?void 0:e.legacyDeviceInfoTimeout)||5e3,gatewayUrl:null==e?void 0:e.gatewayUrl,useCache:!0};this.platform=new ht(n)}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw pt.error("Error getting device info:",e),e}}async getCapabilities(){try{return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}catch(e){throw pt.error("Error getting device capabilities:",e),e}}}const mt=a("BrowserAppControlService");class vt{windowMock;constructor(e){this.windowMock=e}async launch(e,t){mt.debug(`Launching app: ${e} with deepLink: ${t||"none"}`);const i=this.windowMock||window;if(!i||"function"!=typeof i.open)throw new D("Cannot open new window for app launch (window.open not available)",E.NOT_SUPPORTED,{operation:"launch",appId:e,deepLink:t,platform:"browser"});try{return i.open(t||e,"_blank"),mt.info(`Opened new tab for app: ${e}`),!0}catch(n){throw mt.error("Error opening new window for app launch:",n),new D(`Failed to launch app: ${e}`,E.COMMUNICATION_ERROR,{operation:"launch",appId:e,deepLink:t,platform:"browser",originalError:n})}}}const St=a("BrowserSDK");class yt{accessibilityService;deviceInfoService;appControlService;constructor(e){this.accessibilityService=new ut(null==e?void 0:e.windowMock,null==e?void 0:e.mockStorage,(null==e?void 0:e.dev)||!1),this.deviceInfoService=new ft(e,null==e?void 0:e.windowMock,null==e?void 0:e.mockStorage),this.appControlService=new vt(null==e?void 0:e.windowMock),"undefined"!=typeof window&&Object.defineProperty(window,"titanSDK",{value:this,writable:!0,configurable:!0}),(null==e?void 0:e.debug)&&St.debug("BrowserSDK constructor finished")}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>tt(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>tt(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>this.accessibilityService.onTTSSettingsChange(t=>{e(tt(t))}),onTMSettingsChange:e=>this.accessibilityService.onTMSettingsChange(t=>{e(tt(t))})};apps={launch:(e,t)=>this.appControlService.launch(e,t)};get logging(){return new it}get dev(){const e={simulateError(e){switch(e){case"sdk":{const e=new D("Test SDK error for Rollbar integration",E.UNKNOWN,{operation:"dev-api-sdk-error",component:"SDK"});throw R.reportError(e,{operation:"dev-api-sdk-error",component:"SDK"}),e}case"bridge":{const e=new D("Test bridge communication error",E.COMMUNICATION_ERROR,{operation:"dev-api-bridge-error",component:"SDK"});return R.reportError(e,{operation:"dev-api-bridge-error",component:"SDK"}),Promise.reject(e)}case"async":return new Promise((e,t)=>{setTimeout(()=>{const e=new D("Test async error after timeout",E.TIMEOUT,{operation:"dev-api-async-error",component:"SDK"});R.reportError(e,{operation:"dev-api-async-error",component:"SDK"}),t(e)},100)});default:{const t=new D(`Unknown error type: ${e}`,E.UNKNOWN,{operation:"dev-api-unknown-error",component:"SDK"});throw R.reportError(t,{operation:"dev-api-unknown-error",component:"SDK"}),t}}},async simulateGatewayError(e,t){const i=new D(`Gateway error simulation not supported in browser platform. Error type: ${e}, message: ${t||"default"}`,E.NOT_SUPPORTED,{operation:"dev-api-gateway-error",component:"SDK"});throw R.reportError(i,{operation:"dev-api-gateway-error",component:"SDK"},"critical"===e?"critical":"error"),i}};return{updateTTSSettings:e=>{this.accessibilityService.updateTTSSettings(e)},updateTMSettings:e=>{this.accessibilityService.updateTMSettings(e)},simulateError:e.simulateError,simulateGatewayError:e.simulateGatewayError}}async init(){try{return St.debug("BrowserSDK initialization started"),St.info("BrowserSDK initialized successfully"),!0}catch(e){throw St.error("BrowserSDK initialization failed:",e),e}}}const bt=a("PhilipsDeviceInfoService");class wt{platform;info;bridge;constructor(e,t){this.platform=new Fe(e,t),this.bridge=t,this.info=null}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw bt.error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}const Tt=a("JVCHKCSDK");class It extends nt{constructor(e){const t=new Ue({gatewayUrl:null==e?void 0:e.gatewayUrl,debug:null==e?void 0:e.debug});super(t,new Je(t),new wt(e,t),new et(t))}async init(){try{return await this.deviceInfo.getDeviceInfo(),await this.bridge.waitForInitializationAttempt(),this.bridge.isConnected()||Tt.warn("Bridge initialization completed but bridge is not connected. Some features may not work correctly."),!0}catch(e){throw Tt.error("JVC-HKC SDK initialization failed:",e),e}}}class Et extends me{constructor(e){if(null==e?void 0:e.gatewayUrl)super({gatewayUrl:e.gatewayUrl});else{const e=window.location.hostname.includes("dev01.devview"),t=window.location.hostname.startsWith("dev");super({gatewayUrl:`http://localhost:4660/gateway/${e||t?"dev01":"index"}.html`})}}}const Dt=a("PhilipsSDK");class Ct extends nt{constructor(e){const t=new Ue({gatewayUrl:null==e?void 0:e.gatewayUrl,debug:null==e?void 0:e.debug});super(t,new Je(t),new wt(e,t),new et(t))}async init(){try{return await this.deviceInfo.getDeviceInfo(),await this.bridge.waitForInitializationAttempt(),this.bridge.isConnected()||Dt.warn("Bridge initialization completed but bridge is not connected. Some features may not work correctly."),!0}catch(e){throw Dt.error("TitanSDK initialization failed:",e),e}}}const At=a("AccessibilityService");class Rt{reader=null;async startSpeaking(e){return!1}async stopSpeaking(){return!1}async enableReader(e){return At.warn("Cannot enable Reader: TTS not supported"),!1}async disableReader(){return!1}getReader(){return null}async isTTSSupported(){return!1}async isTextMagnificationSupported(){return!1}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}async getTTSSettings(){return ee}async getTMSettings(){return te}async isTTSEnabled(){return!1}async isTMEnabled(){return!1}}const Pt=a("PhilipsLegacyPlatform");class Mt extends Ie{deviceInfo=null;deviceInfoPromise=null;timeout=7e3;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"TPV",brand:"Philips"},Product:{platform:"TitanOS",year:"2023",deviceID:"philips-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:f(),language:"en"}};constructor(e,t){super(e,null)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent.toLowerCase();return["philips","saphi","nettv","tpvision"].some(t=>e.includes(t))}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product};if(!e.deviceInfo){const e=await this.fetchDeviceInfo();if(e){this.saveToLocalStorage(e);const i=this.formatBridgeResponse({deviceInfo:e,tts:ee,tm:te},t),n=(i.Product.platform,await _e());return{...i,Capability:n}}const i=await _e();return{...t,Capability:i}}const i=this.formatBridgeResponse(e,t),n=(i.Product.platform,await _e());return{...i,Capability:n}}catch(e){throw Pt.warn("Error getting device info:",e),e}}async fetchDeviceInfo(){var e;try{const t="app.titanos.tv",i=await Promise.race([p(0,t,"zeasn"),new Promise(e=>{setTimeout(()=>{Pt.warn("Zeasn backend device info request timed out"),e(null)},this.timeout)})]);if(!i||!(null==(e=i.datas)?void 0:e.cookies))return null;const n=i.datas.cookies.profileid;return{profileId:n,deviceId:decodeURIComponent(i.datas.cookies.deviceid||""),model:i.datas.cookies.deviceYear||"",year:i.datas.cookies.deviceYear||"",firmwareVersion:i.datas.cookies.ufversion||"",country:i.datas.cookies.country||"",language:b("en"),brand:ue.PHILIPS,platformName:ue.PHILIPS,mac:decodeURIComponent(i.datas.cookies.mac||""),ifa:"",ifaType:""}}catch(t){return Pt.warn("Error fetching device info from backend",t),null}}formatBridgeResponse(e,t){let i="TitanOS",n="unknown";if(!e.deviceInfo)return t;if(e.deviceInfo.profileId&&(i=e.deviceInfo.platformName,e.deviceInfo.profileId)){var r=e.deviceInfo.profileId.split("_");i=(r[1]||i).replace(/\d+$/,""),n=r[1]?decodeURIComponent(r[1]):"unknown"}return t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country,t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=i,t.Product.language=e.deviceInfo.language,t.Product.mac=e.deviceInfo.mac,t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.year=e.deviceInfo.year||"",t.Product.firmwareComponentID=n,t}getPriority(){return 100}getId(){return"philips"}}class kt{platform;info;constructor(e){this.platform=new Mt(e),this.info=null}async getDeviceInfo(){const e=await this.platform.getDeviceInfo();return this.info=e,this.info}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}class Ot{async launch(e,t){return!1}}class _t{accessibilityService;deviceInfoService;appControlService;constructor(e){this.accessibilityService=new Rt,this.deviceInfoService=new kt(e),this.appControlService=new Ot}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>tt(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>tt(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>()=>{},onTMSettingsChange:e=>()=>{}};apps={launch:(e,t)=>this.appControlService.launch(e,t)};get logging(){return new it}async init(){return!0}}const Nt=a("VestelTTS"),Lt=e=>({available:!0,enabled:e.enabled,rate:e.rate,pitch:e.pitch,volume:e.level});class Ft extends at{vestelSettings={available:!0,enabled:!1,rate:1,volume:1};windowApi=new h;ttsCallbacks=new Set;tmCallbacks=new Set;settingsInitialized=!1;constructor(){super(),this.initializeSettings()}async initializeSettings(){var e,t;const i=this.windowApi.get("TTSHelper");if(!i)return void Nt.warn("TTSHelper not available during initialization");const n={onSuccess:e=>{this.vestelSettings=Lt(e),this.settingsInitialized=!0},onError:e=>{Nt.error("Error initializing TTS settings:",e),this.settingsInitialized=!0}},r={onSuccess:e=>{this.vestelSettings=Lt(e)},onError:e=>{Nt.error("Error getting TTS info:",e)}};null==(e=i.getTextToSpeechSettings)||e.call(i,n,!1),null==(t=i.getTTSInfo)||t.call(i,r)}getTTSSettings(){var e;if(!this.settingsInitialized){const t=this.windowApi.get("TTSHelper");if(t){const i={onSuccess:e=>{Nt.info("Current TTS settings:",e,e.toString()),this.vestelSettings=Lt(e)},onError:e=>{Nt.error("Error getting current TTS settings:",e)}};null==(e=t.getTextToSpeechSettings)||e.call(t,i,!1)}}return this.vestelSettings}getTMSettings(){return{available:this.getTTSSettings().available,enabled:!1,scale:1}}getSettings(){return{tts:this.getTTSSettings(),tm:this.getTMSettings()}}stopSpeakingButKeepHighlightTask(){this.stopSpeaking()}onTTSSettingsChange(e){var t;const i=this.windowApi.get("TTSHelper");if(!i)return Nt.warn("TTSHelper not available"),()=>{};const n={onSuccess:t=>{Nt.info("TTS settings changed:",t,t.toString()),e(Lt(t)),this.settingsInitialized=!0},onError:e=>{Nt.error("Error getting TTS settings:",e)}};return this.ttsCallbacks.add(n),null==(t=i.getTextToSpeechSettings)||t.call(i,n,!0),()=>{var e;i&&this.ttsCallbacks.has(n)&&(null==(e=i.unsubscribe)||e.call(i,n),this.ttsCallbacks.delete(n))}}onTMSettingsChange(e){this.tmCallbacks.add(e);const t=this.onTTSSettingsChange(t=>{const i={available:t.available,enabled:!1,scale:1};e(i)}),i=this.getTMSettings();return e(i),()=>{this.tmCallbacks.delete(e),t()}}destroy(){const e=this.windowApi.get("TTSHelper");e&&this.ttsCallbacks.forEach(t=>{var i;null==(i=e.unsubscribe)||i.call(e,t)}),this.ttsCallbacks.clear(),this.tmCallbacks.clear()}}const Ht=a("AccessibilityService");class xt{tts;reader=null;constructor(){this.tts=new Ft}async startSpeaking(e){if("string"==typeof e&&(e=[e]),await this.isTTSEnabled())try{return this.tts.startSpeaking(e),!0}catch(t){return Ht.error("Error starting speaking:",t),!1}return!1}async stopSpeaking(){return await this.isTTSEnabled()&&this.tts.stopSpeaking(),!0}async enableReader(e){try{if(!(await this.isTTSSupported()))return Ht.warn("Cannot enable Reader: TTS not supported"),!1;if(!(await this.isTTSEnabled()))return Ht.warn("Cannot enable Reader: TTS not enabled"),!1;this.reader=new qe(e,this.startSpeaking.bind(this),this.stopSpeaking.bind(this));return!!(await this.reader.start())&&(Ht.info("Reader enabled"),!0)}catch(t){return Ht.error("Error enabling Reader:",t),!1}}async disableReader(){try{if(this.reader){const e=await this.reader.stop();return this.reader=null,e&&Ht.info("Reader disabled"),e}return Ht.debug("Reader was not active"),!0}catch(e){return Ht.error("Error disabling Reader:",e),!1}}getReader(){if(!this.reader)throw new Error("Reader is not active");return this.reader}async isTTSSupported(){try{return(await this.getTTSSettings()).available}catch(e){return Ht.error("Error checking TTS support:",e),!1}}async isTextMagnificationSupported(){try{return(await this.getTMSettings()).available}catch(e){return Ht.error("Error checking magnification support:",e),!1}}onTTSSettingsChange(e){return this.tts.onTTSSettingsChange(e)}onTMSettingsChange(e){return this.tts.onTMSettingsChange(e)}async getTTSSettings(){return this.tts.getTTSSettings()}async getTMSettings(){return this.tts.getTMSettings()}async isTTSEnabled(){return(await this.getTTSSettings()).enabled}async isTMEnabled(){return(await this.getTMSettings()).enabled}}function Ut(e){const t=function(){var e;try{const t=document.createElement("object");t.style.display="none",t.setAttribute("id","sysinfo"),t.setAttribute("type","systeminfoobject"),document.body.appendChild(t);const i=t;return{support3d:Boolean(i.has3D),supportUHD:"3840x2160"===(null==(e=i.panelinfo)?void 0:e.toLowerCase()),supportFHD:!0}}catch(t){return{support3d:!1,supportUHD:!1,supportFHD:!0}}}(),i=Re(),n=Ce(),r=Me(),o=ke(),s=Ae(),a={os:"Linux",browserEngine:"Blink",hasStorage:!0,support3d:!1,supportUHD:!0,supportFHD:!0,supportHDR:!0,supportHDR_HDR10:!0,supportHDR_DV:!0,supportHDR_HLG:!0,supportHDR_HDR10Plus:!0,supportWebSocket:!0,supportPlayready:!0,supportWidevineModular:!0,supportAppleHLS:!0,supportMSSmoothStreaming:!1,supportMSSInitiator:!1,supportMPEG_DASH:!0,drmMethod:"widevine",supportOIPF:!1,supportEME:!0,supportKeyNumeric:!0,supportKeyColor:!0,supportFairplay:!1,supportAdobeHDS:!1,supportPrimetime:!1,supportClearKey:!0,supportWidevineClassic:!0,supportDolbyAtmos:!0,supportMultiscreen:!0,supportMultiAudio:!0,supportTTMLInband:!0,supportTTMLOutofband:!0};return"MB191"===e&&(a.supportHDR_DV=!1,a.supportDolbyAtmos=!1,a.supportHDR_HDR10Plus=!1),{...a,...t,...i,...n,...r,...o,...s}}const Vt=a("JVCVestelCompat");class Kt extends Ie{deviceInfo=null;deviceInfoPromise=null;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"Vestel",brand:"JVC"},Product:{platform:"TitanOS",year:"2025",deviceID:"vestel-device",firmwareVersion:"1.0.0",firmwareComponentID:"",mac:"",WhaleAdID:f(),language:"en"}};constructor(e,t){super(e,t)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent,t=e.toLowerCase(),i=w(e),n=t.includes("vestel"),r=T(e);return i&&n&&r}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product},i=this.formatBridgeResponse(e,t),n=Ut(i.Product.platform);return{...i,Capability:n}}catch(e){Vt.error("Error getting device info:",e);const t=Ut();return{Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product,Capability:t}}}formatBridgeResponse(e,t){return e.deviceInfo?(t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country.toUpperCase(),t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=e.deviceInfo.model,t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.mac=e.deviceInfo.mac,t.Product.year=e.deviceInfo.year||"",t):t}getPriority(){return 90}getId(){return"vestel"}}const Bt=a("VestelDeviceInfoService");class zt{platform;info;bridge;constructor(e,t){this.platform=new Kt(e,t),this.bridge=t,this.info=null}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw Bt.error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}}const $t=a("VestelAppControlService");class Gt{bridge;constructor(e){this.bridge=e}async launch(e,t){return await this.bridge.executeWithFallback(()=>this.bridge.launchApp({appId:e,deepLink:t}),async()=>($t.warn("Function unavailable, app launch failed gracefully",{appId:e,deepLink:t}),!1))}}const jt=a("JVCVestelSDK");class Wt extends nt{constructor(e){const t=new Et({gatewayUrl:null==e?void 0:e.gatewayUrl,debug:null==e?void 0:e.debug});super(t,new xt,new zt(e,t),new Gt(t))}async init(){try{return await this.deviceInfo.getDeviceInfo(),!0}catch(e){throw jt.error("TitanSDK initialization failed:",e),e}}}const qt=a("GeocodingService");class Qt{static REQUEST_TIMEOUT=5e3;static MAX_RETRIES=1;static async getCountry(){try{return await this.fetchWithRetry()}catch(e){return qt.warn("Failed to get country from geocoding service:",e),"UNKNOWN"}}static async fetchWithRetry(){let e=null;for(let i=0;i<=this.MAX_RETRIES;i++)try{const e=await this.fetchFromAPI();if("UNKNOWN"!==e)return e}catch(t){e=t,i<this.MAX_RETRIES&&(qt.debug(`Geocoding attempt ${i+1} failed, retrying...`),await new Promise(e=>setTimeout(e,500)))}if(e)throw e;return"UNKNOWN"}static async fetchFromAPI(){if("undefined"==typeof window||void 0===window.fetch)throw new Error("Fetch API is not available");const e=new AbortController,t=setTimeout(()=>e.abort(),this.REQUEST_TIMEOUT);try{const i="https://geoip.app.titanos.tv/",n=await window.fetch(i,{method:"GET",signal:e.signal,headers:{Accept:"application/json"}});if(clearTimeout(t),!n.ok)throw new Error(`Geocoding API returned status ${n.status}: ${n.statusText}`);const r=await n.json();if(!r||"string"!=typeof r.market)throw new Error("Invalid geocoding response format");const o=r.market.toUpperCase();return qt.debug("Country fetched from geocoding service:",o),o}catch(i){if(clearTimeout(t),i instanceof Error){if("AbortError"===i.name)throw new Error("Geocoding request timeout");throw i}throw new Error("Unknown error during geocoding request")}}}const Jt=a("VestelLegacyOIPFService");class Yt{cachedOIPFObject=null;getOIPFObject(){if(this.cachedOIPFObject)return this.cachedOIPFObject;if("undefined"==typeof document)return Jt.warn("Document not available for OIPF access"),null;try{const e=document.createElement("object");return e.type="application/oipfConfiguration",e.style.display="none",document.body.appendChild(e),this.cachedOIPFObject=e,e}catch(e){return Jt.warn("Failed to create OIPF object:",e),null}}async accessOIPFObject(e){try{const t=this.getOIPFObject();return t?e(t):null}catch(t){return Jt.warn("Failed to access OIPF object:",t),null}}cleanup(){if(this.cachedOIPFObject&&this.cachedOIPFObject.parentNode)try{document.body.removeChild(this.cachedOIPFObject)}catch(e){Jt.warn("Failed to cleanup OIPF object:",e)}this.cachedOIPFObject=null}async getMACAddress(){return this.accessOIPFObject(e=>{var t,i;let n=(null==(t=e.configuration)?void 0:t.macAddress)||(null==(i=e.localSystem)?void 0:i.serialNumber)||null;return n&&function(e){if(!e||"string"!=typeof e)return!1;const t=e.replace(/[:\-\.]/g,"").toUpperCase();return/^[0-9A-F]{12}$/.test(t)}(n)?(Jt.debug("MAC address retrieved from OIPF:",n),n):(n&&Jt.debug("MAC address format invalid:",n),null)})}async getFirmwareVersion(){return this.accessOIPFObject(e=>{var t;const i=(null==(t=e.localSystem)?void 0:t.softwareVersion)||null;return i?(Jt.debug("Firmware version retrieved from OIPF:",i),i):null})}async getCountryId(){return this.accessOIPFObject(e=>{var t;const i=(null==(t=e.configuration)?void 0:t.countryId)||null;return i?(Jt.debug("Country ID retrieved from OIPF:",i),i):null})}}const Zt=a("VestelLegacyCompat"),Xt={alb:"AL",arg:"AR",arm:"AM",aut:"AT",aze:"AZ",bhs:"BS",blr:"BY",bel:"BE",bra:"BR",bgr:"BG",chl:"CL",col:"CO",cri:"CR",hrv:"HR",cze:"CZ",dnk:"DK",ecu:"EC",slv:"SV",est:"EE",fin:"FI",fra:"FR",geo:"GE",deu:"DE",grc:"GR",gtm:"GT",hnd:"HN",hun:"HU",isl:"IS",irl:"IE",isr:"IL",ita:"IT",kaz:"KZ",lva:"LV",lie:"LI",ltu:"LT",lux:"LU",mne:"ME",nld:"NL",nic:"NI",mkd:"MK",nor:"NO",pry:"PY",per:"PE",pol:"PL",prt:"PT",rou:"RO",rus:"RU",smr:"SM",srb:"RS",svk:"SK",svn:"SI",esp:"ES",swe:"SE",che:"CH",tur:"TR",ukr:"UA",gbr:"GB",ury:"UY"};class ei extends Ie{deviceInfo=null;deviceInfoPromise=null;oipfService=new Yt;DEFAULT_DEVICE_INFO={Channel:{appStore:"TitanOS",vendor:"Vestel",brand:"JVC"},Product:{platform:"TitanOS",year:"2025",deviceID:"vestel-legacy-device",firmwareVersion:"0.0.0.0",firmwareComponentID:"",mac:"",WhaleAdID:f(),language:"en"}};constructor(e,t){super(e,null)}async canHandle(){if(this.config.forcePlatform===this.getId())return!0;const e=navigator.userAgent,t=e.toLowerCase(),i=t.includes("vestel"),n=e.includes("MB181")||e.includes("MB180")||t.includes("mb181")||t.includes("mb180")||e.includes("Model/Vestel-MB181")||e.includes("Model/Vestel-MB180");return i&&n}async getDeviceInfo(){if(this.deviceInfo)return this.deviceInfo;if(this.deviceInfoPromise)return await this.deviceInfoPromise;this.deviceInfoPromise=this.fetchDeviceInfoInternal();try{const e=await this.deviceInfoPromise;return this.deviceInfo=e,e}catch(e){throw this.deviceInfoPromise=null,e}}async fetchDeviceInfoInternal(){try{const e=await this.getBaseDeviceInfo(),t={Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product};if(!e.deviceInfo){const e=await this.fetchDeviceInfoFromOIPF();if(e){this.saveToLocalStorage(e);const i=this.formatBridgeResponse({deviceInfo:e,tts:ee,tm:te},t),n=i.Product.platform,r=await Ut(n);return{...i,Capability:r}}const i=await Ut();return{...t,Capability:i}}const i=this.formatBridgeResponse(e,t),n=i.Product.platform,r=await Ut(n);return{...i,Capability:r}}catch(e){Zt.warn("Error getting device info:",e);const t=await Ut();return{Channel:this.DEFAULT_DEVICE_INFO.Channel,Product:this.DEFAULT_DEVICE_INFO.Product,Capability:t}}}async fetchDeviceInfoFromOIPF(){try{const e=this.parseUserAgent(),t=await this.oipfService.getMACAddress(),i=await this.oipfService.getFirmwareVersion();let n=await this.getCountryFromGeocoding();if(!n||"UNKNOWN"===n){const e=await this.oipfService.getCountryId();n=e?this.convertOIPFCountryToISO(e):"UNKNOWN"}const r=t||f(),o=i||e.firmwareVersion,s={profileId:`vestel_legacy_${e.boardName}`,deviceId:r,model:e.boardName,year:e.deviceYear,firmwareVersion:o,country:n,language:b("en"),brand:ue.VESTEL,platformName:ue.VESTEL,mac:t||"",ifa:"",ifaType:""};return Zt.debug("Device info fetched from OIPF:",s),s}catch(e){return Zt.warn("Error fetching device info from OIPF:",e),null}}parseUserAgent(){var e;const t=navigator.userAgent;let i=t.match(/Model\/Vestel-(MB\d{3})/i);i||(i=t.match(/MB\d{3}/i));const n=i?(null==(e=i[1])?void 0:e.toUpperCase())||i[0].toUpperCase():"MB181";let r=t.match(/(\d+\.\d+\.\d+\.\d+)/);r||(r=t.match(/(\d+\.\d+\.\d+)/));const o=r?r[1]:"0.0.0.0";let s=t.match(/_TV_[^_]+_(\d{4})_/);s||(s=t.match(/(20\d{2})/));return{boardName:n,firmwareVersion:o,deviceYear:s?s[1]:"2025"}}async getCountryFromGeocoding(){try{const e=await Qt.getCountry();return Zt.debug("Country retrieved from geocoding service:",e),e}catch(e){return Zt.warn("Failed to get country from geocoding service:",e),"UNKNOWN"}}convertOIPFCountryToISO(e){if(!e||"string"!=typeof e)return"UNKNOWN";const t=e.toLowerCase().trim(),i=Xt[t];return i?(Zt.debug(`Converted OIPF country code '${e}' to ISO '${i}'`),i):/^[A-Z]{2}$/.test(e)?e:(Zt.warn(`Unknown OIPF country code '${e}', returning as is`),e.toUpperCase())}formatBridgeResponse(e,t){return e.deviceInfo?(t.Product.firmwareVersion=e.deviceInfo.firmwareVersion,t.Product.country=e.deviceInfo.country,t.Product.deviceID=e.deviceInfo.deviceId,t.Product.platform=e.deviceInfo.model,t.Product.language=e.deviceInfo.language,t.Product.mac=e.deviceInfo.mac,t.Product.ifa=e.deviceInfo.ifa||"",t.Product.ifaType=e.deviceInfo.ifaType||"",t.Product.year=e.deviceInfo.year||"",t.Product.firmwareComponentID=e.deviceInfo.profileId||"",t):t}getPriority(){return 95}getId(){return"vestel-legacy"}}class ti{platform;info=null;bridge;isInitialized=!1;constructor(e,t){this.platform=e,this.bridge=t}async initialize(){try{this.getLogger().debug("Initializing Device Info Service"),await this.getDeviceInfo(),this.isInitialized=!0,this.getLogger().debug("Device Info Service initialized")}catch(e){throw this.getLogger().error("Failed to initialize Device Info Service:",e),e}}async getDeviceInfo(){try{const e=await this.platform.getDeviceInfo();return this.info=e,this.info}catch(e){throw this.getLogger().error("Failed to get device info:",e),e}}async getCapabilities(){return this.info||(this.info=await this.getDeviceInfo()),this.info.Capability}isReady(){return this.isInitialized&&null!==this.info}}const ii=a("VestelLegacyDeviceInfoService");class ni extends ti{constructor(e){super(new ei(e))}getLogger(){return ii}}const ri=a("VestelLegacyAccessibilityService");class oi{reader=null;async startSpeaking(e){return!1}async stopSpeaking(){return!1}async enableReader(e){return ri.warn("Cannot enable Reader: TTS not supported"),!1}async disableReader(){return!1}getReader(){return null}async isTTSSupported(){return!1}async isTextMagnificationSupported(){return!1}onTTSSettingsChange(e){return()=>{}}onTMSettingsChange(e){return()=>{}}async getTTSSettings(){return ee}async getTMSettings(){return te}async isTTSEnabled(){return!1}async isTMEnabled(){return!1}}const si=a("VestelLegacyAppControlService");class ai{async launchApp(e,t){return si.warn("App launching not supported on legacy Vestel devices"),!1}}const ci=a("VestelLegacySDK");class li{accessibilityService;deviceInfoService;appControlService;loggingService;constructor(e){this.accessibilityService=new oi,this.deviceInfoService=new ni(e),this.appControlService=new ai,this.loggingService=new it}deviceInfo={getDeviceInfo:()=>this.deviceInfoService.getDeviceInfo(),getCapabilities:()=>this.deviceInfoService.getCapabilities()};accessibility={enableReader:e=>this.accessibilityService.enableReader(e),disableReader:()=>this.accessibilityService.disableReader(),isTTSSupported:()=>this.accessibilityService.isTTSSupported(),isTTSEnabled:()=>this.accessibilityService.isTTSEnabled(),isTMEnabled:()=>this.accessibilityService.isTMEnabled(),isTextMagnificationSupported:()=>this.accessibilityService.isTextMagnificationSupported(),getTTSSettings:async()=>tt(await this.accessibilityService.getTTSSettings()),getTMSettings:async()=>tt(await this.accessibilityService.getTMSettings()),startSpeaking:e=>this.accessibilityService.startSpeaking(e),stopSpeaking:()=>this.accessibilityService.stopSpeaking(),onTTSSettingsChange:e=>()=>{},onTMSettingsChange:e=>()=>{}};apps={launch:async(e,t)=>{try{return await this.appControlService.launchApp(e,t),!0}catch(i){return ci.error("Failed to launch app:",i),!1}}};get logging(){return this.loggingService}async init(){try{return ci.debug("Initializing Vestel Legacy SDK"),await this.deviceInfoService.initialize(),ci.debug("Vestel Legacy SDK initialized successfully"),!0}catch(e){return ci.error("Failed to initialize Vestel Legacy SDK:",e),!1}}async getCapabilities(){return this.deviceInfoService.getCapabilities()}isReady(){return this.deviceInfoService.isReady()}getVersion(){return"1.0.0"}getPlatform(){return"vestel-legacy"}}const di=a("AnalyticsService");class ui{sdkVersion;constructor(e){this.sdkVersion=e}getEventUrl(){return"https://sdk.titanos.tv/events"}async track(e){if("undefined"==typeof window||void 0===window.fetch)return Promise.resolve();try{const t={event_name:e.eventName,event_type:e.eventType,event_params:e.eventParams,event_timestamp:(new Date).toISOString().replace("T"," ").slice(0,-1)};await window.fetch(this.getEventUrl(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}catch(t){di.warn("TitanSDK: Usage tracking event failed to send.",t)}}trackUsage(){const e={eventName:"sdk",eventType:"sdk-initialized",eventParams:{appHostname:window.location.hostname,sdkVersion:this.sdkVersion}};return this.track(e)}}const gi=a("WrapperUtils");function hi(e){return{getTTSSettings:async()=>(await e()).accessibility.getTTSSettings(),getTMSettings:async()=>(await e()).accessibility.getTMSettings(),isTTSSupported:async()=>(await e()).accessibility.isTTSSupported(),isTTSEnabled:async()=>(await e()).accessibility.isTTSEnabled(),isTMEnabled:async()=>(await e()).accessibility.isTMEnabled(),isTextMagnificationSupported:async()=>(await e()).accessibility.isTextMagnificationSupported(),startSpeaking:async t=>(await e()).accessibility.startSpeaking(t),stopSpeaking:async()=>(await e()).accessibility.stopSpeaking(),enableReader:async t=>(await e()).accessibility.enableReader(t),disableReader:async()=>(await e()).accessibility.disableReader(),onTTSSettingsChange:t=>{let i=null;return e().then(e=>{i=e.accessibility.onTTSSettingsChange(t)}).catch(e=>{gi.error("Failed to set up TTS settings change handler:",e)}),()=>{i&&i()}},onTMSettingsChange:t=>{let i=null;return e().then(e=>{i=e.accessibility.onTMSettingsChange(t)}).catch(e=>{gi.error("Failed to set up TM settings change handler:",e)}),()=>{i&&i()}}}}function pi(e){return{launch:async(t,i)=>(await e()).apps.launch(t,i)}}const fi=a("SDK"),mi={debug:!1,useLegacyDeviceInfo:!1,legacyDeviceInfoTimeout:5e3,fallbackToBrowser:!0},vi="TITAN_SDK_USAGE_SENT";let Si=null,yi=null,bi=null,wi=null,Ti=!1;const Ii=async()=>{if(!Si)throw new D("SDK not created. Call getTitanSDK() first.",E.NOT_INITIALIZED);if(!bi)throw fi.error("SDK initialization not started"),new D("SDK initialization not started.",E.NOT_INITIALIZED);if(!(await bi))throw new D("SDK initialization failed.",E.UNKNOWN);return Si},Ei=e=>{if(yi)return yi;const t={...mi,...e};if(o.setDebugMode(t.debug??!1),!Ti){const e="",t=!1;R.initialize({accessToken:e,enabled:t}),Ti=!0}const n=W.detectPlatform(t).platform;fi.info("Platform detected:",n);try{switch(n){case i.AOC:Si=new ot(t);break;case i.JVC_HKC:Si=new It(t);break;case i.PHILIPS:Si=new Ct(t);break;case i.PHILIPS_OLD:Si=new _t(t);break;case i.JVC_VESTEL:Si=new Wt(t);break;case i.JVC_VESTEL_LEGACY:Si=new li(t);break;case i.BROWSER:default:n!==i.BROWSER&&t.debug&&fi.warn(`Platform ${n} detected but no specific SDK found, using BrowserSDK as fallback.`),Si=new yt(t)}if(!Si)throw new D("Failed to create SDK instance after platform detection",E.UNKNOWN)}catch(c){throw fi.error("Error creating SDK instance:",c),new D(`Failed to create SDK instance after platform detection: ${c}`,E.UNKNOWN)}bi=Si.init(),fi.info("SDK Version:",I);const r={VERSION:I,isReady:bi,deviceInfo:(s=Ii,a=e=>{wi=e},{getDeviceInfo:async()=>{const e=await s(),t=await e.deviceInfo.getDeviceInfo();return null==a||a(t),t}}),accessibility:hi(Ii),apps:pi(Ii)};var s,a;return t.debug&&(fi.info("🔧 [DEBUG MODE] TitanSDK debug access enabled"),r.logging=function(e){let t=null;return{subscribe:(i,n)=>{let r=null;return e().then(e=>{t=e,e.logging&&(r=e.logging.subscribe(i,n))}).catch(e=>{gi.error("Failed to set up logging subscription:",e)}),()=>{r&&r()}},getHistory:()=>(null==t?void 0:t.logging)?t.logging.getHistory():[],clear:()=>{(null==t?void 0:t.logging)&&t.logging.clear()}}}(Ii)),t.dev&&(t.debug&&fi.info("🔧 [DEV MODE] TitanSDK dev access enabled"),n===i.BROWSER&&t.dev&&(fi.info("Available dev methods:"),fi.info(" sdk.dev.updateTTSSettings({ enabled: true, rate: 1.5 })"),fi.info(" sdk.dev.updateTMSettings({ enabled: true, scale: 1.8 })")),r.dev=function(e){return{updateTTSSettings:async t=>{var i,n;return null==(n=null==(i=(await e()).dev)?void 0:i.updateTTSSettings)?void 0:n.call(i,t)},updateTMSettings:async t=>{var i,n;return null==(n=null==(i=(await e()).dev)?void 0:i.updateTMSettings)?void 0:n.call(i,t)},simulateError:async t=>{var i,n;return null==(n=null==(i=(await e()).dev)?void 0:i.simulateError)?void 0:n.call(i,t)},simulateGatewayError:async(t,i)=>{var n,r;return null==(r=null==(n=(await e()).dev)?void 0:n.simulateGatewayError)?void 0:r.call(n,t,i)},isBridgeConnected:async()=>{var t,i;return(null==(i=null==(t=(await e()).dev)?void 0:t.isBridgeConnected)?void 0:i.call(t))??!1}}}(Ii)),yi=r,bi.then(async()=>{try{wi=await Si.deviceInfo.getDeviceInfo();const e=new ui(I);if(!(()=>{try{return!("undefined"==typeof window||!window.localStorage)&&"1"===window.localStorage.getItem(vi)}catch{return!1}})())try{await e.trackUsage(),(()=>{try{if("undefined"==typeof window||!window.localStorage)return;window.localStorage.setItem(vi,"1")}catch{}})()}catch{}}catch(c){t.debug&&fi.warn("Failed to pre-cache device info:",c)}}).catch(e=>{fi.error(`Initialization failed for platform ${n}:`,e)}),yi},Di=async()=>{const e=await Ii(),t=await e.deviceInfo.getDeviceInfo();return wi=t,t};if("undefined"!=typeof document&&document.addEventListener("securitypolicyviolation",e=>{H.getViolations()}),"undefined"!=typeof window)if(window.TitanSDK&&window.TitanSDK.deviceInfo)fi.info("TitanSDK already exists on window, skipping initialization"),fi.info("You can still create a new SDK instance using window.getTitanSDK(options)"),window.getTitanSDK=Ei;else{const e=()=>{window.onDeviceInfoReady=function(e){Di().then(t=>e(t)).catch(t=>e({},String(t)))},Object.defineProperty(window,"DeviceInfo",{get:()=>{if(wi)return wi;if(Si&&yi)try{return Si.deviceInfo.getDeviceInfo()}catch{return null}return null},configurable:!0}),void 0===window.SmartTvA_API&&Object.defineProperty(window,"SmartTvA_API",{value:{exit:()=>window.close()},writable:!1,configurable:!0})},t=e=>{try{const t=null==localStorage?void 0:localStorage.getItem(e);return t?JSON.parse(t):{}}catch(t){return o.isDebugMode()&&fi.error(`Failed to parse localStorage key ${e}:`,t),{}}},i=(new h).get("TITAN_SDK_PARAMS")||t("TITAN_SDK_PARAMS");i&&fi.info("Initializing TitanSDK with params:",i),window.TitanSDK=Ei(i),e(),J(window.TitanSDK).catch(e=>{fi.error("Failed to initialize SmartTvA_API:",e)})}e.VERSION=I,e.getDeviceInfo=Di,e.getTitanSDK=Ei,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});