Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
One-time setup that gathers your project's design context and saves it to CLAUDE.md for future sessions.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/live/ui-core.mjs
1/**2* Framework-neutral Impeccable live chrome contract.3*4* The production browser bundle is intentionally plain DOM so Svelte, React,5* Vue, and static adapters can all mount the same chrome. This module is the6* testable contract/inventory for that bundle; live-browser.js mirrors these7* values at runtime because it is served as a standalone script.8*/910export const LIVE_CHROME_MOUNT_CONTRACT = Object.freeze([11'root',12'transport',13'state',14'actions',15]);1617export const LIVE_UI_SURFACES = Object.freeze([18{19key: 'global-bottom-bar',20ids: [21'impeccable-live-global-bar',22'impeccable-live-global-bar-brand',23'impeccable-live-pick-toggle',24'impeccable-live-insert-toggle',25'impeccable-live-detect-toggle',26'impeccable-live-detect-badge',27'impeccable-live-design-toggle',28'impeccable-live-page-chat',29'impeccable-live-page-chat-input',30'impeccable-live-page-chat-voice',31],32states: ['rest', 'hover', 'focus-visible', 'pressed', 'active', 'tooltip'],33},34{35key: 'pending-copy-edit-dock',36ids: ['impeccable-live-pending-dock'],37states: ['closed', 'open', 'hover', 'pressed', 'loading', 'rollback', 'keep-fixing'],38},39{40key: 'element-selection-chrome',41ids: [42'impeccable-live-highlight',43'impeccable-live-tooltip',44'impeccable-live-bar',45'impeccable-live-selection-pill',46'impeccable-live-input',47'impeccable-live-configure-voice',48'impeccable-live-configure-bar-tooltip',49],50states: ['rest', 'hover', 'focus-visible', 'pressed', 'disabled'],51},52{53key: 'action-picker',54ids: ['impeccable-live-picker'],55states: ['closed', 'open', 'option-hover', 'option-focus'],56},57{58key: 'edit-chrome',59ids: ['impeccable-live-edit-badge'],60states: ['enabled', 'disabled', 'editing', 'cancel', 'save', 'edited-content'],61},62{63key: 'generating-row',64ids: ['impeccable-live-bar', 'impeccable-live-shader'],65states: ['action-label', 'animated-dots', 'generating', 'done'],66},67{68key: 'variant-cycling-row',69ids: ['impeccable-live-bar', 'impeccable-live-params-panel'],70states: ['variant-1', 'variant-2', 'variant-3', 'left-disabled', 'right-disabled', 'dot-click', 'accept', 'discard'],71},72{73key: 'variant-params-panel',74ids: ['impeccable-live-params-panel'],75states: ['closed', 'open-above', 'open-below', 'range', 'steps', 'toggle'],76},77{78key: 'saving-confirmed-rows',79ids: ['impeccable-live-bar'],80states: ['saving', 'applying-variant', 'confirmed'],81},82{83key: 'insert-mode-chrome',84ids: [85'impeccable-live-insert-line',86'impeccable-live-insert-placeholder',87'impeccable-live-placeholder-resize',88'impeccable-live-insert-input',89'impeccable-live-insert-voice',90'impeccable-live-insert-create',91'impeccable-live-insert-create-tooltip',92],93states: ['toggle-active', 'line', 'placeholder', 'resize', 'enabled', 'disabled', 'tooltip'],94},95{96key: 'annotation-chrome',97ids: [98'impeccable-live-annot',99'impeccable-live-annot-svg',100'impeccable-live-annot-pins',101'impeccable-live-annot-clear',102],103states: ['overlay', 'drawing', 'pin', 'pin-edit', 'clear'],104},105{106key: 'design-system-panel',107ids: ['impeccable-live-design-host'],108states: ['closed', 'open', 'tabs', 'token-tiles', 'copy'],109},110{111key: 'toasts-and-errors',112ids: ['impeccable-live-toast'],113states: ['normal', 'error', 'no-variants-mounted'],114},115{116key: 'css-isolation-boundary',117ids: ['impeccable-live-root'],118states: ['shadow-root', 'style-tags', 'hostile-css'],119},120]);121122export const LIVE_UI_COMPONENT_IDS = Object.freeze([123...new Set(LIVE_UI_SURFACES.flatMap((surface) => surface.ids)),124]);125126export function resolveLiveUiRoot(env = globalThis) {127const doc = env?.document;128const explicit = env?.__IMPECCABLE_LIVE_UI_ROOT__129|| env?.window?.__IMPECCABLE_LIVE_UI_ROOT__;130if (explicit && typeof explicit.appendChild === 'function') return explicit;131return doc?.body || null;132}133134export function getLiveUiElementById(id, env = globalThis) {135const doc = env?.document;136const root = resolveLiveUiRoot(env);137if (!id) return null;138if (root?.getElementById) {139const found = root.getElementById(id);140if (found) return found;141}142if (root?.querySelector) {143const found = root.querySelector('#' + escapeCssIdent(id));144if (found) return found;145}146return doc?.getElementById?.(id) || null;147}148149export function appendToLiveUiRoot(el, env = globalThis) {150const root = resolveLiveUiRoot(env);151if (!root) throw new Error('Impeccable live UI root is not available');152root.appendChild(el);153return el;154}155156export function appendStyleToLiveUiRoot(styleEl, env = globalThis) {157const doc = env?.document;158const root = resolveLiveUiRoot(env);159if (root && root !== doc?.body) {160root.appendChild(styleEl);161} else {162(doc?.head || doc?.body || root).appendChild(styleEl);163}164return styleEl;165}166167export function activeElementDeep(doc = globalThis.document) {168let active = doc?.activeElement || null;169while (active?.shadowRoot?.activeElement) {170active = active.shadowRoot.activeElement;171}172return active;173}174175function escapeCssIdent(value) {176if (typeof CSS !== 'undefined' && typeof CSS.escape === 'function') {177return CSS.escape(String(value));178}179return String(value).replace(/([ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, '\\$1');180}181