UNPKG

@nextcloud/vue

Version:
1 lines 1.02 kB
{"version":3,"file":"preloadImage.mjs","sources":["../../src/functions/preloadImage/index.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport PQueue from 'p-queue'\n\nconst queue = new PQueue({ concurrency: 5 })\n\n/**\n * Preload an image URL\n *\n * @param url URL of the image\n */\nexport function preloadImage(url: string): Promise<boolean> {\n\tconst { resolve, promise } = Promise.withResolvers<boolean>()\n\tqueue.add(() => {\n\t\tconst image = new Image()\n\t\timage.onerror = () => resolve(false)\n\t\timage.onload = () => resolve(true)\n\t\timage.src = url\n\t\treturn promise\n\t})\n\n\treturn promise\n}\n"],"names":[],"mappings":";AAOA,MAAM,QAAQ,IAAI,OAAO,EAAE,aAAa,GAAG;AAOpC,SAAS,aAAa,KAA+B;AAC3D,QAAM,EAAE,SAAS,YAAY,QAAQ,cAAA;AACrC,QAAM,IAAI,MAAM;AACf,UAAM,QAAQ,IAAI,MAAA;AAClB,UAAM,UAAU,MAAM,QAAQ,KAAK;AACnC,UAAM,SAAS,MAAM,QAAQ,IAAI;AACjC,UAAM,MAAM;AACZ,WAAO;AAAA,EACR,CAAC;AAED,SAAO;AACR;"}