UNPKG

igniteui-theming

Version:

A set of Sass variables, mixins, and functions for generating palettes, typography, and elevations used by Ignite UI components.

58 lines (57 loc) 1.84 kB
import { createRequire } from "node:module"; import * as path from "node:path"; import { fileURLToPath } from "node:url"; //#region src/utils/theming-resolve.ts /** * Theming package resolution utilities. * * Provides a Sass FileImporter that resolves `@use 'igniteui-theming/sass/...'` * to the theming package's sass/ directory. * * Resolution strategy: * - Dev/test mode: resolves the `igniteui-theming` package via Node module resolution * (workspace symlink in a monorepo). * - Built mode (dist/mcp/utils/): falls back to relative __dirname traversal * since the built MCP lives inside the theming package and can't resolve itself. */ var __filename = fileURLToPath(import.meta.url); var __dirname = path.dirname(__filename); var THEMING_SASS_PREFIX = "igniteui-theming/sass/"; /** * Resolves the root directory of the igniteui-theming package. */ function resolveThemingRoot() { try { const require = createRequire(import.meta.url); return path.dirname(require.resolve("igniteui-theming/package.json")); } catch { return path.resolve(__dirname, "..", "..", ".."); } } /** * Root directory of the igniteui-theming package. */ var THEMING_ROOT = resolveThemingRoot(); /** * Sass FileImporter that resolves `@use 'igniteui-theming/sass/...'` * to the theming package's `sass/` directory. * * @example * ```ts * import { themingImporter } from './theming-resolve.js'; * * const result = await sass.compileStringAsync(code, { * importers: [themingImporter], * }); * ``` */ var themingImporter = { findFileUrl(url) { if (url === "igniteui-theming/sass") return new URL(`file://${path.join(THEMING_ROOT, "sass")}/`); if (url.startsWith(THEMING_SASS_PREFIX)) { const subpath = url.slice(22); return new URL(subpath, `file://${path.join(THEMING_ROOT, "sass")}/`); } return null; } }; //#endregion export { themingImporter };