@osdk/widget.vite-plugin 3.2.0-beta.3 → 3.2.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @osdk/widget.vite-plugin
2
2
 
3
+ ## 3.2.0-beta.4
4
+
5
+ ### Minor Changes
6
+
7
+ - 34df269: Fix widgets dev mode on Windows
8
+
9
+ ### Patch Changes
10
+
11
+ - @osdk/widget.api@3.2.0-beta.4
12
+
3
13
  ## 3.2.0-beta.3
4
14
 
5
15
  ### Minor Changes
@@ -144,9 +144,12 @@ export function FoundryWidgetDevPlugin() {
144
144
  }
145
145
 
146
146
  // Standardize the source file extension and get the full path
147
- const standardizedSource = standardizeFileExtension(getFullSourcePath(source.slice(1), importer));
147
+ const standardizedSource = standardizeFileExtension(getFullSourcePath(
148
+ // If the source path is absolute, resolve it against the current working directory
149
+ source.startsWith("/") ? path.join(process.cwd(), source) : source, importer));
148
150
  // Importers are already full paths, so just standardize the extension
149
- const standardizedImporter = standardizeFileExtension(importer);
151
+ // Normalize to ensure consistent path separators on Windows
152
+ const standardizedImporter = standardizeFileExtension(path.normalize(importer));
150
153
 
151
154
  // In dev mode all entrypoints have a generic HTML importer value
152
155
  if (importer.endsWith("index.html") && !standardizedSource.includes("@fs")) {
@@ -171,7 +174,8 @@ function getFullSourcePath(source, importer) {
171
174
  return path.resolve(path.dirname(importer), source);
172
175
  }
173
176
  function serverPath(server, subPath) {
174
- return path.resolve(server.config.base, subPath);
177
+ // Don't use Windows-style paths when constructing URL paths for the HTTP server
178
+ return path.posix.resolve(server.config.base, subPath);
175
179
  }
176
180
  function printSetupPageUrl(server) {
177
181
  const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;
@@ -1 +1 @@
1
- {"version":3,"file":"FoundryWidgetDevPlugin.js","names":["path","fileURLToPath","color","sirv","CONFIG_FILE_SUFFIX","DEV_PLUGIN_ID","ENTRYPOINTS_PATH","FINISH_PATH","MODULE_EVALUATION_MODE","SETUP_PATH","VITE_INJECTIONS_PATH","getInputHtmlEntrypoints","standardizeFileExtension","extractInjectedScripts","getBaseHref","getFoundryToken","getWidgetIdOverrideMap","publishDevModeSettings","DIR_DIST","__dirname","dirname","import","meta","url","FoundryWidgetDevPlugin","htmlEntrypoints","codeEntrypoints","configFileToEntrypoint","name","enforce","apply","config","command","mode","process","env","VITEST","buildStart","options","resolvedConfig","configureServer","server","printUrls","printSetupPageUrl","middlewares","use","serverPath","req","res","next","originalUrl","endsWith","statusCode","setHeader","end","resolve","single","dev","_","JSON","stringify","map","entrypoint","numEntrypoints","length","numConfigFiles","Object","keys","status","widgetIdToOverrides","injectedScripts","inlineScripts","join","resolveId","source","importer","standardizedSource","getFullSourcePath","slice","standardizedImporter","includes","replace","fullSourcePath","subPath","base","setupRoute","logger","info","green","bold"],"sources":["FoundryWidgetDevPlugin.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport color from \"picocolors\";\nimport sirv from \"sirv\";\nimport type { Plugin, ViteDevServer } from \"vite\";\nimport {\n CONFIG_FILE_SUFFIX,\n DEV_PLUGIN_ID,\n ENTRYPOINTS_PATH,\n FINISH_PATH,\n MODULE_EVALUATION_MODE,\n SETUP_PATH,\n VITE_INJECTIONS_PATH,\n} from \"../common/constants.js\";\nimport { getInputHtmlEntrypoints } from \"../common/getInputHtmlEntrypoints.js\";\nimport { standardizeFileExtension } from \"../common/standardizeFileExtension.js\";\nimport { extractInjectedScripts } from \"./extractInjectedScripts.js\";\nimport { getBaseHref } from \"./getBaseHref.js\";\nimport { getFoundryToken } from \"./getFoundryToken.js\";\nimport { getWidgetIdOverrideMap } from \"./getWidgetIdOverrideMap.js\";\nimport { publishDevModeSettings } from \"./publishDevModeSettings.js\";\n\n// Location of the setup page assets\nconst DIR_DIST: string = typeof __dirname !== \"undefined\"\n ? __dirname\n : path.dirname(fileURLToPath(import.meta.url));\n\nexport function FoundryWidgetDevPlugin(): Plugin {\n // The root HTML entrypoints of the build process\n let htmlEntrypoints: string[];\n // Fully resolved paths to the entrypoint files, mapped to relative paths\n const codeEntrypoints: Record<string, string> = {};\n // Store the map of fully resolved config file paths to entrypoint file paths\n const configFileToEntrypoint: Record<string, string> = {};\n\n return {\n name: DEV_PLUGIN_ID,\n enforce: \"pre\",\n // Only apply this plugin during development, skip during tests and build-mode module evaluation\n apply(config, { command }) {\n if (\n config.mode === MODULE_EVALUATION_MODE || process.env.VITEST != null\n ) {\n return false;\n }\n return command === \"serve\";\n },\n\n /**\n * Capture the entrypoints from the Vite config so that we can manually load them on our\n * setup page and trigger module parsing.\n */\n buildStart(options) {\n htmlEntrypoints = getInputHtmlEntrypoints(options);\n },\n\n /**\n * Check for the required token environment variable in dev mode.\n */\n config(resolvedConfig) {\n getFoundryToken(resolvedConfig.mode);\n },\n\n /**\n * Configure the Vite server to serve the setup page and handle the finish endpoint. This\n * endpoint will set the widget overrides in Foundry and enable dev mode.\n */\n configureServer(server) {\n // Override the printUrls function to print the setup page URL\n server.printUrls = () => printSetupPageUrl(server);\n\n /**\n * Redirect `./.palantir/setup` to `./.palantir/setup/` to ensure that relative paths work\n * correctly. Relative paths must be used so that the dev server UI can be accessed on\n * non-root paths.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n (req, res, next) => {\n if (req.originalUrl?.endsWith(serverPath(server, SETUP_PATH))) {\n res.statusCode = 301;\n res.setHeader(\"Location\", `${serverPath(server, SETUP_PATH)}/`);\n res.end();\n } else {\n next();\n }\n },\n );\n\n /**\n * Serve the setup page that will load the entrypoints in iframes and trigger the finish\n * endpoint once widgets have been loaded.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n sirv(path.resolve(DIR_DIST, \"../../site\"), {\n single: true,\n dev: true,\n }),\n );\n\n /**\n * Make the entrypoints available to the setup page so that it can load them in iframes in\n * order to trigger module parsing.\n */\n server.middlewares.use(\n serverPath(server, ENTRYPOINTS_PATH),\n (_, res) => {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(\n JSON.stringify(\n htmlEntrypoints.map((entrypoint) =>\n serverPath(server, entrypoint)\n ),\n ),\n );\n },\n );\n\n /**\n * Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.\n */\n server.middlewares.use(\n serverPath(server, FINISH_PATH),\n async (_, res) => {\n // Wait for the setup page to trigger the parsing of the config files\n const numEntrypoints = htmlEntrypoints.length;\n const numConfigFiles = Object.keys(configFileToEntrypoint).length;\n if (numConfigFiles < numEntrypoints) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({ status: \"pending\" }));\n return;\n }\n\n // Prepare the widget overrides and finish the setup process\n const widgetIdToOverrides = await getWidgetIdOverrideMap(\n server,\n codeEntrypoints,\n configFileToEntrypoint,\n getBaseHref(server),\n );\n await publishDevModeSettings(\n server,\n widgetIdToOverrides,\n getBaseHref(server),\n res,\n );\n },\n );\n\n /**\n * Serve scripts that would usually be injected into the HTML if Vite had control over the\n * serving of index HTML pages. This is necessary to ensure that plugins like React refresh\n * work correctly.\n */\n server.middlewares.use(\n serverPath(server, VITE_INJECTIONS_PATH),\n async (_, res) => {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.setHeader(\"Content-Type\", \"application/javascript\");\n const injectedScripts = await extractInjectedScripts(server);\n res.end(injectedScripts.inlineScripts.join(\"\\n\"));\n },\n );\n },\n\n /**\n * As module imports are resolved, we need to capture the entrypoint file paths and the config\n * file paths that are imported from them.\n */\n resolveId(source, importer) {\n if (importer == null) {\n return;\n }\n\n // Standardize the source file extension and get the full path\n const standardizedSource = standardizeFileExtension(\n getFullSourcePath(source.slice(1), importer),\n );\n // Importers are already full paths, so just standardize the extension\n const standardizedImporter = standardizeFileExtension(importer);\n\n // In dev mode all entrypoints have a generic HTML importer value\n if (\n importer.endsWith(\"index.html\") && !standardizedSource.includes(\"@fs\")\n ) {\n // Store the fully resolved path and the relative path, as we need the former for mapping\n // config files to entrypoints and the latter as a dev mode override script\n codeEntrypoints[standardizedSource] = source;\n }\n\n // Look for config files that are imported from an entrypoint file\n if (\n standardizedSource.replace(/\\.[^/.]+$/, \"\").endsWith(CONFIG_FILE_SUFFIX)\n && codeEntrypoints[standardizedImporter] != null\n ) {\n const fullSourcePath = standardizeFileExtension(\n getFullSourcePath(source, standardizedImporter),\n );\n configFileToEntrypoint[fullSourcePath] = standardizedImporter;\n }\n },\n };\n}\n\n/**\n * During the resolution phase source are given as relative paths to the importer\n */\nfunction getFullSourcePath(source: string, importer: string): string {\n return path.resolve(path.dirname(importer), source);\n}\n\nfunction serverPath(server: ViteDevServer, subPath: string): string {\n return path.resolve(server.config.base, subPath);\n}\n\nfunction printSetupPageUrl(server: ViteDevServer) {\n const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;\n server.config.logger.info(\n ` ${color.green(\"➜\")} ${\n color.bold(\"Click to enter developer mode for your widget set\")\n }: ${color.green(setupRoute)}`,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,aAAa,QAAQ,UAAU;AACxC,OAAOC,KAAK,MAAM,YAAY;AAC9B,OAAOC,IAAI,MAAM,MAAM;AAEvB,SACEC,kBAAkB,EAClBC,aAAa,EACbC,gBAAgB,EAChBC,WAAW,EACXC,sBAAsB,EACtBC,UAAU,EACVC,oBAAoB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AC,mDAAmD,CAAC,KAC5DvF,KAAK,CAACsF,KAAK,CAACH,UAAU,CAAC,EAC9B,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"FoundryWidgetDevPlugin.js","names":["path","fileURLToPath","color","sirv","CONFIG_FILE_SUFFIX","DEV_PLUGIN_ID","ENTRYPOINTS_PATH","FINISH_PATH","MODULE_EVALUATION_MODE","SETUP_PATH","VITE_INJECTIONS_PATH","getInputHtmlEntrypoints","standardizeFileExtension","extractInjectedScripts","getBaseHref","getFoundryToken","getWidgetIdOverrideMap","publishDevModeSettings","DIR_DIST","__dirname","dirname","import","meta","url","FoundryWidgetDevPlugin","htmlEntrypoints","codeEntrypoints","configFileToEntrypoint","name","enforce","apply","config","command","mode","process","env","VITEST","buildStart","options","resolvedConfig","configureServer","server","printUrls","printSetupPageUrl","middlewares","use","serverPath","req","res","next","originalUrl","endsWith","statusCode","setHeader","end","resolve","single","dev","_","JSON","stringify","map","entrypoint","numEntrypoints","length","numConfigFiles","Object","keys","status","widgetIdToOverrides","injectedScripts","inlineScripts","join","resolveId","source","importer","standardizedSource","getFullSourcePath","startsWith","cwd","standardizedImporter","normalize","includes","replace","fullSourcePath","subPath","posix","base","setupRoute","logger","info","green","bold"],"sources":["FoundryWidgetDevPlugin.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport color from \"picocolors\";\nimport sirv from \"sirv\";\nimport type { Plugin, ViteDevServer } from \"vite\";\nimport {\n CONFIG_FILE_SUFFIX,\n DEV_PLUGIN_ID,\n ENTRYPOINTS_PATH,\n FINISH_PATH,\n MODULE_EVALUATION_MODE,\n SETUP_PATH,\n VITE_INJECTIONS_PATH,\n} from \"../common/constants.js\";\nimport { getInputHtmlEntrypoints } from \"../common/getInputHtmlEntrypoints.js\";\nimport { standardizeFileExtension } from \"../common/standardizeFileExtension.js\";\nimport { extractInjectedScripts } from \"./extractInjectedScripts.js\";\nimport { getBaseHref } from \"./getBaseHref.js\";\nimport { getFoundryToken } from \"./getFoundryToken.js\";\nimport { getWidgetIdOverrideMap } from \"./getWidgetIdOverrideMap.js\";\nimport { publishDevModeSettings } from \"./publishDevModeSettings.js\";\n\n// Location of the setup page assets\nconst DIR_DIST: string = typeof __dirname !== \"undefined\"\n ? __dirname\n : path.dirname(fileURLToPath(import.meta.url));\n\nexport function FoundryWidgetDevPlugin(): Plugin {\n // The root HTML entrypoints of the build process\n let htmlEntrypoints: string[];\n // Fully resolved paths to the entrypoint files, mapped to relative paths\n const codeEntrypoints: Record<string, string> = {};\n // Store the map of fully resolved config file paths to entrypoint file paths\n const configFileToEntrypoint: Record<string, string> = {};\n\n return {\n name: DEV_PLUGIN_ID,\n enforce: \"pre\",\n // Only apply this plugin during development, skip during tests and build-mode module evaluation\n apply(config, { command }) {\n if (\n config.mode === MODULE_EVALUATION_MODE || process.env.VITEST != null\n ) {\n return false;\n }\n return command === \"serve\";\n },\n\n /**\n * Capture the entrypoints from the Vite config so that we can manually load them on our\n * setup page and trigger module parsing.\n */\n buildStart(options) {\n htmlEntrypoints = getInputHtmlEntrypoints(options);\n },\n\n /**\n * Check for the required token environment variable in dev mode.\n */\n config(resolvedConfig) {\n getFoundryToken(resolvedConfig.mode);\n },\n\n /**\n * Configure the Vite server to serve the setup page and handle the finish endpoint. This\n * endpoint will set the widget overrides in Foundry and enable dev mode.\n */\n configureServer(server) {\n // Override the printUrls function to print the setup page URL\n server.printUrls = () => printSetupPageUrl(server);\n\n /**\n * Redirect `./.palantir/setup` to `./.palantir/setup/` to ensure that relative paths work\n * correctly. Relative paths must be used so that the dev server UI can be accessed on\n * non-root paths.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n (req, res, next) => {\n if (req.originalUrl?.endsWith(serverPath(server, SETUP_PATH))) {\n res.statusCode = 301;\n res.setHeader(\"Location\", `${serverPath(server, SETUP_PATH)}/`);\n res.end();\n } else {\n next();\n }\n },\n );\n\n /**\n * Serve the setup page that will load the entrypoints in iframes and trigger the finish\n * endpoint once widgets have been loaded.\n */\n server.middlewares.use(\n serverPath(server, SETUP_PATH),\n sirv(path.resolve(DIR_DIST, \"../../site\"), {\n single: true,\n dev: true,\n }),\n );\n\n /**\n * Make the entrypoints available to the setup page so that it can load them in iframes in\n * order to trigger module parsing.\n */\n server.middlewares.use(\n serverPath(server, ENTRYPOINTS_PATH),\n (_, res) => {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(\n JSON.stringify(\n htmlEntrypoints.map((entrypoint) =>\n serverPath(server, entrypoint)\n ),\n ),\n );\n },\n );\n\n /**\n * Finish the setup process by setting the widget overrides in Foundry and enabling dev mode.\n */\n server.middlewares.use(\n serverPath(server, FINISH_PATH),\n async (_, res) => {\n // Wait for the setup page to trigger the parsing of the config files\n const numEntrypoints = htmlEntrypoints.length;\n const numConfigFiles = Object.keys(configFileToEntrypoint).length;\n if (numConfigFiles < numEntrypoints) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.end(JSON.stringify({ status: \"pending\" }));\n return;\n }\n\n // Prepare the widget overrides and finish the setup process\n const widgetIdToOverrides = await getWidgetIdOverrideMap(\n server,\n codeEntrypoints,\n configFileToEntrypoint,\n getBaseHref(server),\n );\n await publishDevModeSettings(\n server,\n widgetIdToOverrides,\n getBaseHref(server),\n res,\n );\n },\n );\n\n /**\n * Serve scripts that would usually be injected into the HTML if Vite had control over the\n * serving of index HTML pages. This is necessary to ensure that plugins like React refresh\n * work correctly.\n */\n server.middlewares.use(\n serverPath(server, VITE_INJECTIONS_PATH),\n async (_, res) => {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.setHeader(\"Content-Type\", \"application/javascript\");\n const injectedScripts = await extractInjectedScripts(server);\n res.end(injectedScripts.inlineScripts.join(\"\\n\"));\n },\n );\n },\n\n /**\n * As module imports are resolved, we need to capture the entrypoint file paths and the config\n * file paths that are imported from them.\n */\n resolveId(source, importer) {\n if (importer == null) {\n return;\n }\n\n // Standardize the source file extension and get the full path\n const standardizedSource = standardizeFileExtension(\n getFullSourcePath(\n // If the source path is absolute, resolve it against the current working directory\n source.startsWith(\"/\") ? path.join(process.cwd(), source) : source,\n importer,\n ),\n );\n // Importers are already full paths, so just standardize the extension\n // Normalize to ensure consistent path separators on Windows\n const standardizedImporter = standardizeFileExtension(\n path.normalize(importer),\n );\n\n // In dev mode all entrypoints have a generic HTML importer value\n if (\n importer.endsWith(\"index.html\") && !standardizedSource.includes(\"@fs\")\n ) {\n // Store the fully resolved path and the relative path, as we need the former for mapping\n // config files to entrypoints and the latter as a dev mode override script\n codeEntrypoints[standardizedSource] = source;\n }\n\n // Look for config files that are imported from an entrypoint file\n if (\n standardizedSource.replace(/\\.[^/.]+$/, \"\").endsWith(CONFIG_FILE_SUFFIX)\n && codeEntrypoints[standardizedImporter] != null\n ) {\n const fullSourcePath = standardizeFileExtension(\n getFullSourcePath(source, standardizedImporter),\n );\n configFileToEntrypoint[fullSourcePath] = standardizedImporter;\n }\n },\n };\n}\n\n/**\n * During the resolution phase source are given as relative paths to the importer\n */\nfunction getFullSourcePath(source: string, importer: string): string {\n return path.resolve(path.dirname(importer), source);\n}\n\nfunction serverPath(server: ViteDevServer, subPath: string): string {\n // Don't use Windows-style paths when constructing URL paths for the HTTP server\n return path.posix.resolve(server.config.base, subPath);\n}\n\nfunction printSetupPageUrl(server: ViteDevServer) {\n const setupRoute = `${getBaseHref(server)}${SETUP_PATH}/`;\n server.config.logger.info(\n ` ${color.green(\"➜\")} ${\n color.bold(\"Click to enter developer mode for your wid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,OAAO,CAACvD,IAAI,CAACoB,OAAO,CAACuD,QAAQ,CAAC,EAAED,MAAM,CAAC;AACrD;AAEA,SAAS5B,UAAUA,CAACL,MAAqB,EAAE4C,OAAe,EAAU;EAClE;EACA,OAAOrF,IAAI,CAACsF,KAAK,CAAC/B,OAAO,CAACd,MAAM,CAACV,MAAM,CAACwD,IAAI,EAAEF,OAAO,CAAC;AACxD;AAEA,SAAS1C,iBAAiBA,CAACF,MAAqB,EAAE;EAChD,MAAM+C,UAAU,GAAG,GAAG1E,WAAW,CAAC2B,MAAM,CAAC,GAAGhC,UAAU,GAAG;EACzDgC,MAAM,CAACV,MAAM,CAAC0D,MAAM,CAACC,IAAI,CACvB,KAAKxF,KAAK,CAACyF,KAAK,CAAC,GAAG,CAAC,KACnBzF,KAAK,CAAC0F,IAAI,CAAC,mDAAmD,CAAC,KAC5D1F,KAAK,CAACyF,KAAK,CAACH,UAAU,CAAC,EAC9B,CAAC;AACH","ignoreList":[]}
@@ -1 +1 @@
1
- import{I as n}from"./index-Zx5rUdU4.js";import{I as e}from"./index-BrAe7gTM.js";import{p as r,I as s}from"./index-Dm4x3YrF.js";function I(o,t){var a=r(o);return t===s.STANDARD?n[a]:e[a]}function p(o){return r(o)}export{n as IconSvgPaths16,e as IconSvgPaths20,I as getIconPaths,p as iconNameToPathsRecordKey};
1
+ import{I as n}from"./index-DLOviMB1.js";import{I as e}from"./index-B-fsa5Ru.js";import{p as r,I as s}from"./index-D9t4xczX.js";function I(o,t){var a=r(o);return t===s.STANDARD?n[a]:e[a]}function p(o){return r(o)}export{n as IconSvgPaths16,e as IconSvgPaths20,I as getIconPaths,p as iconNameToPathsRecordKey};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./allPaths-DcyFnTvZ.js","./index-Zx5rUdU4.js","./index-BrAe7gTM.js","./index-Dm4x3YrF.js","./index-62l0mIXD.css"])))=>i.map(i=>d[i]);
2
- import{_ as o,a as i,b as n}from"./index-Dm4x3YrF.js";var _=function(e,a){return o(void 0,void 0,void 0,function(){var t;return i(this,function(r){switch(r.label){case 0:return[4,n(()=>import("./allPaths-DcyFnTvZ.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url)];case 1:return t=r.sent().getIconPaths,[2,t(e,a)]}})})};export{_ as allPathsLoader};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./allPaths-C9RDB26n.js","./index-DLOviMB1.js","./index-B-fsa5Ru.js","./index-D9t4xczX.js","./index-CxjWve_y.css"])))=>i.map(i=>d[i]);
2
+ import{_ as o,a as i,b as n}from"./index-D9t4xczX.js";var _=function(e,a){return o(void 0,void 0,void 0,function(){var t;return i(this,function(r){switch(r.label){case 0:return[4,n(()=>import("./allPaths-C9RDB26n.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url)];case 1:return t=r.sent().getIconPaths,[2,t(e,a)]}})})};export{_ as allPathsLoader};