feazy-neo-chat-component 0.1.55 → 0.1.56

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.
@@ -223,11 +223,13 @@ var H3=Object.defineProperty;var J3=(B,Ye,jt)=>Ye in B?H3(B,Ye,{enumerable:!0,co
223
223
  font-style: italic;
224
224
  font-display: swap;
225
225
  }`:"";var z3={grad:.9,turn:360,rad:360/(2*Math.PI)},vt=function(e){return typeof e=="string"?e.length>0:typeof e=="number"},Pe=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=Math.pow(10,t)),Math.round(r*e)/r+0},Re=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=1),e>r?r:e>t?e:t},Au=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},ku=function(e){return{r:Re(e.r,0,255),g:Re(e.g,0,255),b:Re(e.b,0,255),a:Re(e.a)}},va=function(e){return{r:Pe(e.r),g:Pe(e.g),b:Pe(e.b),a:Pe(e.a,3)}},S3=/^#([0-9a-f]{3,8})$/i,Mn=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},zu=function(e){var t=e.r,r=e.g,n=e.b,o=e.a,a=Math.max(t,r,n),i=a-Math.min(t,r,n),s=i?a===t?(r-n)/i:a===r?2+(n-t)/i:4+(t-r)/i:0;return{h:60*(s<0?s+6:s),s:a?i/a*100:0,v:a/255*100,a:o}},Su=function(e){var t=e.h,r=e.s,n=e.v,o=e.a;t=t/360*6,r/=100,n/=100;var a=Math.floor(t),i=n*(1-r),s=n*(1-(t-a)*r),l=n*(1-(1-t+a)*r),c=a%6;return{r:255*[n,s,i,i,l,n][c],g:255*[l,n,n,s,i,i][c],b:255*[i,i,l,n,n,s][c],a:o}},Pu=function(e){return{h:Au(e.h),s:Re(e.s,0,100),l:Re(e.l,0,100),a:Re(e.a)}},Mu=function(e){return{h:Pe(e.h),s:Pe(e.s),l:Pe(e.l),a:Pe(e.a,3)}},Cu=function(e){return Su((r=(t=e).s,{h:t.h,s:(r*=((n=t.l)<50?n:100-n)/100)>0?2*r/(n+r)*100:0,v:n+r,a:t.a}));var t,r,n},Or=function(e){return{h:(t=zu(e)).h,s:(o=(200-(r=t.s))*(n=t.v)/100)>0&&o<200?r*n/100/(o<=100?o:200-o)*100:0,l:o/2,a:t.a};var t,r,n,o},P3=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,M3=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,C3=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,L3=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Lu={string:[[function(e){var t=S3.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?Pe(parseInt(e[3]+e[3],16)/255,2):1}:e.length===6||e.length===8?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:e.length===8?Pe(parseInt(e.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(e){var t=C3.exec(e)||L3.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:ku({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(e){var t=P3.exec(e)||M3.exec(e);if(!t)return null;var r,n,o=Pu({h:(r=t[1],n=t[2],n===void 0&&(n="deg"),Number(r)*(z3[n]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Cu(o)},"hsl"]],object:[[function(e){var t=e.r,r=e.g,n=e.b,o=e.a,a=o===void 0?1:o;return vt(t)&&vt(r)&&vt(n)?ku({r:Number(t),g:Number(r),b:Number(n),a:Number(a)}):null},"rgb"],[function(e){var t=e.h,r=e.s,n=e.l,o=e.a,a=o===void 0?1:o;if(!vt(t)||!vt(r)||!vt(n))return null;var i=Pu({h:Number(t),s:Number(r),l:Number(n),a:Number(a)});return Cu(i)},"hsl"],[function(e){var t=e.h,r=e.s,n=e.v,o=e.a,a=o===void 0?1:o;if(!vt(t)||!vt(r)||!vt(n))return null;var i=function(s){return{h:Au(s.h),s:Re(s.s,0,100),v:Re(s.v,0,100),a:Re(s.a)}}({h:Number(t),s:Number(r),v:Number(n),a:Number(a)});return Su(i)},"hsv"]]},Ou=function(e,t){for(var r=0;r<t.length;r++){var n=t[r][0](e);if(n)return[n,t[r][1]]}return[null,void 0]},O3=function(e){return typeof e=="string"?Ou(e.trim(),Lu.string):typeof e=="object"&&e!==null?Ou(e,Lu.object):[null,void 0]},ya=function(e,t){var r=Or(e);return{h:r.h,s:Re(r.s+100*t,0,100),l:r.l,a:r.a}},xa=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},Du=function(e,t){var r=Or(e);return{h:r.h,s:r.s,l:Re(r.l+100*t,0,100),a:r.a}},Nu=function(){function e(t){this.parsed=O3(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return Pe(xa(this.rgba),2)},e.prototype.isDark=function(){return xa(this.rgba)<.5},e.prototype.isLight=function(){return xa(this.rgba)>=.5},e.prototype.toHex=function(){return t=va(this.rgba),r=t.r,n=t.g,o=t.b,i=(a=t.a)<1?Mn(Pe(255*a)):"","#"+Mn(r)+Mn(n)+Mn(o)+i;var t,r,n,o,a,i},e.prototype.toRgb=function(){return va(this.rgba)},e.prototype.toRgbString=function(){return t=va(this.rgba),r=t.r,n=t.g,o=t.b,(a=t.a)<1?"rgba("+r+", "+n+", "+o+", "+a+")":"rgb("+r+", "+n+", "+o+")";var t,r,n,o,a},e.prototype.toHsl=function(){return Mu(Or(this.rgba))},e.prototype.toHslString=function(){return t=Mu(Or(this.rgba)),r=t.h,n=t.s,o=t.l,(a=t.a)<1?"hsla("+r+", "+n+"%, "+o+"%, "+a+")":"hsl("+r+", "+n+"%, "+o+"%)";var t,r,n,o,a},e.prototype.toHsv=function(){return t=zu(this.rgba),{h:Pe(t.h),s:Pe(t.s),v:Pe(t.v),a:Pe(t.a,3)};var t},e.prototype.invert=function(){return ut({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},e.prototype.saturate=function(t){return t===void 0&&(t=.1),ut(ya(this.rgba,t))},e.prototype.desaturate=function(t){return t===void 0&&(t=.1),ut(ya(this.rgba,-t))},e.prototype.grayscale=function(){return ut(ya(this.rgba,-1))},e.prototype.lighten=function(t){return t===void 0&&(t=.1),ut(Du(this.rgba,t))},e.prototype.darken=function(t){return t===void 0&&(t=.1),ut(Du(this.rgba,-t))},e.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},e.prototype.alpha=function(t){return typeof t=="number"?ut({r:(r=this.rgba).r,g:r.g,b:r.b,a:t}):Pe(this.rgba.a,3);var r},e.prototype.hue=function(t){var r=Or(this.rgba);return typeof t=="number"?ut({h:t,s:r.s,l:r.l,a:r.a}):Pe(r.h)},e.prototype.isEqual=function(t){return this.toHex()===ut(t).toHex()},e}(),ut=function(e){return e instanceof Nu?e:new Nu(e)};class D3 extends HTMLElement{constructor(){super(...arguments);zt(this,"root");zt(this,"container");zt(this,"appliedColorVars",[]);zt(this,"colorOverrideStyle");zt(this,"openChatHandler");zt(this,"remoteConfig");zt(this,"remoteConfigStatus","idle");zt(this,"remoteConfigKey")}static get observedAttributes(){return["prompt-id","api-key","base-url","theme","high-contrast","tenant","config","bubbleless","remote-config"]}connectedCallback(){const r=this.attachShadow({mode:"open"});try{if(!document.querySelector("link[data-inter-rsms]")){const s=document.createElement("link");s.rel="stylesheet",s.href="https://rsms.me/inter/inter.css",s.crossOrigin="anonymous",s.setAttribute("data-inter-rsms",""),document.head.appendChild(s)}}catch{}const n=document.createElement("style");let o=String(x3).replace(/:root/g,":host");const a=16;o=o.replace(/(-?\d*\.?\d+)rem\b/g,(i,s)=>`${Math.round(parseFloat(s)*a*1e3)/1e3}px`),n.textContent=`${k3}
226
- ${o}`,r.appendChild(n),this.colorOverrideStyle=document.createElement("style"),r.appendChild(this.colorOverrideStyle),this.container=document.createElement("div"),this.container.className="widget-root",r.appendChild(this.container),this.render()}attributeChangedCallback(){this.root&&this.render()}normalizeColorValue(r){const n=r.trim();if(!n)return;if(/^\d+(\.\d+)?\s+\d+%?\s+\d+%?$/.test(n))return n;const o=ut(n);if(o.isValid()){const a=o.toHslString(),i=/hsla?\(\s*([\d.]+)[^,]*,\s*([\d.]+)%[^,]*,\s*([\d.]+)%/i.exec(a);if(i){const s=Math.round(parseFloat(i[1])),l=Math.round(parseFloat(i[2])),c=Math.round(parseFloat(i[3]));return`${s} ${l}% ${c}%`}}return n}isThemeColorOverrides(r){if(!r||typeof r!="object")return!1;const n=r,o=a=>a&&typeof a=="object"&&!Array.isArray(a);return o(n.light)||o(n.dark)||o(n.common)}normalizeColorMap(r){if(!r||typeof r!="object"||Array.isArray(r))return;const n={};for(const[o,a]of Object.entries(r)){if(typeof a!="string")continue;const i=this.normalizeColorValue(a);i&&(n[o]=i)}return Object.keys(n).length>0?n:void 0}getThemeAwareColors(r){if(!r)return{};if(!this.isThemeColorOverrides(r))return{dark:r,light:r};const n=r,o=n.common??{},a={...o,...n.dark??{}},i={...o,...n.light??{}};return{dark:Object.keys(a).length>0?a:void 0,light:Object.keys(i).length>0?i:void 0}}buildColorOverrideCss({dark:r,light:n}){const o=l=>{if(!l)return"";const c=[];for(const[u,d]of Object.entries(l)){const f=u.startsWith("--")?u:`--${u}`;c.push(` ${f}: ${d};`)}return c.join(`
227
- `)},a=o(n),i=o(r),s=[];return a&&s.push(`:host .light {
226
+ ${o}`,r.appendChild(n),this.colorOverrideStyle=document.createElement("style"),r.appendChild(this.colorOverrideStyle),this.container=document.createElement("div"),this.container.className="widget-root",r.appendChild(this.container),this.render()}attributeChangedCallback(){this.root&&this.render()}normalizeColorValue(r){const n=r.trim();if(!n)return;if(/^\d+(\.\d+)?\s+\d+%?\s+\d+%?(\s*\/\s*[\d.]+%?)?$/.test(n))return n;const o=ut(n);if(o.isValid()){const a=o.toHsl(),i=Math.round(a.h),s=Math.round(a.s),l=Math.round(a.l),c=`${i} ${s}% ${l}%`;if(typeof a.a=="number"&&a.a<1){const u=Math.round(a.a*1e3)/1e3;return`${c} / ${u}`}return c}return n}normalizeColorKey(r){const n=r.trim();return n&&(n.startsWith("--")?n.slice(2):n).replace(/_/g,"-").replace(/([A-Z]+)([A-Z][a-z0-9]+)/g,"$1-$2").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()||void 0}isGlowCssVar(r){return r==="--glow-primary"||r==="--glow-secondary"||r==="--glow-accent"}applyDefaultGlowAlpha(r,n,o){const a=n.trim();return!this.isGlowCssVar(r)||/\//.test(a)?a:/^\d+(\.\d+)?\s+\d+%?\s+\d+%?$/.test(a)?`${a} / ${o}`:a}isThemeColorOverrides(r){if(!r||typeof r!="object")return!1;const n=r,o=a=>a&&typeof a=="object"&&!Array.isArray(a);return o(n.light)||o(n.dark)||o(n.common)}normalizeColorMap(r){if(!r||typeof r!="object"||Array.isArray(r))return;const n={};for(const[o,a]of Object.entries(r)){if(typeof a!="string")continue;const i=this.normalizeColorKey(o);if(!i)continue;const s=this.normalizeColorValue(a);s&&(n[i]=s)}return Object.keys(n).length>0?n:void 0}getThemeAwareColors(r){if(!r)return{};if(!this.isThemeColorOverrides(r))return{dark:r,light:r};const n=r,o=n.common??{},a={...o,...n.dark??{}},i={...o,...n.light??{}};return{dark:Object.keys(a).length>0?a:void 0,light:Object.keys(i).length>0?i:void 0}}buildColorOverrideCss({dark:r,light:n}){const o=(c,u)=>{if(!c)return"";const d=[];for(const[f,p]of Object.entries(c)){const h=f.startsWith("--")?f:`--${f}`,g=this.applyDefaultGlowAlpha(h,p,u.defaultGlowAlpha);d.push(` ${h}: ${g};`)}return d.join(`
227
+ `)},a=o(n,{defaultGlowAlpha:.2}),i=o(n,{defaultGlowAlpha:.3}),s=o(r,{defaultGlowAlpha:.6}),l=[];return a&&l.push(`:host .light:not(.high-contrast) {
228
228
  ${a}
229
- }`),i&&s.push(`:host .high-contrast:not(.light) {
229
+ }`),i&&l.push(`:host .light.high-contrast {
230
230
  ${i}
231
- }`),s.join(`
231
+ }`),s&&l.push(`:host .high-contrast:not(.light) {
232
+ ${s}
233
+ }`),l.join(`
232
234
 
233
- `)}loadRemoteConfig(r,n){if(!r||!n)return;const o=n.replace(/\/+$/,""),a=`${o}|${r}`;if(this.remoteConfigKey===a&&(this.remoteConfigStatus==="loading"||this.remoteConfigStatus==="loaded"))return;this.remoteConfigKey=a,this.remoteConfigStatus="loading";const i=`${o}/v1/chat-settings/widget-config/${encodeURIComponent(r)}`;fetch(i,{method:"GET"}).then(async s=>{if(!s.ok){console.warn("Failed to load remote chat widget config:",s.status,s.statusText),this.remoteConfigStatus="error";return}const l=await s.json();this.remoteConfig=this.normalizeRemoteConfig(l),this.remoteConfigStatus="loaded",this.render()}).catch(s=>{console.error("Error loading remote chat widget config:",s),this.remoteConfigStatus="error"})}normalizeRemoteConfig(r){if(!r||typeof r!="object")return{};const n=r,o={...n};if(n.api&&typeof n.api=="object"){const a=n.api;typeof a.baseUrl=="string"&&a.baseUrl&&(o.baseUrl=a.baseUrl),typeof a.tenant=="string"&&a.tenant&&(o.tenant=a.tenant)}if(n.colors&&typeof n.colors=="object"){const a=n.colors;if(this.normalizeColorMap(a.common)||this.normalizeColorMap(a.light)||this.normalizeColorMap(a.dark)){const s=this.normalizeColorMap(a.common),l=this.normalizeColorMap(a.light),c=this.normalizeColorMap(a.dark),u={};s&&(u.common=s),l&&(u.light=l),c&&(u.dark=c),o.colors=u}else{const s=this.normalizeColorMap(a);s?o.colors=s:delete o.colors}}return o}render(){if(!this.container)return;const r=this.getAttribute("prompt-id")||void 0,n=this.getAttribute("api-key")||void 0,o=this.getAttribute("base-url")||void 0,a=this.getAttribute("tenant")||void 0,i=this.getAttribute("theme")||"dark",s=this.getAttribute("high-contrast")==="true",l=this.hasAttribute("bubbleless"),c=l?this.getAttribute("bubbleless"):null,u=l?c===null||c===""||c==="true":void 0,d=this.hasAttribute("remote-config"),f=d?this.getAttribute("remote-config"):null,p=d?f===null||f===""||f==="true":!1,h=this.getAttribute("config");let g;if(h)try{g=JSON.parse(h)}catch(P){console.warn("Failed to parse chat-component config attribute:",P)}p?this.loadRemoteConfig(r,o):(this.remoteConfigStatus="idle",this.remoteConfig=null,this.remoteConfigKey=void 0);const w={...g,promptId:(g==null?void 0:g.promptId)??r,apiKey:(g==null?void 0:g.apiKey)??n,baseUrl:(g==null?void 0:g.baseUrl)??o,tenant:(g==null?void 0:g.tenant)??a,theme:(g==null?void 0:g.theme)??i,highContrast:(g==null?void 0:g.highContrast)??s};let b;if(p&&this.remoteConfig){const P=qn(this.remoteConfig);b=bf(P,w)}else b=qn(w);const k=this.getThemeAwareColors(b.colors);if(this.appliedColorVars.forEach(P=>this.container.style.removeProperty(P)),this.appliedColorVars=[],k.dark)for(const[P,M]of Object.entries(k.dark)){const S=P.startsWith("--")?P:`--${P}`;this.container.style.setProperty(S,M),this.appliedColorVars.push(S)}this.colorOverrideStyle&&(this.colorOverrideStyle.textContent=this.buildColorOverrideCss(k));const y=p&&this.remoteConfigStatus!=="loaded"?!0:u;this.root||(this.root=Da(this.container)),this.root.render(m.jsx(B.StrictMode,{children:m.jsx(y3,{config:b,bubbleless:y,registerOpenHandler:P=>{this.openChatHandler=P}})}))}openChat(){this.openChatHandler&&this.openChatHandler()}}customElements.get("chat-component")||customElements.define("chat-component",D3)})(React,ReactDOM);
235
+ `)}loadRemoteConfig(r,n){if(!r||!n)return;const o=n.replace(/\/+$/,""),a=`${o}|${r}`;if(this.remoteConfigKey===a&&(this.remoteConfigStatus==="loading"||this.remoteConfigStatus==="loaded"))return;this.remoteConfigKey=a,this.remoteConfigStatus="loading";const i=`${o}/v1/chat-settings/widget-config/${encodeURIComponent(r)}`;fetch(i,{method:"GET"}).then(async s=>{if(!s.ok){console.warn("Failed to load remote chat widget config:",s.status,s.statusText),this.remoteConfigStatus="error";return}const l=await s.json();this.remoteConfig=this.normalizeRemoteConfig(l),this.remoteConfigStatus="loaded",this.render()}).catch(s=>{console.error("Error loading remote chat widget config:",s),this.remoteConfigStatus="error"})}normalizeRemoteConfig(r){if(!r||typeof r!="object")return{};const n=r,o={...n};if(n.api&&typeof n.api=="object"){const a=n.api;typeof a.baseUrl=="string"&&a.baseUrl&&(o.baseUrl=a.baseUrl),typeof a.tenant=="string"&&a.tenant&&(o.tenant=a.tenant)}if(n.colors&&typeof n.colors=="object"){const a=n.colors;if(this.normalizeColorMap(a.common)||this.normalizeColorMap(a.light)||this.normalizeColorMap(a.dark)){const s=this.normalizeColorMap(a.common),l=this.normalizeColorMap(a.light),c=this.normalizeColorMap(a.dark),u={};s&&(u.common=s),l&&(u.light=l),c&&(u.dark=c),o.colors=u}else{const s=this.normalizeColorMap(a);s?o.colors=s:delete o.colors}}return o}render(){if(!this.container)return;const r=this.getAttribute("prompt-id")||void 0,n=this.getAttribute("api-key")||void 0,o=this.getAttribute("base-url")||void 0,a=this.getAttribute("tenant")||void 0,i=this.getAttribute("theme")||"dark",s=this.getAttribute("high-contrast")==="true",l=this.hasAttribute("bubbleless"),c=l?this.getAttribute("bubbleless"):null,u=l?c===null||c===""||c==="true":void 0,d=this.hasAttribute("remote-config"),f=d?this.getAttribute("remote-config"):null,p=d?f===null||f===""||f==="true":!1,h=this.getAttribute("config");let g;if(h)try{g=JSON.parse(h)}catch(P){console.warn("Failed to parse chat-component config attribute:",P)}p?this.loadRemoteConfig(r,o):(this.remoteConfigStatus="idle",this.remoteConfig=null,this.remoteConfigKey=void 0);const w={...g,promptId:(g==null?void 0:g.promptId)??r,apiKey:(g==null?void 0:g.apiKey)??n,baseUrl:(g==null?void 0:g.baseUrl)??o,tenant:(g==null?void 0:g.tenant)??a,theme:(g==null?void 0:g.theme)??i,highContrast:(g==null?void 0:g.highContrast)??s};let b;if(p&&this.remoteConfig){const P=qn(this.remoteConfig);b=bf(P,w)}else b=qn(w);const k=this.getThemeAwareColors(b.colors);if(this.appliedColorVars.forEach(P=>this.container.style.removeProperty(P)),this.appliedColorVars=[],k.dark)for(const[P,M]of Object.entries(k.dark)){const S=P.startsWith("--")?P:`--${P}`,C=this.applyDefaultGlowAlpha(S,M,.3);this.container.style.setProperty(S,C),this.appliedColorVars.push(S)}this.colorOverrideStyle&&(this.colorOverrideStyle.textContent=this.buildColorOverrideCss(k));const y=p&&this.remoteConfigStatus!=="loaded"?!0:u;this.root||(this.root=Da(this.container)),this.root.render(m.jsx(B.StrictMode,{children:m.jsx(y3,{config:b,bubbleless:y,registerOpenHandler:P=>{this.openChatHandler=P}})}))}openChat(){this.openChatHandler&&this.openChatHandler()}}customElements.get("chat-component")||customElements.define("chat-component",D3)})(React,ReactDOM);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feazy-neo-chat-component",
3
- "version": "0.1.55",
3
+ "version": "0.1.56",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/chat-component.cjs.js",