UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) 4.3 kB
import{__decorate as d}from"tslib";import{Rect as B}from"@expofp/geometry";import l from"color";import y from"color-interpolate";import{computed as u,reaction as m}from"mobx";import h from"../../../../data";import{getFpSvgJs as k}from"../../../../data/fp-payloads";import{createShapeDef as v}from"../../../../renderer";import g,{boothStore as D,layersStore as b,uiState as a}from"../../../../store";import{RegularBooth as x,SpecialBooth as L}from"../../../../store/BoothStore";import{RebookingState as P}from"../../../../store/ExhibitorStore";import{LayersMode as I}from"../../../../store/LayerStore";import{rebookingStateConfig as C}from"../../../../tools/rebooking-config";import s from"../../../../tools/settings";import{BoothDrawerBaseWithoutPainter as w}from"./BoothDrawerBase";import{buildPathDef as A}from"./config-bg";export default function F(i,o){return new c(i,o)}function R(i){if(i.length===0)return null;const o=i[0];return i.every(t=>t===o)?o:null}export function pathToShapeDef(i,o){const e=[];for(const t of i){const r=A({index:t.index,color:t.color,unblinking:t.unblinking},o);r&&e.push(r)}return e}class c extends w{constructor(o,e){if(super(e),this.rendererService=o,e.paths){const t=pathToShapeDef(e.paths,g.layerStore.mode!==I.Default?e.layer.name:"");e.shapes=t.map(r=>{const n=a.monochrome?l(r.color).grayscale().rgb().string():this.getBoothColor().string();return r.color==="transparent"?r.color=n:r.defaultColor=r.color,r})}else{const t=e.borderColor==="none"?0:isNaN(e.borderWidth)?D.borderWidth:e.borderWidth,r=this.booth.rect.expand(-t/2),n=this.getBoothColor().string();e.shapes=[v(new B(r.center,r.size,this.booth.rotate),n)]}m(()=>this.booth.hover,()=>!this.booth.selected&&this.update()),m(()=>[b.layersLoaded,this.booth.skipDim,this.booth.selected,this.boothShape.selectBgAnimationPart],()=>this.update())}getShape(){return this.booth.shapes}update(){if(b.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){if(a.heatmap)return this.getHeatmapColor();const e=this.booth;let t=l(o).hsl();if(e.selected){const r=s.colors.booths.selected;if(k().__fpSettings?.fpVer){const f=this.selectedColorInterpolateFunc(this.boothShape.selectBgAnimationPart),p=l(f==="none"?r:f);return a.monochrome?p.grayscale():p}const n=l(r).hsl(),S=n.lightness()*this.boothShape.selectBgAnimationPart;t=t.hue(n.hue()).lightness(S)}else e.hover&&(t=t.darken(.1));return a.monochrome&&(t=t.grayscale()),t}getHeatmapColor(){const o=this.booth,e=g.heatmapStore.getHeatmapColorForBooth(o);if(o.selected){const t=this.selectedColorInterpolateFunc(this.boothShape.selectBgAnimationPart);return l(t==="none"?"#f33":t)}return o.hover?e.darken(.2).alpha(e.alpha()*1.5):e}get defaultColor(){const o=this.booth;let e=s.colors.booths.default;if(o instanceof L)e=o.color||s.colors.booths.empty;else if(o instanceof x){if(h.isRebooking){if(!o.exhibitors?.length)return C[P.Unasked].color.primary;const r=R((o.exhibitors??[]).map(n=>n.rebookingState));return r!==null?C[r].color.primary:"#000000"}const t=s.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=s.colors.booths.default),l(e)}catch(t){e=s.colors.booths.default,console.error("Booth: defaultColor",t)}return e}get selectedColorInterpolateFunc(){const o=s.colors.booths.seectedLight||(l(this.booth.labelColor||s.boothLabelColor).isLight()?"#000":"#fff"),e=a.selectedRoute?s?.colors?.booths?.wayfinding?.selected:s?.colors?.booths?.selected;return y([o,e])}getBoothColor(){const o=this.booth;if(a.heatmap)return this.getHeatmapColor();let e;o.error?e="#f33":h.isRebooking?e=this.defaultColor:o.selected?e=this.selectedColorInterpolateFunc(this.boothShape.selectBgAnimationPart):e=this.defaultColor;let t;try{t=l(e==="none"?"#f33":e)}catch{t=l(this.defaultColor)}return(o.hover&&!o.selected||o.selected&&h.isRebooking)&&(t=t.darken(.2).alpha(t.alpha()*1.5)),(a.monochrome||a.heatmapYah)&&(t=t.grayscale()),t}}d([u({keepAlive:!0})],c.prototype,"defaultColor",null),d([u({keepAlive:!0})],c.prototype,"selectedColorInterpolateFunc",null);