@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 894 B
JavaScript
import d from"./is-mobile";import h from"./is-webview";import{loadImage as l}from"./loadImage";const u=d||h,f=u?8:512,w=u?100:0;async function p(e){return Promise.all(e.map(async([n,{preferred:a,fallback:i}])=>{let t=null;return a&&(t=await l(a)),!t&&i&&(t=await l(i)),[n,t]}))}export async function loadImagesInBatches(e,n=f,a=w){if(!e.length)return[];const i=[];for(let t=0;t<e.length;t+=n){const r=e.slice(t,t+n).map(async({preferred:o,fallback:c})=>{let s=null;return o&&(s=await l(o)),!s&&c&&(s=await l(c)),s}),m=await Promise.all(r);i.push(...m.filter(o=>o!==null)),await new Promise(o=>setTimeout(o,a))}return i}export async function loadImagesInBatchesById(e,n=f,a=w){if(!e.size)return new Map;const i=Array.from(e.entries()),t=new Map;for(let r=0;r<i.length;r+=n){const m=i.slice(r,r+n);(await p(m)).forEach(([c,s])=>{s&&t.set(c,s)}),a&&await new Promise(c=>setTimeout(c,a))}return t}