@naniteninja/profile-comparison-lib 1.0.2 → 1.0.4
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 +117 -143
- package/fesm2022/naniteninja-profile-comparison-lib.mjs +106 -846
- package/fesm2022/naniteninja-profile-comparison-lib.mjs.map +1 -1
- package/index.d.ts +43 -66
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -1,186 +1,160 @@
|
|
|
1
1
|
# Profile Comparison Library
|
|
2
2
|
|
|
3
|
-
Angular library that renders a side-by-side profile comparison (two profile images, a central draggable shape, and aligned interest lists). It is a **thin client
|
|
3
|
+
Angular library that renders a side-by-side profile comparison (two profile images, a central draggable shape, and semantically aligned interest lists). It is a **thin client** — the library sends user config to a backend and displays the payload it returns. No API keys or key-entry modals live in the library.
|
|
4
4
|
|
|
5
|
-
**You need a backend** that implements the profile comparison API (e.g. the **profile-comparison-server** repo).
|
|
5
|
+
**You need a backend** that implements the profile comparison API (e.g. the **profile-comparison-server** repo). By default the component points at the real deployed backend. Set `[backendMode]="BackendMode.Mock"` to use `localhost:3000` during development.
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Quick start (copy-paste)
|
|
10
10
|
|
|
11
|
-
1.
|
|
11
|
+
### 1. Install
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
2. **Provide the backend URL**
|
|
18
|
-
|
|
19
|
-
In `app.config.ts` (or `AppModule`):
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { PROFILE_COMPARISON_API_BASE_URL } from '@naniteninja/profile-comparison-lib';
|
|
23
|
-
|
|
24
|
-
providers: [
|
|
25
|
-
{ provide: PROFILE_COMPARISON_API_BASE_URL, useValue: 'https://your-backend.com/api' },
|
|
26
|
-
]
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Or with a factory (e.g. runtime toggle between backends):
|
|
30
|
-
|
|
31
|
-
```typescript
|
|
32
|
-
providers: [{
|
|
33
|
-
provide: PROFILE_COMPARISON_API_BASE_URL,
|
|
34
|
-
useFactory: (backendUrl: BackendUrlService) => () => backendUrl.getBaseUrl(),
|
|
35
|
-
deps: [BackendUrlService],
|
|
36
|
-
}]
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
3. **Use the component**
|
|
40
|
-
|
|
41
|
-
Import the module and add the component to a template:
|
|
42
|
-
|
|
43
|
-
```typescript
|
|
44
|
-
import { ProfileComparisonLibModule } from '@naniteninja/profile-comparison-lib';
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
```html
|
|
48
|
-
<lib-profile-comparison [config]="config"></lib-profile-comparison>
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## What the element looks like
|
|
54
|
-
|
|
55
|
-
When you use `<lib-profile-comparison>` in another Angular app you get:
|
|
56
|
-
|
|
57
|
-
- **Side-by-side profile comparison**: two profile images (left and right) with a central draggable “shape” and aligned interest lists between them.
|
|
58
|
-
- **Main regions**: left image, right image, center shape with text, loading indicator when a request is in progress.
|
|
59
|
-
- **Action**: “View Profile” on each side; the component emits `viewProfileClick` with `{ side: 'left' | 'right' }` so the host can route or act.
|
|
60
|
-
|
|
61
|
-
No key-entry modals or API key inputs appear in the library; all keys and third-party API calls live on your backend.
|
|
62
|
-
|
|
63
|
-
---
|
|
13
|
+
```bash
|
|
14
|
+
npm install @naniteninja/profile-comparison-lib
|
|
15
|
+
```
|
|
64
16
|
|
|
65
|
-
|
|
17
|
+
### 2. Wire up the module
|
|
66
18
|
|
|
67
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
import { NgModule } from '@angular/core';
|
|
21
|
+
import { HttpClientModule } from '@angular/common/http';
|
|
22
|
+
import { ProfileComparisonLibModule } from '@naniteninja/profile-comparison-lib';
|
|
68
23
|
|
|
69
|
-
|
|
24
|
+
@NgModule({
|
|
25
|
+
imports: [HttpClientModule, ProfileComparisonLibModule],
|
|
26
|
+
})
|
|
27
|
+
export class AppModule {}
|
|
28
|
+
```
|
|
70
29
|
|
|
71
|
-
|
|
72
|
-
npm install @naniteninja/profile-comparison-lib @angular/core@^20 @angular/common@^20 @tensorflow/tfjs @tensorflow-models/universal-sentence-encoder
|
|
73
|
-
```
|
|
30
|
+
### 3. Add the component to a template
|
|
74
31
|
|
|
75
|
-
|
|
32
|
+
Minimal — uses the real deployed backend with all edges faded:
|
|
76
33
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
import { PROFILE_COMPARISON_API_BASE_URL } from '@naniteninja/profile-comparison-lib';
|
|
34
|
+
```html
|
|
35
|
+
<lib-profile-comparison [config]="profileConfig"></lib-profile-comparison>
|
|
36
|
+
```
|
|
81
37
|
|
|
82
|
-
|
|
83
|
-
providers: [
|
|
84
|
-
provideHttpClient(),
|
|
85
|
-
{ provide: PROFILE_COMPARISON_API_BASE_URL, useValue: 'https://your-backend.com/api' },
|
|
86
|
-
],
|
|
87
|
-
};
|
|
88
|
-
```
|
|
38
|
+
During development, point at a local backend:
|
|
89
39
|
|
|
90
|
-
|
|
40
|
+
```html
|
|
41
|
+
<lib-profile-comparison
|
|
42
|
+
[config]="profileConfig"
|
|
43
|
+
[backendMode]="BackendMode.Mock"
|
|
44
|
+
></lib-profile-comparison>
|
|
45
|
+
```
|
|
91
46
|
|
|
92
|
-
|
|
93
|
-
import { PROFILE_COMPARISON_API_BASE_URL } from '@naniteninja/profile-comparison-lib';
|
|
47
|
+
Or supply a fully custom URL (overrides `backendMode`):
|
|
94
48
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
```
|
|
49
|
+
```html
|
|
50
|
+
<lib-profile-comparison
|
|
51
|
+
[config]="profileConfig"
|
|
52
|
+
[backendUrl]="'https://my-custom-api.example.com/api'"
|
|
53
|
+
></lib-profile-comparison>
|
|
54
|
+
```
|
|
102
55
|
|
|
103
|
-
|
|
56
|
+
Full example with all inputs and outputs:
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<lib-profile-comparison
|
|
60
|
+
[config]="profileConfig"
|
|
61
|
+
[backendMode]="backendMode"
|
|
62
|
+
[backendUrl]="customUrl"
|
|
63
|
+
[fadeAllEdges]="true"
|
|
64
|
+
(matrixDataChange)="onMatrixData($event)"
|
|
65
|
+
(rawLLMOutputChange)="onRawLLM($event)"
|
|
66
|
+
(viewProfileClick)="onViewProfile($event)"
|
|
67
|
+
></lib-profile-comparison>
|
|
68
|
+
```
|
|
104
69
|
|
|
105
|
-
|
|
106
|
-
|
|
70
|
+
### 4. Component class
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { Component } from '@angular/core';
|
|
74
|
+
import { IProfileConfig, IMatrixData, BackendMode } from '@naniteninja/profile-comparison-lib';
|
|
75
|
+
|
|
76
|
+
@Component({ /* ... */ })
|
|
77
|
+
export class AppComponent {
|
|
78
|
+
readonly BackendMode = BackendMode; // expose enum to template
|
|
79
|
+
|
|
80
|
+
backendMode = BackendMode.Real;
|
|
81
|
+
customUrl: string | null = null;
|
|
82
|
+
|
|
83
|
+
profileConfig: IProfileConfig = {
|
|
84
|
+
person1Interests: [
|
|
85
|
+
'Gaming', 'Programming', 'AI/ML', 'Startups',
|
|
86
|
+
'Blockchain', 'Cybersecurity', 'Web Development', 'Data Science',
|
|
87
|
+
],
|
|
88
|
+
person2Interests: [
|
|
89
|
+
'AI machine learning', 'Mobile Games', 'Hardware',
|
|
90
|
+
'Data Science', 'Entrepreneurship', 'Design Thinking', 'Blockchain',
|
|
91
|
+
],
|
|
92
|
+
person3Interests: ['Board Games', 'Machine Learning'],
|
|
93
|
+
user1Image: './assets/user1.jpg', // data-URL or asset path
|
|
94
|
+
user2Image: './assets/user2.jpg',
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
onMatrixData(data: IMatrixData) { console.log('Matrix:', data); }
|
|
98
|
+
onRawLLM(raw: string) { console.log('LLM:', raw); }
|
|
99
|
+
onViewProfile(e: { side: 'left' | 'right' }) {
|
|
100
|
+
console.log('View profile:', e.side);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
imports: [ProfileComparisonLibModule, ...],
|
|
110
|
-
})
|
|
111
|
-
export class YourModule {}
|
|
112
|
-
```
|
|
105
|
+
### 5. Run
|
|
113
106
|
|
|
114
|
-
|
|
107
|
+
```bash
|
|
108
|
+
ng serve
|
|
109
|
+
```
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
<lib-profile-comparison
|
|
118
|
-
[config]="config"
|
|
119
|
-
[fadeAllEdges]="fadeAllEdges"
|
|
120
|
-
(matrixDataChange)="onMatrixData($event)"
|
|
121
|
-
(rawLLMOutputChange)="onRawLLMOutput($event)"
|
|
122
|
-
(viewProfileClick)="onViewProfile($event)"
|
|
123
|
-
></lib-profile-comparison>
|
|
124
|
-
```
|
|
111
|
+
If using `BackendMode.Mock`, start the local backend first:
|
|
125
112
|
|
|
126
|
-
|
|
113
|
+
```bash
|
|
114
|
+
cd ../profile-comparison-server && npm install && npm start # listens on :3000
|
|
115
|
+
```
|
|
127
116
|
|
|
128
117
|
---
|
|
129
118
|
|
|
130
|
-
## Inputs
|
|
131
|
-
|
|
132
|
-
### Inputs
|
|
119
|
+
## Inputs
|
|
133
120
|
|
|
134
|
-
|
|
121
|
+
| Input | Type | Default | Description |
|
|
122
|
+
|-------|------|---------|-------------|
|
|
123
|
+
| `config` | `IProfileConfig` | *required* | Profile data (interests, images) for the comparison. |
|
|
124
|
+
| `backendMode` | `BackendMode` | `BackendMode.Real` (0) | `Real` = deployed backend, `Mock` = `localhost:3000`. |
|
|
125
|
+
| `backendUrl` | `string \| null` | `null` | When non-empty, overrides `backendMode` entirely. |
|
|
126
|
+
| `fadeAllEdges` | `boolean` | `true` | Fade the outer edges of the profile area. |
|
|
135
127
|
|
|
136
|
-
|
|
137
|
-
{
|
|
138
|
-
"person1Interests": ["Gaming", "Programming", "AI/ML"],
|
|
139
|
-
"person2Interests": ["AI machine learning", "Mobile Games", "Data Science"],
|
|
140
|
-
"person3Interests": ["Board Games", "Machine Learning"],
|
|
141
|
-
"user1Image": "data:image/jpeg;base64,...",
|
|
142
|
-
"user2Image": "data:image/jpeg;base64,..."
|
|
143
|
-
}
|
|
144
|
-
```
|
|
128
|
+
## Outputs
|
|
145
129
|
|
|
146
|
-
|
|
130
|
+
All outputs are optional — bind only what you need.
|
|
147
131
|
|
|
148
|
-
|
|
132
|
+
| Output | Type | Description |
|
|
133
|
+
|--------|------|-------------|
|
|
134
|
+
| `matrixDataChange` | `IMatrixData` | Legend, headers, and rows for the similarity matrix. |
|
|
135
|
+
| `rawLLMOutputChange` | `string` | Raw LLM output from the backend (if any). |
|
|
136
|
+
| `viewProfileClick` | `{ side: 'left' \| 'right' }` | Emitted when the user clicks "View Profile". |
|
|
149
137
|
|
|
150
|
-
|
|
138
|
+
## BackendMode enum
|
|
151
139
|
|
|
152
|
-
|
|
140
|
+
```typescript
|
|
141
|
+
import { BackendMode } from '@naniteninja/profile-comparison-lib';
|
|
153
142
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
{
|
|
158
|
-
"legend": [{ "abbr": "Gam", "full": "Gaming" }, { "abbr": "Pro", "full": "Programming" }],
|
|
159
|
-
"headers": ["Gam", "Pro", "AI/ML"],
|
|
160
|
-
"rows": [
|
|
161
|
-
{ "label": "Gam", "values": ["1.00", "0.2", "0.5"] },
|
|
162
|
-
{ "label": "Pro", "values": ["0.2", "1.00", "0.8"] }
|
|
163
|
-
]
|
|
164
|
-
}
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
- **`rawLLMOutputChange`** — `string`: raw LLM output from the backend (if any).
|
|
168
|
-
|
|
169
|
-
- **`viewProfileClick`** — `{ side: 'left' | 'right' }`: emitted when the user clicks “View Profile” on the left or right side. Use this to navigate or open a profile page.
|
|
143
|
+
BackendMode.Real // 0 — deployed backend (default)
|
|
144
|
+
BackendMode.Mock // 1 — localhost:3000
|
|
145
|
+
```
|
|
170
146
|
|
|
171
|
-
|
|
147
|
+
### URL resolution priority
|
|
172
148
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
```
|
|
149
|
+
1. `backendUrl` input (if non-empty)
|
|
150
|
+
2. `backendMode` enum mapping
|
|
151
|
+
3. Legacy `PROFILE_COMPARISON_API_BASE_URL` injection token (backward compatible)
|
|
178
152
|
|
|
179
153
|
---
|
|
180
154
|
|
|
181
155
|
## Backend API contract
|
|
182
156
|
|
|
183
|
-
The library calls
|
|
157
|
+
The library calls `POST {baseUrl}/profile/compare-full` with body `{ config: IProfileConfig }`. The backend returns a display payload (face results, aligned lists, center item, matrix data, raw LLM output). See the **profile-comparison-server** repo and the `IComparisonPayload` interface for the response shape.
|
|
184
158
|
|
|
185
159
|
---
|
|
186
160
|
|
|
@@ -190,4 +164,4 @@ The library calls your backend at `POST {baseUrl}/profile/compare-full` with bod
|
|
|
190
164
|
ng build profile-comparison-lib
|
|
191
165
|
```
|
|
192
166
|
|
|
193
|
-
Output is in `dist/profile-comparison-lib/` (FESM, typings, package.json). Peer dependencies: Angular `^20.0.0
|
|
167
|
+
Output is in `dist/profile-comparison-lib/` (FESM bundles, typings, package.json). Peer dependencies: Angular `^20.0.0`.
|