@folio-agent/widget 0.2.0 → 0.3.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/README.md +2 -0
- package/dist/styles.d.ts +1 -1
- package/dist/styles.js +26 -17
- package/dist/widget-element.js +35 -9
- package/package.json +3 -2
package/README.md
CHANGED
package/dist/styles.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WIDGET_STYLES = "\n :host {\n all: initial;\n font-family: var(--folio-agent-font,
|
|
1
|
+
export declare const WIDGET_STYLES = "\n :host {\n all: initial;\n color: inherit;\n color-scheme: inherit;\n font-family: var(--folio-agent-font, inherit);\n }\n .toggle {\n position: fixed;\n right: 20px;\n bottom: 20px;\n width: 56px;\n height: 56px;\n border-radius: 50%;\n border: none;\n background: var(--folio-agent-accent, CanvasText);\n color: var(--folio-agent-accent-contrast, Canvas);\n font-size: 24px;\n cursor: pointer;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);\n z-index: 2147483000;\n }\n .panel {\n position: fixed;\n right: 20px;\n bottom: 88px;\n width: 320px;\n max-height: 420px;\n display: flex;\n flex-direction: column;\n background: var(--folio-agent-surface, Canvas);\n border-radius: 12px;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);\n overflow: hidden;\n z-index: 2147483000;\n }\n .panel[hidden] {\n display: none;\n }\n .messages {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 10px;\n font-size: 14px;\n line-height: 1.6;\n color: var(--folio-agent-text, CanvasText);\n }\n .message {\n white-space: pre-wrap;\n }\n .message.assistant {\n align-self: flex-start;\n background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 8%, var(--folio-agent-surface, Canvas));\n border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 16%, var(--folio-agent-surface, Canvas));\n border-radius: 8px;\n padding: 10px 14px;\n }\n .message.user {\n align-self: flex-end;\n background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 14%, var(--folio-agent-surface, Canvas));\n border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 24%, var(--folio-agent-surface, Canvas));\n border-radius: 8px;\n padding: 10px 14px;\n }\n .disclosure {\n font-size: 12px;\n color: var(--folio-agent-muted, color-mix(in srgb, CanvasText 55%, Canvas));\n padding: 0 0 4px;\n }\n .disclosure a {\n color: #2563eb;\n }\n form {\n display: flex;\n border-top: 1px solid color-mix(in srgb, CanvasText 16%, Canvas);\n }\n input {\n flex: 1;\n border: none;\n background: transparent;\n color: inherit;\n padding: 10px;\n font-size: 14px;\n }\n input:focus {\n outline: none;\n }\n button[type=\"submit\"] {\n border: none;\n background: none;\n padding: 0 14px;\n cursor: pointer;\n color: var(--folio-agent-accent, CanvasText);\n font-weight: 600;\n }\n";
|
package/dist/styles.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// テーマ注入: 利用側サイトのグローバルCSSで
|
|
2
2
|
// folio-agent-widget { --folio-agent-accent: #...; }
|
|
3
3
|
// のようにカスタムプロパティを指定するとShadow DOM内に継承されテーマが反映される。
|
|
4
|
-
//
|
|
4
|
+
// 未指定の場合は各プロパティがホスト配色(CSSシステムカラー)から導出した値を使い、
|
|
5
|
+
// サイトのライト/ダークいずれの配色にも自動で馴染む。
|
|
5
6
|
export const WIDGET_STYLES = `
|
|
6
7
|
:host {
|
|
7
8
|
all: initial;
|
|
8
|
-
|
|
9
|
+
color: inherit;
|
|
10
|
+
color-scheme: inherit;
|
|
11
|
+
font-family: var(--folio-agent-font, inherit);
|
|
9
12
|
}
|
|
10
13
|
.toggle {
|
|
11
14
|
position: fixed;
|
|
@@ -15,8 +18,8 @@ export const WIDGET_STYLES = `
|
|
|
15
18
|
height: 56px;
|
|
16
19
|
border-radius: 50%;
|
|
17
20
|
border: none;
|
|
18
|
-
background: var(--folio-agent-accent,
|
|
19
|
-
color: var(--folio-agent-accent-contrast,
|
|
21
|
+
background: var(--folio-agent-accent, CanvasText);
|
|
22
|
+
color: var(--folio-agent-accent-contrast, Canvas);
|
|
20
23
|
font-size: 24px;
|
|
21
24
|
cursor: pointer;
|
|
22
25
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
|
|
@@ -30,7 +33,7 @@ export const WIDGET_STYLES = `
|
|
|
30
33
|
max-height: 420px;
|
|
31
34
|
display: flex;
|
|
32
35
|
flex-direction: column;
|
|
33
|
-
background: var(--folio-agent-surface,
|
|
36
|
+
background: var(--folio-agent-surface, Canvas);
|
|
34
37
|
border-radius: 12px;
|
|
35
38
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
36
39
|
overflow: hidden;
|
|
@@ -42,30 +45,34 @@ export const WIDGET_STYLES = `
|
|
|
42
45
|
.messages {
|
|
43
46
|
flex: 1;
|
|
44
47
|
overflow-y: auto;
|
|
45
|
-
padding:
|
|
48
|
+
padding: 16px;
|
|
46
49
|
display: flex;
|
|
47
50
|
flex-direction: column;
|
|
48
|
-
gap:
|
|
51
|
+
gap: 10px;
|
|
49
52
|
font-size: 14px;
|
|
50
|
-
line-height: 1.
|
|
51
|
-
color: var(--folio-agent-text,
|
|
53
|
+
line-height: 1.6;
|
|
54
|
+
color: var(--folio-agent-text, CanvasText);
|
|
55
|
+
}
|
|
56
|
+
.message {
|
|
57
|
+
white-space: pre-wrap;
|
|
52
58
|
}
|
|
53
59
|
.message.assistant {
|
|
54
60
|
align-self: flex-start;
|
|
55
|
-
background: var(--folio-agent-
|
|
61
|
+
background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 8%, var(--folio-agent-surface, Canvas));
|
|
62
|
+
border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 16%, var(--folio-agent-surface, Canvas));
|
|
56
63
|
border-radius: 8px;
|
|
57
|
-
padding:
|
|
64
|
+
padding: 10px 14px;
|
|
58
65
|
}
|
|
59
66
|
.message.user {
|
|
60
67
|
align-self: flex-end;
|
|
61
|
-
background: var(--folio-agent-
|
|
62
|
-
|
|
68
|
+
background: color-mix(in srgb, var(--folio-agent-text, CanvasText) 14%, var(--folio-agent-surface, Canvas));
|
|
69
|
+
border: 1px solid color-mix(in srgb, var(--folio-agent-text, CanvasText) 24%, var(--folio-agent-surface, Canvas));
|
|
63
70
|
border-radius: 8px;
|
|
64
|
-
padding:
|
|
71
|
+
padding: 10px 14px;
|
|
65
72
|
}
|
|
66
73
|
.disclosure {
|
|
67
74
|
font-size: 12px;
|
|
68
|
-
color: var(--folio-agent-muted,
|
|
75
|
+
color: var(--folio-agent-muted, color-mix(in srgb, CanvasText 55%, Canvas));
|
|
69
76
|
padding: 0 0 4px;
|
|
70
77
|
}
|
|
71
78
|
.disclosure a {
|
|
@@ -73,11 +80,13 @@ export const WIDGET_STYLES = `
|
|
|
73
80
|
}
|
|
74
81
|
form {
|
|
75
82
|
display: flex;
|
|
76
|
-
border-top: 1px solid
|
|
83
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 16%, Canvas);
|
|
77
84
|
}
|
|
78
85
|
input {
|
|
79
86
|
flex: 1;
|
|
80
87
|
border: none;
|
|
88
|
+
background: transparent;
|
|
89
|
+
color: inherit;
|
|
81
90
|
padding: 10px;
|
|
82
91
|
font-size: 14px;
|
|
83
92
|
}
|
|
@@ -89,7 +98,7 @@ export const WIDGET_STYLES = `
|
|
|
89
98
|
background: none;
|
|
90
99
|
padding: 0 14px;
|
|
91
100
|
cursor: pointer;
|
|
92
|
-
color: var(--folio-agent-accent,
|
|
101
|
+
color: var(--folio-agent-accent, CanvasText);
|
|
93
102
|
font-weight: 600;
|
|
94
103
|
}
|
|
95
104
|
`;
|
package/dist/widget-element.js
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
import { WIDGET_STYLES } from "./styles.js";
|
|
2
|
-
const
|
|
2
|
+
const WIDGET_TEXT = {
|
|
3
|
+
ja: {
|
|
4
|
+
toggleAriaLabel: "チャットを開く",
|
|
5
|
+
inputPlaceholder: "メッセージを入力",
|
|
6
|
+
submitLabel: "送信",
|
|
7
|
+
disclosureText: "入力内容は品質改善のため記録されます。",
|
|
8
|
+
policyLinkText: "利用データの扱いについて",
|
|
9
|
+
configErrorText: "設定エラー: endpoint属性が指定されていません。",
|
|
10
|
+
answerFallbackText: "回答を取得できませんでした。しばらくしてから再度お試しください。",
|
|
11
|
+
networkErrorText: "通信エラーが発生しました。しばらくしてから再度お試しください。",
|
|
12
|
+
},
|
|
13
|
+
en: {
|
|
14
|
+
toggleAriaLabel: "Open chat",
|
|
15
|
+
inputPlaceholder: "Type a message",
|
|
16
|
+
submitLabel: "Send",
|
|
17
|
+
disclosureText: "Your input is logged for quality improvement.",
|
|
18
|
+
policyLinkText: "About data usage",
|
|
19
|
+
configErrorText: "Configuration error: the endpoint attribute is not set.",
|
|
20
|
+
answerFallbackText: "Couldn't get an answer. Please try again later.",
|
|
21
|
+
networkErrorText: "A network error occurred. Please try again later.",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
function resolveLanguage(value) {
|
|
25
|
+
return value === "en" ? "en" : "ja";
|
|
26
|
+
}
|
|
3
27
|
export class FolioAgentWidgetElement extends HTMLElement {
|
|
4
28
|
static tagName = "folio-agent-widget";
|
|
5
29
|
#open = false;
|
|
@@ -8,7 +32,9 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
8
32
|
#panelEl;
|
|
9
33
|
#messagesEl;
|
|
10
34
|
#inputEl;
|
|
35
|
+
#text = WIDGET_TEXT.ja;
|
|
11
36
|
connectedCallback() {
|
|
37
|
+
this.#text = WIDGET_TEXT[resolveLanguage(this.getAttribute("lang"))];
|
|
12
38
|
const root = this.attachShadow({ mode: "open" });
|
|
13
39
|
const style = document.createElement("style");
|
|
14
40
|
style.textContent = WIDGET_STYLES;
|
|
@@ -16,7 +42,7 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
16
42
|
const toggle = document.createElement("button");
|
|
17
43
|
toggle.className = "toggle";
|
|
18
44
|
toggle.type = "button";
|
|
19
|
-
toggle.setAttribute("aria-label",
|
|
45
|
+
toggle.setAttribute("aria-label", this.#text.toggleAriaLabel);
|
|
20
46
|
toggle.textContent = "💬";
|
|
21
47
|
toggle.addEventListener("click", () => this.#togglePanel());
|
|
22
48
|
root.appendChild(toggle);
|
|
@@ -29,11 +55,11 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
29
55
|
const form = document.createElement("form");
|
|
30
56
|
const input = document.createElement("input");
|
|
31
57
|
input.type = "text";
|
|
32
|
-
input.placeholder =
|
|
58
|
+
input.placeholder = this.#text.inputPlaceholder;
|
|
33
59
|
input.autocomplete = "off";
|
|
34
60
|
const submit = document.createElement("button");
|
|
35
61
|
submit.type = "submit";
|
|
36
|
-
submit.textContent =
|
|
62
|
+
submit.textContent = this.#text.submitLabel;
|
|
37
63
|
form.appendChild(input);
|
|
38
64
|
form.appendChild(submit);
|
|
39
65
|
form.addEventListener("submit", (event) => {
|
|
@@ -66,14 +92,14 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
66
92
|
return;
|
|
67
93
|
const disclosure = document.createElement("div");
|
|
68
94
|
disclosure.className = "disclosure";
|
|
69
|
-
disclosure.append(`${
|
|
95
|
+
disclosure.append(`${this.#text.disclosureText} `);
|
|
70
96
|
const policyHref = this.getAttribute("policy-href");
|
|
71
97
|
if (policyHref) {
|
|
72
98
|
const link = document.createElement("a");
|
|
73
99
|
link.href = policyHref;
|
|
74
100
|
link.target = "_blank";
|
|
75
101
|
link.rel = "noopener noreferrer";
|
|
76
|
-
link.textContent =
|
|
102
|
+
link.textContent = this.#text.policyLinkText;
|
|
77
103
|
disclosure.appendChild(link);
|
|
78
104
|
}
|
|
79
105
|
this.#messagesEl.appendChild(disclosure);
|
|
@@ -85,7 +111,7 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
85
111
|
this.#appendMessage({ role: "user", text });
|
|
86
112
|
const endpoint = this.getAttribute("endpoint");
|
|
87
113
|
if (!endpoint) {
|
|
88
|
-
this.#appendMessage({ role: "assistant", text:
|
|
114
|
+
this.#appendMessage({ role: "assistant", text: this.#text.configErrorText });
|
|
89
115
|
return;
|
|
90
116
|
}
|
|
91
117
|
try {
|
|
@@ -97,13 +123,13 @@ export class FolioAgentWidgetElement extends HTMLElement {
|
|
|
97
123
|
const body = (await response.json());
|
|
98
124
|
this.#appendMessage({
|
|
99
125
|
role: "assistant",
|
|
100
|
-
text: body.answer ??
|
|
126
|
+
text: body.answer ?? this.#text.answerFallbackText,
|
|
101
127
|
});
|
|
102
128
|
}
|
|
103
129
|
catch {
|
|
104
130
|
this.#appendMessage({
|
|
105
131
|
role: "assistant",
|
|
106
|
-
text:
|
|
132
|
+
text: this.#text.networkErrorText,
|
|
107
133
|
});
|
|
108
134
|
}
|
|
109
135
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folio-agent/widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Framework-agnostic reception chat widget (silent until clicked)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "tsc -b"
|
|
31
|
+
"build": "tsc -b",
|
|
32
|
+
"prepublishOnly": "tsc -b --force"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"happy-dom": "^20.10.6"
|