@roxyapi/ui 0.8.1 → 0.9.0

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.
@@ -0,0 +1,27 @@
1
+ import { ROXY_UI_TOKENS_CSS } from '../styles/tokens-css.js';
2
+
3
+ /** Element id of the injected token stylesheet. Stable so injection is idempotent and so a host page can find, inspect, or remove it. */
4
+ export const ROXY_UI_TOKENS_STYLE_ID = 'roxy-ui-tokens';
5
+
6
+ /**
7
+ * Inject the Roxy UI design tokens (light + dark, all theme triggers) into the document head as the cascade's lowest-priority source, so a single CDN script tag yields full theming and dark mode with no separate stylesheet link.
8
+ *
9
+ * @remarks
10
+ * Three invariants hold this safe for every consumer:
11
+ *
12
+ * - SSR-safe: a missing `document` (Node, Lit-SSR, Bun) is a no-op. Only the CDN bundle calls this; the npm/ESM entry (`src/index.ts`) never touches the document, so bundler and server consumers are unaffected.
13
+ * - Idempotent: a second call (two script tags, HMR, re-registration) finds the existing `#roxy-ui-tokens` and returns without duplicating.
14
+ * - Lowest priority: the style is PREPENDED to `<head>`, so it is the earliest source-order rule. Any consumer `:root { --roxy-* }` brand override or linked `tokens.css` appears later and wins ties. This preserves backwards compatibility: existing pages that already link `tokens.css` and set overrides keep their exact behaviour.
15
+ *
16
+ * @returns The injected (or pre-existing) style element, or `null` under SSR.
17
+ */
18
+ export function injectRoxyTokens(): HTMLStyleElement | null {
19
+ if (typeof document === 'undefined') return null;
20
+ const existing = document.getElementById(ROXY_UI_TOKENS_STYLE_ID);
21
+ if (existing) return existing as HTMLStyleElement;
22
+ const style = document.createElement('style');
23
+ style.id = ROXY_UI_TOKENS_STYLE_ID;
24
+ style.textContent = ROXY_UI_TOKENS_CSS;
25
+ document.head.prepend(style);
26
+ return style;
27
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/sync-version.ts. Do not edit.
2
- export const ROXY_UI_VERSION = '0.8.1';
2
+ export const ROXY_UI_VERSION = '0.9.0';