assistant-robot 0.0.2-gamma → 0.0.2

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/dist/type.d.ts CHANGED
@@ -11,9 +11,14 @@ export interface ILanguageModelConfig<T extends LanguageModel> extends ILanguage
11
11
  export interface IOperation {
12
12
  key: string;
13
13
  text: string;
14
- disable: boolean;
14
+ /**
15
+ * To mark that is this item disabled,
16
+ * we just add a `data-disabled` attribute to the menu item,
17
+ * user should implement the funtion
18
+ */
19
+ disabled: boolean;
15
20
  }
16
- export interface IOperationBoxBoxConfig {
21
+ export interface IOperationBoxConfig {
17
22
  hide?: boolean;
18
23
  perationBoxClassName?: string;
19
24
  operationList?: IOperation[];
@@ -25,6 +30,10 @@ export interface IModelConfig {
25
30
  idleActionName: string;
26
31
  helloContent: string;
27
32
  }
33
+ /**
34
+ * Configs for the scene of the assistant robot's 3d model.
35
+ * To see all default value's, look at MODEL_SCENE_CONFIG
36
+ */
28
37
  export interface IModelSceneConfig {
29
38
  backgroundColor: number;
30
39
  backgroundAlpha: number;
@@ -35,27 +44,42 @@ export interface IModelSceneConfig {
35
44
  position: [number, number, number];
36
45
  lookAt: [number, number, number];
37
46
  };
47
+ /**
48
+ * config of the ambient light in the scene.
49
+ * the light globally illuminates all objects in the scene equally.
50
+ */
38
51
  ambientLight: {
39
52
  color: number;
40
53
  intensity: number;
41
54
  };
55
+ /**
56
+ * config of the directional light in the scene.
57
+ * A light that gets emitted in a specific direction
58
+ */
42
59
  directionalLight: {
43
60
  color: number;
44
61
  intensity: number;
45
62
  position: [number, number, number];
46
63
  };
47
64
  }
65
+ /**
66
+ * config for the 3d render part.
67
+ */
48
68
  export type TRobotModelConfig = Partial<IModelSceneConfig> & {
49
69
  modelConfig?: Partial<IModelConfig>;
50
70
  modelUrl?: string;
51
71
  };
52
72
  export interface IUserDetectorConfig {
73
+ /**
74
+ * The path to where the files of the face detect model are located.
75
+ * If your user can not get the public one, the files can be download from there:https://github.com/ymrdf/assistant-robot/tree/main/example/public/face_detection
76
+ */
53
77
  solutionPath?: string;
54
78
  }
55
79
  export interface IAssistantRobotConfig<T extends LanguageModel> {
56
80
  className: string;
57
81
  languageModel: ILanguageModelConfig<T>;
58
- operationBox: IOperationBoxBoxConfig;
82
+ operationBox: IOperationBoxConfig;
59
83
  robotModel: TRobotModelConfig;
60
84
  userDetector: IUserDetectorConfig;
61
85
  }
@@ -1,6 +1,6 @@
1
1
  var c = Object.defineProperty;
2
- var h = (e, t, o) => t in e ? c(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
- var s = (e, t, o) => (h(e, typeof t != "symbol" ? t + "" : t, o), o);
2
+ var h = (t, e, o) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
3
+ var n = (t, e, o) => (h(t, typeof e != "symbol" ? e + "" : e, o), o);
4
4
  const A = 60, y = {
5
5
  position: [0, 0, 0],
6
6
  rotation: [0, Math.PI, 0],
@@ -29,7 +29,7 @@ const A = 60, y = {
29
29
  }, N = {
30
30
  big: { width: 640, height: 480 },
31
31
  small: { width: 360, height: 270 }
32
- }, l = "assistant-robot-model-container", n = "assistant_tip_container", v = '<div class="assistant-robot-container ', R = `">
32
+ }, l = "assistant-robot-model-container", s = "assistant-robot-tip-container", v = '<div class="assistant-robot-container ', R = `">
33
33
  <style>
34
34
  .assistant-robot-container{
35
35
  width: 100%;
@@ -42,7 +42,7 @@ const A = 60, y = {
42
42
  position:relative;
43
43
  width:100%;
44
44
  }
45
- .${n}{
45
+ .${s}{
46
46
  position: absolute;
47
47
  top: 2px;
48
48
  left: 50%;
@@ -59,7 +59,7 @@ const A = 60, y = {
59
59
  0% { opacity: 0; }
60
60
  100% { opacity: 1; }
61
61
  }
62
- .${n}::after{
62
+ .${s}::after{
63
63
  content: '';
64
64
  display: block;
65
65
  position: absolute;
@@ -74,21 +74,21 @@ const A = 60, y = {
74
74
  }
75
75
  </style>
76
76
  <div class="${l}">
77
- <div class="${n}">HI!</div>
77
+ <div class="${s}">HI!</div>
78
78
 
79
79
  </div>
80
80
  <div>
81
- `, S = {
81
+ `, w = {
82
82
  openCamera: "To interactive with the assistant, we'd like to access your device's camera.Take it easy, your pictures and information won't be sent anywhere or be stored.",
83
83
  alreadyOpenCamera: "the camera have be opened"
84
84
  };
85
- var x = /* @__PURE__ */ ((e) => (e.openCamera = "openCamera", e.hello = "hello", e))(x || {});
86
- const b = "assistant-robot-input", u = "assistant-robot-btn", d = "operation_container", p = "menu_btn", i = "menu_list", w = '<div class="assistant-robot-chartbox', E = `">
85
+ var b = /* @__PURE__ */ ((t) => (t.openCamera = "openCamera", t.hello = "hello", t))(b || {});
86
+ const x = "assistant-robot-input", u = "assistant-robot-btn", d = "assistant-robot-operation-container", p = "assistant-robot-menu-btn", r = "assistant-robot-menu-list", S = '<div class="assistant-robot-operationbox', E = `">
87
87
  <style>
88
- .assistant-robot-chartbox{
89
- box-sizing: content-box;
88
+ .assistant-robot-operationbox{
89
+ box-sizing: border-box;
90
90
  width: 100%;
91
- height: 32px;
91
+ height: 52px;
92
92
  display: flex;
93
93
  flex: 0 0 auto;
94
94
  flex-wrap: wrap;
@@ -120,13 +120,13 @@ const b = "assistant-robot-input", u = "assistant-robot-btn", d = "operation_con
120
120
  height: 24px;
121
121
  }
122
122
  .${p}{
123
- color: #dedede;
123
+ color: #aaaaaa;
124
124
  width:24px;
125
125
  height: 24px;
126
126
  cursor: pointer;
127
127
  }
128
128
 
129
- .${i} {
129
+ .${r} {
130
130
  display: none;
131
131
  position: absolute;
132
132
  top: 30px;
@@ -140,14 +140,14 @@ const b = "assistant-robot-input", u = "assistant-robot-btn", d = "operation_con
140
140
  list-style: none;
141
141
  }
142
142
 
143
- .${i} li{
143
+ .${r} li{
144
144
  line-height: 32px;
145
145
  text-wrap: nowrap;
146
146
  border-bottom: 1px solid #dedede;
147
147
  cursor: pointer;
148
148
  }
149
149
 
150
- .${i} li:last-child{
150
+ .${r} li:last-child{
151
151
  border-bottom: none;
152
152
  }
153
153
 
@@ -182,63 +182,68 @@ const b = "assistant-robot-input", u = "assistant-robot-btn", d = "operation_con
182
182
  p-id="1325"
183
183
  ></path>
184
184
  </svg>
185
- <ul class="${i}">
186
- <li data-id="openCamera">Open the Camera</li>
185
+ <ul class="${r}">
186
+ <li data-id="openCamera">eye contact</li>
187
187
  `, k = `</ul>
188
188
  </span>
189
- <input class="${b}" type="text" />
189
+ <input class="${x}" type="text" />
190
190
  <button class="${u}">ask</button>
191
191
  </div>`;
192
- var f = /* @__PURE__ */ ((e) => (e[e.loading = 1] = "loading", e[e.ready = 2] = "ready", e[e.error = 3] = "error", e))(f || {});
192
+ var f = /* @__PURE__ */ ((t) => (t[t.loading = 1] = "loading", t[t.ready = 2] = "ready", t[t.error = 3] = "error", t))(f || {});
193
193
  const $ = 50, L = 2e3;
194
- var g = /* @__PURE__ */ ((e) => (e.init = "init", e.ready = "ready", e.openCameraRejected = "openCameraRejected", e.userMediaUnavailable = "userMediaUnavailable", e.faceDetectorCreateError = "faceDetectorCreateError", e.error = "error", e))(g || {});
194
+ var g = /* @__PURE__ */ ((t) => (t.init = "init", t.ready = "ready", t.openCameraRejected = "openCameraRejected", t.userMediaUnavailable = "userMediaUnavailable", t.faceDetectorCreateError = "faceDetectorCreateError", t.error = "error", t))(g || {});
195
195
  const m = "userDetectorStatusChange";
196
- var O = /* @__PURE__ */ ((e) => (e.languageModelLoaded = "languageModelLoaded", e[e.userDetectorStatusChange = m] = "userDetectorStatusChange", e.menuClick = "menuClick", e.ask = "ask", e.say = "say", e))(O || {});
197
- function _() {
196
+ var O = /* @__PURE__ */ ((t) => (t.languageModelLoaded = "languageModelLoaded", t[t.userDetectorStatusChange = m] = "userDetectorStatusChange", t.menuClick = "menuClick", t.ask = "ask", t.say = "say", t))(O || {});
197
+ function C() {
198
198
  return /iPhone|iPad|iPod/i.test(navigator.userAgent);
199
199
  }
200
200
  function T() {
201
201
  return /Android/i.test(navigator.userAgent);
202
202
  }
203
203
  function P() {
204
- return T() || _();
204
+ return T() || C();
205
205
  }
206
- function B(e) {
207
- return new DOMParser().parseFromString(e, "text/html").body.firstElementChild;
206
+ function B(t) {
207
+ return new DOMParser().parseFromString(t, "text/html").body.firstElementChild;
208
208
  }
209
- function M(e) {
210
- if (!Array.isArray(e) || e.length === 0)
209
+ function M(t) {
210
+ if (!Array.isArray(t) || t.length === 0)
211
211
  return null;
212
- let t = -1 / 0, o = null;
213
- for (let a = 0; a < e.length; a++) {
214
- const r = e[a];
215
- r && typeof r.score == "number" && r.score > t && (t = r.score, o = r);
212
+ let e = -1 / 0, o = null;
213
+ for (let a = 0; a < t.length; a++) {
214
+ const i = t[a];
215
+ i && typeof i.score == "number" && i.score > e && (e = i.score, o = i);
216
216
  }
217
217
  return o;
218
218
  }
219
219
  class D {
220
220
  constructor() {
221
- s(this, "listeners", {});
221
+ n(this, "listeners", {});
222
222
  }
223
- addEventListener(t, o) {
224
- this.listeners[t] ? this.get(t).push(o) : this.listeners[t] = [o];
223
+ addEventListener(e, o) {
224
+ this.listeners[e] ? this.get(e).push(o) : this.listeners[e] = [o];
225
225
  }
226
- removeEventListener(t, o) {
227
- this.listeners[t] && (this.listeners[t] = this.get(t).filter(
226
+ removeEventListener(e, o) {
227
+ this.listeners[e] && (this.listeners[e] = this.get(e).filter(
228
228
  (a) => a !== o
229
229
  ));
230
230
  }
231
- emit(t, ...o) {
232
- this.get(t).map((a) => {
231
+ emit(e, ...o) {
232
+ this.get(e).map((a) => {
233
233
  a(...o);
234
234
  });
235
235
  }
236
- get(t) {
237
- return this.listeners[t] || [];
236
+ get(e) {
237
+ return this.listeners[e] || [];
238
238
  }
239
239
  }
240
+ function H(t, e) {
241
+ for (; t.firstChild; )
242
+ t.removeChild(t.firstChild);
243
+ t.appendChild(e);
244
+ }
240
245
  export {
241
- n as A,
246
+ s as A,
242
247
  v as C,
243
248
  D as E,
244
249
  I as M,
@@ -249,20 +254,21 @@ export {
249
254
  N as V,
250
255
  y as a,
251
256
  g as b,
252
- w as c,
257
+ S as c,
253
258
  E as d,
254
259
  k as e,
255
260
  u as f,
256
- b as g,
261
+ x as g,
257
262
  p as h,
258
263
  P as i,
259
- i as j,
264
+ r as j,
260
265
  R as k,
261
266
  l,
262
267
  O as m,
263
- x as n,
268
+ b as n,
264
269
  f as o,
265
270
  B as p,
266
271
  M as q,
267
- S as t
272
+ H as r,
273
+ w as t
268
274
  };
@@ -1,4 +1,4 @@
1
- "use strict";var E=Object.defineProperty;var b=(e,t,o)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var d=(e,t,o)=>(b(e,typeof t!="symbol"?t+"":t,o),o);const x={position:[0,0,0],rotation:[0,Math.PI,0],helloActionName:"hello",idleActionName:"idle",helloContent:"Hi, you can talk to me!"},I={backgroundColor:0,backgroundAlpha:0,camera:{fov:50,near:.1,far:10,position:[0,0,2],lookAt:[0,0,0]},ambientLight:{color:16777215,intensity:.5},directionalLight:{color:16777215,intensity:2,position:[10,10,0]}},N={big:{width:640,height:480},small:{width:360,height:270}},s="assistant-robot-model-container",n="assistant_tip_container",f='<div class="assistant-robot-container ',g=`">
1
+ "use strict";var A=Object.defineProperty;var E=(t,e,o)=>e in t?A(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var d=(t,e,o)=>(E(t,typeof e!="symbol"?e+"":e,o),o);const x={position:[0,0,0],rotation:[0,Math.PI,0],helloActionName:"hello",idleActionName:"idle",helloContent:"Hi, you can talk to me!"},f={backgroundColor:0,backgroundAlpha:0,camera:{fov:50,near:.1,far:10,position:[0,0,2],lookAt:[0,0,0]},ambientLight:{color:16777215,intensity:.5},directionalLight:{color:16777215,intensity:2,position:[10,10,0]}},I={big:{width:640,height:480},small:{width:360,height:270}},s="assistant-robot-model-container",n="assistant-robot-tip-container",C='<div class="assistant-robot-container ',N=`">
2
2
  <style>
3
3
  .assistant-robot-container{
4
4
  width: 100%;
@@ -47,12 +47,12 @@
47
47
 
48
48
  </div>
49
49
  <div>
50
- `,C={openCamera:"To interactive with the assistant, we'd like to access your device's camera.Take it easy, your pictures and information won't be sent anywhere or be stored.",alreadyOpenCamera:"the camera have be opened"};var p=(e=>(e.openCamera="openCamera",e.hello="hello",e))(p||{});const _="assistant-robot-input",O="assistant-robot-btn",c="operation_container",l="menu_btn",a="menu_list",S='<div class="assistant-robot-chartbox',m=`">
50
+ `,g={openCamera:"To interactive with the assistant, we'd like to access your device's camera.Take it easy, your pictures and information won't be sent anywhere or be stored.",alreadyOpenCamera:"the camera have be opened"};var p=(t=>(t.openCamera="openCamera",t.hello="hello",t))(p||{});const O="assistant-robot-input",h="assistant-robot-btn",c="assistant-robot-operation-container",l="assistant-robot-menu-btn",a="assistant-robot-menu-list",S='<div class="assistant-robot-operationbox',m=`">
51
51
  <style>
52
- .assistant-robot-chartbox{
53
- box-sizing: content-box;
52
+ .assistant-robot-operationbox{
53
+ box-sizing: border-box;
54
54
  width: 100%;
55
- height: 32px;
55
+ height: 52px;
56
56
  display: flex;
57
57
  flex: 0 0 auto;
58
58
  flex-wrap: wrap;
@@ -84,7 +84,7 @@
84
84
  height: 24px;
85
85
  }
86
86
  .${l}{
87
- color: #dedede;
87
+ color: #aaaaaa;
88
88
  width:24px;
89
89
  height: 24px;
90
90
  cursor: pointer;
@@ -147,9 +147,9 @@
147
147
  ></path>
148
148
  </svg>
149
149
  <ul class="${a}">
150
- <li data-id="openCamera">Open the Camera</li>
150
+ <li data-id="openCamera">eye contact</li>
151
151
  `,R=`</ul>
152
152
  </span>
153
- <input class="${_}" type="text" />
154
- <button class="${O}">ask</button>
155
- </div>`;var T=(e=>(e[e.loading=1]="loading",e[e.ready=2]="ready",e[e.error=3]="error",e))(T||{});const y=50,L=2e3;var h=(e=>(e.init="init",e.ready="ready",e.openCameraRejected="openCameraRejected",e.userMediaUnavailable="userMediaUnavailable",e.faceDetectorCreateError="faceDetectorCreateError",e.error="error",e))(h||{});const u="userDetectorStatusChange";var A=(e=>(e.languageModelLoaded="languageModelLoaded",e[e.userDetectorStatusChange=u]="userDetectorStatusChange",e.menuClick="menuClick",e.ask="ask",e.say="say",e))(A||{});function v(){return/iPhone|iPad|iPod/i.test(navigator.userAgent)}function B(){return/Android/i.test(navigator.userAgent)}function D(){return B()||v()}function M(e){return new DOMParser().parseFromString(e,"text/html").body.firstElementChild}function P(e){if(!Array.isArray(e)||e.length===0)return null;let t=-1/0,o=null;for(let i=0;i<e.length;i++){const r=e[i];r&&typeof r.score=="number"&&r.score>t&&(t=r.score,o=r)}return o}class w{constructor(){d(this,"listeners",{})}addEventListener(t,o){this.listeners[t]?this.get(t).push(o):this.listeners[t]=[o]}removeEventListener(t,o){this.listeners[t]&&(this.listeners[t]=this.get(t).filter(i=>i!==o))}emit(t,...o){this.get(t).map(i=>{i(...o)})}get(t){return this.listeners[t]||[]}}exports.ASSISTANT_MODEL_CONTAINER_CLASS=s;exports.ASSISTANT_TIP_CONTAINER=n;exports.CONTAINER_BODY=g;exports.CONTAINER_HEAD=f;exports.EAssistantEvent=A;exports.ELanguageModelStatus=T;exports.EMenuKey=p;exports.EUserDetectorStatus=h;exports.EventListener=w;exports.MENU_BTN_CLASS=l;exports.MENU_LIST_CLASS=a;exports.MODEL_CONFIG=x;exports.MODEL_SCENE_CONFIG=I;exports.ONE_LETTER_READ_TIME=y;exports.READ_WAIT_TIME=L;exports.ROBOT_OPERATION_BOX_BODY=m;exports.ROBOT_OPERATION_BOX_HEAD=S;exports.ROBOT_OPERATION_BOX_TAIL=R;exports.ROBOT_OPERATION_BTN_CLASS=O;exports.ROBOT_OPERATION_INPUT_CLASS=_;exports.TARGET_FPS=60;exports.USER_DETECTOR_STATUS_CHANGE_EVENT=u;exports.VIDEO_SIZE=N;exports.findHighestScoreItem=P;exports.isMobile=D;exports.parseHTML=M;exports.tips=C;
153
+ <input class="${O}" type="text" />
154
+ <button class="${h}">ask</button>
155
+ </div>`;var _=(t=>(t[t.loading=1]="loading",t[t.ready=2]="ready",t[t.error=3]="error",t))(_||{});const y=50,L=2e3;var T=(t=>(t.init="init",t.ready="ready",t.openCameraRejected="openCameraRejected",t.userMediaUnavailable="userMediaUnavailable",t.faceDetectorCreateError="faceDetectorCreateError",t.error="error",t))(T||{});const b="userDetectorStatusChange";var u=(t=>(t.languageModelLoaded="languageModelLoaded",t[t.userDetectorStatusChange=b]="userDetectorStatusChange",t.menuClick="menuClick",t.ask="ask",t.say="say",t))(u||{});function v(){return/iPhone|iPad|iPod/i.test(navigator.userAgent)}function B(){return/Android/i.test(navigator.userAgent)}function D(){return B()||v()}function w(t){return new DOMParser().parseFromString(t,"text/html").body.firstElementChild}function M(t){if(!Array.isArray(t)||t.length===0)return null;let e=-1/0,o=null;for(let i=0;i<t.length;i++){const r=t[i];r&&typeof r.score=="number"&&r.score>e&&(e=r.score,o=r)}return o}class P{constructor(){d(this,"listeners",{})}addEventListener(e,o){this.listeners[e]?this.get(e).push(o):this.listeners[e]=[o]}removeEventListener(e,o){this.listeners[e]&&(this.listeners[e]=this.get(e).filter(i=>i!==o))}emit(e,...o){this.get(e).map(i=>{i(...o)})}get(e){return this.listeners[e]||[]}}function k(t,e){for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(e)}exports.ASSISTANT_MODEL_CONTAINER_CLASS=s;exports.ASSISTANT_TIP_CONTAINER=n;exports.CONTAINER_BODY=N;exports.CONTAINER_HEAD=C;exports.EAssistantEvent=u;exports.ELanguageModelStatus=_;exports.EMenuKey=p;exports.EUserDetectorStatus=T;exports.EventListener=P;exports.MENU_BTN_CLASS=l;exports.MENU_LIST_CLASS=a;exports.MODEL_CONFIG=x;exports.MODEL_SCENE_CONFIG=f;exports.ONE_LETTER_READ_TIME=y;exports.READ_WAIT_TIME=L;exports.ROBOT_OPERATION_BOX_BODY=m;exports.ROBOT_OPERATION_BOX_HEAD=S;exports.ROBOT_OPERATION_BOX_TAIL=R;exports.ROBOT_OPERATION_BTN_CLASS=h;exports.ROBOT_OPERATION_INPUT_CLASS=O;exports.TARGET_FPS=60;exports.USER_DETECTOR_STATUS_CHANGE_EVENT=b;exports.VIDEO_SIZE=I;exports.findHighestScoreItem=M;exports.isMobile=D;exports.parseHTML=w;exports.replaceChildren=k;exports.tips=g;
package/dist/utils.d.ts CHANGED
@@ -1,10 +1,18 @@
1
- import { TEventListenFunc } from "./type";
2
1
  import type { Answer } from "@tensorflow-models/qna/dist/question_and_answer";
2
+ import { TEventListenFunc } from "./type";
3
3
  export declare function isiOS(): boolean;
4
4
  export declare function isAndroid(): boolean;
5
5
  export declare function isMobile(): boolean;
6
+ /**
7
+ * turn a html string to dom
8
+ * @param htmlString a html string
9
+ * @returns a dom tree
10
+ */
6
11
  export declare function parseHTML(htmlString: string): Element | null;
7
12
  export declare function findHighestScoreItem(data: Answer[]): Answer | null;
13
+ /**
14
+ * utils class which implement Observer Pattern
15
+ */
8
16
  export declare class EventListener {
9
17
  private listeners;
10
18
  addEventListener(name: string, func: TEventListenFunc): void;
@@ -12,3 +20,9 @@ export declare class EventListener {
12
20
  emit(event: string, ...args: any[]): void;
13
21
  get(name: string): TEventListenFunc[];
14
22
  }
23
+ /**
24
+ * to replace all children of parentNode to a new node
25
+ * @param parentNode the pareent node
26
+ * @param newNode the child node will insert to the parent node
27
+ */
28
+ export declare function replaceChildren(parentNode: Node, newNode: Node): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistant-robot",
3
- "version": "0.0.2-gamma",
3
+ "version": "0.0.2",
4
4
  "description": "An assistant widget, have a 3D robot which can interact with user, have a simple LLM which can chat with user.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/readme.md ADDED
File without changes