@upstep/js 0.8.0 → 0.10.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 +20 -2
- package/dist/{api-ZTIiZxlg.mjs → api-CROQwfAo.mjs} +23 -9
- package/dist/api-j3GMTEE7.js +1 -0
- package/dist/api.d.ts +11 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/index.cjs +65 -51
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +247 -198
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +14 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +493 -471
- package/dist/support.cjs +1 -1
- package/dist/support.d.ts +10 -1
- package/dist/support.d.ts.map +1 -1
- package/dist/support.js +50 -33
- package/dist/theme.cjs +1 -0
- package/dist/theme.d.ts +76 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +177 -0
- package/dist/upstep.global.js +65 -51
- package/dist/widget.d.ts +12 -1
- package/dist/widget.d.ts.map +1 -1
- package/package.json +14 -9
- package/dist/api-BdOCiCLM.js +0 -1
package/dist/support.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(a,t){if(t===null)return[];const e=a.filter(n=>n.role!=="SYSTEM"),s=e.findIndex(n=>n.id===t);return s<0?[]:e.slice(s+1).filter(n=>n.role!=="CUSTOMER")}function d(a,t=120){const e=a.replace(/\s+/g," ").trim();return e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e}class c extends Error{constructor(t,e){super(t),this.status=e}}function h(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const t=Math.floor(Math.random()*16);return(a==="x"?t:t&3|8).toString(16)})}class y{constructor(t,e,s=fetch){this.storage=e,this.transport=s,this.token=null,this.session=null,this.epoch=0,this.baseUrl=(t.baseUrl||"https://upstep.dev").replace(/\/$/,""),this.key=t.apiKey,this.identityToken=t.supportIdentityToken,this.storageKey=`upstep:support:${this.baseUrl}:${this.key}`,this.seenKey=`upstep:support-seen:${this.baseUrl}:${this.key}`,this.soundKey=`upstep:support-sound:${this.baseUrl}:${this.key}`}async identify(t){var e;t!==this.identityToken&&(this.epoch++,this.identityToken=t,this.token=null,this.session=null,await((e=this.storage)==null?void 0:e.removeItem(this.storageKey).catch(()=>{})))}async request(t,e){var i;const s=new AbortController,n=setTimeout(()=>s.abort(),2e4);try{const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(a,t){if(t===null)return[];const e=a.filter(n=>n.role!=="SYSTEM"),s=e.findIndex(n=>n.id===t);return s<0?[]:e.slice(s+1).filter(n=>n.role!=="CUSTOMER")}function d(a,t=120){const e=a.replace(/\s+/g," ").trim();return e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e}class c extends Error{constructor(t,e){super(t),this.status=e}}function h(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const t=Math.floor(Math.random()*16);return(a==="x"?t:t&3|8).toString(16)})}class y{constructor(t,e,s=fetch){this.storage=e,this.transport=s,this.token=null,this.session=null,this.epoch=0,this.baseUrl=(t.baseUrl||"https://upstep.dev").replace(/\/$/,""),this.key=t.apiKey,this.identityToken=t.supportIdentityToken,this.storageKey=`upstep:support:${this.baseUrl}:${this.key}`,this.seenKey=`upstep:support-seen:${this.baseUrl}:${this.key}`,this.soundKey=`upstep:support-sound:${this.baseUrl}:${this.key}`}async identify(t){var e;t!==this.identityToken&&(this.epoch++,this.identityToken=t,this.token=null,this.session=null,await((e=this.storage)==null?void 0:e.removeItem(this.storageKey).catch(()=>{})))}async request(t,e){var i;const s=new AbortController,n=setTimeout(()=>s.abort(),2e4);try{const r=await this.transport(`${this.baseUrl}/api/sdk/support${t}`,{method:e===void 0?"GET":"POST",headers:{"Content-Type":"application/json","x-api-key":this.key,...this.token?{Authorization:`Bearer ${this.token}`}:{}},...e===void 0?{}:{body:JSON.stringify(e)},credentials:"omit",redirect:"error",signal:s.signal}),o=await r.json();if(!r.ok)throw r.status===401&&t&&(this.token=null,await((i=this.storage)==null?void 0:i.removeItem(this.storageKey).catch(()=>{}))),new c(typeof o.error=="string"?o.error:"Could not connect to support.",r.status);return o}finally{clearTimeout(n)}}async configuration(){try{return await this.request("")}catch(t){if(t instanceof c&&[402,404].includes(t.status))return null;throw t}}async ensureSession(){if(!this.token){if(!this.session){const t=this.epoch,e=this.identityToken,s=(async()=>{var i,r;if(!e)try{const o=await((i=this.storage)==null?void 0:i.getItem(this.storageKey));if(o&&t===this.epoch){this.token=o;return}}catch{}if(t!==this.epoch)throw new Error("Customer identity changed.");const n=await this.request("",e?{identityToken:e}:{});if(t!==this.epoch)throw new Error("Customer identity changed.");this.token=n.token,e||await((r=this.storage)==null?void 0:r.setItem(this.storageKey,n.token).catch(()=>{}))})();this.session=s,s.finally(()=>{this.session===s&&(this.session=null)}).catch(()=>{})}await this.session}}async conversations(){return await this.ensureSession(),(await this.request("/conversations")).conversations}async startConversation(){return await this.ensureSession(),this.request("/conversations",{})}async conversation(t){return await this.ensureSession(),this.request(`/conversations/${encodeURIComponent(t)}`)}async send(t,e,s=h()){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"message",content:e,clientMessageId:s})}async details(t,e){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"details",...e,clientMessageId:e.clientMessageId||h()})}async idea(t,e,s){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"idea",promptId:e,...s})}static activeIdeaPrompt(t){var s,n;const e=t.activeWidgetMessageId?(n=(s=t.messages.find(i=>i.id===t.activeWidgetMessageId))==null?void 0:s.metadata)==null?void 0:n.ideaPrompt:void 0;return e?t.messages.some(i=>{var r;return((r=i.metadata)==null?void 0:r.ideaPromptId)===e.id})?null:e:null}async handoff(t,e,s){await this.ensureSession(),await this.request(`/conversations/${encodeURIComponent(t)}`,{action:"handoff",name:e,email:s})}async hasSession(){var t;if(this.token||this.identityToken)return!0;try{return!!await((t=this.storage)==null?void 0:t.getItem(this.storageKey))}catch{return!1}}async seenId(t){var e;try{const s=JSON.parse(await((e=this.storage)==null?void 0:e.getItem(this.seenKey))||"null");return(s==null?void 0:s.chat)===t?s.id:null}catch{return null}}async markSeen(t){var n;const e=t.messages.filter(i=>i.role!=="SYSTEM").at(-1);if(!e)return;const s={chat:t.id,id:e.id};await((n=this.storage)==null?void 0:n.setItem(this.seenKey,JSON.stringify(s)).catch(()=>{}))}async unread(){var u;const t={count:0,chatId:null};if(!await this.hasSession())return t;const e=(await this.conversations())[0];if(!e)return t;const s=await this.conversation(e.id);if(!s.messages.filter(p=>p.role!=="SYSTEM").at(-1))return{count:0,chatId:s.id};let i=null;try{i=JSON.parse(await((u=this.storage)==null?void 0:u.getItem(this.seenKey))||"null")}catch{i=null}if((i==null?void 0:i.chat)!==s.id)return await this.markSeen(s),{count:0,chatId:s.id};const r=l(s.messages,i.id),o=r.at(-1);return{count:r.length,chatId:s.id,...o?{latest:{author:o.role==="ASSISTANT"?"AI":o.authorName,role:o.role,preview:d(o.content)}}:{}}}async soundEnabled(){var t;try{return await((t=this.storage)==null?void 0:t.getItem(this.soundKey))!=="off"}catch{return!0}}async setSoundEnabled(t){var e;await((e=this.storage)==null?void 0:e.setItem(this.soundKey,t?"on":"off").catch(()=>{}))}}exports.SupportApiError=c;exports.SupportClient=y;exports.supportMessageId=h;exports.supportPreview=d;exports.unreadSupportMessages=l;
|
package/dist/support.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportConfiguration, SupportConversation, UpstepConfig } from '@upstep/types';
|
|
1
|
+
import { IdeaPrompt, SupportConfiguration, SupportConversation, UpstepConfig } from '@upstep/types';
|
|
2
2
|
export interface SupportStorage {
|
|
3
3
|
getItem(key: string): Promise<string | null>;
|
|
4
4
|
setItem(key: string, value: string): Promise<void>;
|
|
@@ -60,6 +60,15 @@ export declare class SupportClient {
|
|
|
60
60
|
reference?: string;
|
|
61
61
|
clientMessageId?: string;
|
|
62
62
|
}): Promise<void>;
|
|
63
|
+
/** Answers an idea prompt: vote for one of its matches, or post a new idea. */
|
|
64
|
+
idea(id: string, promptId: string, answer: {
|
|
65
|
+
feedbackId: string;
|
|
66
|
+
} | {
|
|
67
|
+
title: string;
|
|
68
|
+
details?: string;
|
|
69
|
+
}): Promise<void>;
|
|
70
|
+
/** The open idea prompt: on the latest AI reply and not yet answered. */
|
|
71
|
+
static activeIdeaPrompt(chat: SupportConversation): IdeaPrompt | null;
|
|
63
72
|
handoff(id: string, name: string, email: string): Promise<void>;
|
|
64
73
|
/** True when this customer already has a support session, so checking for replies creates nothing new. */
|
|
65
74
|
hasSession(): Promise<boolean>;
|
package/dist/support.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../src/support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AACD,qEAAqE;AACrE,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAA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;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B;IASH,+EAA+E;IACzE,IAAI,CACR,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAStE,yEAAyE;IACzE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,mBAAmB,GAAG,UAAU,GAAG,IAAI;IAU/D,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAQrD,0GAA0G;IACpG,UAAU;IAQhB,qFAAqF;IAC/E,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUpD,yEAAyE;IACnE,QAAQ,CAAC,YAAY,EAAE,mBAAmB;IAUhD;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAkCvC,YAAY;IAOZ,eAAe,CAAC,OAAO,EAAE,OAAO;CAKvC"}
|
package/dist/support.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
function d(
|
|
1
|
+
function d(o, t) {
|
|
2
2
|
if (t === null) return [];
|
|
3
|
-
const e =
|
|
3
|
+
const e = o.filter((n) => n.role !== "SYSTEM"), s = e.findIndex((n) => n.id === t);
|
|
4
4
|
return s < 0 ? [] : e.slice(s + 1).filter((n) => n.role !== "CUSTOMER");
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
const e =
|
|
6
|
+
function p(o, t = 120) {
|
|
7
|
+
const e = o.replace(/\s+/g, " ").trim();
|
|
8
8
|
return e.length > t ? `${e.slice(0, t - 1).trimEnd()}…` : e;
|
|
9
9
|
}
|
|
10
|
-
class
|
|
10
|
+
class h extends Error {
|
|
11
11
|
constructor(t, e) {
|
|
12
12
|
super(t), this.status = e;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
function u() {
|
|
16
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (
|
|
16
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (o) => {
|
|
17
17
|
const t = Math.floor(Math.random() * 16);
|
|
18
|
-
return (
|
|
18
|
+
return (o === "x" ? t : t & 3 | 8).toString(16);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class y {
|
|
22
22
|
constructor(t, e, s = fetch) {
|
|
23
23
|
this.storage = e, this.transport = s, this.token = null, this.session = null, this.epoch = 0, this.baseUrl = (t.baseUrl || "https://upstep.dev").replace(/\/$/, ""), this.key = t.apiKey, this.identityToken = t.supportIdentityToken, this.storageKey = `upstep:support:${this.baseUrl}:${this.key}`, this.seenKey = `upstep:support-seen:${this.baseUrl}:${this.key}`, this.soundKey = `upstep:support-sound:${this.baseUrl}:${this.key}`;
|
|
24
24
|
}
|
|
@@ -31,7 +31,7 @@ class p {
|
|
|
31
31
|
var i;
|
|
32
32
|
const s = new AbortController(), n = setTimeout(() => s.abort(), 2e4);
|
|
33
33
|
try {
|
|
34
|
-
const
|
|
34
|
+
const r = await this.transport(`${this.baseUrl}/api/sdk/support${t}`, {
|
|
35
35
|
method: e === void 0 ? "GET" : "POST",
|
|
36
36
|
headers: {
|
|
37
37
|
"Content-Type": "application/json",
|
|
@@ -42,14 +42,14 @@ class p {
|
|
|
42
42
|
credentials: "omit",
|
|
43
43
|
redirect: "error",
|
|
44
44
|
signal: s.signal
|
|
45
|
-
}),
|
|
46
|
-
if (!
|
|
47
|
-
throw
|
|
48
|
-
}))), new
|
|
49
|
-
typeof
|
|
50
|
-
|
|
45
|
+
}), a = await r.json();
|
|
46
|
+
if (!r.ok)
|
|
47
|
+
throw r.status === 401 && t && (this.token = null, await ((i = this.storage) == null ? void 0 : i.removeItem(this.storageKey).catch(() => {
|
|
48
|
+
}))), new h(
|
|
49
|
+
typeof a.error == "string" ? a.error : "Could not connect to support.",
|
|
50
|
+
r.status
|
|
51
51
|
);
|
|
52
|
-
return
|
|
52
|
+
return a;
|
|
53
53
|
} finally {
|
|
54
54
|
clearTimeout(n);
|
|
55
55
|
}
|
|
@@ -58,7 +58,7 @@ class p {
|
|
|
58
58
|
try {
|
|
59
59
|
return await this.request("");
|
|
60
60
|
} catch (t) {
|
|
61
|
-
if (t instanceof
|
|
61
|
+
if (t instanceof h && [402, 404].includes(t.status))
|
|
62
62
|
return null;
|
|
63
63
|
throw t;
|
|
64
64
|
}
|
|
@@ -67,12 +67,12 @@ class p {
|
|
|
67
67
|
if (!this.token) {
|
|
68
68
|
if (!this.session) {
|
|
69
69
|
const t = this.epoch, e = this.identityToken, s = (async () => {
|
|
70
|
-
var i,
|
|
70
|
+
var i, r;
|
|
71
71
|
if (!e)
|
|
72
72
|
try {
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
this.token =
|
|
73
|
+
const a = await ((i = this.storage) == null ? void 0 : i.getItem(this.storageKey));
|
|
74
|
+
if (a && t === this.epoch) {
|
|
75
|
+
this.token = a;
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
} catch {
|
|
@@ -83,7 +83,7 @@ class p {
|
|
|
83
83
|
e ? { identityToken: e } : {}
|
|
84
84
|
);
|
|
85
85
|
if (t !== this.epoch) throw new Error("Customer identity changed.");
|
|
86
|
-
this.token = n.token, e || await ((
|
|
86
|
+
this.token = n.token, e || await ((r = this.storage) == null ? void 0 : r.setItem(this.storageKey, n.token).catch(() => {
|
|
87
87
|
}));
|
|
88
88
|
})();
|
|
89
89
|
this.session = s, s.finally(() => {
|
|
@@ -121,6 +121,23 @@ class p {
|
|
|
121
121
|
clientMessageId: e.clientMessageId || u()
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
|
+
/** Answers an idea prompt: vote for one of its matches, or post a new idea. */
|
|
125
|
+
async idea(t, e, s) {
|
|
126
|
+
await this.ensureSession(), await this.request(`/conversations/${encodeURIComponent(t)}`, {
|
|
127
|
+
action: "idea",
|
|
128
|
+
promptId: e,
|
|
129
|
+
...s
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** The open idea prompt: on the latest AI reply and not yet answered. */
|
|
133
|
+
static activeIdeaPrompt(t) {
|
|
134
|
+
var s, n;
|
|
135
|
+
const e = t.activeWidgetMessageId ? (n = (s = t.messages.find((i) => i.id === t.activeWidgetMessageId)) == null ? void 0 : s.metadata) == null ? void 0 : n.ideaPrompt : void 0;
|
|
136
|
+
return e ? t.messages.some((i) => {
|
|
137
|
+
var r;
|
|
138
|
+
return ((r = i.metadata) == null ? void 0 : r.ideaPromptId) === e.id;
|
|
139
|
+
}) ? null : e : null;
|
|
140
|
+
}
|
|
124
141
|
async handoff(t, e, s) {
|
|
125
142
|
await this.ensureSession(), await this.request(`/conversations/${encodeURIComponent(t)}`, {
|
|
126
143
|
action: "handoff",
|
|
@@ -164,7 +181,7 @@ class p {
|
|
|
164
181
|
* no saved record counts as read, so returning customers never see a stale count.
|
|
165
182
|
*/
|
|
166
183
|
async unread() {
|
|
167
|
-
var
|
|
184
|
+
var c;
|
|
168
185
|
const t = { count: 0, chatId: null };
|
|
169
186
|
if (!await this.hasSession()) return t;
|
|
170
187
|
const e = (await this.conversations())[0];
|
|
@@ -173,21 +190,21 @@ class p {
|
|
|
173
190
|
if (!s.messages.filter((l) => l.role !== "SYSTEM").at(-1)) return { count: 0, chatId: s.id };
|
|
174
191
|
let i = null;
|
|
175
192
|
try {
|
|
176
|
-
i = JSON.parse(await ((
|
|
193
|
+
i = JSON.parse(await ((c = this.storage) == null ? void 0 : c.getItem(this.seenKey)) || "null");
|
|
177
194
|
} catch {
|
|
178
195
|
i = null;
|
|
179
196
|
}
|
|
180
197
|
if ((i == null ? void 0 : i.chat) !== s.id)
|
|
181
198
|
return await this.markSeen(s), { count: 0, chatId: s.id };
|
|
182
|
-
const
|
|
199
|
+
const r = d(s.messages, i.id), a = r.at(-1);
|
|
183
200
|
return {
|
|
184
|
-
count:
|
|
201
|
+
count: r.length,
|
|
185
202
|
chatId: s.id,
|
|
186
|
-
...
|
|
203
|
+
...a ? {
|
|
187
204
|
latest: {
|
|
188
|
-
author:
|
|
189
|
-
role:
|
|
190
|
-
preview:
|
|
205
|
+
author: a.role === "ASSISTANT" ? "AI" : a.authorName,
|
|
206
|
+
role: a.role,
|
|
207
|
+
preview: p(a.content)
|
|
191
208
|
}
|
|
192
209
|
} : {}
|
|
193
210
|
};
|
|
@@ -207,9 +224,9 @@ class p {
|
|
|
207
224
|
}
|
|
208
225
|
}
|
|
209
226
|
export {
|
|
210
|
-
|
|
211
|
-
|
|
227
|
+
h as SupportApiError,
|
|
228
|
+
y as SupportClient,
|
|
212
229
|
u as supportMessageId,
|
|
213
|
-
|
|
230
|
+
p as supportPreview,
|
|
214
231
|
d as unreadSupportMessages
|
|
215
232
|
};
|
package/dist/theme.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="#C9481F",F="#FF7A50",L=g;function R(t){return t==="dark"?F:g}const A=12,$=32,U=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,d="(\\d{1,3}(?:\\.\\d+)?)",M="(\\d*\\.?\\d+%?)",H=new RegExp(`^rgba?\\(\\s*${d}\\s*(?:,\\s*${d}\\s*,\\s*${d}\\s*(?:,\\s*${M}\\s*)?|\\s+${d}\\s+${d}\\s*(?:\\/\\s*${M}\\s*)?)\\)$`,"i");function i(t){if(typeof t!="string"||t.length>64)return null;const r=t.trim();if(U.test(r)){let u=r.slice(1);u.length<=4&&(u=u.split("").map(f=>f+f).join(""));const b=f=>parseInt(u.slice(f,f+2),16);return[b(0),b(2),b(4),u.length===8?Math.round(b(6)/255*1e3)/1e3:1]}const e=H.exec(r);if(!e)return null;const[n,o,c,a]=[e[1],e[2]??e[5],e[3]??e[6],e[4]??e[7]],s=[n,o,c].map(Number);if(s.some(u=>!(u>=0&&u<=255)))return null;let l=1;return a!==void 0&&(l=a.endsWith("%")?Number(a.slice(0,-1))/100:Number(a),!(l>=0&&l<=1))?null:[s[0],s[1],s[2],l]}function D(t){return i(t)!==null}function T([t,r,e,n]){const o=c=>Math.round(Math.min(255,Math.max(0,c))).toString(16).padStart(2,"0");return`#${o(t)}${o(r)}${o(e)}${n<1?o(n*255):""}`}function N(t,r,e){const n=i(t),o=i(r);if(!n||!o)return null;const c=Math.min(1,Math.max(0,e));return T([n[0]+(o[0]-n[0])*c,n[1]+(o[1]-n[1])*c,n[2]+(o[2]-n[2])*c,n[3]+(o[3]-n[3])*c])}function p(t,r){const e=i(t);return e?T([e[0],e[1],e[2],e[3]*r]):null}function S([t,r,e]){const n=o=>{const c=o/255;return c<=.03928?c/12.92:((c+.055)/1.055)**2.4};return .2126*n(t)+.7152*n(r)+.0722*n(e)}function x(t,r){const e=i(t),n=i(r);if(!e||!n)return null;const[o,c]=[S(e),S(n)].sort((a,s)=>s-a);return(o+.05)/(c+.05)}const m="#ffffff",E="#1a1915";function v(t){const r=x(t,m);return r===null||r>=3?m:(x(t,E)??0)>r?E:m}function h(t){const r=typeof t=="number"?t:Number(t);return t==null||t===""||!Number.isFinite(r)?A:Math.round(Math.min($,Math.max(0,r)))}function k(t,r){return Math.round(t*r/A)}const y=["background","surface","border","text","textMuted","accentText"];function C(t,r){const e={};if(!t)return e;for(const n of[t,t[r]])if(n)for(const o of y){const c=n[o];typeof c=="string"&&c.trim()&&(e[o]=c.trim())}return e}const I={bg:"#ffffff",bgSoft:"#f5f5f5",bgHover:"#ededed",text:"#1a1915",textSoft:"#56544d",textFaint:"#9b9890",border:"#e8e6df",overlay:"rgba(26,25,21,.45)"},O={bg:"#000000",bgSoft:"#171717",bgHover:"#262626",text:"#f5f4f0",textSoft:"#b4b1a8",textFaint:"#7d7a72",border:"#33312c",overlay:"rgba(0,0,0,.6)"};function _(t,r,e){return N(t,r,e)??`color-mix(in srgb, ${t} ${Math.round((1-e)*100)}%, ${r})`}function P(t){var s;const r=t.mode==="dark"?O:I,e=C(t.colors,t.mode),n=((s=t.accentColor)==null?void 0:s.trim())||R(t.mode),o=e.background??r.bg,c=e.text??r.text,a=e.surface??r.bgSoft;return{dark:t.mode==="dark",bg:o,bgSoft:a,bgHover:e.surface||e.text?_(a,c,.06):r.bgHover,text:c,textSoft:e.textMuted??r.textSoft,textFaint:e.textMuted||e.background?_(e.textMuted??r.textSoft,o,.4):r.textFaint,border:e.border??r.border,overlay:r.overlay,accent:n,accentText:e.accentText??v(n),accentTint:p(n,.1)??`color-mix(in srgb, ${n} 10%, transparent)`,radius:h(t.radius)}}function G(t){var o;const r=C(t.colors,t.mode),e={},n={background:"bg",surface:"surface",border:"border",text:"text",textMuted:"muted",accentText:"accentText"};for(const c of y){const a=r[c];D(a)&&(e[n[c]]=a)}return t.radius!==void 0&&(e.radius=String(h(t.radius))),(o=t.fontFamily)!=null&&o.trim()&&(e.font=t.fontFamily.trim()),e}exports.DEFAULT_ACCENT=L;exports.DEFAULT_ACCENT_DARK=F;exports.DEFAULT_ACCENT_LIGHT=g;exports.DEFAULT_RADIUS=A;exports.MAX_RADIUS=$;exports.buildWidgetPalette=P;exports.clampRadius=h;exports.contrastRatio=x;exports.defaultAccent=R;exports.formatHex=T;exports.isSupportedColor=D;exports.mixColors=N;exports.parseColor=i;exports.readableTextOn=v;exports.resolveColorOverrides=C;exports.scaleRadius=k;exports.supportThemeParams=G;exports.withAlpha=p;
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { UpstepColorOverrides, UpstepThemeColors } from '@upstep/types';
|
|
2
|
+
/** Brand orange for light panels; white text reads on it. */
|
|
3
|
+
export declare const DEFAULT_ACCENT_LIGHT = "#C9481F";
|
|
4
|
+
/** Brighter brand orange for dark panels; dark text reads on it. */
|
|
5
|
+
export declare const DEFAULT_ACCENT_DARK = "#FF7A50";
|
|
6
|
+
/** The light-mode default, kept for callers that need a single color. */
|
|
7
|
+
export declare const DEFAULT_ACCENT = "#C9481F";
|
|
8
|
+
/** The accent to use: the host's own, or the brand default for the mode. */
|
|
9
|
+
export declare function defaultAccent(mode: "light" | "dark"): string;
|
|
10
|
+
/** Base corner radius in px. Every other corner in the widgets scales from it. */
|
|
11
|
+
export declare const DEFAULT_RADIUS = 12;
|
|
12
|
+
export declare const MAX_RADIUS = 32;
|
|
13
|
+
/** Red, green, blue in 0–255 and alpha in 0–1. */
|
|
14
|
+
export type Rgba = [number, number, number, number];
|
|
15
|
+
/** Parses hex (#rgb, #rgba, #rrggbb, #rrggbbaa) and rgb()/rgba() colors. Anything else is null. */
|
|
16
|
+
export declare function parseColor(input: unknown): Rgba | null;
|
|
17
|
+
/** Whether a value is a hex or rgb color, the only formats every SDK and the support chat accept. */
|
|
18
|
+
export declare function isSupportedColor(input: unknown): input is string;
|
|
19
|
+
export declare function formatHex([r, g, b, a]: Rgba): string;
|
|
20
|
+
/** Blends `amount` (0–1) of `toward` into `color`. Null if either color can't be parsed. */
|
|
21
|
+
export declare function mixColors(color: string, toward: string, amount: number): string | null;
|
|
22
|
+
/** The color at the given opacity. Null if it can't be parsed. */
|
|
23
|
+
export declare function withAlpha(color: string, alpha: number): string | null;
|
|
24
|
+
/** WCAG contrast ratio between two opaque colors (1–21). Null if either can't be parsed. */
|
|
25
|
+
export declare function contrastRatio(a: string, b: string): number | null;
|
|
26
|
+
/**
|
|
27
|
+
* Text color for a filled accent surface. White while it keeps at least 3:1
|
|
28
|
+
* contrast (WCAG's bar for bold UI text), otherwise whichever of white or
|
|
29
|
+
* near-black reads better. Unparseable accents get white, as before.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readableTextOn(background: string): string;
|
|
32
|
+
/** Clamps a radius to 0–32 px. Missing or invalid values give the default. */
|
|
33
|
+
export declare function clampRadius(value: unknown): number;
|
|
34
|
+
/** Scales one of the widget's built-in radii (designed for the 12 px default) to the chosen radius. */
|
|
35
|
+
export declare function scaleRadius(designed: number, radius: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Flattens `colors` for one mode: top-level keys, then that mode's keys on top.
|
|
38
|
+
* Empty or non-string values are dropped so they fall back to the defaults.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveColorOverrides(colors: UpstepColorOverrides | undefined, mode: "light" | "dark"): Partial<UpstepThemeColors>;
|
|
41
|
+
/** The web widget's palette. */
|
|
42
|
+
export interface WidgetPalette {
|
|
43
|
+
dark: boolean;
|
|
44
|
+
bg: string;
|
|
45
|
+
bgSoft: string;
|
|
46
|
+
bgHover: string;
|
|
47
|
+
text: string;
|
|
48
|
+
textSoft: string;
|
|
49
|
+
textFaint: string;
|
|
50
|
+
border: string;
|
|
51
|
+
overlay: string;
|
|
52
|
+
accent: string;
|
|
53
|
+
accentText: string;
|
|
54
|
+
/** Accent at low opacity, for selected/voted fills. */
|
|
55
|
+
accentTint: string;
|
|
56
|
+
radius: number;
|
|
57
|
+
}
|
|
58
|
+
/** Builds the web widget palette: defaults for the mode, then any overrides. */
|
|
59
|
+
export declare function buildWidgetPalette(options: {
|
|
60
|
+
mode: "light" | "dark";
|
|
61
|
+
accentColor?: string | undefined;
|
|
62
|
+
colors?: UpstepColorOverrides | undefined;
|
|
63
|
+
radius?: number | undefined;
|
|
64
|
+
}): WidgetPalette;
|
|
65
|
+
/**
|
|
66
|
+
* Query parameters for the hosted support chat. Only hex/rgb colors are
|
|
67
|
+
* sent, and only the keys that were overridden, so the chat keeps its own
|
|
68
|
+
* defaults for the rest.
|
|
69
|
+
*/
|
|
70
|
+
export declare function supportThemeParams(options: {
|
|
71
|
+
mode: "light" | "dark";
|
|
72
|
+
colors?: UpstepColorOverrides | undefined;
|
|
73
|
+
radius?: number | undefined;
|
|
74
|
+
fontFamily?: string | undefined;
|
|
75
|
+
}): Record<string, string>;
|
|
76
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE7E,6DAA6D;AAC7D,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAC9C,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,yEAAyE;AACzE,eAAO,MAAM,cAAc,YAAuB,CAAC;AAEnD,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAE5D;AACD,kFAAkF;AAClF,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B,kDAAkD;AAClD,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAWpD,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAmCtD;AAED,qGAAqG;AACrG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED,wBAAgB,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAMpD;AAED,4FAA4F;AAC5F,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAWf;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,KAAK,E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IAC1C,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,GAAG,aAAa,CA2BhB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBzB"}
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const M = "#C9481F", N = "#FF7A50", I = M;
|
|
2
|
+
function y(t) {
|
|
3
|
+
return t === "dark" ? N : M;
|
|
4
|
+
}
|
|
5
|
+
const C = 12, R = 32, _ = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i, d = "(\\d{1,3}(?:\\.\\d+)?)", m = "(\\d*\\.?\\d+%?)", k = new RegExp(
|
|
6
|
+
`^rgba?\\(\\s*${d}\\s*(?:,\\s*${d}\\s*,\\s*${d}\\s*(?:,\\s*${m}\\s*)?|\\s+${d}\\s+${d}\\s*(?:\\/\\s*${m}\\s*)?)\\)$`,
|
|
7
|
+
"i"
|
|
8
|
+
);
|
|
9
|
+
function f(t) {
|
|
10
|
+
if (typeof t != "string" || t.length > 64) return null;
|
|
11
|
+
const n = t.trim();
|
|
12
|
+
if (_.test(n)) {
|
|
13
|
+
let u = n.slice(1);
|
|
14
|
+
u.length <= 4 && (u = u.split("").map((i) => i + i).join(""));
|
|
15
|
+
const b = (i) => parseInt(u.slice(i, i + 2), 16);
|
|
16
|
+
return [
|
|
17
|
+
b(0),
|
|
18
|
+
b(2),
|
|
19
|
+
b(4),
|
|
20
|
+
u.length === 8 ? Math.round(b(6) / 255 * 1e3) / 1e3 : 1
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
const e = k.exec(n);
|
|
24
|
+
if (!e) return null;
|
|
25
|
+
const [r, o, c, s] = [
|
|
26
|
+
e[1],
|
|
27
|
+
e[2] ?? e[5],
|
|
28
|
+
e[3] ?? e[6],
|
|
29
|
+
e[4] ?? e[7]
|
|
30
|
+
], a = [r, o, c].map(Number);
|
|
31
|
+
if (a.some((u) => !(u >= 0 && u <= 255))) return null;
|
|
32
|
+
let l = 1;
|
|
33
|
+
return s !== void 0 && (l = s.endsWith("%") ? Number(s.slice(0, -1)) / 100 : Number(s), !(l >= 0 && l <= 1)) ? null : [a[0], a[1], a[2], l];
|
|
34
|
+
}
|
|
35
|
+
function v(t) {
|
|
36
|
+
return f(t) !== null;
|
|
37
|
+
}
|
|
38
|
+
function $([t, n, e, r]) {
|
|
39
|
+
const o = (c) => Math.round(Math.min(255, Math.max(0, c))).toString(16).padStart(2, "0");
|
|
40
|
+
return `#${o(t)}${o(n)}${o(e)}${r < 1 ? o(r * 255) : ""}`;
|
|
41
|
+
}
|
|
42
|
+
function H(t, n, e) {
|
|
43
|
+
const r = f(t), o = f(n);
|
|
44
|
+
if (!r || !o) return null;
|
|
45
|
+
const c = Math.min(1, Math.max(0, e));
|
|
46
|
+
return $([
|
|
47
|
+
r[0] + (o[0] - r[0]) * c,
|
|
48
|
+
r[1] + (o[1] - r[1]) * c,
|
|
49
|
+
r[2] + (o[2] - r[2]) * c,
|
|
50
|
+
r[3] + (o[3] - r[3]) * c
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
function D(t, n) {
|
|
54
|
+
const e = f(t);
|
|
55
|
+
return e ? $([e[0], e[1], e[2], e[3] * n]) : null;
|
|
56
|
+
}
|
|
57
|
+
function g([t, n, e]) {
|
|
58
|
+
const r = (o) => {
|
|
59
|
+
const c = o / 255;
|
|
60
|
+
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
61
|
+
};
|
|
62
|
+
return 0.2126 * r(t) + 0.7152 * r(n) + 0.0722 * r(e);
|
|
63
|
+
}
|
|
64
|
+
function h(t, n) {
|
|
65
|
+
const e = f(t), r = f(n);
|
|
66
|
+
if (!e || !r) return null;
|
|
67
|
+
const [o, c] = [g(e), g(r)].sort((s, a) => a - s);
|
|
68
|
+
return (o + 0.05) / (c + 0.05);
|
|
69
|
+
}
|
|
70
|
+
const x = "#ffffff", A = "#1a1915";
|
|
71
|
+
function L(t) {
|
|
72
|
+
const n = h(t, x);
|
|
73
|
+
return n === null || n >= 3 ? x : (h(t, A) ?? 0) > n ? A : x;
|
|
74
|
+
}
|
|
75
|
+
function S(t) {
|
|
76
|
+
const n = typeof t == "number" ? t : Number(t);
|
|
77
|
+
return t == null || t === "" || !Number.isFinite(n) ? C : Math.round(Math.min(R, Math.max(0, n)));
|
|
78
|
+
}
|
|
79
|
+
function O(t, n) {
|
|
80
|
+
return Math.round(t * n / C);
|
|
81
|
+
}
|
|
82
|
+
const F = [
|
|
83
|
+
"background",
|
|
84
|
+
"surface",
|
|
85
|
+
"border",
|
|
86
|
+
"text",
|
|
87
|
+
"textMuted",
|
|
88
|
+
"accentText"
|
|
89
|
+
];
|
|
90
|
+
function E(t, n) {
|
|
91
|
+
const e = {};
|
|
92
|
+
if (!t) return e;
|
|
93
|
+
for (const r of [t, t[n]])
|
|
94
|
+
if (r)
|
|
95
|
+
for (const o of F) {
|
|
96
|
+
const c = r[o];
|
|
97
|
+
typeof c == "string" && c.trim() && (e[o] = c.trim());
|
|
98
|
+
}
|
|
99
|
+
return e;
|
|
100
|
+
}
|
|
101
|
+
const p = {
|
|
102
|
+
bg: "#ffffff",
|
|
103
|
+
bgSoft: "#f5f5f5",
|
|
104
|
+
bgHover: "#ededed",
|
|
105
|
+
text: "#1a1915",
|
|
106
|
+
textSoft: "#56544d",
|
|
107
|
+
textFaint: "#9b9890",
|
|
108
|
+
border: "#e8e6df",
|
|
109
|
+
overlay: "rgba(26,25,21,.45)"
|
|
110
|
+
}, U = {
|
|
111
|
+
bg: "#000000",
|
|
112
|
+
bgSoft: "#171717",
|
|
113
|
+
bgHover: "#262626",
|
|
114
|
+
text: "#f5f4f0",
|
|
115
|
+
textSoft: "#b4b1a8",
|
|
116
|
+
textFaint: "#7d7a72",
|
|
117
|
+
border: "#33312c",
|
|
118
|
+
overlay: "rgba(0,0,0,.6)"
|
|
119
|
+
};
|
|
120
|
+
function T(t, n, e) {
|
|
121
|
+
return H(t, n, e) ?? `color-mix(in srgb, ${t} ${Math.round((1 - e) * 100)}%, ${n})`;
|
|
122
|
+
}
|
|
123
|
+
function G(t) {
|
|
124
|
+
var a;
|
|
125
|
+
const n = t.mode === "dark" ? U : p, e = E(t.colors, t.mode), r = ((a = t.accentColor) == null ? void 0 : a.trim()) || y(t.mode), o = e.background ?? n.bg, c = e.text ?? n.text, s = e.surface ?? n.bgSoft;
|
|
126
|
+
return {
|
|
127
|
+
dark: t.mode === "dark",
|
|
128
|
+
bg: o,
|
|
129
|
+
bgSoft: s,
|
|
130
|
+
bgHover: e.surface || e.text ? T(s, c, 0.06) : n.bgHover,
|
|
131
|
+
text: c,
|
|
132
|
+
textSoft: e.textMuted ?? n.textSoft,
|
|
133
|
+
textFaint: e.textMuted || e.background ? T(e.textMuted ?? n.textSoft, o, 0.4) : n.textFaint,
|
|
134
|
+
border: e.border ?? n.border,
|
|
135
|
+
overlay: n.overlay,
|
|
136
|
+
accent: r,
|
|
137
|
+
accentText: e.accentText ?? L(r),
|
|
138
|
+
accentTint: D(r, 0.1) ?? `color-mix(in srgb, ${r} 10%, transparent)`,
|
|
139
|
+
radius: S(t.radius)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function K(t) {
|
|
143
|
+
var o;
|
|
144
|
+
const n = E(t.colors, t.mode), e = {}, r = {
|
|
145
|
+
background: "bg",
|
|
146
|
+
surface: "surface",
|
|
147
|
+
border: "border",
|
|
148
|
+
text: "text",
|
|
149
|
+
textMuted: "muted",
|
|
150
|
+
accentText: "accentText"
|
|
151
|
+
};
|
|
152
|
+
for (const c of F) {
|
|
153
|
+
const s = n[c];
|
|
154
|
+
v(s) && (e[r[c]] = s);
|
|
155
|
+
}
|
|
156
|
+
return t.radius !== void 0 && (e.radius = String(S(t.radius))), (o = t.fontFamily) != null && o.trim() && (e.font = t.fontFamily.trim()), e;
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
I as DEFAULT_ACCENT,
|
|
160
|
+
N as DEFAULT_ACCENT_DARK,
|
|
161
|
+
M as DEFAULT_ACCENT_LIGHT,
|
|
162
|
+
C as DEFAULT_RADIUS,
|
|
163
|
+
R as MAX_RADIUS,
|
|
164
|
+
G as buildWidgetPalette,
|
|
165
|
+
S as clampRadius,
|
|
166
|
+
h as contrastRatio,
|
|
167
|
+
y as defaultAccent,
|
|
168
|
+
$ as formatHex,
|
|
169
|
+
v as isSupportedColor,
|
|
170
|
+
H as mixColors,
|
|
171
|
+
f as parseColor,
|
|
172
|
+
L as readableTextOn,
|
|
173
|
+
E as resolveColorOverrides,
|
|
174
|
+
O as scaleRadius,
|
|
175
|
+
K as supportThemeParams,
|
|
176
|
+
D as withAlpha
|
|
177
|
+
};
|