@hidemikimura/chit-ui 0.1.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/LICENSE +21 -0
- package/README.md +440 -0
- package/dist/chit-ui.iife.min.js +964 -0
- package/dist/chit-ui.iife.min.js.map +1 -0
- package/dist/chit-ui.min.js +964 -0
- package/dist/chit-ui.min.js.map +1 -0
- package/dist/types/bundle.d.ts +7 -0
- package/dist/types/chit-ui.d.ts +251 -0
- package/dist/types/controllers/breakpoint-controller.d.ts +29 -0
- package/dist/types/controllers/composer-controller.d.ts +54 -0
- package/dist/types/controllers/scroll-controller.d.ts +44 -0
- package/dist/types/controllers/state-controller.d.ts +61 -0
- package/dist/types/controllers/theme-controller.d.ts +47 -0
- package/dist/types/element.d.ts +1 -0
- package/dist/types/events.d.ts +28 -0
- package/dist/types/global.d.ts +25 -0
- package/dist/types/i18n/labels.d.ts +68 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/render/composer.d.ts +15 -0
- package/dist/types/render/content.d.ts +75 -0
- package/dist/types/render/launcher.d.ts +18 -0
- package/dist/types/render/message-list.d.ts +17 -0
- package/dist/types/render/message.d.ts +14 -0
- package/dist/types/render/panel.d.ts +10 -0
- package/dist/types/styles/adopted-sheet.d.ts +20 -0
- package/dist/types/styles/composer.css.d.ts +1 -0
- package/dist/types/styles/content.css.d.ts +9 -0
- package/dist/types/styles/host.css.d.ts +9 -0
- package/dist/types/styles/launcher.css.d.ts +1 -0
- package/dist/types/styles/message.css.d.ts +1 -0
- package/dist/types/styles/panel.css.d.ts +1 -0
- package/dist/types/theme/default-theme.d.ts +97 -0
- package/dist/types/theme/merge-theme.d.ts +33 -0
- package/dist/types/theme/theme-to-css.d.ts +24 -0
- package/dist/types/types.d.ts +268 -0
- package/package.json +71 -0
- package/src/bundle.js +11 -0
- package/src/chit-ui.js +548 -0
- package/src/controllers/breakpoint-controller.js +82 -0
- package/src/controllers/composer-controller.js +215 -0
- package/src/controllers/scroll-controller.js +252 -0
- package/src/controllers/state-controller.js +316 -0
- package/src/controllers/theme-controller.js +75 -0
- package/src/element.js +4 -0
- package/src/events.js +33 -0
- package/src/global.d.ts +25 -0
- package/src/i18n/labels.js +72 -0
- package/src/index.js +9 -0
- package/src/render/composer.js +72 -0
- package/src/render/content.js +211 -0
- package/src/render/launcher.js +64 -0
- package/src/render/message-list.js +67 -0
- package/src/render/message.js +82 -0
- package/src/render/panel.js +77 -0
- package/src/styles/adopted-sheet.js +72 -0
- package/src/styles/composer.css.js +108 -0
- package/src/styles/content.css.js +119 -0
- package/src/styles/host.css.js +160 -0
- package/src/styles/launcher.css.js +139 -0
- package/src/styles/message.css.js +192 -0
- package/src/styles/panel.css.js +126 -0
- package/src/theme/default-theme.js +111 -0
- package/src/theme/merge-theme.js +100 -0
- package/src/theme/theme-to-css.js +94 -0
- package/src/types.js +143 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which form a message uses. Also drives the `data-content` attribute, because
|
|
3
|
+
* plain text is the one form whose whitespace has to survive.
|
|
4
|
+
*
|
|
5
|
+
* @param {Message} message
|
|
6
|
+
* @returns {'text' | 'html' | 'template' | 'element' | 'component'}
|
|
7
|
+
*/
|
|
8
|
+
export function contentField(message: Message): "text" | "html" | "template" | "element" | "component";
|
|
9
|
+
/**
|
|
10
|
+
* The value a message's content is built from. Used to decide whether a
|
|
11
|
+
* message actually changed, so `chat-message-render` does not fire on every
|
|
12
|
+
* unrelated update.
|
|
13
|
+
*
|
|
14
|
+
* @param {Message} message
|
|
15
|
+
* @returns {unknown}
|
|
16
|
+
*/
|
|
17
|
+
export function contentKey(message: Message): unknown;
|
|
18
|
+
/**
|
|
19
|
+
* Build (or reuse) an element for a component reference and write its props.
|
|
20
|
+
*
|
|
21
|
+
* The instance is kept across renders so the component keeps its own state; a
|
|
22
|
+
* changed reference replaces it, and changed props are assigned one by one so
|
|
23
|
+
* the component's own setters see each change.
|
|
24
|
+
*
|
|
25
|
+
* @param {ChitUI} host
|
|
26
|
+
* @param {string} key Cache key.
|
|
27
|
+
* @param {(new () => HTMLElement) | string} source
|
|
28
|
+
* @param {Record<string, unknown>} [props]
|
|
29
|
+
* @returns {HTMLElement}
|
|
30
|
+
*/
|
|
31
|
+
export function resolveComponent(host: ChitUI, key: string, source: (new () => HTMLElement) | string, props?: Record<string, unknown>): HTMLElement;
|
|
32
|
+
/**
|
|
33
|
+
* Drop cached instances for messages that are gone, so a long conversation
|
|
34
|
+
* does not hold on to elements it will never show again. Non-message entries,
|
|
35
|
+
* such as the launcher's, are left alone.
|
|
36
|
+
*
|
|
37
|
+
* @param {ChitUI} host
|
|
38
|
+
* @param {Set<string>} liveIds
|
|
39
|
+
*/
|
|
40
|
+
export function pruneComponents(host: ChitUI, liveIds: Set<string>): void;
|
|
41
|
+
/**
|
|
42
|
+
* The component instance backing a message, when it has one.
|
|
43
|
+
*
|
|
44
|
+
* @param {ChitUI} host
|
|
45
|
+
* @param {string} id
|
|
46
|
+
* @returns {HTMLElement | undefined}
|
|
47
|
+
*/
|
|
48
|
+
export function componentInstance(host: ChitUI, id: string): HTMLElement | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Turn a message's content into something Lit can render as a child value.
|
|
51
|
+
*
|
|
52
|
+
* All four shapes collapse here: an HTML string becomes an `unsafeHTML`
|
|
53
|
+
* directive, a Lit template passes straight through, and an element or a
|
|
54
|
+
* component becomes a Node, which Lit inserts as-is.
|
|
55
|
+
*
|
|
56
|
+
* @param {ChitUI} host
|
|
57
|
+
* @param {Message} message
|
|
58
|
+
* @returns {unknown}
|
|
59
|
+
*/
|
|
60
|
+
export function renderContent(host: ChitUI, message: Message): unknown;
|
|
61
|
+
/** The cache key for the closed-state component. */
|
|
62
|
+
export const LAUNCHER_KEY: "launcher";
|
|
63
|
+
export type ComponentEntry = {
|
|
64
|
+
/**
|
|
65
|
+
* What `component` held when this was built.
|
|
66
|
+
*/
|
|
67
|
+
source: (new () => HTMLElement) | string;
|
|
68
|
+
element: HTMLElement;
|
|
69
|
+
/**
|
|
70
|
+
* Last props written to the element.
|
|
71
|
+
*/
|
|
72
|
+
props: Record<string, unknown>;
|
|
73
|
+
};
|
|
74
|
+
import type { Message } from '../types.js';
|
|
75
|
+
import type { ChitUI } from '../chit-ui.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @import { ChitUI } from '../chit-ui.js' */
|
|
2
|
+
/**
|
|
3
|
+
* The closed state: one button.
|
|
4
|
+
*
|
|
5
|
+
* What goes inside it has three routes, in order of how much the consumer
|
|
6
|
+
* takes over:
|
|
7
|
+
*
|
|
8
|
+
* - the theme's image or label, drawn inside the themed circle;
|
|
9
|
+
* - the `launcher` slot, their markup inside that same circle;
|
|
10
|
+
* - `closed.component`, a component that draws the whole launcher — the button
|
|
11
|
+
* then keeps only its role, and gives up its size, background, shadow and
|
|
12
|
+
* radius, because two parties styling one box is how things end up clipped.
|
|
13
|
+
*
|
|
14
|
+
* @param {ChitUI} host
|
|
15
|
+
* @returns {import('lit').TemplateResult}
|
|
16
|
+
*/
|
|
17
|
+
export function renderLauncher(host: ChitUI): import("lit").TemplateResult;
|
|
18
|
+
import type { ChitUI } from '../chit-ui.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @import { ChitUI } from '../chit-ui.js' */
|
|
2
|
+
/**
|
|
3
|
+
* The scrolling conversation.
|
|
4
|
+
*
|
|
5
|
+
* `repeat` keys on the message id so an existing bubble's DOM is reused when
|
|
6
|
+
* the consumer assigns a new array; without it Lit would reorder by position
|
|
7
|
+
* and a component message would lose its state on every insert.
|
|
8
|
+
*
|
|
9
|
+
* Clicks are handled once here and re-published as `chat-message-click`, which
|
|
10
|
+
* is how a consumer reaches a button inside a message without hunting through
|
|
11
|
+
* the shadow root.
|
|
12
|
+
*
|
|
13
|
+
* @param {ChitUI} host
|
|
14
|
+
* @returns {import('lit').TemplateResult}
|
|
15
|
+
*/
|
|
16
|
+
export function renderMessageList(host: ChitUI): import("lit").TemplateResult;
|
|
17
|
+
import type { ChitUI } from '../chit-ui.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One message.
|
|
3
|
+
*
|
|
4
|
+
* `system` messages are a centred line rather than a bubble: they are the
|
|
5
|
+
* widget talking about the conversation ("an operator joined"), not a party to
|
|
6
|
+
* it, so they get no avatar, no name and no timestamp.
|
|
7
|
+
*
|
|
8
|
+
* @param {ChitUI} host
|
|
9
|
+
* @param {Message} message
|
|
10
|
+
* @returns {import('lit').TemplateResult}
|
|
11
|
+
*/
|
|
12
|
+
export function renderMessage(host: ChitUI, message: Message): import("lit").TemplateResult;
|
|
13
|
+
import type { ChitUI } from '../chit-ui.js';
|
|
14
|
+
import type { Message } from '../types.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @import { ChitUI } from '../chit-ui.js' */
|
|
2
|
+
/**
|
|
3
|
+
* The open state. Header and footer are slots; the message list and the
|
|
4
|
+
* composer arrive in later milestones and are placeholders for now.
|
|
5
|
+
*
|
|
6
|
+
* @param {ChitUI} host
|
|
7
|
+
* @returns {import('lit').TemplateResult}
|
|
8
|
+
*/
|
|
9
|
+
export function renderPanel(host: ChitUI): import("lit").TemplateResult;
|
|
10
|
+
import type { ChitUI } from '../chit-ui.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stylesheet the component owns and rewrites at runtime, appended after the
|
|
3
|
+
* component's static styles so its declarations win over them.
|
|
4
|
+
*/
|
|
5
|
+
export class AdoptedSheet {
|
|
6
|
+
/** @param {string} marker Identifies the sheet in the DOM when the fallback is used. */
|
|
7
|
+
constructor(marker: string);
|
|
8
|
+
/** @param {ShadowRoot | HTMLElement | DocumentFragment} root */
|
|
9
|
+
attach(root: ShadowRoot | HTMLElement | DocumentFragment): void;
|
|
10
|
+
/**
|
|
11
|
+
* Replace the sheet's contents. Cheap to call on every update: identical CSS
|
|
12
|
+
* is ignored.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} css
|
|
15
|
+
* @param {ShadowRoot | HTMLElement | DocumentFragment} root
|
|
16
|
+
*/
|
|
17
|
+
write(css: string, root: ShadowRoot | HTMLElement | DocumentFragment): void;
|
|
18
|
+
detach(): void;
|
|
19
|
+
#private;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const composerStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything that keeps arbitrary consumer HTML inside its bubble.
|
|
3
|
+
*
|
|
4
|
+
* The widget has no say over what goes in a message, so the containment is
|
|
5
|
+
* structural rather than a list of rules per element: the content box declares
|
|
6
|
+
* its own size, refuses to grow past the bubble, and contains its layout and
|
|
7
|
+
* paint so a stray position or margin cannot escape.
|
|
8
|
+
*/
|
|
9
|
+
export const contentStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-level concerns: the coordinate space the widget lives in, the theme
|
|
3
|
+
* fallbacks, and the transition animations.
|
|
4
|
+
*
|
|
5
|
+
* Every custom property here is a fallback only. ThemeController writes the
|
|
6
|
+
* real values into an adopted stylesheet that sits ahead of this one, and page
|
|
7
|
+
* CSS (`chit-ui { --chit-color-accent: ... }`) beats both.
|
|
8
|
+
*/
|
|
9
|
+
export const hostStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const launcherStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const messageStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const panelStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export namespace defaultTheme {
|
|
2
|
+
let breakpoint: number;
|
|
3
|
+
let zIndex: number;
|
|
4
|
+
namespace font {
|
|
5
|
+
let family: string;
|
|
6
|
+
let size: number;
|
|
7
|
+
}
|
|
8
|
+
namespace closed {
|
|
9
|
+
export { CLOSED_PC as pc };
|
|
10
|
+
export let mobile: ResolvedClosed;
|
|
11
|
+
}
|
|
12
|
+
namespace open {
|
|
13
|
+
let width: number;
|
|
14
|
+
let height: number;
|
|
15
|
+
let position: "bottom-right";
|
|
16
|
+
namespace offset {
|
|
17
|
+
let x: number;
|
|
18
|
+
let y: number;
|
|
19
|
+
}
|
|
20
|
+
let radius: number;
|
|
21
|
+
let launcher: "hidden";
|
|
22
|
+
namespace header {
|
|
23
|
+
let title: null;
|
|
24
|
+
let logo: null;
|
|
25
|
+
let avatar: null;
|
|
26
|
+
}
|
|
27
|
+
namespace background {
|
|
28
|
+
let image: null;
|
|
29
|
+
}
|
|
30
|
+
namespace colors {
|
|
31
|
+
import background_1 = PALETTE.surface;
|
|
32
|
+
export { background_1 as background };
|
|
33
|
+
import text = PALETTE.ink;
|
|
34
|
+
export { text };
|
|
35
|
+
import accent = PALETTE.accent;
|
|
36
|
+
export { accent };
|
|
37
|
+
import border = PALETTE.line;
|
|
38
|
+
export { border };
|
|
39
|
+
export let shadow: string;
|
|
40
|
+
import headerBackground = PALETTE.surface;
|
|
41
|
+
export { headerBackground };
|
|
42
|
+
import headerText = PALETTE.ink;
|
|
43
|
+
export { headerText };
|
|
44
|
+
import userBubble = PALETTE.accent;
|
|
45
|
+
export { userBubble };
|
|
46
|
+
import userText = PALETTE.onAccent;
|
|
47
|
+
export { userText };
|
|
48
|
+
import assistantBubble = PALETTE.raised;
|
|
49
|
+
export { assistantBubble };
|
|
50
|
+
import assistantText = PALETTE.ink;
|
|
51
|
+
export { assistantText };
|
|
52
|
+
import systemText = PALETTE.muted;
|
|
53
|
+
export { systemText };
|
|
54
|
+
import inputBackground = PALETTE.surface;
|
|
55
|
+
export { inputBackground };
|
|
56
|
+
import inputText = PALETTE.ink;
|
|
57
|
+
export { inputText };
|
|
58
|
+
import inputPlaceholder = PALETTE.muted;
|
|
59
|
+
export { inputPlaceholder };
|
|
60
|
+
}
|
|
61
|
+
namespace animation {
|
|
62
|
+
let enter: "scale";
|
|
63
|
+
let exit: "fade";
|
|
64
|
+
let duration: number;
|
|
65
|
+
let scroll: "smooth";
|
|
66
|
+
}
|
|
67
|
+
namespace input {
|
|
68
|
+
let maxRows: number;
|
|
69
|
+
let placeholder: null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
namespace hidden {
|
|
73
|
+
export namespace animation_1 {
|
|
74
|
+
let exit_1: "fade";
|
|
75
|
+
export { exit_1 as exit };
|
|
76
|
+
let duration_1: number;
|
|
77
|
+
export { duration_1 as duration };
|
|
78
|
+
}
|
|
79
|
+
export { animation_1 as animation };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** The measurements a phone falls back to when only `closed.pc` was given. */
|
|
83
|
+
export const mobileClosedDefaults: Partial<ResolvedClosed>;
|
|
84
|
+
/** @type {ResolvedClosed} */
|
|
85
|
+
declare const CLOSED_PC: ResolvedClosed;
|
|
86
|
+
import type { ResolvedClosed } from '../types.js';
|
|
87
|
+
declare namespace PALETTE {
|
|
88
|
+
let accent_1: string;
|
|
89
|
+
export { accent_1 as accent };
|
|
90
|
+
export let ink: string;
|
|
91
|
+
export let muted: string;
|
|
92
|
+
export let surface: string;
|
|
93
|
+
export let raised: string;
|
|
94
|
+
export let line: string;
|
|
95
|
+
export let onAccent: string;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge `override` onto `base`, recursing into plain objects.
|
|
3
|
+
*
|
|
4
|
+
* `undefined` means "say nothing" and leaves the base value alone; `null` means
|
|
5
|
+
* "clear it", so `{ image: null }` removes a default icon rather than being
|
|
6
|
+
* ignored. There are no arrays anywhere in a theme, so a plain recursive merge
|
|
7
|
+
* is enough.
|
|
8
|
+
*
|
|
9
|
+
* @template {Record<string, any>} T
|
|
10
|
+
* @param {T} base
|
|
11
|
+
* @param {Record<string, any> | undefined} override
|
|
12
|
+
* @returns {T}
|
|
13
|
+
*/
|
|
14
|
+
export function mergeTheme<T extends Record<string, any>>(base: T, override: Record<string, any> | undefined): T;
|
|
15
|
+
/**
|
|
16
|
+
* Fill every gap in a user theme and narrow it to one device.
|
|
17
|
+
*
|
|
18
|
+
* @param {Theme | undefined} theme
|
|
19
|
+
* @param {Device} device
|
|
20
|
+
* @returns {ResolvedTheme}
|
|
21
|
+
*/
|
|
22
|
+
export function resolveTheme(theme: Theme | undefined, device: Device): ResolvedTheme;
|
|
23
|
+
/**
|
|
24
|
+
* The breakpoint a theme asks for, readable before the full resolve (the
|
|
25
|
+
* device is not known until the breakpoint is).
|
|
26
|
+
*
|
|
27
|
+
* @param {Theme | undefined} theme
|
|
28
|
+
* @returns {number}
|
|
29
|
+
*/
|
|
30
|
+
export function breakpointOf(theme: Theme | undefined): number;
|
|
31
|
+
import type { Theme } from '../types.js';
|
|
32
|
+
import type { Device } from '../types.js';
|
|
33
|
+
import type { ResolvedTheme } from '../types.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn a resolved theme into the custom properties the stylesheets read.
|
|
3
|
+
*
|
|
4
|
+
* Only values CSS can act on are here. Positions, animation effects, text and
|
|
5
|
+
* images that belong in markup are applied as attributes or drawn by the
|
|
6
|
+
* render functions instead.
|
|
7
|
+
*
|
|
8
|
+
* Animation durations are deliberately absent: the transition code has to know
|
|
9
|
+
* when an animation ends, so the theme is the single source of truth for them
|
|
10
|
+
* and it writes the duration onto the element as it starts. A custom property
|
|
11
|
+
* here would look like a knob that does nothing.
|
|
12
|
+
*
|
|
13
|
+
* @param {ResolvedTheme} theme
|
|
14
|
+
* @returns {Record<string, string>}
|
|
15
|
+
*/
|
|
16
|
+
export function themeToVariables(theme: ResolvedTheme): Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* The stylesheet text for a resolved theme.
|
|
19
|
+
*
|
|
20
|
+
* @param {ResolvedTheme} theme
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
export function themeToCss(theme: ResolvedTheme): string;
|
|
24
|
+
import type { ResolvedTheme } from '../types.js';
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
3
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
4
|
+
*/
|
|
5
|
+
export type Role = "user" | "assistant" | "system";
|
|
6
|
+
/**
|
|
7
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
8
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
9
|
+
*/
|
|
10
|
+
export type MessageStatus = "sending" | "sent" | "error";
|
|
11
|
+
/**
|
|
12
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
13
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
14
|
+
*/
|
|
15
|
+
export type ChatState = "closed" | "open" | "hidden";
|
|
16
|
+
/**
|
|
17
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
18
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
19
|
+
*/
|
|
20
|
+
export type Trigger = "user" | "api";
|
|
21
|
+
/**
|
|
22
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
23
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
24
|
+
*/
|
|
25
|
+
export type Device = "pc" | "mobile";
|
|
26
|
+
/**
|
|
27
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
28
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
29
|
+
*/
|
|
30
|
+
export type Effect = "fade" | "scale" | "slide" | "none";
|
|
31
|
+
/**
|
|
32
|
+
* Public types for Chit UI. This module has no runtime value; it exists so that
|
|
33
|
+
* every other file can `@import` from one place and so `tsc` can emit .d.ts.
|
|
34
|
+
*/
|
|
35
|
+
export type Position = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
36
|
+
export type MessageBase = {
|
|
37
|
+
/**
|
|
38
|
+
* Unique within the array; used as the diffing key.
|
|
39
|
+
*/
|
|
40
|
+
id: string;
|
|
41
|
+
role: Role;
|
|
42
|
+
time?: string | Date | undefined;
|
|
43
|
+
name?: string | undefined;
|
|
44
|
+
avatar?: string | undefined;
|
|
45
|
+
status?: MessageStatus | undefined;
|
|
46
|
+
streaming?: boolean | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Never touched by the library.
|
|
49
|
+
*/
|
|
50
|
+
meta?: unknown;
|
|
51
|
+
};
|
|
52
|
+
export type TextMessage = MessageBase & {
|
|
53
|
+
text: string;
|
|
54
|
+
};
|
|
55
|
+
export type HtmlMessage = MessageBase & {
|
|
56
|
+
html: string;
|
|
57
|
+
};
|
|
58
|
+
export type TemplateMessage = MessageBase & {
|
|
59
|
+
template: import("lit").TemplateResult;
|
|
60
|
+
};
|
|
61
|
+
export type ElementMessage = MessageBase & {
|
|
62
|
+
element: HTMLElement;
|
|
63
|
+
};
|
|
64
|
+
export type ComponentMessage = MessageBase & {
|
|
65
|
+
component: (new () => HTMLElement) | string;
|
|
66
|
+
props?: Record<string, unknown>;
|
|
67
|
+
};
|
|
68
|
+
export type Message = TextMessage | HtmlMessage | TemplateMessage | ElementMessage | ComponentMessage;
|
|
69
|
+
export type Animation = {
|
|
70
|
+
enter?: Effect | undefined;
|
|
71
|
+
exit?: Effect | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* ms
|
|
74
|
+
*/
|
|
75
|
+
duration?: number | undefined;
|
|
76
|
+
};
|
|
77
|
+
export type Offset = {
|
|
78
|
+
x?: number | undefined;
|
|
79
|
+
y?: number | undefined;
|
|
80
|
+
};
|
|
81
|
+
export type ClosedTheme = {
|
|
82
|
+
/**
|
|
83
|
+
* Launcher edge length in px, or 'auto' to let its content decide.
|
|
84
|
+
*/
|
|
85
|
+
size?: number | "auto" | undefined;
|
|
86
|
+
position?: Position | undefined;
|
|
87
|
+
offset?: Offset | undefined;
|
|
88
|
+
radius?: number | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Icon image URL; null clears the default.
|
|
91
|
+
*/
|
|
92
|
+
image?: string | null | undefined;
|
|
93
|
+
label?: string | null | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* A component that draws the whole launcher.
|
|
96
|
+
*/
|
|
97
|
+
component?: string | (new () => HTMLElement) | null | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Properties written to that component.
|
|
100
|
+
*/
|
|
101
|
+
props?: Record<string, unknown> | undefined;
|
|
102
|
+
colors?: {
|
|
103
|
+
background?: string;
|
|
104
|
+
text?: string;
|
|
105
|
+
shadow?: string;
|
|
106
|
+
} | undefined;
|
|
107
|
+
animation?: (Animation & {
|
|
108
|
+
idle?: "none" | "pulse" | "bounce";
|
|
109
|
+
}) | undefined;
|
|
110
|
+
};
|
|
111
|
+
export type OpenColors = {
|
|
112
|
+
background?: string | undefined;
|
|
113
|
+
text?: string | undefined;
|
|
114
|
+
accent?: string | undefined;
|
|
115
|
+
border?: string | undefined;
|
|
116
|
+
shadow?: string | undefined;
|
|
117
|
+
headerBackground?: string | undefined;
|
|
118
|
+
headerText?: string | undefined;
|
|
119
|
+
userBubble?: string | undefined;
|
|
120
|
+
userText?: string | undefined;
|
|
121
|
+
assistantBubble?: string | undefined;
|
|
122
|
+
assistantText?: string | undefined;
|
|
123
|
+
systemText?: string | undefined;
|
|
124
|
+
inputBackground?: string | undefined;
|
|
125
|
+
inputText?: string | undefined;
|
|
126
|
+
inputPlaceholder?: string | undefined;
|
|
127
|
+
};
|
|
128
|
+
export type OpenTheme = {
|
|
129
|
+
/**
|
|
130
|
+
* Ignored on mobile (always full screen).
|
|
131
|
+
*/
|
|
132
|
+
width?: number | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Ignored on mobile (always full screen).
|
|
135
|
+
*/
|
|
136
|
+
height?: number | undefined;
|
|
137
|
+
position?: Position | undefined;
|
|
138
|
+
offset?: Offset | undefined;
|
|
139
|
+
radius?: number | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Keep the launcher visible while open.
|
|
142
|
+
*/
|
|
143
|
+
launcher?: "hidden" | "visible" | undefined;
|
|
144
|
+
header?: {
|
|
145
|
+
title?: string | null;
|
|
146
|
+
logo?: string | null;
|
|
147
|
+
avatar?: string | null;
|
|
148
|
+
} | undefined;
|
|
149
|
+
background?: {
|
|
150
|
+
image?: string | null;
|
|
151
|
+
} | undefined;
|
|
152
|
+
colors?: OpenColors | undefined;
|
|
153
|
+
animation?: (Animation & {
|
|
154
|
+
scroll?: "smooth" | "instant";
|
|
155
|
+
}) | undefined;
|
|
156
|
+
input?: {
|
|
157
|
+
maxRows?: number;
|
|
158
|
+
placeholder?: string | null;
|
|
159
|
+
} | undefined;
|
|
160
|
+
};
|
|
161
|
+
export type Theme = {
|
|
162
|
+
/**
|
|
163
|
+
* Widths below this are treated as mobile.
|
|
164
|
+
*/
|
|
165
|
+
breakpoint?: number | undefined;
|
|
166
|
+
zIndex?: number | undefined;
|
|
167
|
+
font?: {
|
|
168
|
+
family?: string;
|
|
169
|
+
size?: number;
|
|
170
|
+
} | undefined;
|
|
171
|
+
closed?: ClosedTheme | {
|
|
172
|
+
pc?: ClosedTheme;
|
|
173
|
+
mobile?: ClosedTheme;
|
|
174
|
+
} | undefined;
|
|
175
|
+
open?: OpenTheme | undefined;
|
|
176
|
+
hidden?: {
|
|
177
|
+
animation?: {
|
|
178
|
+
exit?: Effect;
|
|
179
|
+
duration?: number;
|
|
180
|
+
};
|
|
181
|
+
} | undefined;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* A theme with every gap filled in and `closed` narrowed to the device in use.
|
|
185
|
+
* This is what the render functions and the CSS generator read.
|
|
186
|
+
*/
|
|
187
|
+
export type ResolvedClosed = {
|
|
188
|
+
size: number | "auto";
|
|
189
|
+
position: Position;
|
|
190
|
+
offset: {
|
|
191
|
+
x: number;
|
|
192
|
+
y: number;
|
|
193
|
+
};
|
|
194
|
+
radius: number;
|
|
195
|
+
image: string | null;
|
|
196
|
+
label: string | null;
|
|
197
|
+
component: (new () => HTMLElement) | string | null;
|
|
198
|
+
props: Record<string, unknown>;
|
|
199
|
+
colors: {
|
|
200
|
+
background: string;
|
|
201
|
+
text: string;
|
|
202
|
+
shadow: string;
|
|
203
|
+
};
|
|
204
|
+
animation: {
|
|
205
|
+
enter: Effect;
|
|
206
|
+
exit: Effect;
|
|
207
|
+
duration: number;
|
|
208
|
+
idle: "none" | "pulse" | "bounce";
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* A theme with every gap filled in and `closed` narrowed to the device in use.
|
|
213
|
+
* This is what the render functions and the CSS generator read.
|
|
214
|
+
*/
|
|
215
|
+
export type ResolvedOpen = {
|
|
216
|
+
width: number;
|
|
217
|
+
height: number;
|
|
218
|
+
position: Position;
|
|
219
|
+
offset: {
|
|
220
|
+
x: number;
|
|
221
|
+
y: number;
|
|
222
|
+
};
|
|
223
|
+
radius: number;
|
|
224
|
+
launcher: "hidden" | "visible";
|
|
225
|
+
header: {
|
|
226
|
+
title: string | null;
|
|
227
|
+
logo: string | null;
|
|
228
|
+
avatar: string | null;
|
|
229
|
+
};
|
|
230
|
+
background: {
|
|
231
|
+
image: string | null;
|
|
232
|
+
};
|
|
233
|
+
colors: Required<OpenColors>;
|
|
234
|
+
animation: {
|
|
235
|
+
enter: Effect;
|
|
236
|
+
exit: Effect;
|
|
237
|
+
duration: number;
|
|
238
|
+
scroll: "smooth" | "instant";
|
|
239
|
+
};
|
|
240
|
+
input: {
|
|
241
|
+
maxRows: number;
|
|
242
|
+
placeholder: string | null;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* A theme with every gap filled in and `closed` narrowed to the device in use.
|
|
247
|
+
* This is what the render functions and the CSS generator read.
|
|
248
|
+
*/
|
|
249
|
+
export type ResolvedTheme = {
|
|
250
|
+
breakpoint: number;
|
|
251
|
+
zIndex: number;
|
|
252
|
+
font: {
|
|
253
|
+
family: string;
|
|
254
|
+
size: number;
|
|
255
|
+
};
|
|
256
|
+
closed: ResolvedClosed;
|
|
257
|
+
open: ResolvedOpen;
|
|
258
|
+
hidden: {
|
|
259
|
+
animation: {
|
|
260
|
+
exit: Effect;
|
|
261
|
+
duration: number;
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Which bucket `closed` was narrowed to.
|
|
266
|
+
*/
|
|
267
|
+
device: Device;
|
|
268
|
+
};
|