@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 4.56 kB
JavaScript
import{__esDecorate as g,__runInitializers as k}from"tslib";import a from"color";import v from"color-interpolate";import{computed as b,reaction as C}from"mobx";import u from"../../../../data";import{createShapeDef as _}from"../../../../renderer";import p,{boothStore as D,layersStore as S,uiState as f}from"../../../../store";import{RegularBooth as I,SpecialBooth as w}from"../../../../store/BoothStore";import{LayersMode as P}from"../../../../store/LayerStore";import n from"../../../../tools/settings";import{defaultRebookingOptions as B}from"../../../RebookingRadioGroup";import{BoothDrawerBaseWithoutPainter as x}from"./BoothDrawerBase";import{buildPathDef as L}from"./config-bg";import{Rect as F}from"./Rect";export default function R(s,i){return new W(s,i)}function A(s){if(s.length===0)return null;const i=s[0];return s.every(h=>h===i)?i:null}export function pathToShapeDef(s,i){const c=[];for(const h of s){const d=L({index:h.index,color:h.color,unblinking:h.unblinking},i);d&&c.push(d)}return c}let W=(()=>{let s=x,i=[],c,h;return class extends s{static{const o=typeof Symbol=="function"&&Symbol.metadata?Object.create(s[Symbol.metadata]??null):void 0;c=[b({keepAlive:!0})],h=[b({keepAlive:!0})],g(this,null,c,{kind:"getter",name:"defaultColor",static:!1,private:!1,access:{has:e=>"defaultColor"in e,get:e=>e.defaultColor},metadata:o},null,i),g(this,null,h,{kind:"getter",name:"selectedColorInterpolateFunc",static:!1,private:!1,access:{has:e=>"selectedColorInterpolateFunc"in e,get:e=>e.selectedColorInterpolateFunc},metadata:o},null,i),o&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:o})}rendererService=k(this,i);constructor(o,e){if(super(e),this.rendererService=o,e.paths){const t=pathToShapeDef(e.paths,p.layerStore.mode!==P.Default?e.layer.name:"");e.shapes=t.map(r=>{const l=f.monochrome?a(r.color).grayscale().rgb().string():this.getBoothColor().string();return r.color==="transparent"?r.color=l:r.defaultColor=r.color,r})}else{const t=e.borderColor==="none"?0:isNaN(e.borderWidth)?D.borderWidth:e.borderWidth;let r=this.booth.rect.withPadding(t/2,t/2);const l=this.getBoothColor().string();e.shapes=[_(F.fromCoreRect(r,this.booth.rotate),l)]}C(()=>this.booth.hover,()=>!this.booth.selected&&this.update()),C(()=>[S.layersLoaded,this.booth.skipDim,this.booth.selected,this.boothShape.selectBgAnimationPart],()=>this.update())}getShape(){return this.booth.shapes}update(){if(S.layersLoaded)for(const o of this.booth.shapes){if(o.dim=this.booth.skipDim?!1:void 0,o.color&&!o.unblinking){const e=o.defaultColor?this.getBoothPathColor(o.defaultColor):this.getBoothColor();o.color=e.string()}this.rendererService.update(o)}}getBoothPathColor(o){const e=this.booth;let t=a(o).hsl();if(e.selected){const r=n.colors.booths.selected;if(window.__fpSettings?.fpVer){let m=this.selectedColorInterpolateFunc(this.boothShape.selectBgAnimationPart);return a(m==="none"?r:m)}const l=a(r).hsl(),y=l.lightness()*this.boothShape.selectBgAnimationPart;t=t.hue(l.hue()).lightness(y)}else e.hover&&(t=t.darken(.1));return t}get defaultColor(){const o=this.booth;let e;if(o instanceof w)e=o.color||n.colors.booths.empty;else if(o instanceof I){if(u.isRebooking){if(!o.exhibitors?.length)return B[0].color.primary;const r=A((o.exhibitors??[]).map(l=>l.rebookingState));return r!==null?B[r].color.primary:"#000000"}const t=n.colors.booths;o.onHold?e=o.holdColor||t.defaultHold:o.exhibitors.length||o.reserved?e=o.soldColor||t.defaultSold:e=o.availColor||t.empty}try{e==="none"&&(e=n.colors.booths.default),a(e)}catch(t){e=n.colors.booths.default,console.error("Booth: defaultColor",t)}return e}get selectedColorInterpolateFunc(){const o=n.colors.booths.seectedLight||(a(this.booth.labelColor||n.boothLabelColor).isLight()?"#000":"#fff"),e=f.selectedRoute?n?.colors?.booths?.wayfinding?.selected:n?.colors?.booths?.selected;return v([o,e])}getBoothColor(){const o=this.booth;let e;if(f.heatmap){const r=p.heatmapStore.getTotalClicksByBooth(o),l=a(p.heatmapStore.getColorByClicks(r));return o.selected?(e=this.selectedColorInterpolateFunc(this.boothShape.selectBgAnimationPart),a(e==="none"?"#f33":e)):o.hover?l.darken(.2).alpha(l.alpha()*1.5):l}o.error?e="#f33":u.isRebooking?e=this.defaultColor:o.selected?e=this.selectedColorInterpolateFunc(this.boothShape.selectBgAnimationPart):e=this.defaultColor;let t;try{t=a(e==="none"?"#f33":e)}catch{t=a(this.defaultColor)}return(o.hover&&!o.selected||o.selected&&u.isRebooking)&&(t=t.darken(.2).alpha(t.alpha()*1.5)),(f.monochrome||f.heatmapYah)&&(t=t.grayscale()),t}}})();