@cloro-dev/response-parser 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,2 @@
1
- "use strict";var e,t=require("react"),r={exports:{}},n={};var o,i={};
2
- /**
3
- * @license React
4
- * react-jsx-runtime.development.js
5
- *
6
- * Copyright (c) Facebook, Inc. and its affiliates.
7
- *
8
- * This source code is licensed under the MIT license found in the
9
- * LICENSE file in the root directory of this source tree.
10
- */"production"===process.env.NODE_ENV?r.exports=function(){if(e)return n;e=1;var r=t,o=Symbol.for("react.element"),i=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,s=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var n,i={},c=null,u=null;for(n in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(u=t.ref),t)a.call(t,n)&&!l.hasOwnProperty(n)&&(i[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===i[n]&&(i[n]=t[n]);return{$$typeof:o,type:e,key:c,ref:u,props:i,_owner:s.current}}return n.Fragment=i,n.jsx=c,n.jsxs=c,n}():r.exports=(o||(o=1,"production"!==process.env.NODE_ENV&&function(){var e,r=t,n=Symbol.for("react.element"),o=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),l=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),u=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),m=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),v=Symbol.for("react.offscreen"),y=Symbol.iterator,b=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function g(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=b.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(t+="%s",r=r.concat([n]));var o=r.map(function(e){return String(e)});o.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,o)}("error",e,r)}function x(e){return e.displayName||"Context"}function w(e){if(null==e)return null;if("number"==typeof e.tag&&g("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case a:return"Fragment";case o:return"Portal";case l:return"Profiler";case s:return"StrictMode";case p:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case u:return x(e)+".Consumer";case c:return x(e._context)+".Provider";case d:return function(e,t,r){var n=e.displayName;if(n)return n;var o=t.displayName||t.name||"";return""!==o?r+"("+o+")":r}(e,e.render,"ForwardRef");case m:var t=e.displayName||null;return null!==t?t:w(e.type)||"Memo";case h:var r=e,n=r._payload,i=r._init;try{return w(i(n))}catch(e){return null}}return null}e=Symbol.for("react.module.reference");var S,k,j,_,E,O,P,R=Object.assign,I=0;function T(){}T.__reactDisabledLog=!0;var C,D=b.ReactCurrentDispatcher;function N(e,t,r){if(void 0===C)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);C=n&&n[1]||""}return"\n"+C+e}var $,F=!1,A="function"==typeof WeakMap?WeakMap:Map;function U(e,t){if(!e||F)return"";var r,n=$.get(e);if(void 0!==n)return n;F=!0;var o,i=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=D.current,D.current=null,function(){if(0===I){S=console.log,k=console.info,j=console.warn,_=console.error,E=console.group,O=console.groupCollapsed,P=console.groupEnd;var e={configurable:!0,enumerable:!0,value:T,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}I++}();try{if(t){var a=function(){throw Error()};if(Object.defineProperty(a.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(a,[])}catch(e){r=e}Reflect.construct(e,[],a)}else{try{a.call()}catch(e){r=e}e.call(a.prototype)}}else{try{throw Error()}catch(e){r=e}e()}}catch(t){if(t&&r&&"string"==typeof t.stack){for(var s=t.stack.split("\n"),l=r.stack.split("\n"),c=s.length-1,u=l.length-1;c>=1&&u>=0&&s[c]!==l[u];)u--;for(;c>=1&&u>=0;c--,u--)if(s[c]!==l[u]){if(1!==c||1!==u)do{if(c--,--u<0||s[c]!==l[u]){var d="\n"+s[c].replace(" at new "," at ");return e.displayName&&d.includes("<anonymous>")&&(d=d.replace("<anonymous>",e.displayName)),"function"==typeof e&&$.set(e,d),d}}while(c>=1&&u>=0);break}}}finally{F=!1,D.current=o,function(){if(0===--I){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:R({},e,{value:S}),info:R({},e,{value:k}),warn:R({},e,{value:j}),error:R({},e,{value:_}),group:R({},e,{value:E}),groupCollapsed:R({},e,{value:O}),groupEnd:R({},e,{value:P})})}I<0&&g("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=i}var p=e?e.displayName||e.name:"",f=p?N(p):"";return"function"==typeof e&&$.set(e,f),f}function L(e,t,r){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return N(e);switch(e){case p:return N("Suspense");case f:return N("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case d:return U(e.render,!1);case m:return L(e.type,t,r);case h:var o=e,i=o._payload,a=o._init;try{return L(a(i),t,r)}catch(e){}}return""}$=new A;var W=Object.prototype.hasOwnProperty,G={},M=b.ReactDebugCurrentFrame;function V(e){if(e){var t=e._owner,r=L(e.type,e._source,t?t.type:null);M.setExtraStackFrame(r)}else M.setExtraStackFrame(null)}var H=Array.isArray;function Y(e){return H(e)}function z(e){return""+e}function B(e){if(function(e){try{return z(e),!1}catch(e){return!0}}(e))return g("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),z(e)}var X,q,Z=b.ReactCurrentOwner,J={key:!0,ref:!0,__self:!0,__source:!0};function K(e,t,r,o,i){var a,s={},l=null,c=null;for(a in void 0!==r&&(B(r),l=""+r),function(e){if(W.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(B(t.key),l=""+t.key),function(e){if(W.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e){"string"==typeof e.ref&&Z.current}(t)),t)W.call(t,a)&&!J.hasOwnProperty(a)&&(s[a]=t[a]);if(e&&e.defaultProps){var u=e.defaultProps;for(a in u)void 0===s[a]&&(s[a]=u[a])}if(l||c){var d="function"==typeof e?e.displayName||e.name||"Unknown":e;l&&function(e,t){var r=function(){X||(X=!0,g("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(s,d),c&&function(e,t){var r=function(){q||(q=!0,g("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(s,d)}return function(e,t,r,o,i,a,s){var l={$$typeof:n,type:e,key:t,ref:r,props:s,_owner:a,_store:{}};return Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l}(e,l,c,i,o,Z.current,s)}var Q,ee=b.ReactCurrentOwner,te=b.ReactDebugCurrentFrame;function re(e){if(e){var t=e._owner,r=L(e.type,e._source,t?t.type:null);te.setExtraStackFrame(r)}else te.setExtraStackFrame(null)}function ne(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(ee.current){var e=w(ee.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}Q=!1;var ie={};function ae(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=oe();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!ie[r]){ie[r]=!0;var n="";e&&e._owner&&e._owner!==ee.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),re(e),g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,n),re(null)}}}function se(e,t){if("object"==typeof e)if(Y(e))for(var r=0;r<e.length;r++){var n=e[r];ne(n)&&ae(n,t)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var t=y&&e[y]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof o&&o!==e.entries)for(var i,a=o.call(e);!(i=a.next()).done;)ne(i.value)&&ae(i.value,t)}}function le(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==d&&r.$$typeof!==m)return;t=r.propTypes}if(t){var n=w(r);!function(e,t,r,n,o){var i=Function.call.bind(W);for(var a in e)if(i(e,a)){var s=void 0;try{if("function"!=typeof e[a]){var l=Error((n||"React class")+": "+r+" type `"+a+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[a]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw l.name="Invariant Violation",l}s=e[a](t,a,n,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){s=e}!s||s instanceof Error||(V(o),g("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",r,a,typeof s),V(null)),s instanceof Error&&!(s.message in G)&&(G[s.message]=!0,V(o),g("Failed %s type: %s",r,s.message),V(null))}}(t,e.props,"prop",n,e)}else void 0===r.PropTypes||Q||(Q=!0,g("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||g("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ce={};function ue(t,r,o,i,y,b){var x=function(t){return"string"==typeof t||"function"==typeof t||t===a||t===l||t===s||t===p||t===f||t===v||"object"==typeof t&&null!==t&&(t.$$typeof===h||t.$$typeof===m||t.$$typeof===c||t.$$typeof===u||t.$$typeof===d||t.$$typeof===e||void 0!==t.getModuleId)}(t);if(!x){var S,k="";(void 0===t||"object"==typeof t&&null!==t&&0===Object.keys(t).length)&&(k+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),k+=oe(),null===t?S="null":Y(t)?S="array":void 0!==t&&t.$$typeof===n?(S="<"+(w(t.type)||"Unknown")+" />",k=" Did you accidentally export a JSX literal instead of a component?"):S=typeof t,g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",S,k)}var j=K(t,r,o,y,b);if(null==j)return j;if(x){var _=r.children;if(void 0!==_)if(i)if(Y(_)){for(var E=0;E<_.length;E++)se(_[E],t);Object.freeze&&Object.freeze(_)}else g("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else se(_,t)}if(W.call(r,"key")){var O=w(t),P=Object.keys(r).filter(function(e){return"key"!==e}),R=P.length>0?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}";ce[O+R]||(g('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',R,O,P.length>0?"{"+P.join(": ..., ")+": ...}":"{}",O),ce[O+R]=!0)}return t===a?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){re(e),g("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),re(null);break}}null!==e.ref&&(re(e),g("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}(j):le(j),j}var de=function(e,t,r){return ue(e,t,r,!1)},pe=function(e,t,r){return ue(e,t,r,!0)};i.Fragment=a,i.jsx=de,i.jsxs=pe}()),i);var a=r.exports;class s{static detect(e){const t={CHATGPT:0,GEMINI:0,PERPLEXITY:0,COPILOT:0,AIOVERVIEW:0,AIMODE:0};for(const[r,n]of Object.entries(this.PROVIDER_PATTERNS))for(const o of n)try{o(e)&&t[r]++}catch(e){}let r=0,n=null;for(const[e,o]of Object.entries(t))o>r&&(r=o,n=e);return 0===r?null:{provider:n,confidence:r/Object.values(t).reduce((e,t)=>Math.max(e,t),1)}}static getAllProviders(e){const t=[];for(const[r,n]of Object.entries(this.PROVIDER_PATTERNS)){let o=0;for(const t of n)try{t(e)&&o++}catch(e){}o>0&&t.push({provider:r,confidence:o/n.length})}return t.sort((e,t)=>t.confidence-e.confidence)}static validate(e,t){const r=this.detect(e);return(null==r?void 0:r.provider)===t&&r.confidence>.5}}s.PROVIDER_PATTERNS={CHATGPT:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("bg-token-bg-primary")||r.includes("text-token-text-secondary")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("chatgpt.com")||r.includes("openai.com")}],GEMINI:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("bard-sidenav")||r.includes("mat-sidenav")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("gemini.google.com")||r.includes("gem-sys-color")}],PERPLEXITY:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("perplexity.ai")||r.includes("prose")}],COPILOT:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("copilot.microsoft.com")||r.includes('data-testid="sidebar-container"')}],AIOVERVIEW:[e=>{var t,r,n,o;if(null===(r=null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.aioverview)||void 0===r?void 0:r.text)return!0;if(null===(n=null==e?void 0:e.aioverview)||void 0===n?void 0:n.text)return!0;const i=(null===(o=null==e?void 0:e.result)||void 0===o?void 0:o.html)||(null==e?void 0:e.html)||"";return i.includes("WIZ_global_data")||i.includes("DnVkpd")}],AIMODE:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("DZ13He")||r.includes("wYq63b")||r.includes("AI Mode")}]};class l{injectStyles(e,t){let r=e;(null==t?void 0:t.baseUrl)&&!e.includes("<base ")&&(r=r.includes("<head>")?r.replace("<head>",`<head><base href="${t.baseUrl}">`):r.replace(/(<html[^>]*>)/i,`$1<head><base href="${t.baseUrl}"></head>`));const n=(null==t?void 0:t.customCSS)?this.defaultStyles+"\n"+t.customCSS:this.defaultStyles;return r=r.includes("<head>")?r.replace("<head>",`<head><style>${n}</style>`):r.replace(/(<html[^>]*>)/i,`$1<head><style>${n}</style></head>`),r}sanitizeHtml(e){let t=e.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,"");return t=t.replace(/<noscript[\s\S]*?<\/noscript>/gi,""),t}isFullDocument(e){return/^\s*(<html|<!DOCTYPE)/i.test(e)}wrapFragment(e){return`<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline';">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${e}\n</body>\n</html>`}}class c extends l{constructor(){super(...arguments),this.name="CHATGPT",this.baseUrl="https://chatgpt.com",this.defaultStyles='\n /* Force Dark Background on main containers and wrappers */\n html, body, main, article, footer, form,\n [class*="bg-"], [class*="footer"], [class*="bottom"],\n div[class*="border-t"],\n #thread-bottom-container, #thread-bottom,\n #thread, .composer-parent, [class*="group\\/thread"] {\n background-color: #131314 !important;\n color: #e3e3e3 !important;\n border-color: #2a2b36 !important;\n }\n\n /* Force background on specific white artifacts in the footer */\n #thread-bottom-container .bg-clip-padding,\n #thread-bottom-container .content-fade,\n #thread-bottom-container .absolute {\n background-color: transparent !important;\n }\n\n /* Specific targeting for the composer/input box (was white) */\n form .bg-token-bg-primary, form .shadow-short {\n background-color: #2a2b36 !important;\n border-color: #3e3f4b !important;\n box-shadow: none !important;\n }\n\n /* Disclaimer Footer - Force Dark Background */\n div[class*="text-token-text-secondary"] {\n color: #9ca3af !important;\n background-color: #131314 !important;\n }\n\n /* Force Text Color to Light */\n p, h1, h2, h3, h4, h5, h6, li, span, div, td, th, textarea, button {\n color: #e3e3e3 !important;\n }\n\n /* Links - Light Blue */\n a, a span {\n color: #8ab4f8 !important;\n }\n\n /* Code Blocks */\n pre, code, pre div, code span {\n background-color: #2a2b36 !important;\n color: #e3e3e3 !important;\n text-shadow: none !important;\n }\n\n /* Inputs/Textareas */\n input, textarea {\n background-color: transparent !important;\n color: #e3e3e3 !important;\n border-color: #3e3f4b !important;\n }\n\n /* Placeholder text */\n textarea::placeholder {\n color: #9ca3af !important;\n }\n\n /* Hide Sidebar */\n nav, [class*="sidebar"] {\n display: none !important;\n }\n\n /* Media visibility */\n img, video {\n opacity: 1 !important;\n }\n '}extractContent(e){let t="",r="",n=e;return e.result&&(n=e.result),"string"==typeof n?n.trim().startsWith("<")&&n.includes(">")?t=n:r=n:"object"==typeof n&&null!==n&&(n.html?t=n.html:n.content?n.content.trim().startsWith("<")?t=n.content:r=n.content:n.text&&(r=n.text)),{html:t,text:r}}parse(e,t){const{html:r,text:n}=this.extractContent(e);if(!r&&!n)throw new Error("No content found in ChatGPT response");let o=r||"";return!o&&n&&(o=`<div>${n.replace(/\n/g,"<br>")}</div>`),o=this.sanitizeHtml(o),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl}),{provider:this.name,html:o,text:n,metadata:{isFullDocument:this.isFullDocument(o)}}}}class u extends l{constructor(){super(...arguments),this.name="GEMINI",this.baseUrl="https://gemini.google.com",this.defaultStyles='\n /* Gemini Dark Mode Variable Overrides */\n :root {\n --gem-sys-color--surface: #131314 !important;\n --gem-sys-color--surface-container: #1e1f20 !important;\n --gem-sys-color--on-surface: #e3e3e3 !important;\n --bard-color-synthetic--chat-window-surface: #131314 !important;\n --bard-color-surface-dim-tmp: #131314 !important;\n }\n\n /* UI hiding - Gemini */\n bard-sidenav, mat-sidenav, .mat-drawer-backdrop, .side-nav-menu-button,\n\n /* Gemini "About Gemini" footer/navigation block */\n .gb_5a, .gb_5c, .gb_5d, .gb_5e,\n .gb_Uc, .gb_Vc, .gb_Wc,\n a[href*="about"],\n a[href*="subscriptions"],\n a[href*="business"],\n div[class*="gb_5"],\n .gb_Pd, .gb_Qd, .gb_Rd,\n .gb_Sd, .gb_Td, .gb_Ud, .gb_Vd,\n [aria-label*="About"],\n [aria-label*="Gemini App"],\n [aria-label*="Subscriptions"],\n [aria-label*="For Business"],\n *:contains("About Gemini"),\n *:contains("Gemini App"),\n *:contains("Subscriptions"),\n *:contains("For Business") {\n display: none !important;\n }\n\n /* General Layout */\n main { width: 100% !important; max-width: 100% !important; margin: 0 !important; }\n\n /* Force Dark Mode on Body and Gemini Containers */\n body, .content-container, chat-app, .main-content, .chat-container {\n background-color: #131314 !important;\n color: #e3e3e3 !important;\n }\n '}extractContent(e){let t="",r="",n=[],o=e;return e.result&&(o=e.result),"string"==typeof o?o.trim().startsWith("<")&&o.includes(">")?t=o:r=o:"object"==typeof o&&null!==o&&(o.html?t=o.html:o.content?o.content.trim().startsWith("<")?t=o.content:r=o.content:o.text&&(r=o.text),o.aioverview&&(o.aioverview.text&&(r=o.aioverview.text),o.aioverview.sources&&(n=o.aioverview.sources))),{html:t,text:r,sources:n}}parse(e,t){const{html:r,text:n,sources:o}=this.extractContent(e);if(!r&&!n)throw new Error("No content found in Gemini response");let i=r||"";return!i&&n&&(i=`<div>${n.replace(/\n/g,"<br>")}</div>`),i=this.sanitizeHtml(i),i=this.injectStyles(i,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl}),{provider:this.name,html:i,text:n,sources:o,metadata:{isFullDocument:this.isFullDocument(i)}}}}class d extends l{constructor(){super(...arguments),this.name="PERPLEXITY",this.baseUrl="https://www.perplexity.ai",this.defaultStyles="\n html {\n filter: invert(1) hue-rotate(180deg);\n background-color: white !important;\n }\n img, video, iframe, svg {\n filter: invert(1) hue-rotate(180deg);\n }\n "}extractContent(e){let t="",r="",n=e;return e.result&&(n=e.result),"string"==typeof n?n.trim().startsWith("<")&&n.includes(">")?t=n:r=n:"object"==typeof n&&null!==n&&(n.html?t=n.html:n.content?n.content.trim().startsWith("<")?t=n.content:r=n.content:n.text&&(r=n.text)),{html:t,text:r}}parse(e,t){const{html:r,text:n}=this.extractContent(e);if(!r&&!n)throw new Error("No content found in Perplexity response");let o=r||"";return!o&&n&&(o=`<div>${n.replace(/\n/g,"<br>")}</div>`),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl,customCSS:"light"===(null==t?void 0:t.theme)?"":this.defaultStyles}),{provider:this.name,html:o,text:n,metadata:{isFullDocument:this.isFullDocument(o)}}}}class p extends l{constructor(){super(...arguments),this.name="COPILOT",this.baseUrl="https://copilot.microsoft.com",this.defaultStyles='\n /* Copilot Sidebar & Header */\n div:has(> [data-testid="sidebar-container"]),\n [data-testid="sidebar-container"],\n [data-testid="sticky-header"],\n .side-nav-menu-button {\n display: none !important;\n }\n\n /* General Layout Fixes */\n main {\n width: 100% !important;\n max-width: 100% !important;\n margin: 0 !important;\n }\n '}extractContent(e){let t="",r="",n=e;return e.result&&(n=e.result),"string"==typeof n?n.trim().startsWith("<")&&n.includes(">")?t=n:r=n:"object"==typeof n&&null!==n&&(n.html?t=n.html:n.content?n.content.trim().startsWith("<")?t=n.content:r=n.content:n.text&&(r=n.text)),{html:t,text:r}}parse(e,t){const{html:r,text:n}=this.extractContent(e);if(!r&&!n)throw new Error("No content found in Copilot response");let o=r||"";return!o&&n&&(o=`<div>${n.replace(/\n/g,"<br>")}</div>`),o=o.replace(/<noscript[\s\S]*?<\/noscript>/gi,""),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl}),{provider:this.name,html:o,text:n,metadata:{isFullDocument:this.isFullDocument(o)}}}}class f extends l{constructor(){super(...arguments),this.name="AIOVERVIEW",this.baseUrl="https://www.google.com",this.defaultStyles='\n /* UI hiding - Google Search (AI Overview) */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L,\n\n /* Specific AI Mode Selectors */\n .DZ13He,\n .wYq63b,\n .eT9Cje,\n .bNg8Rb,\n .S6VXfe,\n .Lu57id {\n display: none !important;\n }\n\n /* General Layout */\n main { width: 100% !important; max-width: 100% !important; margin: 0 !important; }\n '}extractContent(e){let t="",r="",n=[],o=e;if(e.result&&(o=e.result),o.aioverview&&(o.aioverview.text&&(r=o.aioverview.text),o.aioverview.sources&&(n=o.aioverview.sources)),"string"==typeof o?o.trim().startsWith("<")&&o.includes(">")?t=o:r=r||o:"object"==typeof o&&null!==o&&(o.html&&!r?t=o.html:o.content&&!r?o.content.trim().startsWith("<")?t=o.content:r=o.content:o.text&&!r&&(r=o.text)),t){const e=t.match(/"DnVkpd"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(e&&e[1])try{let t=JSON.parse(`"${e[1]}"`);t=t.replace(/∰/g,'<hr class="gemini-separator">'),t=t.replace(/∞(https:\/\/[^ ]+\.(?:jpg|png|webp|gif|jpeg)(?:\?[^ ]*)?)/gi,'<br><img src="$1" class="gemini-image" alt="Generated Image"><br>'),t=t.replace(/∞/g,"<br>"),t=t.replace(/\n/g,"<br>"),r=t}catch(e){console.error("Failed to parse AI Overview WIZ data",e)}}return{html:t,text:r,sources:n}}parse(e,t){const{html:r,text:n,sources:o}=this.extractContent(e);if(!r&&!n)throw new Error("No content found in AI Overview response");let i="";if(n&&!r){const e="\n body {\n font-family: 'Google Sans', Roboto, sans-serif;\n line-height: 1.5;\n padding: 20px;\n color: #e3e3e3;\n background-color: #131314;\n }\n .gemini-separator {\n border: 0;\n border-top: 1px solid #444;\n margin: 24px 0;\n }\n .gemini-image {\n max-width: 100%;\n border-radius: 8px;\n margin: 12px 0;\n border: 1px solid #333;\n }\n a { color: #8ab4f8; }\n table { border-collapse: collapse; width: 100%; margin: 16px 0; }\n th, td { border: 1px solid #444; padding: 8px; text-align: left; }\n th { background-color: #1f1f1f; }\n ";i=`<!DOCTYPE html>\n <html>\n <head>\n <base href="${(null==t?void 0:t.baseUrl)||this.baseUrl}">\n <style>${e}</style>\n </head>\n <body>\n ${n}\n </body>\n </html>`}else i=r||"",i=this.sanitizeHtml(i),i=this.injectStyles(i,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl,hideUI:!0});return{provider:this.name,html:i,text:n,sources:o,metadata:{isFullDocument:this.isFullDocument(i),hasWizData:!!n&&!r}}}}class m extends l{constructor(){super(...arguments),this.name="AIMODE",this.baseUrl="https://www.google.com",this.defaultStyles='\n /* UI hiding - Google Search (AI Mode) */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L,\n\n /* Specific AI Mode Selectors found in analysis */\n .DZ13He, /* Main sticky top bar */\n .wYq63b, /* Accessibility links bar */\n .eT9Cje, /* History/New Search buttons */\n .bNg8Rb, /* Hidden H1 headers */\n .S6VXfe, /* Accessibility container */\n .Lu57id /* Potential other top bar */ {\n display: none !important;\n }\n\n /* General Layout */\n main { width: 100% !important; max-width: 100% !important; margin: 0 !important; }\n '}extractContent(e){let t="",r="",n=e;return e.result&&(n=e.result),"string"==typeof n?n.trim().startsWith("<")&&n.includes(">")?t=n:r=n:"object"==typeof n&&null!==n&&(n.html?t=n.html:n.content?n.content.trim().startsWith("<")?t=n.content:r=n.content:n.text&&(r=n.text)),{html:t,text:r}}parse(e,t){const{html:r,text:n}=this.extractContent(e);if(!r&&!n)throw new Error("No content found in AI Mode response");let o=r||"";return!o&&n&&(o=`<div>${n.replace(/\n/g,"<br>")}</div>`),o=this.sanitizeHtml(o),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl,hideUI:!0}),{provider:this.name,html:o,text:n,metadata:{isFullDocument:this.isFullDocument(o)}}}}const h=new class{constructor(){this.providers=new Map,this.providers.set("CHATGPT",new c),this.providers.set("GEMINI",new u),this.providers.set("PERPLEXITY",new d),this.providers.set("COPILOT",new p),this.providers.set("AIOVERVIEW",new f),this.providers.set("AIMODE",new m)}parse(e,t){const r=s.detect(e);if(!r)return this.parseGeneric(e,t);const n=this.providers.get(r.provider);if(!n)return null;try{const o=n.parse(e,t);return{...o,metadata:{...o.metadata,detectionConfidence:r.confidence}}}catch(e){return console.error(`Failed to parse response with ${r.provider}:`,e),null}}parseWithProvider(e,t,r){const n=this.providers.get(t);if(!n)throw new Error(`Unknown provider: ${t}`);try{return n.parse(e,r)}catch(e){return console.error(`Failed to parse response with ${t}:`,e),null}}detectProvider(e){const t=s.detect(e);return(null==t?void 0:t.provider)||null}detectAllProviders(e){return s.getAllProviders(e)}parseGeneric(e,t){let r="",n="";let o=e;var i;return e.result&&(o=e.result),"string"==typeof(i=o)?i.trim().startsWith("<")&&i.includes(">")?r=i:n=i:"object"==typeof i&&null!==i&&(i.html?r=i.html:i.content?i.content.trim().startsWith("<")?r=i.content:n=i.content:i.text&&(n=i.text)),r||n?(r&&(r=r.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,""),r=r.replace(/<noscript[\s\S]*?<\/noscript>/gi,"")),{provider:"CHATGPT",html:r,text:n,metadata:{isGeneric:!0}}):null}getSupportedProviders(){return Array.from(this.providers.keys())}registerProvider(e,t){this.providers.set(e,t)}},v=(e,t)=>h.parse(e,t);function y(e,r={}){const{autoDetect:n=!0,provider:o,theme:i="dark",baseUrl:a,sanitize:s=!0,includeStyles:l=!0,onProviderDetected:c,onError:u}=r,[d,p]=t.useState(!1),[f,m]=t.useState(null),[y,b]=t.useState(null),[g,x]=t.useState(0),w=t.useMemo(()=>o||(n&&e?(e=>h.detectProvider(e))(e):null),[e,o,n,g]);t.useEffect(()=>{null==c||c(w)},[w,c]),t.useEffect(()=>{if(!e)return b(null),void m(null);p(!0),m(null);try{const t={theme:i,baseUrl:a,sanitize:s,includeStyles:l};let r;r=v(e,t),b(r)}catch(e){const t=e instanceof Error?e:new Error("Failed to parse AI response");m(t),null==u||u(t)}finally{p(!1)}},[e,i,a,s,l,o,g]);return{parsed:y,provider:(null==y?void 0:y.provider)||w,isLoading:d,error:f,html:(null==y?void 0:y.html)||null,text:(null==y?void 0:y.text)||null,sources:(null==y?void 0:y.sources)||null,reparse:e=>{x(e=>e+1)}}}const b=t.forwardRef(({html:e,className:t="",style:r,sandbox:n="allow-popups allow-same-origin",title:o="AI Response",onLoad:i,onError:s},l)=>{const c=()=>{null==i||i()},u=()=>{null==s||s()};return e.trim().startsWith("http")?a.jsx("iframe",{ref:l,src:e,className:t,style:r,sandbox:n,title:o,onLoad:c,onError:u}):a.jsx("iframe",{ref:l,srcDoc:e,className:t,style:r,sandbox:n,title:o,onLoad:c,onError:u})});b.displayName="IframeRenderer";exports.AiResponseRenderer=({response:e,className:r="",style:n,iframeProps:o={},loadingComponent:i,errorComponent:s,fallbackComponent:l,onRenderComplete:c,...u})=>{const{parsed:d,provider:p,isLoading:f,error:m,html:h,text:v,sources:g,reparse:x}=y(e,u);return t.useEffect(()=>{!h||f||m||null==c||c(h)},[h,f,m,c]),f?i?a.jsx(i,{isLoading:!0}):a.jsx("div",{className:`ai-response-loading ${r}`,style:n,children:a.jsxs("div",{className:"animate-pulse",children:[a.jsx("div",{className:"h-4 bg-gray-300 rounded w-3/4 mb-2"}),a.jsx("div",{className:"h-4 bg-gray-300 rounded w-1/2 mb-2"}),a.jsx("div",{className:"h-4 bg-gray-300 rounded w-5/6"})]})}):m?s?a.jsx(s,{error:m,retry:x}):a.jsx("div",{className:`ai-response-error ${r}`,style:n,children:a.jsxs("div",{className:"text-red-500",children:[a.jsx("p",{children:"Failed to render AI response:"}),a.jsx("p",{className:"text-sm",children:m.message}),a.jsx("button",{onClick:()=>x(),className:"mt-2 px-3 py-1 bg-red-100 text-red-700 rounded hover:bg-red-200",children:"Retry"})]})}):d||h||v?!h&&v?a.jsx("div",{className:`ai-response-text ${r}`,style:{...n,whiteSpace:"pre-wrap",wordWrap:"break-word"},children:v}):h?a.jsx("div",{className:`ai-response-container ${r}`,style:n,children:a.jsx(b,{html:h,className:"w-full h-full border-0 rounded-md",title:`${p||"AI"} Response`,...o})}):null:l?a.jsx(l,{provider:p}):a.jsx("div",{className:`ai-response-empty ${r}`,style:n,children:a.jsxs("div",{className:"text-gray-500 text-center",children:[a.jsx("p",{children:"No content available"}),p&&a.jsxs("p",{className:"text-sm",children:["Detected provider: ",p]})]})})},exports.IframeRenderer=b,exports.useAiResponse=y;
1
+ "use strict";var e=require("react/jsx-runtime"),t=require("react");class n{static detect(e){const t={CHATGPT:0,GEMINI:0,PERPLEXITY:0,COPILOT:0,AIOVERVIEW:0,AIMODE:0};for(const[n,r]of Object.entries(this.PROVIDER_PATTERNS))for(const o of r)try{o(e)&&t[n]++}catch(e){}let n=0,r=null;for(const[e,o]of Object.entries(t))o>n&&(n=o,r=e);return 0===n?null:{provider:r,confidence:n/Object.values(t).reduce((e,t)=>Math.max(e,t),1)}}static getAllProviders(e){const t=[];for(const[n,r]of Object.entries(this.PROVIDER_PATTERNS)){let o=0;for(const t of r)try{t(e)&&o++}catch(e){}o>0&&t.push({provider:n,confidence:o/r.length})}return t.sort((e,t)=>t.confidence-e.confidence)}static validate(e,t){const n=this.detect(e);return(null==n?void 0:n.provider)===t&&n.confidence>.5}}n.PROVIDER_PATTERNS={CHATGPT:[e=>{var t;const n=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return n.includes("bg-token-bg-primary")||n.includes("text-token-text-secondary")},e=>{var t;const n=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return n.includes("chatgpt.com")||n.includes("openai.com")}],GEMINI:[e=>{var t;const n=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return n.includes("bard-sidenav")||n.includes("mat-sidenav")},e=>{var t;const n=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return n.includes("gemini.google.com")||n.includes("gem-sys-color")}],PERPLEXITY:[e=>{var t;const n=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return n.includes("perplexity.ai")||n.includes("prose")}],COPILOT:[e=>{var t;const n=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return n.includes("copilot.microsoft.com")||n.includes('data-testid="sidebar-container"')}],AIOVERVIEW:[e=>{var t,n,r,o;if(null===(n=null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.aioverview)||void 0===n?void 0:n.text)return!0;if(null===(r=null==e?void 0:e.aioverview)||void 0===r?void 0:r.text)return!0;const s=(null===(o=null==e?void 0:e.result)||void 0===o?void 0:o.html)||(null==e?void 0:e.html)||"";return s.includes("WIZ_global_data")||s.includes("DnVkpd")}],AIMODE:[e=>{var t;const n=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return n.includes("DZ13He")||n.includes("wYq63b")||n.includes("AI Mode")}]};class r{injectStyles(e,t){let n=e;(null==t?void 0:t.baseUrl)&&!e.includes("<base ")&&(n=n.includes("<head>")?n.replace("<head>",`<head><base href="${t.baseUrl}">`):n.replace(/(<html[^>]*>)/i,`$1<head><base href="${t.baseUrl}"></head>`));const r=(null==t?void 0:t.customCSS)?this.defaultStyles+"\n"+t.customCSS:this.defaultStyles;return n=n.includes("<head>")?n.replace("<head>",`<head><style>${r}</style>`):n.replace(/(<html[^>]*>)/i,`$1<head><style>${r}</style></head>`),n}sanitizeHtml(e){let t=e.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,"");return t=t.replace(/<noscript[\s\S]*?<\/noscript>/gi,""),t}isFullDocument(e){return/^\s*(<html|<!DOCTYPE)/i.test(e)}wrapFragment(e){return`<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline';">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${e}\n</body>\n</html>`}}class o extends r{constructor(){super(...arguments),this.name="CHATGPT",this.baseUrl="https://chatgpt.com",this.defaultStyles='\n /* Force Dark Background on main containers and wrappers */\n html, body, main, article, footer, form,\n [class*="bg-"], [class*="footer"], [class*="bottom"],\n div[class*="border-t"],\n #thread-bottom-container, #thread-bottom,\n #thread, .composer-parent, [class*="group\\/thread"] {\n background-color: #131314 !important;\n color: #e3e3e3 !important;\n border-color: #2a2b36 !important;\n }\n\n /* Force background on specific white artifacts in the footer */\n #thread-bottom-container .bg-clip-padding,\n #thread-bottom-container .content-fade,\n #thread-bottom-container .absolute {\n background-color: transparent !important;\n }\n\n /* Specific targeting for the composer/input box (was white) */\n form .bg-token-bg-primary, form .shadow-short {\n background-color: #2a2b36 !important;\n border-color: #3e3f4b !important;\n box-shadow: none !important;\n }\n\n /* Disclaimer Footer - Force Dark Background */\n div[class*="text-token-text-secondary"] {\n color: #9ca3af !important;\n background-color: #131314 !important;\n }\n\n /* Force Text Color to Light */\n p, h1, h2, h3, h4, h5, h6, li, span, div, td, th, textarea, button {\n color: #e3e3e3 !important;\n }\n\n /* Links - Light Blue */\n a, a span {\n color: #8ab4f8 !important;\n }\n\n /* Code Blocks */\n pre, code, pre div, code span {\n background-color: #2a2b36 !important;\n color: #e3e3e3 !important;\n text-shadow: none !important;\n }\n\n /* Inputs/Textareas */\n input, textarea {\n background-color: transparent !important;\n color: #e3e3e3 !important;\n border-color: #3e3f4b !important;\n }\n\n /* Placeholder text */\n textarea::placeholder {\n color: #9ca3af !important;\n }\n\n /* Hide Sidebar */\n nav, [class*="sidebar"] {\n display: none !important;\n }\n\n /* Media visibility */\n img, video {\n opacity: 1 !important;\n }\n '}extractContent(e){let t="",n="",r=e;return e.result&&(r=e.result),"string"==typeof r?r.trim().startsWith("<")&&r.includes(">")?t=r:n=r:"object"==typeof r&&null!==r&&(r.html?t=r.html:r.content?r.content.trim().startsWith("<")?t=r.content:n=r.content:r.text&&(n=r.text)),{html:t,text:n}}parse(e,t){const{html:n,text:r}=this.extractContent(e);if(!n&&!r)throw new Error("No content found in ChatGPT response");let o=n||"";return!o&&r&&(o=`<div>${r.replace(/\n/g,"<br>")}</div>`),o=this.sanitizeHtml(o),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl}),{provider:this.name,html:o,text:r,metadata:{isFullDocument:this.isFullDocument(o)}}}}class s extends r{constructor(){super(...arguments),this.name="GEMINI",this.baseUrl="https://gemini.google.com",this.defaultStyles='\n /* Gemini Dark Mode Variable Overrides */\n :root {\n --gem-sys-color--surface: #131314 !important;\n --gem-sys-color--surface-container: #1e1f20 !important;\n --gem-sys-color--on-surface: #e3e3e3 !important;\n --bard-color-synthetic--chat-window-surface: #131314 !important;\n --bard-color-surface-dim-tmp: #131314 !important;\n }\n\n /* UI hiding - Gemini */\n bard-sidenav, mat-sidenav, .mat-drawer-backdrop, .side-nav-menu-button,\n\n /* Gemini "About Gemini" footer/navigation block */\n .gb_5a, .gb_5c, .gb_5d, .gb_5e,\n .gb_Uc, .gb_Vc, .gb_Wc,\n a[href*="about"],\n a[href*="subscriptions"],\n a[href*="business"],\n div[class*="gb_5"],\n .gb_Pd, .gb_Qd, .gb_Rd,\n .gb_Sd, .gb_Td, .gb_Ud, .gb_Vd,\n [aria-label*="About"],\n [aria-label*="Gemini App"],\n [aria-label*="Subscriptions"],\n [aria-label*="For Business"],\n *:contains("About Gemini"),\n *:contains("Gemini App"),\n *:contains("Subscriptions"),\n *:contains("For Business") {\n display: none !important;\n }\n\n /* General Layout */\n main { width: 100% !important; max-width: 100% !important; margin: 0 !important; }\n\n /* Force Dark Mode on Body and Gemini Containers */\n body, .content-container, chat-app, .main-content, .chat-container {\n background-color: #131314 !important;\n color: #e3e3e3 !important;\n }\n '}extractContent(e){let t="",n="",r=[],o=e;return e.result&&(o=e.result),"string"==typeof o?o.trim().startsWith("<")&&o.includes(">")?t=o:n=o:"object"==typeof o&&null!==o&&(o.html?t=o.html:o.content?o.content.trim().startsWith("<")?t=o.content:n=o.content:o.text&&(n=o.text),o.aioverview&&(o.aioverview.text&&(n=o.aioverview.text),o.aioverview.sources&&(r=o.aioverview.sources))),{html:t,text:n,sources:r}}parse(e,t){const{html:n,text:r,sources:o}=this.extractContent(e);if(!n&&!r)throw new Error("No content found in Gemini response");let s=n||"";return!s&&r&&(s=`<div>${r.replace(/\n/g,"<br>")}</div>`),s=this.sanitizeHtml(s),s=this.injectStyles(s,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl}),{provider:this.name,html:s,text:r,sources:o,metadata:{isFullDocument:this.isFullDocument(s)}}}}class i extends r{constructor(){super(...arguments),this.name="PERPLEXITY",this.baseUrl="https://www.perplexity.ai",this.defaultStyles="\n html {\n filter: invert(1) hue-rotate(180deg);\n background-color: white !important;\n }\n img, video, iframe, svg {\n filter: invert(1) hue-rotate(180deg);\n }\n "}extractContent(e){let t="",n="",r=e;return e.result&&(r=e.result),"string"==typeof r?r.trim().startsWith("<")&&r.includes(">")?t=r:n=r:"object"==typeof r&&null!==r&&(r.html?t=r.html:r.content?r.content.trim().startsWith("<")?t=r.content:n=r.content:r.text&&(n=r.text)),{html:t,text:n}}parse(e,t){const{html:n,text:r}=this.extractContent(e);if(!n&&!r)throw new Error("No content found in Perplexity response");let o=n||"";return!o&&r&&(o=`<div>${r.replace(/\n/g,"<br>")}</div>`),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl,customCSS:"light"===(null==t?void 0:t.theme)?"":this.defaultStyles}),{provider:this.name,html:o,text:r,metadata:{isFullDocument:this.isFullDocument(o)}}}}class a extends r{constructor(){super(...arguments),this.name="COPILOT",this.baseUrl="https://copilot.microsoft.com",this.defaultStyles='\n /* Copilot Sidebar & Header */\n div:has(> [data-testid="sidebar-container"]),\n [data-testid="sidebar-container"],\n [data-testid="sticky-header"],\n .side-nav-menu-button {\n display: none !important;\n }\n\n /* General Layout Fixes */\n main {\n width: 100% !important;\n max-width: 100% !important;\n margin: 0 !important;\n }\n '}extractContent(e){let t="",n="",r=e;return e.result&&(r=e.result),"string"==typeof r?r.trim().startsWith("<")&&r.includes(">")?t=r:n=r:"object"==typeof r&&null!==r&&(r.html?t=r.html:r.content?r.content.trim().startsWith("<")?t=r.content:n=r.content:r.text&&(n=r.text)),{html:t,text:n}}parse(e,t){const{html:n,text:r}=this.extractContent(e);if(!n&&!r)throw new Error("No content found in Copilot response");let o=n||"";return!o&&r&&(o=`<div>${r.replace(/\n/g,"<br>")}</div>`),o=o.replace(/<noscript[\s\S]*?<\/noscript>/gi,""),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl}),{provider:this.name,html:o,text:r,metadata:{isFullDocument:this.isFullDocument(o)}}}}class l extends r{constructor(){super(...arguments),this.name="AIOVERVIEW",this.baseUrl="https://www.google.com",this.defaultStyles='\n /* UI hiding - Google Search (AI Overview) */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L,\n\n /* Specific AI Mode Selectors */\n .DZ13He,\n .wYq63b,\n .eT9Cje,\n .bNg8Rb,\n .S6VXfe,\n .Lu57id {\n display: none !important;\n }\n\n /* General Layout */\n main { width: 100% !important; max-width: 100% !important; margin: 0 !important; }\n '}extractContent(e){let t="",n="",r=[],o=e;if(e.result&&(o=e.result),o.aioverview&&(o.aioverview.text&&(n=o.aioverview.text),o.aioverview.sources&&(r=o.aioverview.sources)),"string"==typeof o?o.trim().startsWith("<")&&o.includes(">")?t=o:n=n||o:"object"==typeof o&&null!==o&&(o.html&&!n?t=o.html:o.content&&!n?o.content.trim().startsWith("<")?t=o.content:n=o.content:o.text&&!n&&(n=o.text)),t){const e=t.match(/"DnVkpd"\s*:\s*"((?:[^"\\]|\\.)*)"/);if(e&&e[1])try{let t=JSON.parse(`"${e[1]}"`);t=t.replace(/∰/g,'<hr class="gemini-separator">'),t=t.replace(/∞(https:\/\/[^ ]+\.(?:jpg|png|webp|gif|jpeg)(?:\?[^ ]*)?)/gi,'<br><img src="$1" class="gemini-image" alt="Generated Image"><br>'),t=t.replace(/∞/g,"<br>"),t=t.replace(/\n/g,"<br>"),n=t}catch(e){console.error("Failed to parse AI Overview WIZ data",e)}}return{html:t,text:n,sources:r}}parse(e,t){const{html:n,text:r,sources:o}=this.extractContent(e);if(!n&&!r)throw new Error("No content found in AI Overview response");let s="";if(r&&!n){const e="\n body {\n font-family: 'Google Sans', Roboto, sans-serif;\n line-height: 1.5;\n padding: 20px;\n color: #e3e3e3;\n background-color: #131314;\n }\n .gemini-separator {\n border: 0;\n border-top: 1px solid #444;\n margin: 24px 0;\n }\n .gemini-image {\n max-width: 100%;\n border-radius: 8px;\n margin: 12px 0;\n border: 1px solid #333;\n }\n a { color: #8ab4f8; }\n table { border-collapse: collapse; width: 100%; margin: 16px 0; }\n th, td { border: 1px solid #444; padding: 8px; text-align: left; }\n th { background-color: #1f1f1f; }\n ";s=`<!DOCTYPE html>\n <html>\n <head>\n <base href="${(null==t?void 0:t.baseUrl)||this.baseUrl}">\n <style>${e}</style>\n </head>\n <body>\n ${r}\n </body>\n </html>`}else s=n||"",s=this.sanitizeHtml(s),s=this.injectStyles(s,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl,hideUI:!0});return{provider:this.name,html:s,text:r,sources:o,metadata:{isFullDocument:this.isFullDocument(s),hasWizData:!!r&&!n}}}}class c extends r{constructor(){super(...arguments),this.name="AIMODE",this.baseUrl="https://www.google.com",this.defaultStyles='\n /* UI hiding - Google Search (AI Mode) */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L,\n\n /* Specific AI Mode Selectors found in analysis */\n .DZ13He, /* Main sticky top bar */\n .wYq63b, /* Accessibility links bar */\n .eT9Cje, /* History/New Search buttons */\n .bNg8Rb, /* Hidden H1 headers */\n .S6VXfe, /* Accessibility container */\n .Lu57id /* Potential other top bar */ {\n display: none !important;\n }\n\n /* General Layout */\n main { width: 100% !important; max-width: 100% !important; margin: 0 !important; }\n '}extractContent(e){let t="",n="",r=e;return e.result&&(r=e.result),"string"==typeof r?r.trim().startsWith("<")&&r.includes(">")?t=r:n=r:"object"==typeof r&&null!==r&&(r.html?t=r.html:r.content?r.content.trim().startsWith("<")?t=r.content:n=r.content:r.text&&(n=r.text)),{html:t,text:n}}parse(e,t){const{html:n,text:r}=this.extractContent(e);if(!n&&!r)throw new Error("No content found in AI Mode response");let o=n||"";return!o&&r&&(o=`<div>${r.replace(/\n/g,"<br>")}</div>`),o=this.sanitizeHtml(o),o=this.injectStyles(o,{theme:(null==t?void 0:t.theme)||"dark",baseUrl:(null==t?void 0:t.baseUrl)||this.baseUrl,hideUI:!0}),{provider:this.name,html:o,text:r,metadata:{isFullDocument:this.isFullDocument(o)}}}}const d=new class{constructor(){this.providers=new Map,this.providers.set("CHATGPT",new o),this.providers.set("GEMINI",new s),this.providers.set("PERPLEXITY",new i),this.providers.set("COPILOT",new a),this.providers.set("AIOVERVIEW",new l),this.providers.set("AIMODE",new c)}parse(e,t){const r=n.detect(e);if(!r)return this.parseGeneric(e,t);const o=this.providers.get(r.provider);if(!o)return null;try{const n=o.parse(e,t);return{...n,metadata:{...n.metadata,detectionConfidence:r.confidence}}}catch(e){return console.error(`Failed to parse response with ${r.provider}:`,e),null}}parseWithProvider(e,t,n){const r=this.providers.get(t);if(!r)throw new Error(`Unknown provider: ${t}`);try{return r.parse(e,n)}catch(e){return console.error(`Failed to parse response with ${t}:`,e),null}}detectProvider(e){const t=n.detect(e);return(null==t?void 0:t.provider)||null}detectAllProviders(e){return n.getAllProviders(e)}parseGeneric(e,t){let n="",r="";let o=e;var s;return e.result&&(o=e.result),"string"==typeof(s=o)?s.trim().startsWith("<")&&s.includes(">")?n=s:r=s:"object"==typeof s&&null!==s&&(s.html?n=s.html:s.content?s.content.trim().startsWith("<")?n=s.content:r=s.content:s.text&&(r=s.text)),n||r?(n&&(n=n.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,""),n=n.replace(/<noscript[\s\S]*?<\/noscript>/gi,"")),{provider:"CHATGPT",html:n,text:r,metadata:{isGeneric:!0}}):null}getSupportedProviders(){return Array.from(this.providers.keys())}registerProvider(e,t){this.providers.set(e,t)}},u=(e,t)=>d.parse(e,t);function m(e,n={}){const{autoDetect:r=!0,provider:o,theme:s="dark",baseUrl:i,sanitize:a=!0,includeStyles:l=!0,onProviderDetected:c,onError:m}=n,[h,p]=t.useState(!1),[b,v]=t.useState(null),[g,f]=t.useState(null),[x,y]=t.useState(0),w=t.useMemo(()=>o||(r&&e?(e=>d.detectProvider(e))(e):null),[e,o,r,x]);t.useEffect(()=>{null==c||c(w)},[w,c]),t.useEffect(()=>{if(!e)return f(null),void v(null);p(!0),v(null);try{const t={theme:s,baseUrl:i,sanitize:a,includeStyles:l};let n;n=u(e,t),f(n)}catch(e){const t=e instanceof Error?e:new Error("Failed to parse AI response");v(t),null==m||m(t)}finally{p(!1)}},[e,s,i,a,l,o,x]);return{parsed:g,provider:(null==g?void 0:g.provider)||w,isLoading:h,error:b,html:(null==g?void 0:g.html)||null,text:(null==g?void 0:g.text)||null,sources:(null==g?void 0:g.sources)||null,reparse:e=>{y(e=>e+1)}}}const h=t.forwardRef(({html:t,className:n="",style:r,sandbox:o="allow-popups allow-same-origin",title:s="AI Response",onLoad:i,onError:a},l)=>{const c=()=>{null==i||i()},d=()=>{null==a||a()};return t.trim().startsWith("http")?e.jsx("iframe",{ref:l,src:t,className:n,style:r,sandbox:o,title:s,onLoad:c,onError:d}):e.jsx("iframe",{ref:l,srcDoc:t,className:n,style:r,sandbox:o,title:s,onLoad:c,onError:d})});h.displayName="IframeRenderer";exports.AiResponseRenderer=({response:n,className:r="",style:o,iframeProps:s={},loadingComponent:i,errorComponent:a,fallbackComponent:l,onRenderComplete:c,...d})=>{const{parsed:u,provider:p,isLoading:b,error:v,html:g,text:f,sources:x,reparse:y}=m(n,d);return t.useEffect(()=>{!g||b||v||null==c||c(g)},[g,b,v,c]),b?i?e.jsx(i,{isLoading:!0}):e.jsx("div",{className:`ai-response-loading ${r}`,style:o,children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-4 bg-gray-300 rounded w-3/4 mb-2"}),e.jsx("div",{className:"h-4 bg-gray-300 rounded w-1/2 mb-2"}),e.jsx("div",{className:"h-4 bg-gray-300 rounded w-5/6"})]})}):v?a?e.jsx(a,{error:v,retry:y}):e.jsx("div",{className:`ai-response-error ${r}`,style:o,children:e.jsxs("div",{className:"text-red-500",children:[e.jsx("p",{children:"Failed to render AI response:"}),e.jsx("p",{className:"text-sm",children:v.message}),e.jsx("button",{onClick:()=>y(),className:"mt-2 px-3 py-1 bg-red-100 text-red-700 rounded hover:bg-red-200",children:"Retry"})]})}):u||g||f?!g&&f?e.jsx("div",{className:`ai-response-text ${r}`,style:{...o,whiteSpace:"pre-wrap",wordWrap:"break-word"},children:f}):g?e.jsx("div",{className:`ai-response-container ${r}`,style:o,children:e.jsx(h,{html:g,className:"w-full h-full border-0 rounded-md",title:`${p||"AI"} Response`,...s})}):null:l?e.jsx(l,{provider:p}):e.jsx("div",{className:`ai-response-empty ${r}`,style:o,children:e.jsxs("div",{className:"text-gray-500 text-center",children:[e.jsx("p",{children:"No content available"}),p&&e.jsxs("p",{className:"text-sm",children:["Detected provider: ",p]})]})})},exports.IframeRenderer=h,exports.useAiResponse=m;
11
2
  //# sourceMappingURL=index.js.map