UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) • 832 B
export function createStyleTransform(l,p){if(typeof l!="string")return;const y=new URL(l,window.location.href).href,o=i=>new URL(i,y).href.replace(/%7B/g,"{").replace(/%7D/g,"}"),u=i=>{if(!i.startsWith("pmtiles://"))return o(i);const n=o(i.slice(10));return p?.(n),`pmtiles://${n}`};return(i,n)=>{const e={...n};typeof e.sprite=="string"?e.sprite=o(e.sprite):Array.isArray(e.sprite)&&(e.sprite=e.sprite.map(r=>{if(!r||typeof r!="object")return r;const t=r;return typeof t.url!="string"?r:{...t,url:o(t.url)}})),typeof e.glyphs=="string"&&(e.glyphs=o(e.glyphs));const c=e.sources;if(c){e.sources={...c};for(const[r,t]of Object.entries(c)){if(!t||typeof t!="object")continue;const s={...t};typeof s.url=="string"&&(s.url=u(s.url)),Array.isArray(s.tiles)&&(s.tiles=s.tiles.map(f=>typeof f=="string"?u(f):f)),e.sources[r]=s}}return e}}