@m4trix/core 0.5.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 +72 -0
- package/dist/api/index.cjs +83 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.cts +74 -0
- package/dist/api/index.d.ts +74 -0
- package/dist/api/index.js +81 -0
- package/dist/api/index.js.map +1 -0
- package/dist/helper/index.cjs +253 -0
- package/dist/helper/index.cjs.map +1 -0
- package/dist/helper/index.d.cts +92 -0
- package/dist/helper/index.d.ts +92 -0
- package/dist/helper/index.js +251 -0
- package/dist/helper/index.js.map +1 -0
- package/dist/index.cjs +2670 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2656 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +1324 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +213 -0
- package/dist/react/index.d.ts +213 -0
- package/dist/react/index.js +1316 -0
- package/dist/react/index.js.map +1 -0
- package/dist/stream/index.cjs +716 -0
- package/dist/stream/index.cjs.map +1 -0
- package/dist/stream/index.d.cts +304 -0
- package/dist/stream/index.d.ts +304 -0
- package/dist/stream/index.js +712 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/ui/index.cjs +316 -0
- package/dist/ui/index.cjs.map +1 -0
- package/dist/ui/index.d.cts +30 -0
- package/dist/ui/index.d.ts +30 -0
- package/dist/ui/index.js +314 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +123 -0
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { css, LitElement, html } from 'lit';
|
|
2
|
+
import { property, state, customElement } from 'lit/decorators.js';
|
|
3
|
+
import { createRef, ref } from 'lit/directives/ref.js';
|
|
4
|
+
import { createTimeline } from 'animejs';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
9
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
10
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
11
|
+
if (decorator = decorators[i])
|
|
12
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
13
|
+
if (kind && result)
|
|
14
|
+
__defProp(target, key, result);
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
var AiCursorComponentStyle = css`
|
|
18
|
+
:host {
|
|
19
|
+
--ai-local-cursor-size: var(--sk-ai-cursor-size, 1rem);
|
|
20
|
+
--ai-local-cursor-label-padding: var(
|
|
21
|
+
--sk-ai-cursor-label-padding,
|
|
22
|
+
0.25rem 0.25rem
|
|
23
|
+
);
|
|
24
|
+
--ai-local-cursor-border-radius: var(--sk-ai-cursor-border-radius, 0.25rem);
|
|
25
|
+
--ai-local-label-offset: var(--sk-ai-cursor-label-offset, 1rem);
|
|
26
|
+
|
|
27
|
+
--ai-local-label-font-size: var(--sk-ai-cursor-label-font-size, 12px);
|
|
28
|
+
--ai-local-label-font-weight: var(--sk-ai-cursor-label-font-weight, bold);
|
|
29
|
+
--ai-local-label-color: var(--sk-ai-cursor-label-color, white);
|
|
30
|
+
--ai-local-label-background-color: var(
|
|
31
|
+
--sk-ai-cursor-label-background-color,
|
|
32
|
+
black
|
|
33
|
+
);
|
|
34
|
+
--ai-local-label-border-color: var(
|
|
35
|
+
--sk-ai-cursor-label-border-color,
|
|
36
|
+
white
|
|
37
|
+
);
|
|
38
|
+
--ai-local-label-border-width: var(
|
|
39
|
+
--sk-ai-cursor-label-border-width,
|
|
40
|
+
0.1rem
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
color: black;
|
|
44
|
+
stroke: white;
|
|
45
|
+
position: absolute;
|
|
46
|
+
/* Insetting in the parent element (body) */
|
|
47
|
+
top: 0;
|
|
48
|
+
left: 0;
|
|
49
|
+
bottom: 0;
|
|
50
|
+
right: 0;
|
|
51
|
+
pointer-events: none;
|
|
52
|
+
width: var(--ai-local-cursor-size);
|
|
53
|
+
height: var(--ai-local-cursor-size);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#cursor-graphic-parent {
|
|
57
|
+
position: absolute;
|
|
58
|
+
top: 0;
|
|
59
|
+
left: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#label-text {
|
|
63
|
+
position: absolute;
|
|
64
|
+
color: white;
|
|
65
|
+
font-size: 12px;
|
|
66
|
+
font-weight: bold;
|
|
67
|
+
padding: var(--ai-local-cursor-label-padding);
|
|
68
|
+
border-radius: var(--ai-local-cursor-border-radius);
|
|
69
|
+
|
|
70
|
+
white-space: nowrap;
|
|
71
|
+
overflow: hidden;
|
|
72
|
+
text-overflow: ellipsis;
|
|
73
|
+
|
|
74
|
+
width: fit-content;
|
|
75
|
+
min-width: fit-content;
|
|
76
|
+
top: var(--ai-local-label-offset);
|
|
77
|
+
left: var(--ai-local-label-offset);
|
|
78
|
+
|
|
79
|
+
border: var(--ai-local-label-border-width) solid
|
|
80
|
+
var(--ai-local-label-border-color);
|
|
81
|
+
background-color: var(--ai-local-label-background-color);
|
|
82
|
+
color: var(--ai-local-label-color);
|
|
83
|
+
font-size: var(--ai-local-label-font-size);
|
|
84
|
+
font-weight: var(--ai-local-label-font-weight);
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
// src/ui/ai-cursor/rendering/AiCursorComponent.ts
|
|
89
|
+
var AiCursorComponent = class extends LitElement {
|
|
90
|
+
constructor() {
|
|
91
|
+
super();
|
|
92
|
+
this.eventHooks = {
|
|
93
|
+
defineSetPosition: () => {
|
|
94
|
+
},
|
|
95
|
+
defineAddPositionToQueue: () => {
|
|
96
|
+
},
|
|
97
|
+
definePlayQueue: () => {
|
|
98
|
+
},
|
|
99
|
+
defineSetShowCursor: () => {
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
this.isShowingCursor = true;
|
|
103
|
+
this.labelText = "AI Cursor";
|
|
104
|
+
this.cursorPosition = [0, 0];
|
|
105
|
+
this._cursorRef = createRef();
|
|
106
|
+
this._labelRef = createRef();
|
|
107
|
+
}
|
|
108
|
+
updated(_changedProperties) {
|
|
109
|
+
if (_changedProperties.has("_cursorRef")) {
|
|
110
|
+
if (this._cursorRef.value) {
|
|
111
|
+
this.hookUpCallbacks();
|
|
112
|
+
} else {
|
|
113
|
+
this._timeline?.pause();
|
|
114
|
+
this._timeline?.refresh();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
super.updated(_changedProperties);
|
|
118
|
+
}
|
|
119
|
+
render() {
|
|
120
|
+
const cursorSvg = html`
|
|
121
|
+
<svg
|
|
122
|
+
width=${24}
|
|
123
|
+
height=${24}
|
|
124
|
+
viewBox="0 0 100 100"
|
|
125
|
+
fill="none"
|
|
126
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
127
|
+
>
|
|
128
|
+
<g clip-path="url(#clip0_3576_285)">
|
|
129
|
+
<path
|
|
130
|
+
class="cursor-path"
|
|
131
|
+
d="M2.14849 7.04749C1.35153 4.07321 4.07319 1.35155 7.04747 2.14851L77.3148 20.9766C80.2891 21.7735 81.2853 25.4914 79.108 27.6687L27.6687 79.108C25.4914 81.2853 21.7735 80.2891 20.9766 77.3149L2.14849 7.04749Z"
|
|
132
|
+
fill="currentColor"
|
|
133
|
+
/>
|
|
134
|
+
</g>
|
|
135
|
+
<defs>
|
|
136
|
+
<clipPath id="clip0_3576_285">
|
|
137
|
+
<rect width="100" height="100" fill="white" />
|
|
138
|
+
</clipPath>
|
|
139
|
+
</defs>
|
|
140
|
+
</svg>
|
|
141
|
+
`;
|
|
142
|
+
return html`
|
|
143
|
+
<span
|
|
144
|
+
id="cursor-graphic-parent"
|
|
145
|
+
${ref(this._cursorRef)}
|
|
146
|
+
?hidden=${!this.isShowingCursor}
|
|
147
|
+
>
|
|
148
|
+
${cursorSvg}
|
|
149
|
+
<span
|
|
150
|
+
${ref(this._labelRef)}
|
|
151
|
+
id="label-text"
|
|
152
|
+
?hidden=${!this.isShowingCursor}
|
|
153
|
+
>${this.labelText}</span
|
|
154
|
+
>
|
|
155
|
+
</span>
|
|
156
|
+
`;
|
|
157
|
+
}
|
|
158
|
+
// private methods
|
|
159
|
+
/**
|
|
160
|
+
* The primary way to control the cursor is using an external API.
|
|
161
|
+
* This interface exposes controlling methods. The Lit Component itself is
|
|
162
|
+
* intended to be a controlled component.
|
|
163
|
+
*/
|
|
164
|
+
hookUpCallbacks() {
|
|
165
|
+
const animationTarget = this._cursorRef.value;
|
|
166
|
+
if (!animationTarget) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this._timeline = createTimeline({ defaults: { duration: 750 } });
|
|
170
|
+
if (!this._timeline) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this.eventHooks.defineSetPosition((position) => {
|
|
174
|
+
this._timeline?.add(animationTarget, {
|
|
175
|
+
translateX: position[0],
|
|
176
|
+
translateY: position[1],
|
|
177
|
+
duration: 1
|
|
178
|
+
});
|
|
179
|
+
this._timeline?.play();
|
|
180
|
+
});
|
|
181
|
+
this.eventHooks.defineAddPositionToQueue((position) => {
|
|
182
|
+
this._timeline?.add(animationTarget, {
|
|
183
|
+
translateX: position[0],
|
|
184
|
+
translateY: position[1],
|
|
185
|
+
duration: 1e3
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
this.eventHooks.defineSetShowCursor((show) => {
|
|
189
|
+
this.isShowingCursor = show;
|
|
190
|
+
});
|
|
191
|
+
this.eventHooks.definePlayQueue(() => {
|
|
192
|
+
this._timeline?.play();
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// Getters
|
|
196
|
+
get cursorRef() {
|
|
197
|
+
return this._cursorRef.value;
|
|
198
|
+
}
|
|
199
|
+
get labelRef() {
|
|
200
|
+
return this._labelRef.value;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
// Define scoped styles right with your component, in plain CSS
|
|
204
|
+
AiCursorComponent.styles = AiCursorComponentStyle;
|
|
205
|
+
__decorateClass([
|
|
206
|
+
property({
|
|
207
|
+
type: Object
|
|
208
|
+
})
|
|
209
|
+
], AiCursorComponent.prototype, "eventHooks", 2);
|
|
210
|
+
__decorateClass([
|
|
211
|
+
property({ type: Boolean })
|
|
212
|
+
], AiCursorComponent.prototype, "isShowingCursor", 2);
|
|
213
|
+
__decorateClass([
|
|
214
|
+
property({ type: String })
|
|
215
|
+
], AiCursorComponent.prototype, "labelText", 2);
|
|
216
|
+
__decorateClass([
|
|
217
|
+
property({ type: Array })
|
|
218
|
+
], AiCursorComponent.prototype, "cursorPosition", 2);
|
|
219
|
+
__decorateClass([
|
|
220
|
+
state()
|
|
221
|
+
], AiCursorComponent.prototype, "_cursorRef", 2);
|
|
222
|
+
__decorateClass([
|
|
223
|
+
state()
|
|
224
|
+
], AiCursorComponent.prototype, "_labelRef", 2);
|
|
225
|
+
AiCursorComponent = __decorateClass([
|
|
226
|
+
customElement("ai-cursor")
|
|
227
|
+
], AiCursorComponent);
|
|
228
|
+
|
|
229
|
+
// src/ui/ai-cursor/rendering/index.ts
|
|
230
|
+
var mountAiCursor = (aiCursorProps) => {
|
|
231
|
+
const root = document.body;
|
|
232
|
+
const cursor = document.createElement("ai-cursor");
|
|
233
|
+
cursor.eventHooks = aiCursorProps.eventHooks;
|
|
234
|
+
root.appendChild(cursor);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/ui/ai-cursor/AiCursor.ts
|
|
238
|
+
var AiCursor = class _AiCursor {
|
|
239
|
+
constructor() {
|
|
240
|
+
}
|
|
241
|
+
// Static constructors
|
|
242
|
+
static spawn() {
|
|
243
|
+
const newCursor = new _AiCursor();
|
|
244
|
+
newCursor.mount();
|
|
245
|
+
return newCursor;
|
|
246
|
+
}
|
|
247
|
+
jumpTo(target) {
|
|
248
|
+
const position = targetToPosition(target);
|
|
249
|
+
if (position) {
|
|
250
|
+
this.setPosition?.(position);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
moveTo(target) {
|
|
254
|
+
const position = targetToPosition(target);
|
|
255
|
+
if (position) {
|
|
256
|
+
this.addPositionToQueue?.(position);
|
|
257
|
+
this.playQueue?.();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
scheduleMoves(targets) {
|
|
261
|
+
targets.forEach((target) => {
|
|
262
|
+
const position = targetToPosition(target);
|
|
263
|
+
if (position) {
|
|
264
|
+
this.addPositionToQueue?.(position);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
this.playQueue?.();
|
|
268
|
+
}
|
|
269
|
+
show() {
|
|
270
|
+
this.setShowCursor?.(true);
|
|
271
|
+
}
|
|
272
|
+
hide() {
|
|
273
|
+
this.setShowCursor?.(false);
|
|
274
|
+
}
|
|
275
|
+
mount() {
|
|
276
|
+
mountAiCursor({
|
|
277
|
+
eventHooks: {
|
|
278
|
+
defineSetPosition: (callback) => {
|
|
279
|
+
this.setPosition = callback;
|
|
280
|
+
},
|
|
281
|
+
defineAddPositionToQueue: (callback) => {
|
|
282
|
+
this.addPositionToQueue = callback;
|
|
283
|
+
},
|
|
284
|
+
definePlayQueue: (callback) => {
|
|
285
|
+
this.playQueue = callback;
|
|
286
|
+
},
|
|
287
|
+
defineSetShowCursor: (callback) => {
|
|
288
|
+
this.setShowCursor = callback;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
function calculateClickPositionFromElement(element) {
|
|
295
|
+
const rect = element.getBoundingClientRect();
|
|
296
|
+
return [rect.left + rect.width / 2, rect.top + rect.height / 2];
|
|
297
|
+
}
|
|
298
|
+
function targetToPosition(target) {
|
|
299
|
+
if (Array.isArray(target) && target.length === 2 && typeof target[0] === "number" && typeof target[1] === "number") {
|
|
300
|
+
return target;
|
|
301
|
+
} else if (target instanceof HTMLElement) {
|
|
302
|
+
return calculateClickPositionFromElement(target);
|
|
303
|
+
} else if (typeof target === "string") {
|
|
304
|
+
const element = document.querySelector(target);
|
|
305
|
+
if (element) {
|
|
306
|
+
return calculateClickPositionFromElement(element);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return void 0;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export { AiCursor };
|
|
313
|
+
//# sourceMappingURL=out.js.map
|
|
314
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ui/ai-cursor/rendering/AiCursorComponent.ts","../../src/ui/ai-cursor/rendering/AiCursorComponent.style.ts","../../src/ui/ai-cursor/rendering/index.ts","../../src/ui/ai-cursor/AiCursor.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,SAAS,YAA4C,YAAY;AACjE,SAAS,eAAe,UAAU,aAAa;AAC/C,SAAS,WAAW,WAAW;AAC/B,SAAS,sBAAgC;;;ACHzC,SAAS,WAAW;AAEb,IAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ADoB/B,IAAM,oBAAN,cAAgC,WAAW;AAAA,EA0BhD,cAAc;AACZ,UAAM;AAvBR,sBAAkC;AAAA,MAChC,mBAAmB,MAAM;AAAA,MAAC;AAAA,MAC1B,0BAA0B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,SAAS,CAAC;AAChE;AAEA,SAAS,iBAAiB,QAAoD;AAC5E,MACE,MAAM,QAAQ,MAAM,KACpB,OAAO,WAAW,KAClB,OAAO,OAAO,CAAC,MAAM,YACrB,OAAO,OAAO,CAAC,MAAM,UACrB;AACA,WAAO;AAAA,EACT,WAAW,kBAAkB,aAAa;AACxC,WAAO,kCAAkC,MAAM;AAAA,EACjD,WAAW,OAAO,WAAW,UAAU;AACrC,UAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,QAAI,SAAS;AACX,aAAO,kCAAkC,OAAO;AAAA,IAClD;AAAA,EACF;AACA,SAAO;AACT","sourcesContent":["import { LitElement, PropertyValues, TemplateResult, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport { createRef, ref } from 'lit/directives/ref.js';\nimport { createTimeline, Timeline } from 'animejs';\nimport { AiCursorComponentStyle } from './AiCursorComponent.style';\n\nexport type Props = {\n /**\n * The event hooks are functions that let you connect the inner logic of the solid js component and the AiCursor Class that acts\n * as an API.\n */\n eventHooks: {\n defineSetPosition: (fn: (position: [number, number]) => void) => void;\n defineAddPositionToQueue: (\n fn: (position: [number, number]) => void\n ) => void;\n definePlayQueue: (fn: () => void) => void;\n defineSetShowCursor: (fn: (show: boolean) => void) => void;\n };\n};\n\n@customElement('ai-cursor')\nexport class AiCursorComponent extends LitElement {\n @property({\n type: Object,\n })\n eventHooks: Props['eventHooks'] = {\n defineSetPosition: () => {},\n defineAddPositionToQueue: () => {},\n definePlayQueue: () => {},\n defineSetShowCursor: () => {},\n };\n\n @property({ type: Boolean })\n isShowingCursor = true;\n @property({ type: String })\n labelText = 'AI Cursor';\n\n @property({ type: Array })\n cursorPosition: [number, number] = [0, 0];\n\n private _timeline: Timeline | undefined;\n\n @state()\n private _cursorRef = createRef<HTMLSpanElement>();\n @state()\n private _labelRef = createRef<HTMLSpanElement>();\n\n constructor() {\n super();\n }\n\n updated(_changedProperties: PropertyValues): void {\n if (_changedProperties.has('_cursorRef')) {\n if (this._cursorRef.value) {\n this.hookUpCallbacks();\n } else {\n this._timeline?.pause();\n this._timeline?.refresh();\n }\n }\n super.updated(_changedProperties);\n }\n\n // Define scoped styles right with your component, in plain CSS\n static styles = AiCursorComponentStyle;\n\n render(): TemplateResult {\n const cursorSvg = html`\n <svg\n width=${24}\n height=${24}\n viewBox=\"0 0 100 100\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <g clip-path=\"url(#clip0_3576_285)\">\n <path\n class=\"cursor-path\"\n d=\"M2.14849 7.04749C1.35153 4.07321 4.07319 1.35155 7.04747 2.14851L77.3148 20.9766C80.2891 21.7735 81.2853 25.4914 79.108 27.6687L27.6687 79.108C25.4914 81.2853 21.7735 80.2891 20.9766 77.3149L2.14849 7.04749Z\"\n fill=\"currentColor\"\n />\n </g>\n <defs>\n <clipPath id=\"clip0_3576_285\">\n <rect width=\"100\" height=\"100\" fill=\"white\" />\n </clipPath>\n </defs>\n </svg>\n `;\n\n return html`\n <span\n id=\"cursor-graphic-parent\"\n ${ref(this._cursorRef)}\n ?hidden=${!this.isShowingCursor}\n >\n ${cursorSvg}\n <span\n ${ref(this._labelRef)}\n id=\"label-text\"\n ?hidden=${!this.isShowingCursor}\n >${this.labelText}</span\n >\n </span>\n `;\n }\n\n // private methods\n\n /**\n * The primary way to control the cursor is using an external API.\n * This interface exposes controlling methods. The Lit Component itself is\n * intended to be a controlled component.\n */\n private hookUpCallbacks(): void {\n const animationTarget = this._cursorRef.value;\n\n if (!animationTarget) {\n return;\n }\n\n this._timeline = createTimeline({ defaults: { duration: 750 } });\n\n if (!this._timeline) {\n return;\n }\n\n this.eventHooks.defineSetPosition((position) => {\n this._timeline?.add(animationTarget, {\n translateX: position[0],\n translateY: position[1],\n duration: 1,\n });\n this._timeline?.play();\n });\n\n this.eventHooks.defineAddPositionToQueue((position) => {\n this._timeline?.add(animationTarget, {\n translateX: position[0],\n translateY: position[1],\n duration: 1000,\n });\n });\n\n this.eventHooks.defineSetShowCursor((show) => {\n this.isShowingCursor = show;\n });\n\n this.eventHooks.definePlayQueue(() => {\n this._timeline?.play();\n });\n }\n\n // Getters\n get cursorRef(): HTMLSpanElement | undefined {\n return this._cursorRef.value;\n }\n\n get labelRef(): HTMLSpanElement | undefined {\n return this._labelRef.value;\n }\n}\n","import { css } from 'lit';\n\nexport const AiCursorComponentStyle = css`\n :host {\n --ai-local-cursor-size: var(--sk-ai-cursor-size, 1rem);\n --ai-local-cursor-label-padding: var(\n --sk-ai-cursor-label-padding,\n 0.25rem 0.25rem\n );\n --ai-local-cursor-border-radius: var(--sk-ai-cursor-border-radius, 0.25rem);\n --ai-local-label-offset: var(--sk-ai-cursor-label-offset, 1rem);\n\n --ai-local-label-font-size: var(--sk-ai-cursor-label-font-size, 12px);\n --ai-local-label-font-weight: var(--sk-ai-cursor-label-font-weight, bold);\n --ai-local-label-color: var(--sk-ai-cursor-label-color, white);\n --ai-local-label-background-color: var(\n --sk-ai-cursor-label-background-color,\n black\n );\n --ai-local-label-border-color: var(\n --sk-ai-cursor-label-border-color,\n white\n );\n --ai-local-label-border-width: var(\n --sk-ai-cursor-label-border-width,\n 0.1rem\n );\n\n color: black;\n stroke: white;\n position: absolute;\n /* Insetting in the parent element (body) */\n top: 0;\n left: 0;\n bottom: 0;\n right: 0;\n pointer-events: none;\n width: var(--ai-local-cursor-size);\n height: var(--ai-local-cursor-size);\n }\n\n #cursor-graphic-parent {\n position: absolute;\n top: 0;\n left: 0;\n }\n\n #label-text {\n position: absolute;\n color: white;\n font-size: 12px;\n font-weight: bold;\n padding: var(--ai-local-cursor-label-padding);\n border-radius: var(--ai-local-cursor-border-radius);\n\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n\n width: fit-content;\n min-width: fit-content;\n top: var(--ai-local-label-offset);\n left: var(--ai-local-label-offset);\n\n border: var(--ai-local-label-border-width) solid\n var(--ai-local-label-border-color);\n background-color: var(--ai-local-label-background-color);\n color: var(--ai-local-label-color);\n font-size: var(--ai-local-label-font-size);\n font-weight: var(--ai-local-label-font-weight);\n }\n`;\n","import './AiCursorComponent';\nimport { AiCursorComponent, Props as AiCursorProps } from './AiCursorComponent';\n/**\n * The AI Cursor is a Lit Element.\n * Why Lit.dev?\n * Lit.dev is a tiny on memory and bundle size. It is quite fast in rendering.\n * And since UI elements in this library shall be isolated and scoped components,\n * Lit.dev is a good fit.\n * It follows reactivity principles with very fine granularity,\n *\n * Also Solid.js (which was the first version of that - prooved to be annoying because of jsx compiler extras).\n *\n * A downside of Lit.dev is that it is not a very common library. Further, it is close to the DOM using native DOM APIs.\n * Causing it to be a bit different than libs like react using virtual DOM.\n * For other contributors I would recommend reading the /life-cycle section of the docs.\n *\n * Author: @Pascal-Lohscheidt\n */\nexport const mountAiCursor = (aiCursorProps: AiCursorProps): void => {\n const root = document.body;\n const cursor = document.createElement('ai-cursor') as AiCursorComponent;\n cursor.eventHooks = aiCursorProps.eventHooks;\n\n root.appendChild(cursor);\n};\n","import { mountAiCursor } from './rendering';\nimport { Props as AiCursorProps } from './rendering/AiCursorComponent';\n\ntype Selector = string;\ntype CursorTarget = HTMLElement | Selector | [number, number];\n\n/**\n * The AiCursor is a class that is used to create a cursor element and acts an interface to control the cursor.\n * It is used to move the cursor to a target, show or hide the cursor, and to schedule moves.\n *\n * @example\n * ```ts\n * const cursor = AiCursor.spawn();\n * cursor.moveTo('#target-element');\n * ```\n *\n * @author @Pascal-Lohscheidt\n */\nexport class AiCursor {\n private setPosition?: (position: [number, number]) => void;\n private addPositionToQueue?: (position: [number, number]) => void;\n private playQueue?: () => void;\n private setShowCursor?: (show: boolean) => void;\n\n constructor() {}\n\n // Static constructors\n static spawn(): AiCursor {\n const newCursor = new AiCursor();\n newCursor.mount();\n return newCursor;\n }\n\n jumpTo(target: CursorTarget): void {\n const position = targetToPosition(target);\n if (position) {\n this.setPosition?.(position);\n }\n }\n\n moveTo(target: CursorTarget): void {\n const position = targetToPosition(target);\n if (position) {\n this.addPositionToQueue?.(position);\n this.playQueue?.();\n }\n }\n\n scheduleMoves(targets: CursorTarget[]): void {\n targets.forEach((target) => {\n const position = targetToPosition(target);\n if (position) {\n this.addPositionToQueue?.(position);\n }\n });\n this.playQueue?.();\n }\n\n show(): void {\n this.setShowCursor?.(true);\n }\n\n hide(): void {\n this.setShowCursor?.(false);\n }\n\n private mount(): void {\n mountAiCursor({\n eventHooks: {\n defineSetPosition: (callback): void => {\n this.setPosition = callback;\n },\n defineAddPositionToQueue: (callback): void => {\n this.addPositionToQueue = callback;\n },\n definePlayQueue: (callback): void => {\n this.playQueue = callback;\n },\n defineSetShowCursor: (callback): void => {\n this.setShowCursor = callback;\n },\n },\n } satisfies AiCursorProps);\n }\n}\n\nfunction calculateClickPositionFromElement(element: Element): [number, number] {\n const rect = element.getBoundingClientRect();\n return [rect.left + rect.width / 2, rect.top + rect.height / 2];\n}\n\nfunction targetToPosition(target: CursorTarget): [number, number] | undefined {\n if (\n Array.isArray(target) &&\n target.length === 2 &&\n typeof target[0] === 'number' &&\n typeof target[1] === 'number'\n ) {\n return target;\n } else if (target instanceof HTMLElement) {\n return calculateClickPositionFromElement(target);\n } else if (typeof target === 'string') {\n const element = document.querySelector(target);\n if (element) {\n return calculateClickPositionFromElement(element);\n }\n }\n return undefined;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@m4trix/core",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "A powerful TypeScript library for building AI-driven web applications",
|
|
5
|
+
"main": "./dist/index/index.cjs",
|
|
6
|
+
"module": "./dist/index/index.js",
|
|
7
|
+
"types": "./dist/index/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index/index.d.ts",
|
|
11
|
+
"import": "./dist/index/index.js",
|
|
12
|
+
"require": "./dist/index/index.cjs",
|
|
13
|
+
"default": "./dist/index/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./react": {
|
|
16
|
+
"types": "./dist/react/index.d.ts",
|
|
17
|
+
"import": "./dist/react/index.js",
|
|
18
|
+
"require": "./dist/react/index.cjs",
|
|
19
|
+
"default": "./dist/react/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./ui": {
|
|
22
|
+
"types": "./dist/ui/index.d.ts",
|
|
23
|
+
"import": "./dist/ui/index.js",
|
|
24
|
+
"require": "./dist/ui/index.cjs",
|
|
25
|
+
"default": "./dist/ui/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./stream": {
|
|
28
|
+
"types": "./dist/stream/index.d.ts",
|
|
29
|
+
"import": "./dist/stream/index.js",
|
|
30
|
+
"require": "./dist/stream/index.cjs",
|
|
31
|
+
"default": "./dist/stream/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./api": {
|
|
34
|
+
"types": "./dist/api/index.d.ts",
|
|
35
|
+
"import": "./dist/api/index.js",
|
|
36
|
+
"require": "./dist/api/index.cjs",
|
|
37
|
+
"default": "./dist/api/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./helper": {
|
|
40
|
+
"types": "./dist/helper/index.d.ts",
|
|
41
|
+
"import": "./dist/helper/index.js",
|
|
42
|
+
"require": "./dist/helper/index.cjs",
|
|
43
|
+
"default": "./dist/helper/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"dev": "tsup --watch",
|
|
52
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
53
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
54
|
+
"prepare": "pnpm run build",
|
|
55
|
+
"publish-package": "npm publish --no-git-checks"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"ai",
|
|
59
|
+
"web",
|
|
60
|
+
"typescript",
|
|
61
|
+
"visualization"
|
|
62
|
+
],
|
|
63
|
+
"author": "Pascal Lohscheidt",
|
|
64
|
+
"license": "MIT",
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "^20.0.0",
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
68
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
69
|
+
"@vitest/coverage-v8": "^1.0.0",
|
|
70
|
+
"eslint": "^8.0.0",
|
|
71
|
+
"prettier": "^3.0.0",
|
|
72
|
+
"tsup": "^7.0.0",
|
|
73
|
+
"tsup-preset-solid": "^2.2.0",
|
|
74
|
+
"typescript": "^5.0.0",
|
|
75
|
+
"vitest": "^1.0.0"
|
|
76
|
+
},
|
|
77
|
+
"publishConfig": {
|
|
78
|
+
"access": "public"
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"@floating-ui/dom": "^1.6.13",
|
|
82
|
+
"@langchain/community": "^0.3.47",
|
|
83
|
+
"@langchain/core": "^0.3.61",
|
|
84
|
+
"@langchain/langgraph": "^0.3.6",
|
|
85
|
+
"@langchain/langgraph-sdk": "^0.0.84",
|
|
86
|
+
"@langchain/openai": "^0.5.16",
|
|
87
|
+
"@types/react": "^19.1.2",
|
|
88
|
+
"@types/react-dom": "^19.1.2",
|
|
89
|
+
"ai": "^5.0.28",
|
|
90
|
+
"animejs": "^4.0.1",
|
|
91
|
+
"effect": "^3.16.10",
|
|
92
|
+
"lit": "^3.3.0",
|
|
93
|
+
"react": "^19.1.0",
|
|
94
|
+
"react-dom": "^19.1.0",
|
|
95
|
+
"socket.io": "^4.7.2",
|
|
96
|
+
"socket.io-client": "^4.7.2",
|
|
97
|
+
"solid-js": "^1.9.5"
|
|
98
|
+
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"@floating-ui/dom": ">=1.6.13",
|
|
101
|
+
"@langchain/community": ">=0.3.0",
|
|
102
|
+
"@langchain/core": ">=0.3.0",
|
|
103
|
+
"@langchain/langgraph": ">=0.3.0",
|
|
104
|
+
"@langchain/langgraph-sdk": ">=0.3.0",
|
|
105
|
+
"@langchain/openai": ">=0.3.0",
|
|
106
|
+
"animejs": ">=4.0.1",
|
|
107
|
+
"effect": ">=3.0.0",
|
|
108
|
+
"lit": ">=3.3.0",
|
|
109
|
+
"react": ">=16.8.0 <21.0.0",
|
|
110
|
+
"react-dom": ">=16.8.0 <21.0.0",
|
|
111
|
+
"solid-js": ">=1.9.5"
|
|
112
|
+
},
|
|
113
|
+
"browser": {},
|
|
114
|
+
"type": "module",
|
|
115
|
+
"repository": {
|
|
116
|
+
"type": "git",
|
|
117
|
+
"url": "git+https://github.com/Pascal-Lohscheidt/build-ai.git"
|
|
118
|
+
},
|
|
119
|
+
"bugs": {
|
|
120
|
+
"url": "https://github.com/Pascal-Lohscheidt/build-ai/issues"
|
|
121
|
+
},
|
|
122
|
+
"homepage": "https://github.com/Pascal-Lohscheidt/build-ai#readme"
|
|
123
|
+
}
|