@iyulab/chat-components 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.
Files changed (79) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +21 -0
  3. package/README.md +20 -0
  4. package/dist/components/blocks/UCodeBlock.component.d.ts +24 -0
  5. package/dist/components/blocks/UCodeBlock.component.js +65 -0
  6. package/dist/components/blocks/UCodeBlock.d.ts +7 -0
  7. package/dist/components/blocks/UCodeBlock.js +5 -0
  8. package/dist/components/blocks/UCodeBlock.styles.d.ts +1 -0
  9. package/dist/components/blocks/UCodeBlock.styles.js +175 -0
  10. package/dist/components/blocks/UMarkedBlock.component.d.ts +24 -0
  11. package/dist/components/blocks/UMarkedBlock.component.js +80 -0
  12. package/dist/components/blocks/UMarkedBlock.d.ts +7 -0
  13. package/dist/components/blocks/UMarkedBlock.js +5 -0
  14. package/dist/components/blocks/UMarkedBlock.styles.d.ts +1 -0
  15. package/dist/components/blocks/UMarkedBlock.styles.js +1240 -0
  16. package/dist/components/blocks/UTextBlock.component.d.ts +37 -0
  17. package/dist/components/blocks/UTextBlock.component.js +123 -0
  18. package/dist/components/blocks/UTextBlock.d.ts +7 -0
  19. package/dist/components/blocks/UTextBlock.js +5 -0
  20. package/dist/components/blocks/UTextBlock.styles.d.ts +1 -0
  21. package/dist/components/blocks/UTextBlock.styles.js +71 -0
  22. package/dist/components/blocks/UThinkBlock.component.d.ts +28 -0
  23. package/dist/components/blocks/UThinkBlock.component.js +84 -0
  24. package/dist/components/blocks/UThinkBlock.d.ts +7 -0
  25. package/dist/components/blocks/UThinkBlock.js +5 -0
  26. package/dist/components/blocks/UThinkBlock.styles.d.ts +1 -0
  27. package/dist/components/blocks/UThinkBlock.styles.js +93 -0
  28. package/dist/components/blocks/UToolBlock.component.d.ts +16 -0
  29. package/dist/components/blocks/UToolBlock.component.js +126 -0
  30. package/dist/components/blocks/UToolBlock.d.ts +7 -0
  31. package/dist/components/blocks/UToolBlock.js +5 -0
  32. package/dist/components/blocks/UToolBlock.styles.d.ts +1 -0
  33. package/dist/components/blocks/UToolBlock.styles.js +107 -0
  34. package/dist/components/buttons/UAttachButton.component.d.ts +24 -0
  35. package/dist/components/buttons/UAttachButton.component.js +78 -0
  36. package/dist/components/buttons/UAttachButton.d.ts +7 -0
  37. package/dist/components/buttons/UAttachButton.js +5 -0
  38. package/dist/components/buttons/UAttachButton.styles.d.ts +1 -0
  39. package/dist/components/buttons/UAttachButton.styles.js +21 -0
  40. package/dist/components/buttons/UCopyButton.component.d.ts +25 -0
  41. package/dist/components/buttons/UCopyButton.component.js +105 -0
  42. package/dist/components/buttons/UCopyButton.d.ts +7 -0
  43. package/dist/components/buttons/UCopyButton.js +5 -0
  44. package/dist/components/buttons/UCopyButton.styles.d.ts +1 -0
  45. package/dist/components/buttons/UCopyButton.styles.js +47 -0
  46. package/dist/components/buttons/USendButton.component.d.ts +13 -0
  47. package/dist/components/buttons/USendButton.component.js +46 -0
  48. package/dist/components/buttons/USendButton.d.ts +7 -0
  49. package/dist/components/buttons/USendButton.js +5 -0
  50. package/dist/components/buttons/USendButton.styles.d.ts +1 -0
  51. package/dist/components/buttons/USendButton.styles.js +23 -0
  52. package/dist/components/buttons/UThinkButton.component.d.ts +19 -0
  53. package/dist/components/buttons/UThinkButton.component.js +73 -0
  54. package/dist/components/buttons/UThinkButton.d.ts +7 -0
  55. package/dist/components/buttons/UThinkButton.js +5 -0
  56. package/dist/components/buttons/UThinkButton.styles.d.ts +1 -0
  57. package/dist/components/buttons/UThinkButton.styles.js +72 -0
  58. package/dist/components/json-viewer/UJsonViewer.component.d.ts +44 -0
  59. package/dist/components/json-viewer/UJsonViewer.component.js +137 -0
  60. package/dist/components/json-viewer/UJsonViewer.d.ts +7 -0
  61. package/dist/components/json-viewer/UJsonViewer.js +5 -0
  62. package/dist/components/json-viewer/UJsonViewer.lib.d.ts +16 -0
  63. package/dist/components/json-viewer/UJsonViewer.lib.js +28 -0
  64. package/dist/components/json-viewer/UJsonViewer.styles.d.ts +1 -0
  65. package/dist/components/json-viewer/UJsonViewer.styles.js +115 -0
  66. package/dist/components/message/UMessage.component.d.ts +13 -0
  67. package/dist/components/message/UMessage.component.js +104 -0
  68. package/dist/components/message/UMessage.d.ts +8 -0
  69. package/dist/components/message/UMessage.js +5 -0
  70. package/dist/components/message/UMessage.styles.d.ts +1 -0
  71. package/dist/components/message/UMessage.styles.js +72 -0
  72. package/dist/components/message/UMessage.types.d.ts +21 -0
  73. package/dist/events/UStopEvent.d.ts +6 -0
  74. package/dist/events/USubmitEvent.d.ts +6 -0
  75. package/dist/index.d.ts +13 -0
  76. package/dist/index.js +22 -0
  77. package/dist/internals/date-helpers.d.ts +8 -0
  78. package/dist/internals/date-helpers.js +27 -0
  79. package/package.json +65 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2025-12-19)
4
+ - Initial library version release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Iyulab, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @iyulab/chat-components
2
+
3
+ 대화형 LLM 채팅 인터페이스를 구현하기 위해 필요한 컴포넌트들을 제공합니다.
4
+ 현재 개발중으로, 일부 컴포넌트는 미완성 상태입니다.
5
+
6
+ ## 📦 Insta
7
+
8
+ ```bash
9
+ npm install @iyulab/chat-components
10
+ ```
11
+
12
+ ## 🚀 Usage
13
+
14
+ ```javascript
15
+ import '@iyulab/chat-components';
16
+ ```
17
+
18
+ ## 📄 LI
19
+
20
+ MIT © iyulab
@@ -0,0 +1,24 @@
1
+ import { nothing } from 'lit';
2
+ import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
3
+ /**
4
+ * 코드 블록을 렌더링하는 컴포넌트입니다.
5
+ * 언어와 코드를 받아 syntax highlighting을 적용합니다.
6
+ */
7
+ export declare class UCodeBlock extends BaseElement {
8
+ static styles: import('lit').CSSResultGroup[];
9
+ static dependencies: Record<string, typeof BaseElement>;
10
+ /** 코드 블록의 헤더를 숨길지 여부를 지정합니다. */
11
+ headless: boolean;
12
+ /** 코드 언어를 지정합니다. */
13
+ language: string;
14
+ /** 표시할 코드 내용입니다. */
15
+ value?: string;
16
+ render(): typeof nothing | import('lit-html').TemplateResult<1>;
17
+ /**
18
+ * 코드에 구문 강조를 적용합니다.
19
+ * @param value 코드 문자열
20
+ * @param lang 코드 언어
21
+ * @returns 구문 강조가 적용된 HTML 문자열
22
+ */
23
+ private parse;
24
+ }
@@ -0,0 +1,65 @@
1
+ import { nothing, html } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
4
+ import hljs from 'highlight.js';
5
+ import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
6
+ import { UCopyButton } from '../buttons/UCopyButton.component.js';
7
+ import { styles } from './UCodeBlock.styles.js';
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __decorateClass = (decorators, target, key, kind) => {
11
+ var result = void 0 ;
12
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
13
+ if (decorator = decorators[i])
14
+ result = (decorator(target, key, result) ) || result;
15
+ if (result) __defProp(target, key, result);
16
+ return result;
17
+ };
18
+ class UCodeBlock extends BaseElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.headless = false;
22
+ this.language = "plaintext";
23
+ }
24
+ static {
25
+ this.styles = [super.styles, styles];
26
+ }
27
+ static {
28
+ this.dependencies = {
29
+ "u-copy-button": UCopyButton
30
+ };
31
+ }
32
+ render() {
33
+ if (!this.value) return nothing;
34
+ const lang = hljs.getLanguage(this.language) ? this.language : "plaintext";
35
+ return html`
36
+ <div class="header" ?hidden=${this.headless}>
37
+ <span class="language">${lang}</span>
38
+ <u-copy-button mode="badge" .value="${this.value}"></u-copy-button>
39
+ </div>
40
+ ${unsafeHTML(`<pre class="hljs">${this.parse(this.value, lang)}</pre>`)}
41
+ `;
42
+ }
43
+ /**
44
+ * 코드에 구문 강조를 적용합니다.
45
+ * @param value 코드 문자열
46
+ * @param lang 코드 언어
47
+ * @returns 구문 강조가 적용된 HTML 문자열
48
+ */
49
+ parse(value, lang) {
50
+ return hljs.highlight(value, {
51
+ language: lang
52
+ }).value;
53
+ }
54
+ }
55
+ __decorateClass([
56
+ property({ type: Boolean, reflect: true })
57
+ ], UCodeBlock.prototype, "headless");
58
+ __decorateClass([
59
+ property({ type: String })
60
+ ], UCodeBlock.prototype, "language");
61
+ __decorateClass([
62
+ property({ type: String })
63
+ ], UCodeBlock.prototype, "value");
64
+
65
+ export { UCodeBlock };
@@ -0,0 +1,7 @@
1
+ import { UCodeBlock } from './UCodeBlock.component.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ "u-code-block": UCodeBlock;
5
+ }
6
+ }
7
+ export { UCodeBlock };
@@ -0,0 +1,5 @@
1
+ import { UCodeBlock } from './UCodeBlock.component.js';
2
+
3
+ UCodeBlock.define("u-code-block");
4
+
5
+ export { UCodeBlock };
@@ -0,0 +1 @@
1
+ export declare const styles: import('lit').CSSResult;
@@ -0,0 +1,175 @@
1
+ import { css } from 'lit';
2
+
3
+ const styles = css`
4
+ :host {
5
+ --hljs-text-color: #24292e;
6
+ --hljs-background-color: #ffffff;
7
+ --hljs-keyword-color: #d73a49;
8
+ --hljs-entity-color: #6f42c1;
9
+ --hljs-constant-color: #005cc5;
10
+ --hljs-string-color: #032f62;
11
+ --hljs-variable-color: #e36209;
12
+ --hljs-comment-color: #6a737d;
13
+ --hljs-entity-tag-color: #22863a;
14
+ --hljs-markup-heading-color: #005cc5;
15
+ --hljs-markup-list-color: #735c0f;
16
+ --hljs-addition-color: #22863a;
17
+ --hljs-addition-bg-color: #f0fff4;
18
+ --hljs-deletion-color: #b31d28;
19
+ --hljs-deletion-bg-color: #ffeef0;
20
+ }
21
+ :host-context([theme="dark"]) {
22
+ --hljs-text-color: #c9d1d9;
23
+ --hljs-background-color: #0d1117;
24
+ --hljs-keyword-color: #ff7b72;
25
+ --hljs-entity-color: #d2a8ff;
26
+ --hljs-constant-color: #79c0ff;
27
+ --hljs-string-color: #a5d6ff;
28
+ --hljs-variable-color: #ffa657;
29
+ --hljs-comment-color: #8b949e;
30
+ --hljs-entity-tag-color: #7ee787;
31
+ --hljs-markup-heading-color: #1f6feb;
32
+ --hljs-markup-list-color: #f2cc60;
33
+ --hljs-addition-color: #aff5b4;
34
+ --hljs-addition-bg-color: #033a16;
35
+ --hljs-deletion-color: #ffdcd7;
36
+ --hljs-deletion-bg-color: #67060c;
37
+ }
38
+
39
+ :host {
40
+ display: block;
41
+ width: 100%;
42
+ border: 1px solid var(--u-border-color);
43
+ border-radius: 8px;
44
+ background-color: var(--u-neutral-100);
45
+ padding: 8px 16px;
46
+ }
47
+
48
+ .header {
49
+ width: 100%;
50
+ display: flex;
51
+ flex-direction: row;
52
+ align-items: center;
53
+ justify-content: space-between;
54
+ font-family: Arial, Helvetica, sans-serif;
55
+ font-size: 12px;
56
+ font-weight: 300;
57
+ color: var(--u-txt-color-strong);
58
+ margin-bottom: 12px;
59
+ user-select: none;
60
+ }
61
+
62
+ /* highlight.js styles */
63
+ .hljs {
64
+ display: block;
65
+ overflow-x: auto;
66
+ margin: 0;
67
+ padding: 0;
68
+ color: var(--hljs-text-color);
69
+ font-family: var(--fontStack-monospace, ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace);
70
+ font-size: 14px;
71
+ line-height: 1.45;
72
+ white-space: pre;
73
+ scrollbar-width: thin;
74
+ scrollbar-color: var(--u-scrollbar-color) transparent;
75
+ scrollbar-gutter: stable;
76
+ }
77
+
78
+ .hljs-doctag,
79
+ .hljs-keyword,
80
+ .hljs-meta .hljs-keyword,
81
+ .hljs-template-tag,
82
+ .hljs-template-variable,
83
+ .hljs-type,
84
+ .hljs-variable.language_ {
85
+ color: var(--hljs-keyword-color);
86
+ }
87
+
88
+ .hljs-title,
89
+ .hljs-title.class_,
90
+ .hljs-title.class_.inherited__,
91
+ .hljs-title.function_ {
92
+ color: var(--hljs-entity-color);
93
+ }
94
+
95
+ .hljs-attr,
96
+ .hljs-attribute,
97
+ .hljs-literal,
98
+ .hljs-meta,
99
+ .hljs-number,
100
+ .hljs-operator,
101
+ .hljs-variable,
102
+ .hljs-selector-attr,
103
+ .hljs-selector-class,
104
+ .hljs-selector-id {
105
+ color: var(--hljs-constant-color);
106
+ }
107
+
108
+ .hljs-regexp,
109
+ .hljs-string,
110
+ .hljs-meta .hljs-string {
111
+ color: var(--hljs-string-color);
112
+ }
113
+
114
+ .hljs-built_in,
115
+ .hljs-symbol {
116
+ color: var(--hljs-variable-color);
117
+ }
118
+
119
+ .hljs-comment,
120
+ .hljs-code,
121
+ .hljs-formula {
122
+ color: var(--hljs-comment-color);
123
+ }
124
+
125
+ .hljs-name,
126
+ .hljs-quote,
127
+ .hljs-selector-tag,
128
+ .hljs-selector-pseudo {
129
+ color: var(--hljs-entity-tag-color);
130
+ }
131
+
132
+ .hljs-subst {
133
+ color: var(--hljs-text-color);
134
+ }
135
+
136
+ .hljs-section {
137
+ color: var(--hljs-markup-heading-color);
138
+ font-weight: bold;
139
+ }
140
+
141
+ .hljs-bullet {
142
+ color: var(--hljs-markup-list-color);
143
+ }
144
+
145
+ .hljs-emphasis {
146
+ color: var(--hljs-text-color);
147
+ font-style: italic;
148
+ }
149
+
150
+ .hljs-strong {
151
+ color: var(--hljs-text-color);
152
+ font-weight: bold;
153
+ }
154
+
155
+ .hljs-addition {
156
+ color: var(--hljs-addition-color);
157
+ background-color: var(--hljs-addition-bg-color);
158
+ }
159
+
160
+ .hljs-deletion {
161
+ color: var(--hljs-deletion-color);
162
+ background-color: var(--hljs-deletion-bg-color);
163
+ }
164
+
165
+ .hljs-char.escape_,
166
+ .hljs-link,
167
+ .hljs-params,
168
+ .hljs-property,
169
+ .hljs-punctuation,
170
+ .hljs-tag {
171
+ color: currentColor;
172
+ }
173
+ `;
174
+
175
+ export { styles };
@@ -0,0 +1,24 @@
1
+ import { nothing } from 'lit';
2
+ import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
3
+ /**
4
+ * 마크다운 컨텐츠를 렌더링하는 컴포넌트입니다.
5
+ */
6
+ export declare class UMarkedBlock extends BaseElement {
7
+ static styles: import('lit').CSSResultGroup[];
8
+ static dependencies: Record<string, typeof BaseElement>;
9
+ private parser;
10
+ /** 마크다운 컨텐츠를 렌더링할 때 사용할 값입니다. */
11
+ value?: string;
12
+ render(): typeof nothing | import('lit-html').TemplateResult<1>;
13
+ /**
14
+ * 마크다운 문자열을 HTML로 변환합니다.
15
+ * @param value 변환할 마크다운 문자열
16
+ * @returns 변환된 HTML 문자열
17
+ */
18
+ private parse;
19
+ /**
20
+ * HTML 속성에 안전하게 삽입하기 위해 특수문자를 이스케이프합니다.
21
+ * @param value 원본 문자열
22
+ */
23
+ private sanitizeCode;
24
+ }
@@ -0,0 +1,80 @@
1
+ import { nothing, html } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
4
+ import { Marked } from 'marked';
5
+ import markedAlert from 'marked-alert';
6
+ import markedFootnote from 'marked-footnote';
7
+ import markedKatex from 'marked-katex-extension';
8
+ import { BaseElement } from '@iyulab/components/dist/components/BaseElement.js';
9
+ import { UCodeBlock } from './UCodeBlock.component.js';
10
+ import { styles } from './UMarkedBlock.styles.js';
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __decorateClass = (decorators, target, key, kind) => {
14
+ var result = void 0 ;
15
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
16
+ if (decorator = decorators[i])
17
+ result = (decorator(target, key, result) ) || result;
18
+ if (result) __defProp(target, key, result);
19
+ return result;
20
+ };
21
+ class UMarkedBlock extends BaseElement {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.parser = new Marked({
25
+ pedantic: false,
26
+ // 엄격한 마크다운 규격 준수하지 않음 (markdown.pl을 따르지 않음)
27
+ gfm: true,
28
+ // GitHub Flavored Markdown 사용
29
+ breaks: true,
30
+ // 단순 줄바꿈 또한 <br> 태그로 변환
31
+ silent: true,
32
+ // 파싱 오류 발생 시 예외를 발생시키지 않고 메시지를 출력
33
+ renderer: {
34
+ code: ({ text, lang }) => {
35
+ lang ||= "plaintext";
36
+ text = this.sanitizeCode(text);
37
+ return `<u-code-block language="${lang}" value="${text}"></u-code-block>`;
38
+ }
39
+ }
40
+ }).use(markedAlert()).use(markedFootnote()).use(markedKatex({ output: "mathml" }));
41
+ }
42
+ static {
43
+ this.styles = [super.styles, styles];
44
+ }
45
+ static {
46
+ this.dependencies = {
47
+ "u-code-block": UCodeBlock
48
+ };
49
+ }
50
+ render() {
51
+ if (!this.value) return nothing;
52
+ return html`
53
+ <div class="markdown-body">
54
+ ${unsafeHTML(this.parse(this.value))}
55
+ </div>
56
+ `;
57
+ }
58
+ /**
59
+ * 마크다운 문자열을 HTML로 변환합니다.
60
+ * @param value 변환할 마크다운 문자열
61
+ * @returns 변환된 HTML 문자열
62
+ */
63
+ parse(value) {
64
+ value = value.replace(/\u200B|\u200C|\u200D|\u200E|\u200F|\uFEFF/g, "");
65
+ value = this.parser.parse(value, { async: false });
66
+ return value;
67
+ }
68
+ /**
69
+ * HTML 속성에 안전하게 삽입하기 위해 특수문자를 이스케이프합니다.
70
+ * @param value 원본 문자열
71
+ */
72
+ sanitizeCode(value) {
73
+ return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
74
+ }
75
+ }
76
+ __decorateClass([
77
+ property({ type: String })
78
+ ], UMarkedBlock.prototype, "value");
79
+
80
+ export { UMarkedBlock };
@@ -0,0 +1,7 @@
1
+ import { UMarkedBlock } from './UMarkedBlock.component.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ "u-marked-block": UMarkedBlock;
5
+ }
6
+ }
7
+ export { UMarkedBlock };
@@ -0,0 +1,5 @@
1
+ import { UMarkedBlock } from './UMarkedBlock.component.js';
2
+
3
+ UMarkedBlock.define("u-marked-block");
4
+
5
+ export { UMarkedBlock };
@@ -0,0 +1 @@
1
+ export declare const styles: import('lit').CSSResult;