vanilla-agent 0.1.0 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-agent",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Themeable, plugable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -32,6 +32,26 @@ const widgetCssHref = (): string | null => {
32
32
  const mountStyles = (root: ShadowRoot | HTMLElement) => {
33
33
  const href = widgetCssHref();
34
34
 
35
+ const adoptExistingStylesheet = () => {
36
+ if (!(root instanceof ShadowRoot)) {
37
+ return;
38
+ }
39
+
40
+ if (root.querySelector('link[data-vanilla-agent]')) {
41
+ return;
42
+ }
43
+
44
+ const globalLink = document.head.querySelector<HTMLLinkElement>(
45
+ 'link[data-vanilla-agent]'
46
+ );
47
+ if (!globalLink) {
48
+ return;
49
+ }
50
+
51
+ const clonedLink = globalLink.cloneNode(true) as HTMLLinkElement;
52
+ root.insertBefore(clonedLink, root.firstChild);
53
+ };
54
+
35
55
  if (root instanceof ShadowRoot) {
36
56
  // For shadow DOM, we need to load CSS into the shadow root
37
57
  if (href) {
@@ -40,6 +60,8 @@ const mountStyles = (root: ShadowRoot | HTMLElement) => {
40
60
  link.href = href;
41
61
  link.setAttribute("data-vanilla-agent", "true");
42
62
  root.insertBefore(link, root.firstChild);
63
+ } else {
64
+ adoptExistingStylesheet();
43
65
  }
44
66
  // If href is null (IIFE build), CSS should already be loaded globally
45
67
  } else {