agent-robot-avatar 0.3.1 → 0.5.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/CHANGELOG.md +170 -111
- package/LICENSE +21 -21
- package/README.md +186 -446
- package/agent-robot-avatar.js +28 -25
- package/docs/README.de.md +186 -166
- package/docs/README.es.md +186 -225
- package/docs/README.fr.md +186 -225
- package/docs/README.ja.md +186 -225
- package/docs/README.ko.md +186 -225
- package/docs/README.pt.md +186 -225
- package/docs/README.ru.md +186 -0
- package/docs/README.zh-CN.md +190 -396
- package/docs/README.zh-TW.md +186 -227
- package/index.d.ts +128 -108
- package/package.json +77 -77
- package/src/agent-robot-avatar-actions.js +400 -400
- package/src/agent-robot-avatar-antenna-flash.js +127 -127
- package/src/agent-robot-avatar-antenna.js +152 -152
- package/src/agent-robot-avatar-core.js +1155 -1135
- package/src/agent-robot-avatar-extension-host.js +78 -78
- package/src/agent-robot-avatar-failure.js +131 -131
- package/src/agent-robot-avatar-geometry.js +40 -40
- package/src/agent-robot-avatar-gestures.js +161 -0
- package/src/agent-robot-avatar-head-roundness.js +103 -103
- package/src/agent-robot-avatar-inspect.js +242 -242
- package/src/agent-robot-avatar-love.js +226 -0
- package/src/agent-robot-avatar-random.js +272 -0
- package/src/agent-robot-avatar-runtime.js +905 -875
- package/src/agent-robot-avatar-version.js +3 -3
- package/src/agent-robot-avatar-waiting.js +130 -121
- package/src/agent-robot-avatar-wrap.js +66 -0
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import AgentRobotAvatar from './agent-robot-avatar-extension-host.js';
|
|
2
|
-
import { flattenHeadPoints } from './agent-robot-avatar-geometry.js';
|
|
3
|
-
import { VERSION } from './agent-robot-avatar-version.js';
|
|
4
|
-
|
|
5
|
-
const proto = AgentRobotAvatar.prototype;
|
|
6
|
-
const DEFAULT_ROUNDNESS = 50;
|
|
7
|
-
|
|
8
|
-
function clamp(value, min, max) {
|
|
9
|
-
return Math.max(min, Math.min(max, value));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function ensureDefaultGeometry(instance) {
|
|
13
|
-
if (!instance?._headShape || !instance._baseHeadPoints?.length) return false;
|
|
14
|
-
if (instance._headRoundnessDefaultPoints?.length) return true;
|
|
15
|
-
|
|
16
|
-
let points = instance._baseHeadPoints.map(point => ({ x: point.x, y: point.y }));
|
|
17
|
-
|
|
18
|
-
if (!instance._headFlattenedR32) {
|
|
19
|
-
points = flattenHeadPoints(points);
|
|
20
|
-
instance._headFlattenedR32 = true;
|
|
21
|
-
instance._baseHeadPoints = points.map(point => ({ ...point }));
|
|
22
|
-
instance._baseHeadPathD = instance._pointsToPath(points);
|
|
23
|
-
instance._headShape.setAttribute('d', instance._baseHeadPathD);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
instance._headRoundnessDefaultPoints = instance._baseHeadPoints.map(point => ({ x: point.x, y: point.y }));
|
|
27
|
-
instance._headRoundness = DEFAULT_ROUNDNESS;
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function superellipsePoint(angle, cx, cy, halfW, halfH, exponent) {
|
|
32
|
-
const cos = Math.cos(angle);
|
|
33
|
-
const sin = Math.sin(angle);
|
|
34
|
-
const xTerm = Math.pow(Math.abs(cos) / Math.max(0.001, halfW), exponent);
|
|
35
|
-
const yTerm = Math.pow(Math.abs(sin) / Math.max(0.001, halfH), exponent);
|
|
36
|
-
const denom = Math.pow(xTerm + yTerm, 1 / exponent);
|
|
37
|
-
const radius = denom > 0 ? 1 / denom : 0;
|
|
38
|
-
return { x: cx + cos * radius, y: cy + sin * radius };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function targetShape(points, exponent) {
|
|
42
|
-
const minX = Math.min(...points.map(point => point.x));
|
|
43
|
-
const maxX = Math.max(...points.map(point => point.x));
|
|
44
|
-
const minY = Math.min(...points.map(point => point.y));
|
|
45
|
-
const maxY = Math.max(...points.map(point => point.y));
|
|
46
|
-
const cx = (minX + maxX) / 2;
|
|
47
|
-
const cy = (minY + maxY) / 2;
|
|
48
|
-
const halfW = (maxX - minX) / 2;
|
|
49
|
-
const halfH = (maxY - minY) / 2;
|
|
50
|
-
|
|
51
|
-
return points.map(point => {
|
|
52
|
-
const angle = Math.atan2(point.y - cy, point.x - cx);
|
|
53
|
-
return superellipsePoint(angle, cx, cy, halfW, halfH, exponent);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function mixPoints(from, to, amount) {
|
|
58
|
-
const t = clamp(amount, 0, 1);
|
|
59
|
-
return from.map((point, index) => ({
|
|
60
|
-
x: point.x + (to[index].x - point.x) * t,
|
|
61
|
-
y: point.y + (to[index].y - point.y) * t,
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
proto.setHeadRoundness = function(value = DEFAULT_ROUNDNESS) {
|
|
66
|
-
if (!ensureDefaultGeometry(this)) return this;
|
|
67
|
-
|
|
68
|
-
const roundness = clamp(Number(value) || 0, 0, 100);
|
|
69
|
-
const baseline = this._headRoundnessDefaultPoints;
|
|
70
|
-
let points = baseline.map(point => ({ ...point }));
|
|
71
|
-
|
|
72
|
-
if (roundness < DEFAULT_ROUNDNESS) {
|
|
73
|
-
const squarer = targetShape(baseline, 10);
|
|
74
|
-
points = mixPoints(baseline, squarer, (DEFAULT_ROUNDNESS - roundness) / DEFAULT_ROUNDNESS);
|
|
75
|
-
} else if (roundness > DEFAULT_ROUNDNESS) {
|
|
76
|
-
const rounder = targetShape(baseline, 2.2);
|
|
77
|
-
points = mixPoints(baseline, rounder, (roundness - DEFAULT_ROUNDNESS) / DEFAULT_ROUNDNESS);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this._headRoundness = roundness;
|
|
81
|
-
this._baseHeadPoints = points;
|
|
82
|
-
this._baseHeadPathD = this._pointsToPath(points);
|
|
83
|
-
|
|
84
|
-
if (this._dragJelly?.active || this._dragJelly?.returning) this._applyHeadDeform?.();
|
|
85
|
-
else this._headShape.setAttribute('d', this._baseHeadPathD);
|
|
86
|
-
|
|
87
|
-
this.dispatchEvent(new CustomEvent('head-roundness-change', {
|
|
88
|
-
detail: { value: roundness, version: VERSION }
|
|
89
|
-
}));
|
|
90
|
-
return this;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
proto.getHeadRoundness = function() {
|
|
94
|
-
return Number.isFinite(this._headRoundness) ? this._headRoundness : DEFAULT_ROUNDNESS;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
if (typeof window !== 'undefined') {
|
|
98
|
-
window.AgentRobotAvatarVersion = VERSION;
|
|
99
|
-
window.AgentRobotAvatarHeadRoundnessDefault = DEFAULT_ROUNDNESS;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { AgentRobotAvatar, DEFAULT_ROUNDNESS, VERSION };
|
|
103
|
-
export default AgentRobotAvatar;
|
|
1
|
+
import AgentRobotAvatar from './agent-robot-avatar-extension-host.js';
|
|
2
|
+
import { flattenHeadPoints } from './agent-robot-avatar-geometry.js';
|
|
3
|
+
import { VERSION } from './agent-robot-avatar-version.js';
|
|
4
|
+
|
|
5
|
+
const proto = AgentRobotAvatar.prototype;
|
|
6
|
+
const DEFAULT_ROUNDNESS = 50;
|
|
7
|
+
|
|
8
|
+
function clamp(value, min, max) {
|
|
9
|
+
return Math.max(min, Math.min(max, value));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function ensureDefaultGeometry(instance) {
|
|
13
|
+
if (!instance?._headShape || !instance._baseHeadPoints?.length) return false;
|
|
14
|
+
if (instance._headRoundnessDefaultPoints?.length) return true;
|
|
15
|
+
|
|
16
|
+
let points = instance._baseHeadPoints.map(point => ({ x: point.x, y: point.y }));
|
|
17
|
+
|
|
18
|
+
if (!instance._headFlattenedR32) {
|
|
19
|
+
points = flattenHeadPoints(points);
|
|
20
|
+
instance._headFlattenedR32 = true;
|
|
21
|
+
instance._baseHeadPoints = points.map(point => ({ ...point }));
|
|
22
|
+
instance._baseHeadPathD = instance._pointsToPath(points);
|
|
23
|
+
instance._headShape.setAttribute('d', instance._baseHeadPathD);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
instance._headRoundnessDefaultPoints = instance._baseHeadPoints.map(point => ({ x: point.x, y: point.y }));
|
|
27
|
+
instance._headRoundness = DEFAULT_ROUNDNESS;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function superellipsePoint(angle, cx, cy, halfW, halfH, exponent) {
|
|
32
|
+
const cos = Math.cos(angle);
|
|
33
|
+
const sin = Math.sin(angle);
|
|
34
|
+
const xTerm = Math.pow(Math.abs(cos) / Math.max(0.001, halfW), exponent);
|
|
35
|
+
const yTerm = Math.pow(Math.abs(sin) / Math.max(0.001, halfH), exponent);
|
|
36
|
+
const denom = Math.pow(xTerm + yTerm, 1 / exponent);
|
|
37
|
+
const radius = denom > 0 ? 1 / denom : 0;
|
|
38
|
+
return { x: cx + cos * radius, y: cy + sin * radius };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function targetShape(points, exponent) {
|
|
42
|
+
const minX = Math.min(...points.map(point => point.x));
|
|
43
|
+
const maxX = Math.max(...points.map(point => point.x));
|
|
44
|
+
const minY = Math.min(...points.map(point => point.y));
|
|
45
|
+
const maxY = Math.max(...points.map(point => point.y));
|
|
46
|
+
const cx = (minX + maxX) / 2;
|
|
47
|
+
const cy = (minY + maxY) / 2;
|
|
48
|
+
const halfW = (maxX - minX) / 2;
|
|
49
|
+
const halfH = (maxY - minY) / 2;
|
|
50
|
+
|
|
51
|
+
return points.map(point => {
|
|
52
|
+
const angle = Math.atan2(point.y - cy, point.x - cx);
|
|
53
|
+
return superellipsePoint(angle, cx, cy, halfW, halfH, exponent);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function mixPoints(from, to, amount) {
|
|
58
|
+
const t = clamp(amount, 0, 1);
|
|
59
|
+
return from.map((point, index) => ({
|
|
60
|
+
x: point.x + (to[index].x - point.x) * t,
|
|
61
|
+
y: point.y + (to[index].y - point.y) * t,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
proto.setHeadRoundness = function(value = DEFAULT_ROUNDNESS) {
|
|
66
|
+
if (!ensureDefaultGeometry(this)) return this;
|
|
67
|
+
|
|
68
|
+
const roundness = clamp(Number(value) || 0, 0, 100);
|
|
69
|
+
const baseline = this._headRoundnessDefaultPoints;
|
|
70
|
+
let points = baseline.map(point => ({ ...point }));
|
|
71
|
+
|
|
72
|
+
if (roundness < DEFAULT_ROUNDNESS) {
|
|
73
|
+
const squarer = targetShape(baseline, 10);
|
|
74
|
+
points = mixPoints(baseline, squarer, (DEFAULT_ROUNDNESS - roundness) / DEFAULT_ROUNDNESS);
|
|
75
|
+
} else if (roundness > DEFAULT_ROUNDNESS) {
|
|
76
|
+
const rounder = targetShape(baseline, 2.2);
|
|
77
|
+
points = mixPoints(baseline, rounder, (roundness - DEFAULT_ROUNDNESS) / DEFAULT_ROUNDNESS);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this._headRoundness = roundness;
|
|
81
|
+
this._baseHeadPoints = points;
|
|
82
|
+
this._baseHeadPathD = this._pointsToPath(points);
|
|
83
|
+
|
|
84
|
+
if (this._dragJelly?.active || this._dragJelly?.returning) this._applyHeadDeform?.();
|
|
85
|
+
else this._headShape.setAttribute('d', this._baseHeadPathD);
|
|
86
|
+
|
|
87
|
+
this.dispatchEvent(new CustomEvent('head-roundness-change', {
|
|
88
|
+
detail: { value: roundness, version: VERSION }
|
|
89
|
+
}));
|
|
90
|
+
return this;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
proto.getHeadRoundness = function() {
|
|
94
|
+
return Number.isFinite(this._headRoundness) ? this._headRoundness : DEFAULT_ROUNDNESS;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
if (typeof window !== 'undefined') {
|
|
98
|
+
window.AgentRobotAvatarVersion = VERSION;
|
|
99
|
+
window.AgentRobotAvatarHeadRoundnessDefault = DEFAULT_ROUNDNESS;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { AgentRobotAvatar, DEFAULT_ROUNDNESS, VERSION };
|
|
103
|
+
export default AgentRobotAvatar;
|