widget-component
Skill2 starsChanged 4 months agoMITView on GitHub
Use when building any UI piece inside packages/widget — the embeddable vanilla-JS chat widget. Establishes the Shadow-DOM + tokens.css contract and bundle-size guardrails that keep the embed safe to drop on any host page.
In this repository3 other files it gives its agents.
- agent-uiSkill
- mock-stateSkill
- webrtc-mockSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 4 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 21
Import design tokens from @indianic/shared/design/tokens.css and inject the stylesheet into the Shadow root with <link> or constructable …
- Very specific: line 22
Keep all state in a single store object (plain TS object behind a small getState/setState/subscribe API).
- Distinctive: line 23
Use event delegation on the Shadow root for clicks.
- Distinctive: line 31
Don't render outside Shadow DOM.
- Very specific: line 32
Don't use innerHTML / insertAdjacentHTML with anything that touched a network payload, the host page, or visitor input.
- Distinctive: line 33
Don't import React, lit-html, or any UI framework.
- Very specific: line 34
Don't read or write localStorage for anything other than the visitor UUID.
- Very specific: line 35
Don't bind global event listeners on window/document outside the widget's mount lifecycle — and always remove them in unmount().
- Very specific: line 36
Don't console.log past Phase 0.
- Distinctive: line 37
Don't load fonts from a third-party CDN at runtime.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
widget-component
The widget is loaded via <script src="…widget.iife.js"> on host pages we don't control (indianic.com, careers, etc.). Anything that leaks from the widget — global names, styles, focus traps, console noise — is a bug. Defensive defaults beat clever ones here.
When to use
- Touching any file in
packages/widget/src/ - Adding a new visitor-facing UI piece (bubble, panel, pre-chat form, chat scroller, video tile, file-share UI)
- Wiring widget state, host-page integration, or any DOM observation
Skip for code that is purely shared (event types, design tokens) — that lives in packages/shared.
Do
- Mount everything inside a single Shadow DOM root attached to a host
<div>the widget injects intodocument.body. The Shadow host is the widget's only contact with the host page. - Import design tokens from
@indianic/shared/design/tokens.cssand inject the stylesheet into the Shadow root with<link>or constructable stylesheets. Reference tokens as CSS custom properties (var(--inic-paper)etc.). - Keep all state in a single store object (plain TS object behind a small
getState/setState/subscribeAPI). No external state libs — they cost bytes and the widget should ship under 100KB gzipped. - Use event delegation on the Shadow root for clicks; do not attach a listener per button.
- Persist only the visitor UUID to
localStorage(key:indianic.visitor.id). Everything else is in-memory. - Build DOM with
document.createElement+textContent+append. The host page is untrusted; user-supplied strings (visitor name, geo, messages) must never reachinnerHTML. - Bundle to a single IIFE (
vite build) that self-mounts on load. The IIFE entry createswindow.IndianicWidget(read-only handle for the host page). - Honor
prefers-reduced-motion— already routed through the token CSS layer; don't override.
Don't
- Don't render outside Shadow DOM. Light-DOM injection will collide with host CSS.
- Don't use
innerHTML/insertAdjacentHTMLwith anything that touched a network payload, the host page, or visitor input. XSS vector. - Don't import React, lit-html, or any UI framework. Vanilla JS + small helpers only. If a pattern feels like it needs React, write it as a Web Component.
- Don't read or write
localStoragefor anything other than the visitor UUID. Use the in-memory store. - Don't bind global event listeners on
window/documentoutside the widget's mount lifecycle — and always remove them inunmount(). - Don't
console.logpast Phase 0. Use awidgetLog()helper that is silenced in production builds. - Don't load fonts from a third-party CDN at runtime. Host fonts ourselves once Phase 5 ships; until then accept the system fallback.
One short example
// packages/widget/src/mount.ts
import tokensCss from '@indianic/shared/design/tokens.css?inline';
export function mount(host: HTMLElement = document.body) {
const shadowHost = document.createElement('div');
shadowHost.setAttribute('data-indianic-widget', '');
host.appendChild(shadowHost);
const root = shadowHost.attachShadow({ mode: 'open' });
const style = new CSSStyleSheet();
style.replaceSync(tokensCss);
root.adoptedStyleSheets = [style];
const bubble = document.createElement('button');
bubble.type = 'button';
bubble.className = 'bubble';
bubble.setAttribute('aria-label', 'Open chat');
bubble.textContent = '●';
bubble.addEventListener('click', () => openPanel(root));
root.append(bubble);
}Reference
- Aesthetic + tokens:
packages/shared/src/design/README.md - Event schema (what to emit):
packages/shared/src/events/schema.ts - Phase doc:
dev-docs/phase-1-widget-mockup.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

