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