UNPKG

iobroker.lovelace

Version:

With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI

1 lines 15.1 kB
export const __rspack_esm_id=87941;export const __rspack_esm_ids=[87941];export const __webpack_modules__={10020(t,e,r){r.d(e,{j:()=>a});r(14603),r(47566),r(98721);class i{scaleDown(t){const e=this.getWidth(),r=this.getHeight();let i=1;if(t.maxDimension>0){const n=Math.max(e,r);n>t.maxDimension&&(i=t.maxDimension/n)}else i=1/t.quality;i<1&&this.resize(e*i,r*i,i)}}r(18111),r(7588);function n(t,...e){return e.forEach(e=>{if(e)for(const r in e)if(e.hasOwnProperty(r)){const i=e[r];Array.isArray(i)?t[r]=i.slice(0):"object"==typeof i?(t[r]||(t[r]={}),n(t[r],i)):t[r]=i}}),t}r(44114);class s{maxColorCount(t){return this._opts.colorCount=t,this}maxDimension(t){return this._opts.maxDimension=t,this}addFilter(t){return this._opts.filters?this._opts.filters.push(t):this._opts.filters=[t],this}removeFilter(t){if(this._opts.filters){const e=this._opts.filters.indexOf(t);e>0&&this._opts.filters.splice(e)}return this}clearFilters(){return this._opts.filters=[],this}quality(t){return this._opts.quality=t,this}useImageClass(t){return this._opts.ImageClass=t,this}useGenerator(t,e){return this._opts.generators||(this._opts.generators=[]),this._opts.generators.push(e?{name:t,options:e}:t),this}useQuantizer(t,e){return this._opts.quantizer=e?{name:t,options:e}:t,this}build(){return new a(this._src,this._opts)}getPalette(){return this.build().getPalette()}constructor(t,e={}){this._src=t,this._opts=n({},a.DefaultOpts,e)}}const o=class t{static use(t){this._pipeline=t}static from(t){return new s(t)}get result(){return this._result}_process(e,r){e.scaleDown(this.opts);const i=function(t,e){const{colorCount:r,quantizer:i,generators:s,filters:o}=t,a={colorCount:r},h="string"==typeof i?{name:i,options:{}}:i;return h.options=n({},a,h.options),n({},{quantizer:h,generators:s,filters:o},e)}(this.opts,r);return t._pipeline.process(e.getImageData(),i)}async getPalette(){const t=new this.opts.ImageClass;try{const e=await t.load(this._src),r=await this._process(e,{generators:["default"]});this._result=r;const i=r.palettes.default;if(!i)throw new Error("Something went wrong and a palette was not found, please file a bug against our GitHub repo: https://github.com/vibrant-Colors/node-vibrant/");return t.remove(),i}catch(e){return t.remove(),Promise.reject(e)}}async getPalettes(){const t=new this.opts.ImageClass;try{const e=await t.load(this._src),r=await this._process(e,{generators:["*"]});this._result=r;const i=r.palettes;return t.remove(),i}catch(e){return t.remove(),Promise.reject(e)}}constructor(e,r){this._src=e,this.opts=n({},t.DefaultOpts,r)}};o.DefaultOpts={colorCount:64,quality:5,filters:[]};let a=o;a.DefaultOpts.quantizer="mmcq",a.DefaultOpts.generators=["default"],a.DefaultOpts.filters=["default"],a.DefaultOpts.ImageClass=class extends i{_getCanvas(){if(!this._canvas)throw new Error("Canvas is not initialized");return this._canvas}_getContext(){if(!this._context)throw new Error("Context is not initialized");return this._context}_getWidth(){if(!this._width)throw new Error("Width is not initialized");return this._width}_getHeight(){if(!this._height)throw new Error("Height is not initialized");return this._height}_initCanvas(){const t=this.image;if(!t)throw new Error("Image is not initialized");const e=this._canvas=document.createElement("canvas"),r=e.getContext("2d");if(!r)throw new ReferenceError("Failed to create canvas context");this._context=r,e.className="@vibrant/canvas",e.style.display="none",this._width=e.width=t.width,this._height=e.height=t.height,r.drawImage(t,0,0),document.body.appendChild(e)}load(t){let e,r;if("string"==typeof t)e=document.createElement("img"),r=t,function(t){const e=new URL(t,location.href);return e.protocol===location.protocol&&e.host===location.host&&e.port===location.port}(r)||function(t,e){const r=new URL(t),i=new URL(e);return r.protocol===i.protocol&&r.hostname===i.hostname&&r.port===i.port}(window.location.href,r)||(e.crossOrigin="anonymous"),e.src=r;else{if(!(t instanceof HTMLImageElement))return Promise.reject(new Error("Cannot load buffer as an image in browser"));e=t,r=t.src}return this.image=e,new Promise((t,i)=>{const n=()=>{this._initCanvas(),t(this)};e.complete?n():(e.onload=n,e.onerror=t=>i(new Error(`Fail to load image: ${r}`)))})}clear(){this._getContext().clearRect(0,0,this._getWidth(),this._getHeight())}update(t){this._getContext().putImageData(t,0,0)}getWidth(){return this._getWidth()}getHeight(){return this._getHeight()}resize(t,e,r){if(!this.image)throw new Error("Image is not initialized");this._width=this._getCanvas().width=t,this._height=this._getCanvas().height=e,this._getContext().scale(r,r),this._getContext().drawImage(this.image,0,0)}getPixelCount(){return this._getWidth()*this._getHeight()}getImageData(){return this._getContext().getImageData(0,0,this._getWidth(),this._getHeight())}remove(){this._canvas&&this._canvas.parentNode&&this._canvas.parentNode.removeChild(this._canvas)}};r(22489);function h(t,e,r){let i,n,s;function o(t,e,r){return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t}if(0===e)i=n=s=r;else{const a=r<.5?r*(1+e):r+e-r*e,h=2*r-a;i=o(h,a,t+1/3),n=o(h,a,t),s=o(h,a,t-1/3)}return[255*i,255*n,255*s]}class u{static applyFilters(t,e){return e.length>0?t.filter(({r:t,g:r,b:i})=>{for(let n=0;n<e.length;n++)if(!e[n]?.(t,r,i,255))return!1;return!0}):t}static clone(t){return new u(t._rgb,t._population)}get r(){return this._rgb[0]}get g(){return this._rgb[1]}get b(){return this._rgb[2]}get rgb(){return this._rgb}get hsl(){if(!this._hsl){const[t,e,r]=this._rgb;this._hsl=function(t,e,r){t/=255,e/=255,r/=255;const i=Math.max(t,e,r),n=Math.min(t,e,r);let s=0,o=0;const a=(i+n)/2;if(i!==n){const h=i-n;switch(o=a>.5?h/(2-i-n):h/(i+n),i){case t:s=(e-r)/h+(e<r?6:0);break;case e:s=(r-t)/h+2;break;case r:s=(t-e)/h+4}s/=6}return[s,o,a]}(t,e,r)}return this._hsl}get hex(){if(!this._hex){const[t,e,r]=this._rgb;this._hex=function(t,e,r){return"#"+((1<<24)+(t<<16)+(e<<8)+r).toString(16).slice(1,7)}(t,e,r)}return this._hex}get population(){return this._population}toJSON(){return{rgb:this.rgb,population:this.population}}getYiq(){if(!this._yiq){const t=this._rgb;this._yiq=(299*t[0]+587*t[1]+114*t[2])/1e3}return this._yiq}get titleTextColor(){return this._titleTextColor||(this._titleTextColor=this.getYiq()<200?"#fff":"#000"),this._titleTextColor}get bodyTextColor(){return this._bodyTextColor||(this._bodyTextColor=this.getYiq()<150?"#fff":"#000"),this._bodyTextColor}constructor(t,e){this._rgb=t,this._population=e}}r(16573),r(78100),r(77936),r(37467),r(44732),r(79577);class l{get colorCount(){return this._colorCount}constructor(t,e){this.pixels=t,this.opts=e;const{sigBits:r}=e,i=(t,e,i)=>(t<<2*r)+(e<<r)+i;this.getColorIndex=i;const n=8-r,s=new Uint32Array(1<<3*r);let o,a,h,u,l,c,g,m,f,_;o=h=l=0,a=u=c=Number.MAX_VALUE;const p=t.length/4;let d=0;for(;d<p;){const e=4*d;if(d++,g=t[e+0],m=t[e+1],f=t[e+2],_=t[e+3],0===_)continue;g>>=n,m>>=n,f>>=n;const r=i(g,m,f);void 0===s[r]&&(s[r]=0),s[r]+=1,g>o&&(o=g),g<a&&(a=g),m>h&&(h=m),m<u&&(u=m),f>l&&(l=f),f<c&&(c=f)}this._colorCount=s.reduce((t,e)=>e>0?t+1:t,0),this.hist=s,this.rmax=o,this.rmin=a,this.gmax=h,this.gmin=u,this.bmax=l,this.bmin=c}}class c{static build(t){const e=new l(t,{sigBits:5}),{rmin:r,rmax:i,gmin:n,gmax:s,bmin:o,bmax:a}=e;return new c(r,i,n,s,o,a,e)}invalidate(){this._volume=this._count=-1,this._avg=null}volume(){if(this._volume<0){const{r1:t,r2:e,g1:r,g2:i,b1:n,b2:s}=this.dimension;this._volume=(e-t+1)*(i-r+1)*(s-n+1)}return this._volume}count(){if(this._count<0){const{hist:t,getColorIndex:e}=this.histogram,{r1:r,r2:i,g1:n,g2:s,b1:o,b2:a}=this.dimension;let h=0;for(let u=r;u<=i;u++)for(let r=n;r<=s;r++)for(let i=o;i<=a;i++){const n=e(u,r,i);t[n]&&(h+=t[n])}this._count=h}return this._count}clone(){const{histogram:t}=this,{r1:e,r2:r,g1:i,g2:n,b1:s,b2:o}=this.dimension;return new c(e,r,i,n,s,o,t)}avg(){if(!this._avg){const{hist:t,getColorIndex:e}=this.histogram,{r1:r,r2:i,g1:n,g2:s,b1:o,b2:a}=this.dimension;let h=0;const u=8;let l,c,g;l=c=g=0;for(let m=r;m<=i;m++)for(let r=n;r<=s;r++)for(let i=o;i<=a;i++){const n=t[e(m,r,i)];n&&(h+=n,l+=n*(m+.5)*u,c+=n*(r+.5)*u,g+=n*(i+.5)*u)}this._avg=h?[~~(l/h),~~(c/h),~~(g/h)]:[~~(u*(r+i+1)/2),~~(u*(n+s+1)/2),~~(u*(o+a+1)/2)]}return this._avg}contains(t){let[e,r,i]=t;const{r1:n,r2:s,g1:o,g2:a,b1:h,b2:u}=this.dimension;return e>>=3,r>>=3,i>>=3,e>=n&&e<=s&&r>=o&&r<=a&&i>=h&&i<=u}split(){const{hist:t,getColorIndex:e}=this.histogram,{r1:r,r2:i,g1:n,g2:s,b1:o,b2:a}=this.dimension,h=this.count();if(!h)return[];if(1===h)return[this.clone()];const u=i-r+1,l=s-n+1,c=a-o+1,g=Math.max(u,l,c);let m,f,_=null;m=f=0;let p=null;if(g===u){p="r",_=new Uint32Array(i+1);for(let h=r;h<=i;h++){m=0;for(let r=n;r<=s;r++)for(let i=o;i<=a;i++){const n=e(h,r,i);t[n]&&(m+=t[n])}f+=m,_[h]=f}}else if(g===l){p="g",_=new Uint32Array(s+1);for(let h=n;h<=s;h++){m=0;for(let n=r;n<=i;n++)for(let r=o;r<=a;r++){const i=e(n,h,r);t[i]&&(m+=t[i])}f+=m,_[h]=f}}else{p="b",_=new Uint32Array(a+1);for(let h=o;h<=a;h++){m=0;for(let o=r;o<=i;o++)for(let r=n;r<=s;r++){const i=e(o,r,h);t[i]&&(m+=t[i])}f+=m,_[h]=f}}let d=-1;const b=new Uint32Array(_.length);for(let t=0;t<_.length;t++){const e=_[t];e&&(d<0&&e>f/2&&(d=t),b[t]=f-e)}const w=this;return function(t){const e=t+"1",r=t+"2",i=w.dimension[e];let n=w.dimension[r];const s=w.clone(),o=w.clone(),a=d-i,h=n-d;for(a<=h?(n=Math.min(n-1,~~(d+h/2)),n=Math.max(0,n)):(n=Math.max(i,~~(d-1-a/2)),n=Math.min(w.dimension[r],n));!_[n];)n++;let u=b[n];for(;!u&&_[n-1];)u=b[--n];return s.dimension[r]=n,o.dimension[e]=n+1,[s,o]}(p)}constructor(t,e,r,i,n,s,o){this.histogram=o,this._volume=-1,this._avg=null,this._count=-1,this.dimension={r1:t,r2:e,g1:r,g2:i,b1:n,b2:s}}}r(61701);class g{_sort(){this._sorted||(this.contents.sort(this._comparator),this._sorted=!0)}push(t){this.contents.push(t),this._sorted=!1}peek(t){return this._sort(),t="number"==typeof t?t:this.contents.length-1,this.contents[t]}pop(){return this._sort(),this.contents.pop()}size(){return this.contents.length}map(t){return this._sort(),this.contents.map(t)}constructor(t){this._comparator=t,this.contents=[],this._sorted=!1}}function m(t,e){let r=t.size();for(;t.size()<e;){const e=t.pop();if(!(e&&e.count()>0))break;{const[i,n]=e.split();if(!i)break;if(t.push(i),n&&n.count()>0&&t.push(n),t.size()===r)break;r=t.size()}}}const f={targetDarkLuma:.26,maxDarkLuma:.45,minLightLuma:.55,targetLightLuma:.74,minNormalLuma:.3,targetNormalLuma:.5,maxNormalLuma:.7,targetMutesSaturation:.3,maxMutesSaturation:.4,targetVibrantSaturation:1,minVibrantSaturation:.35,weightSaturation:3,weightLuma:6.5,weightPopulation:.5};function _(t,e,r,i,n,s,o,a,h,u){let l=null,c=0;return e.forEach(e=>{const[,g,m]=e.hsl;if(g>=a&&g<=h&&m>=n&&m<=s&&!function(t,e){return t.Vibrant===e||t.DarkVibrant===e||t.LightVibrant===e||t.Muted===e||t.DarkMuted===e||t.LightMuted===e}(t,e)){const t=function(t,e,r,i,n,s,o){function a(t,e){return 1-Math.abs(t-e)}return function(...t){let e=0,r=0;for(let i=0;i<t.length;i+=2){const n=t[i],s=t[i+1];n&&s&&(e+=n*s,r+=s)}return e/r}(a(t,e),o.weightSaturation,a(r,i),o.weightLuma,n/s,o.weightPopulation)}(g,o,m,i,e.population,r,u);(null===l||t>c)&&(l=e,c=t)}}),l}r(18237);class p{names(){return Object.keys(this._map)}has(t){return!!this._map[t]}get(t){return this._map[t]}register(t,e){return this._map[t]=e,this.pipeline}constructor(t){this.pipeline=t,this._map={}}}const d=(new class{_buildProcessTasks({filters:t,quantizer:e,generators:r}){return 1===r.length&&"*"===r[0]&&(r=this.generator.names()),{filters:t.map(t=>i(this.filter,t)),quantizer:i(this.quantizer,e),generators:r.map(t=>i(this.generator,t))};function i(t,e){let r,i;return"string"==typeof e?r=e:(r=e.name,i=e.options),{name:r,fn:t.get(r),options:i}}}async process(t,e){const{filters:r,quantizer:i,generators:n}=this._buildProcessTasks(e),s=await this._filterColors(r,t),o=await this._generateColors(i,s);return{colors:o,palettes:await this._generatePalettes(n,o)}}_filterColors(t,e){return Promise.resolve(function(t,e){if(e.length>0){const r=t.data,i=r.length/4;let n,s,o,a,h;for(let t=0;t<i;t++){n=4*t,s=r[n+0],o=r[n+1],a=r[n+2],h=r[n+3];for(let t=0;t<e.length;t++)if(!e[t]?.(s,o,a,h)){r[n+3]=0;break}}}return t}(e,t.map(({fn:t})=>t)))}_generateColors(t,e){return Promise.resolve(t.fn(e.data,t.options))}async _generatePalettes(t,e){const r=await Promise.all(t.map(({fn:t,options:r})=>Promise.resolve(t(e,r))));return Promise.resolve(r.reduce((e,r,i)=>(e[t[i].name]=r,e),{}))}constructor(){this.filter=new p(this),this.quantizer=new p(this),this.generator=new p(this)}}).filter.register("default",(t,e,r,i)=>i>=125&&!(t>250&&e>250&&r>250)).quantizer.register("mmcq",(t,e)=>{if(0===t.length||e.colorCount<2||e.colorCount>256)throw new Error("Wrong MMCQ parameters");const r=c.build(t);r.histogram.colorCount;const i=new g((t,e)=>t.count()-e.count());i.push(r),m(i,.75*e.colorCount);const n=new g((t,e)=>t.count()*t.volume()-e.count()*e.volume());return n.contents=i.contents,m(n,e.colorCount-n.size()),function(t){const e=[];for(;t.size();){const r=t.pop(),i=r.avg(),[n,s,o]=i;e.push(new u(i,r.count()))}return e}(n)}).generator.register("default",(t,e)=>{e=Object.assign({},f,e);const r=function(t){let e=0;return t.forEach(t=>{e=Math.max(e,t.population)}),e}(t),i=function(t,e,r){const i={Vibrant:null,DarkVibrant:null,LightVibrant:null,Muted:null,DarkMuted:null,LightMuted:null};return i.Vibrant=_(i,t,e,r.targetNormalLuma,r.minNormalLuma,r.maxNormalLuma,r.targetVibrantSaturation,r.minVibrantSaturation,1,r),i.LightVibrant=_(i,t,e,r.targetLightLuma,r.minLightLuma,1,r.targetVibrantSaturation,r.minVibrantSaturation,1,r),i.DarkVibrant=_(i,t,e,r.targetDarkLuma,0,r.maxDarkLuma,r.targetVibrantSaturation,r.minVibrantSaturation,1,r),i.Muted=_(i,t,e,r.targetNormalLuma,r.minNormalLuma,r.maxNormalLuma,r.targetMutesSaturation,0,r.maxMutesSaturation,r),i.LightMuted=_(i,t,e,r.targetLightLuma,r.minLightLuma,1,r.targetMutesSaturation,0,r.maxMutesSaturation,r),i.DarkMuted=_(i,t,e,r.targetDarkLuma,0,r.maxDarkLuma,r.targetMutesSaturation,0,r.maxMutesSaturation,r),i}(t,r,e);return function(t,e,r){if(!t.Vibrant&&!t.DarkVibrant&&!t.LightVibrant){if(!t.DarkVibrant&&t.DarkMuted){let[e,i,n]=t.DarkMuted.hsl;n=r.targetDarkLuma,t.DarkVibrant=new u(h(e,i,n),0)}if(!t.LightVibrant&&t.LightMuted){let[e,i,n]=t.LightMuted.hsl;n=r.targetDarkLuma,t.DarkVibrant=new u(h(e,i,n),0)}}if(!t.Vibrant&&t.DarkVibrant){let[e,i,n]=t.DarkVibrant.hsl;n=r.targetNormalLuma,t.Vibrant=new u(h(e,i,n),0)}else if(!t.Vibrant&&t.LightVibrant){let[e,i,n]=t.LightVibrant.hsl;n=r.targetNormalLuma,t.Vibrant=new u(h(e,i,n),0)}if(!t.DarkVibrant&&t.Vibrant){let[e,i,n]=t.Vibrant.hsl;n=r.targetDarkLuma,t.DarkVibrant=new u(h(e,i,n),0)}if(!t.LightVibrant&&t.Vibrant){let[e,i,n]=t.Vibrant.hsl;n=r.targetLightLuma,t.LightVibrant=new u(h(e,i,n),0)}if(!t.Muted&&t.Vibrant){let[e,i,n]=t.Vibrant.hsl;n=r.targetMutesSaturation,t.Muted=new u(h(e,i,n),0)}if(!t.DarkMuted&&t.DarkVibrant){let[e,i,n]=t.DarkVibrant.hsl;n=r.targetMutesSaturation,t.DarkMuted=new u(h(e,i,n),0)}if(!t.LightMuted&&t.LightVibrant){let[e,i,n]=t.LightVibrant.hsl;n=r.targetMutesSaturation,t.LightMuted=new u(h(e,i,n),0)}}(i,0,e),i});a.use(d)}};