// Version utility. // // NILE_ELEMENTS_VERSION is this package's own version and is still substituted // at build time by scripts/replace-version.cjs. // // The tokens version is read from the loaded Nile stylesheet's --nile-version // custom property (stamped by @aquera/nile's scripts/stamp-css-version.mjs), // falling back to the @aquera/nile installed alongside this package. // // Reading the stylesheet is what makes a tokens-only release visible. The // imported constant alone is not enough: rollup.config.js bundles // @aquera/nile/lib/version.js into dist/index.js, so on the CDN build it is // frozen at this package's build time. The stylesheet is the live source. import { NILE_VERSION as BUILT_IN_NILE_VERSION } from '@aquera/nile/lib/version.js'; export const NILE_ELEMENTS_VERSION = '__NILE_ELEMENTS_VERSION__'; function readStylesheetNileVersion(): string | null { if (typeof window === 'undefined' || typeof getComputedStyle !== 'function') { return null; } try { const value = getComputedStyle(document.documentElement) .getPropertyValue('--nile-version') .trim() .replace(/^["']|["']$/g, ''); return value || null; } catch { return null; } } /** * The version of @aquera/nile (tokens/stylesheets) whose CSS is loaded in the * page, falling back to the @aquera/nile bundled into this package when no * stamped stylesheet is present. * * This is the canonical runtime API. It resolves on every call rather than * caching, so it is correct even when the Nile stylesheet is added to the page * after this module evaluates - which is the common case, and why no * module-evaluation-time snapshot of it is exported. */ export function getNileVersion(): string { return readStylesheetNileVersion() ?? BUILT_IN_NILE_VERSION; } // Set global versions for runtime access if (typeof window !== 'undefined') { (window as any).nileElementsVersion = NILE_ELEMENTS_VERSION; // A getter rather than a value, so window.nileVersion reflects whichever // stylesheet is loaded at read time regardless of script/style ordering. let override: string | null = null; Object.defineProperty(window, 'nileVersion', { configurable: true, get: () => override ?? getNileVersion(), set: (value: string) => { override = value; }, }); (window as any).process = (window as any).process || { env: { NODE_ENV: 'production' }, }; }