@7ots/cli 0.1.19 → 0.1.36
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/.env.example +14 -0
- package/brand/logos/base.svg +1 -0
- package/brand/logos/clawpump.png +0 -0
- package/brand/logos/conductors.svg +1 -0
- package/brand/logos/notlogin.svg +12 -0
- package/brand/logos/pumpfun.png +0 -0
- package/brand/logos/solana.png +0 -0
- package/brand/logos/spawnerbot.svg +1 -0
- package/brand/logos/virtuals.png +0 -0
- package/cli/7ots.mjs +59 -1
- package/cli/lib/account.mjs +23 -3
- package/cli/lib/assistant.mjs +88 -13
- package/cli/lib/brain.mjs +76 -8
- package/cli/lib/config.mjs +14 -3
- package/cli/lib/desktop-sync.mjs +177 -0
- package/cli/lib/i18n.mjs +9 -0
- package/cli/lib/inferences.mjs +19 -2
- package/cli/lib/integrations.mjs +61 -6
- package/cli/lib/pet-server.mjs +316 -41
- package/cli/lib/prompts.mjs +1 -1
- package/cli/lib/senses/gestures.mjs +121 -0
- package/cli/lib/senses/index.mjs +490 -0
- package/cli/lib/senses/rules.mjs +159 -0
- package/cli/lib/senses/sources/activity.mjs +95 -0
- package/cli/lib/senses/sources/calendar.mjs +75 -0
- package/cli/lib/senses/sources/index.mjs +17 -0
- package/cli/lib/senses/sources/mail.mjs +48 -0
- package/cli/lib/senses/sources/system.mjs +39 -0
- package/cli/lib/senses/util.mjs +41 -0
- package/cli/lib/senses/vendor.mjs +78 -0
- package/cli/lib/stt-local.py +16 -8
- package/cli/lib/stt.mjs +53 -6
- package/cli/lib/tooluse.mjs +56 -0
- package/cli/lib/vm.mjs +1 -1
- package/cli/lib/wake-local.py +109 -0
- package/cli/lib/wake.mjs +102 -0
- package/cli/pet/electron/main.cjs +137 -13
- package/cli/pet/pet.html +125 -26
- package/cli/pet/senses.html +342 -0
- package/cli/pet/settings.html +787 -86
- package/dist/7ots.esm.js +373 -146
- package/dist/7ots.esm.js.map +4 -4
- package/dist/7ots.iife.js +373 -146
- package/dist/7ots.iife.js.map +4 -4
- package/llms.txt +27 -0
- package/package.json +5 -2
- package/server/channels/apuchat.mjs +2 -0
- package/server/errors.mjs +90 -0
- package/server/notify.mjs +78 -0
- package/server/server.mjs +68 -12
- package/server/settings.mjs +3 -0
- package/server/site.mjs +401 -0
- package/server/tts.mjs +29 -5
- package/src/avatar/AvatarStage.js +2 -2
- package/src/avatar/three.js +3 -2
- package/src/character/AvatarEditor.js +2 -1
- package/src/character/Character.js +1 -1
- package/src/character/TradingCard.js +2 -0
- package/src/character/beat.js +64 -2
- package/src/character/mods/orc.js +8 -1
- package/src/character/mods.js +104 -10
- package/src/character/motion.js +162 -0
- package/src/character/parts.js +40 -38
- package/src/character/styles.js +40 -38
- package/src/character3d/Character3D.js +26 -5
- package/src/character3d/body.js +14 -12
- package/src/character3d/export.js +693 -0
- package/src/character3d/fx.js +13 -0
- package/src/character3d/index.js +2 -0
- package/src/character3d/materials.js +106 -10
- package/src/character3d/room-themes.js +1184 -0
- package/src/character3d/room.js +487 -0
- package/src/character3d/stage.js +2 -1
- package/src/creator/StepCreator.js +316 -0
- package/src/i18n/index.js +3 -3
- package/src/i18n/messages/character.js +352 -4
- package/src/i18n/messages/creator.js +138 -0
- package/src/i18n/messages/identity.js +89 -1
- package/src/i18n/messages/platform.js +255 -1
- package/src/i18n/messages/server.js +443 -1
- package/src/i18n/messages/widget.js +233 -0
- package/src/identity/random.js +14 -2
- package/src/identity/schema.js +2 -1
- package/src/index.js +9 -2
- package/src/voice/tags.js +22 -0
- package/server/platform/apuchat.mjs +0 -266
- package/server/platform/auth.mjs +0 -337
- package/server/platform/byte.mjs +0 -291
- package/server/platform/connect.mjs +0 -391
- package/server/platform/crypto.mjs +0 -80
- package/server/platform/db.mjs +0 -293
- package/server/platform/device.mjs +0 -247
- package/server/platform/integrations.mjs +0 -169
- package/server/platform/look.mjs +0 -20
- package/server/platform/mods.mjs +0 -222
- package/server/platform/orquesta.mjs +0 -611
- package/server/platform/profile.mjs +0 -182
- package/server/platform/routes.mjs +0 -589
- package/server/platform/runtime.mjs +0 -286
- package/server/platform/sites.mjs +0 -146
- package/server/platform/stage3d.mjs +0 -82
- package/server/platform/store.mjs +0 -469
- package/server/platform/vm.mjs +0 -1057
- package/server/platform/wallet.mjs +0 -255
package/server/site.mjs
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capa pública de 7ots.com sobre los estáticos de site/:
|
|
3
|
+
*
|
|
4
|
+
* - idioma servido desde el servidor: ?lang → cookie 7ots-lang → Accept-Language → inglés.
|
|
5
|
+
* <html lang>, textos data-i18n (site/i18n.js), canonical, hreflang (es/en/pt/zh/hi + x-default),
|
|
6
|
+
* og:locale/og:title/og:description/og:image por idioma.
|
|
7
|
+
* - pie común (ecosistema con logos, privacidad, términos, contacto, idiomas) + botón de feedback.
|
|
8
|
+
* - /site/privacy/ · /site/terms/ · /site/contact/ (site/footer/legal.js)
|
|
9
|
+
* - POST /api/site/contact formulario de contacto/feedback → correo interno (server/notify.mjs)
|
|
10
|
+
* - /robots.txt · /sitemap.xml · página 404 en HTML para navegadores
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { SITE_LANGS, OG_LOCALE, LANG_NAMES, STRINGS, footerHtml, pickLang } from '../site/footer/strings.js';
|
|
14
|
+
import { LEGAL, UPDATED } from '../site/footer/legal.js';
|
|
15
|
+
import siteMessages from '../site/i18n.js';
|
|
16
|
+
import { sendNotify } from './notify.mjs';
|
|
17
|
+
|
|
18
|
+
const env = process.env;
|
|
19
|
+
const BASE = () => (env.PLATFORM_URL || 'https://7ots.com').replace(/\/+$/, '');
|
|
20
|
+
const LANG_COOKIE = '7ots-lang';
|
|
21
|
+
const EMAIL_RE = /^[^\s@]{1,64}@[^\s@]+\.[^\s@]{2,}$/;
|
|
22
|
+
|
|
23
|
+
/** Páginas que llevan el pie común (las demás son apps/embeds con su propia UI). */
|
|
24
|
+
const FOOTER_PAGES = new Set(['site/start/index.html', 'site/index.html']);
|
|
25
|
+
/** Páginas indexables (sitemap). */
|
|
26
|
+
const PUBLIC_PAGES = ['/site/start/', '/site/', '/site/pet/', '/site/plaza/', '/site/contact/', '/site/privacy/', '/site/terms/'];
|
|
27
|
+
|
|
28
|
+
// ───────────────────────────── idioma ─────────────────────────────
|
|
29
|
+
|
|
30
|
+
function cookies(req) {
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const part of String(req.headers.cookie || '').split(';')) {
|
|
33
|
+
const i = part.indexOf('=');
|
|
34
|
+
if (i > 0) out[part.slice(0, i).trim()] = part.slice(i + 1).trim();
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Idioma del sitio para esta petición. */
|
|
40
|
+
export function siteLocale(req, url) {
|
|
41
|
+
const q = (url.searchParams.get('lang') || '').toLowerCase().split('-')[0];
|
|
42
|
+
if (SITE_LANGS.includes(q)) return q;
|
|
43
|
+
const c = (cookies(req)[LANG_COOKIE] || '').toLowerCase().split('-')[0];
|
|
44
|
+
if (SITE_LANGS.includes(c)) return c;
|
|
45
|
+
const prefs = String(req.headers['accept-language'] || '')
|
|
46
|
+
.split(',')
|
|
47
|
+
.map((p, i) => {
|
|
48
|
+
const [tag, ...params] = p.trim().split(';');
|
|
49
|
+
const qv = params.map((x) => x.trim()).find((x) => x.startsWith('q='));
|
|
50
|
+
return { lang: tag.toLowerCase().split('-')[0], q: qv ? Number(qv.slice(2)) || 0 : 1, i };
|
|
51
|
+
})
|
|
52
|
+
.filter((p) => p.lang && p.q > 0)
|
|
53
|
+
.sort((a, b) => b.q - a.q || a.i - b.i);
|
|
54
|
+
for (const p of prefs) if (SITE_LANGS.includes(p.lang)) return p.lang;
|
|
55
|
+
return 'en';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Catálogo del sitio aplanado: lang → Map(clave → texto).
|
|
59
|
+
const flat = {};
|
|
60
|
+
function flatten(obj, prefix, map) {
|
|
61
|
+
for (const [k, v] of Object.entries(obj || {})) {
|
|
62
|
+
const key = prefix ? `${prefix}.${k}` : k;
|
|
63
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) flatten(v, key, map);
|
|
64
|
+
else if (typeof v === 'string') map.set(key, v);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const l of SITE_LANGS) {
|
|
68
|
+
flat[l] = new Map();
|
|
69
|
+
flatten(siteMessages[l], '', flat[l]);
|
|
70
|
+
}
|
|
71
|
+
const msg = (lang, key) => flat[lang]?.get(key);
|
|
72
|
+
|
|
73
|
+
const esc = (v) => String(v ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
74
|
+
const unesc = (v) => String(v ?? '').replace(/&(amp|lt|gt|quot|#39);/g, (m, e) => ({ amp: '&', lt: '<', gt: '>', quot: '"', '#39': "'" })[e]);
|
|
75
|
+
|
|
76
|
+
/** URL de una variante de idioma (en = sin parámetro sería ambiguo con la detección: se marca explícito). */
|
|
77
|
+
const langUrl = (path, l) => `${BASE()}${path}?lang=${l}`;
|
|
78
|
+
|
|
79
|
+
function headTags(path, lang, explicit, { title, description }) {
|
|
80
|
+
const canonical = explicit ? langUrl(path, lang) : `${BASE()}${path}`;
|
|
81
|
+
const alt = SITE_LANGS.map((l) => `<link rel="alternate" hreflang="${l}" href="${langUrl(path, l)}">`).join('\n');
|
|
82
|
+
const ogImg = lang === 'es' ? 'og-es.png' : lang === 'pt' ? 'og-pt.png' : 'og.png';
|
|
83
|
+
const others = SITE_LANGS.filter((l) => l !== lang).map((l) => `<meta property="og:locale:alternate" content="${OG_LOCALE[l]}">`).join('\n');
|
|
84
|
+
const fonts = lang === 'zh' || lang === 'hi'
|
|
85
|
+
? `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=${lang === 'zh' ? 'Noto+Sans+SC' : 'Noto+Sans+Devanagari'}:wght@400;600;700&display=swap">\n<style>:root{--font-body:Inter,${lang === 'zh' ? "'Noto Sans SC'" : "'Noto Sans Devanagari'"},system-ui,sans-serif;--font-display:'Bricolage Grotesque',${lang === 'zh' ? "'Noto Sans SC'" : "'Noto Sans Devanagari'"},Inter,system-ui,sans-serif}</style>`
|
|
86
|
+
: '';
|
|
87
|
+
return [
|
|
88
|
+
`<link rel="canonical" href="${canonical}">`,
|
|
89
|
+
alt,
|
|
90
|
+
`<link rel="alternate" hreflang="x-default" href="${BASE()}${path}">`,
|
|
91
|
+
`<meta property="og:locale" content="${OG_LOCALE[lang]}">`,
|
|
92
|
+
others,
|
|
93
|
+
`<meta property="og:url" content="${canonical}">`,
|
|
94
|
+
title ? `<meta property="og:title" content="${esc(title)}">\n<meta name="twitter:title" content="${esc(title)}">` : '',
|
|
95
|
+
description ? `<meta property="og:description" content="${esc(description)}">\n<meta name="twitter:description" content="${esc(description)}">` : '',
|
|
96
|
+
`<meta property="og:image" content="${BASE()}/brand/${ogImg}">`,
|
|
97
|
+
`<meta name="twitter:image" content="${BASE()}/brand/${ogImg}">`,
|
|
98
|
+
fonts,
|
|
99
|
+
].filter(Boolean).join('\n');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function jsonLd(lang) {
|
|
103
|
+
const data = {
|
|
104
|
+
'@context': 'https://schema.org',
|
|
105
|
+
'@graph': [
|
|
106
|
+
{ '@type': 'Organization', '@id': `${BASE()}/#org`, name: '7ots', url: BASE(), logo: `${BASE()}/brand/apple-touch-icon.png`, sameAs: ['https://github.com/7ots/pet', 'https://www.npmjs.com/package/@7ots/cli'] },
|
|
107
|
+
{ '@type': 'WebSite', '@id': `${BASE()}/#site`, name: '7ots', url: BASE(), inLanguage: SITE_LANGS, publisher: { '@id': `${BASE()}/#org` } },
|
|
108
|
+
{
|
|
109
|
+
'@type': 'SoftwareApplication',
|
|
110
|
+
name: '7ots',
|
|
111
|
+
applicationCategory: 'LifestyleApplication',
|
|
112
|
+
operatingSystem: 'Windows, macOS, Linux, Web',
|
|
113
|
+
description: msg(lang, 'site.meta.description') || msg('en', 'site.meta.description'),
|
|
114
|
+
offers: { '@type': 'Offer', price: '0', priceCurrency: 'USD' },
|
|
115
|
+
url: BASE(),
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
};
|
|
119
|
+
return `<script type="application/ld+json">${JSON.stringify(data).replace(/</g, '\\u003c')}</script>`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Traduce y completa una página HTML de site/ para el idioma de la petición.
|
|
124
|
+
* @param {string} rel ruta relativa al repo (site/start/index.html)
|
|
125
|
+
*/
|
|
126
|
+
export function renderSitePage(req, url, rel, html) {
|
|
127
|
+
const lang = siteLocale(req, url);
|
|
128
|
+
const explicit = SITE_LANGS.includes((url.searchParams.get('lang') || '').toLowerCase());
|
|
129
|
+
const embed = url.searchParams.has('embed');
|
|
130
|
+
const path = url.pathname;
|
|
131
|
+
const tr = (key) => {
|
|
132
|
+
const v = msg(lang, key);
|
|
133
|
+
return v !== undefined && !v.includes('{') ? v : undefined;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
let out = html.replace(/<html\b([^>]*?)\slang=(["'])[^"']*\2/i, `<html$1 lang="${lang}"`);
|
|
137
|
+
if (lang !== 'en') {
|
|
138
|
+
// Texto de elementos con data-i18n y sin hijos.
|
|
139
|
+
out = out.replace(/(<([a-z0-9]+)\b[^>]*?\sdata-i18n="([\w.-]+)"[^>]*>)([^<]*)(<\/\2>)/gi, (m, open, tag, key, inner, close) => {
|
|
140
|
+
const v = tr(key);
|
|
141
|
+
return v === undefined ? m : `${open}${esc(v)}${close}`;
|
|
142
|
+
});
|
|
143
|
+
// Atributos traducibles.
|
|
144
|
+
const ATTRS = { content: 'content', aria: 'aria-label', placeholder: 'placeholder', value: 'value', title: 'title' };
|
|
145
|
+
out = out.replace(/<[a-z0-9]+\b[^>]*\sdata-i18n-(content|aria|placeholder|value|title)="[\w.-]+"[^>]*>/gi, (tagStr) => {
|
|
146
|
+
let t = tagStr;
|
|
147
|
+
for (const [k, attr] of Object.entries(ATTRS)) {
|
|
148
|
+
const km = t.match(new RegExp(`\\sdata-i18n-${k}="([\\w.-]+)"`));
|
|
149
|
+
if (!km) continue;
|
|
150
|
+
const v = tr(km[1]);
|
|
151
|
+
if (v === undefined) continue;
|
|
152
|
+
const re = new RegExp(`(\\s${attr}=)(["'])[^"']*\\2`);
|
|
153
|
+
t = re.test(t) ? t.replace(re, `$1"${esc(v)}"`) : t.replace(/\s*\/?>$/, (end) => ` ${attr}="${esc(v)}"${end}`);
|
|
154
|
+
}
|
|
155
|
+
return t;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const title = unesc((out.match(/<title[^>]*>([^<]*)<\/title>/i) || [])[1] || '');
|
|
160
|
+
const description = unesc((out.match(/<meta\s+name="description"\s+content="([^"]*)"/i) || [])[1] || '');
|
|
161
|
+
// Fuera lo que se vuelve a poner por idioma.
|
|
162
|
+
out = out.replace(/\s*<link rel="canonical"[^>]*>/gi, '')
|
|
163
|
+
.replace(/\s*<link rel="alternate" hreflang=[^>]*>/gi, '')
|
|
164
|
+
.replace(/\s*<meta property="og:(url|title|description|image|locale)"[^>]*>/gi, '')
|
|
165
|
+
.replace(/\s*<meta name="twitter:(title|description|image)"[^>]*>/gi, '');
|
|
166
|
+
|
|
167
|
+
let head = headTags(path, lang, explicit, { title, description }) + '\n<script src="/site/footer/errors.js" defer></script>';
|
|
168
|
+
if (FOOTER_PAGES.has(rel) && !embed) head += `\n<link rel="stylesheet" href="/site/footer/footer.css">\n${jsonLd(lang)}`;
|
|
169
|
+
out = out.replace(/<\/head>/i, `${head}\n</head>`);
|
|
170
|
+
if (FOOTER_PAGES.has(rel) && !embed) {
|
|
171
|
+
out = out.replace(/<\/body>(?![\s\S]*<\/body>)/i, `${footerHtml(lang)}\n<script type="module" src="/site/footer/footer.js"></script>\n</body>`);
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ───────────────────────────── páginas propias ─────────────────────────────
|
|
177
|
+
|
|
178
|
+
function pageShell(req, url, { lang, path, title, description, body, noindex = false }) {
|
|
179
|
+
const explicit = SITE_LANGS.includes((url.searchParams.get('lang') || '').toLowerCase());
|
|
180
|
+
return `<!doctype html>
|
|
181
|
+
<html lang="${lang}">
|
|
182
|
+
<head>
|
|
183
|
+
<meta charset="utf-8">
|
|
184
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
185
|
+
<title>${esc(title)} · 7ots</title>
|
|
186
|
+
<meta name="description" content="${esc(description)}">
|
|
187
|
+
${noindex ? '<meta name="robots" content="noindex">' : ''}
|
|
188
|
+
<meta property="og:type" content="website">
|
|
189
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
190
|
+
<meta name="theme-color" content="#120d33">
|
|
191
|
+
<link rel="icon" type="image/svg+xml" href="/brand/favicon.svg">
|
|
192
|
+
<link rel="apple-touch-icon" href="/brand/apple-touch-icon.png">
|
|
193
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
194
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
195
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,700;12..96,800&family=Inter:wght@400;500;600&display=swap">
|
|
196
|
+
<link rel="stylesheet" href="/brand/tokens.css">
|
|
197
|
+
<link rel="stylesheet" href="/site/footer/footer.css">
|
|
198
|
+
${headTags(path, lang, explicit, { title: `${title} · 7ots`, description })}
|
|
199
|
+
<script src="/site/footer/errors.js" defer></script>
|
|
200
|
+
</head>
|
|
201
|
+
<body class="ots-page">
|
|
202
|
+
<header class="ots-page-top"><a class="ots-page-logo" href="/site/start/${lang === 'en' ? '' : `?lang=${lang}`}" aria-label="7ots.com"><img src="/brand/mark.svg" alt="" width="28" height="28"><span>7ots</span></a></header>
|
|
203
|
+
<main class="ots-page-main">
|
|
204
|
+
${body}
|
|
205
|
+
</main>
|
|
206
|
+
${footerHtml(lang)}
|
|
207
|
+
<script type="module" src="/site/footer/footer.js"></script>
|
|
208
|
+
</body>
|
|
209
|
+
</html>`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function legalBody(lang, doc) {
|
|
213
|
+
const L = LEGAL[lang];
|
|
214
|
+
const d = L[doc];
|
|
215
|
+
const secs = d.sections.map(([h, ps]) => `<section><h2>${esc(h)}</h2>${ps.map((p) => `<p>${esc(p)}</p>`).join('')}</section>`).join('\n');
|
|
216
|
+
return `<article class="ots-legal-doc"><h1>${esc(d.title)}</h1><p class="ots-lead">${esc(d.lead)}</p>${secs}<p class="ots-updated">${esc(L.updated)}: <time datetime="${UPDATED}">${UPDATED}</time></p></article>`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function contactBody(lang, url) {
|
|
220
|
+
const L = LEGAL[lang].contact;
|
|
221
|
+
const t = STRINGS[lang];
|
|
222
|
+
const sent = url.searchParams.get('sent') === '1';
|
|
223
|
+
const err = url.searchParams.get('error');
|
|
224
|
+
const kind = url.searchParams.get('kind') === 'feedback' ? 'feedback' : 'contact';
|
|
225
|
+
if (sent) return `<article class="ots-legal-doc"><h1>${esc(L.sentTitle)}</h1><p class="ots-lead">${esc(t.sent)}</p><p><a href="/site/start/${lang === 'en' ? '' : `?lang=${lang}`}">${esc(L.back)}</a></p></article>`;
|
|
226
|
+
return `<article class="ots-legal-doc"><h1>${esc(kind === 'feedback' ? t.feedbackTitle : L.title)}</h1><p class="ots-lead">${esc(kind === 'feedback' ? t.feedbackLead : L.lead)}</p>
|
|
227
|
+
${err ? `<p class="ots-form-msg err" role="alert">${esc(err === 'invalid' ? t.invalid : t.error)}</p>` : ''}
|
|
228
|
+
<form class="ots-form" method="post" action="/api/site/contact" data-ots-form>
|
|
229
|
+
<input type="hidden" name="kind" value="${kind}">
|
|
230
|
+
<input type="hidden" name="lang" value="${lang}">
|
|
231
|
+
<div class="ots-hp" aria-hidden="true"><label>Website <input name="website" tabindex="-1" autocomplete="off"></label></div>
|
|
232
|
+
<label>${esc(t.name)}<input name="name" maxlength="80" autocomplete="name"></label>
|
|
233
|
+
<label>${esc(kind === 'feedback' ? t.emailOpt : t.email)}<input name="email" type="email" maxlength="200" autocomplete="email"${kind === 'feedback' ? '' : ' required'}></label>
|
|
234
|
+
<label>${esc(t.message)}<textarea name="message" rows="6" maxlength="5000" required></textarea></label>
|
|
235
|
+
<button type="submit" class="ots-btn">${esc(t.send)}</button>
|
|
236
|
+
</form></article>`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ───────────────────────────── contacto / feedback ─────────────────────────────
|
|
240
|
+
|
|
241
|
+
const hits = new Map(); // ip → timestamps
|
|
242
|
+
let dayCount = { day: '', n: 0 };
|
|
243
|
+
function contactAllowed(ip) {
|
|
244
|
+
const now = Date.now();
|
|
245
|
+
const day = new Date(now).toISOString().slice(0, 10);
|
|
246
|
+
if (dayCount.day !== day) dayCount = { day, n: 0 };
|
|
247
|
+
if (dayCount.n >= Number(env.CONTACT_MAX_PER_DAY || 300)) return { ok: false, retry: 3600 };
|
|
248
|
+
const list = (hits.get(ip) || []).filter((t) => now - t < 86400_000);
|
|
249
|
+
const recent = list.filter((t) => now - t < 600_000);
|
|
250
|
+
if (recent.length >= 5) return { ok: false, retry: Math.ceil((600_000 - (now - recent[0])) / 1000) };
|
|
251
|
+
if (list.length >= 20) return { ok: false, retry: Math.ceil((86400_000 - (now - list[0])) / 1000) };
|
|
252
|
+
list.push(now);
|
|
253
|
+
hits.set(ip, list);
|
|
254
|
+
if (hits.size > 5000) hits.clear();
|
|
255
|
+
dayCount.n++;
|
|
256
|
+
return { ok: true };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function readBody(req, limit) {
|
|
260
|
+
let size = 0;
|
|
261
|
+
const chunks = [];
|
|
262
|
+
for await (const c of req) {
|
|
263
|
+
size += c.length;
|
|
264
|
+
if (size > limit) return null;
|
|
265
|
+
chunks.push(c);
|
|
266
|
+
}
|
|
267
|
+
const raw = Buffer.concat(chunks).toString('utf8');
|
|
268
|
+
const type = String(req.headers['content-type'] || '');
|
|
269
|
+
if (type.includes('application/json')) {
|
|
270
|
+
try {
|
|
271
|
+
return JSON.parse(raw || '{}');
|
|
272
|
+
} catch {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return Object.fromEntries(new URLSearchParams(raw));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const clip = (v, n) => String(v ?? '').replace(/\r/g, '').slice(0, n).trim();
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @param {{ send: Function, clientIp: (req) => string, originOf: (req) => string }} deps
|
|
283
|
+
*/
|
|
284
|
+
export function createSite({ send, clientIp, originOf }) {
|
|
285
|
+
function html(res, status, body, req) {
|
|
286
|
+
res.writeHead(status, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-cache', Vary: 'Accept-Language, Cookie', 'X-Content-Type-Options': 'nosniff' });
|
|
287
|
+
res.end(req.method === 'HEAD' ? undefined : body);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function contact(req, res, url) {
|
|
291
|
+
const origin = req.headers.origin;
|
|
292
|
+
if (origin && origin !== originOf(req) && origin !== new URL(BASE()).origin) return send(res, 403, { error: 'origin not allowed' });
|
|
293
|
+
const json = String(req.headers['content-type'] || '').includes('application/json');
|
|
294
|
+
const body = await readBody(req, 32 * 1024);
|
|
295
|
+
const lang = pickLang(body?.lang);
|
|
296
|
+
const kind = body?.kind === 'feedback' ? 'feedback' : 'contact';
|
|
297
|
+
const back = (q) => {
|
|
298
|
+
res.writeHead(303, { Location: `/site/contact/?lang=${lang}&kind=${kind}&${q}`, 'Cache-Control': 'no-store' });
|
|
299
|
+
res.end();
|
|
300
|
+
};
|
|
301
|
+
if (!body) return json ? send(res, 400, { error: 'bad request' }) : back('error=invalid');
|
|
302
|
+
// Honeypot: el bot cree que salió.
|
|
303
|
+
if (body.website) return json ? send(res, 200, { ok: true }) : back('sent=1');
|
|
304
|
+
const message = clip(body.message, 5000);
|
|
305
|
+
const email = clip(body.email, 200).toLowerCase();
|
|
306
|
+
const name = clip(body.name, 80);
|
|
307
|
+
const rating = body.rating === 'up' || body.rating === 'down' ? body.rating : '';
|
|
308
|
+
if (message.length < 2 || (email && !EMAIL_RE.test(email)) || (kind === 'contact' && !email)) {
|
|
309
|
+
return json ? send(res, 400, { error: STRINGS[lang].invalid }) : back('error=invalid');
|
|
310
|
+
}
|
|
311
|
+
const lim = contactAllowed(clientIp(req));
|
|
312
|
+
if (!lim.ok) {
|
|
313
|
+
res.setHeader('Retry-After', String(lim.retry));
|
|
314
|
+
return json ? send(res, 429, { error: STRINGS[lang].error }) : back('error=limit');
|
|
315
|
+
}
|
|
316
|
+
const page = clip(body.page || req.headers.referer, 300);
|
|
317
|
+
const text = [
|
|
318
|
+
message,
|
|
319
|
+
'',
|
|
320
|
+
'—',
|
|
321
|
+
`Tipo: ${kind}${rating ? ` (${rating === 'up' ? '👍' : '👎'})` : ''}`,
|
|
322
|
+
`Nombre: ${name || '-'}`,
|
|
323
|
+
`Email: ${email || '-'}`,
|
|
324
|
+
`Idioma: ${lang}`,
|
|
325
|
+
`Página: ${page || '-'}`,
|
|
326
|
+
`Fecha: ${new Date().toISOString()}`,
|
|
327
|
+
].join('\n');
|
|
328
|
+
try {
|
|
329
|
+
await sendNotify({
|
|
330
|
+
to: env.CONTACT_TO || 'maestro@apumail.com',
|
|
331
|
+
subject: `[7ots ${kind}] ${clip(message.split('\n')[0], 80)}`,
|
|
332
|
+
text,
|
|
333
|
+
replyTo: email || undefined,
|
|
334
|
+
});
|
|
335
|
+
} catch (e) {
|
|
336
|
+
console.warn('[7ots] contacto no enviado:', e.message);
|
|
337
|
+
return json ? send(res, 502, { error: STRINGS[lang].error }) : back('error=send');
|
|
338
|
+
}
|
|
339
|
+
return json ? send(res, 200, { ok: true }) : back('sent=1');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** @returns {Promise<boolean>} true si atendió la petición */
|
|
343
|
+
async function handle(req, res, url) {
|
|
344
|
+
const p = url.pathname;
|
|
345
|
+
const get = req.method === 'GET' || req.method === 'HEAD';
|
|
346
|
+
if (p === '/api/site/contact') {
|
|
347
|
+
if (req.method !== 'POST') return send(res, 405, { error: 'method not allowed' }), true;
|
|
348
|
+
await contact(req, res, url);
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
if (p === '/robots.txt' && get) {
|
|
352
|
+
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'public, max-age=3600' });
|
|
353
|
+
res.end(req.method === 'HEAD' ? undefined : `User-agent: *\nAllow: /\nDisallow: /api/\nDisallow: /auth/\nDisallow: /app/\nDisallow: /backoffice/\n\nSitemap: ${BASE()}/sitemap.xml\n`);
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
if (p === '/sitemap.xml' && get) {
|
|
357
|
+
const urls = PUBLIC_PAGES.map((pg) => {
|
|
358
|
+
const alts = SITE_LANGS.map((l) => ` <xhtml:link rel="alternate" hreflang="${l}" href="${langUrl(pg, l)}"/>`).join('\n');
|
|
359
|
+
return ` <url>\n <loc>${BASE()}${pg}</loc>\n${alts}\n <xhtml:link rel="alternate" hreflang="x-default" href="${BASE()}${pg}"/>\n </url>`;
|
|
360
|
+
}).join('\n');
|
|
361
|
+
res.writeHead(200, { 'Content-Type': 'application/xml; charset=utf-8', 'Cache-Control': 'public, max-age=3600' });
|
|
362
|
+
res.end(req.method === 'HEAD' ? undefined : `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n${urls}\n</urlset>\n`);
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
const m = p.match(/^\/site\/(privacy|terms|contact)(\/?)$/);
|
|
366
|
+
if (m && get) {
|
|
367
|
+
if (!m[2]) {
|
|
368
|
+
res.writeHead(301, { Location: `${p}/${url.search}` });
|
|
369
|
+
res.end();
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
const lang = siteLocale(req, url);
|
|
373
|
+
const doc = m[1];
|
|
374
|
+
const L = LEGAL[lang];
|
|
375
|
+
const body = doc === 'contact' ? contactBody(lang, url) : legalBody(lang, doc);
|
|
376
|
+
const sub = url.searchParams.has('sent') || url.searchParams.has('error');
|
|
377
|
+
html(res, 200, pageShell(req, url, { lang, path: `/site/${doc}/`, title: L[doc].title, description: L[doc].lead, body, noindex: sub }), req);
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** 404 propia: HTML para navegadores, JSON para el resto. */
|
|
384
|
+
function notFound(req, res, url, jsonBody) {
|
|
385
|
+
const accept = String(req.headers.accept || '');
|
|
386
|
+
if ((req.method === 'GET' || req.method === 'HEAD') && accept.includes('text/html') && !url.pathname.startsWith('/api/')) {
|
|
387
|
+
const lang = siteLocale(req, url);
|
|
388
|
+
const T = { en: ['Page not found', 'This page does not exist or was moved.', 'Go to 7ots.com'], es: ['Página no encontrada', 'Esta página no existe o se movió.', 'Ir a 7ots.com'], pt: ['Página não encontrada', 'Esta página não existe ou foi movida.', 'Ir para 7ots.com'], zh: ['页面未找到', '此页面不存在或已被移动。', '前往 7ots.com'], hi: ['पेज नहीं मिला', 'यह पेज मौजूद नहीं है या हटा दिया गया है।', '7ots.com पर जाएँ'] }[lang];
|
|
389
|
+
const body = `<article class="ots-legal-doc ots-404"><p class="ots-404-code">404</p><h1>${esc(T[0])}</h1><p class="ots-lead">${esc(T[1])}</p><p><a class="ots-btn" href="/site/start/${lang === 'en' ? '' : `?lang=${lang}`}">${esc(T[2])}</a></p></article>`;
|
|
390
|
+
const page = pageShell(req, url, { lang, path: '/site/start/', title: T[0], description: T[1], body, noindex: true })
|
|
391
|
+
.replace(/\s*<link rel="(canonical|alternate)"[^>]*>/g, '');
|
|
392
|
+
html(res, 404, page, req);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
send(res, 404, jsonBody);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return { handle, notFound };
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export { LANG_NAMES };
|
package/server/tts.mjs
CHANGED
|
@@ -161,7 +161,10 @@ async function openaiClient(apiKey) {
|
|
|
161
161
|
return openaiClients.get(apiKey);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* POST JSON con tiempo límite. Si el proveedor falla, 502 con un motivo accionable: solo el código y el mensaje
|
|
166
|
+
* corto del proveedor (sin correos ni ids de request), nunca su respuesta entera (podría llevar datos de la cuenta).
|
|
167
|
+
*/
|
|
165
168
|
async function post(url, { headers, body }, name) {
|
|
166
169
|
let res;
|
|
167
170
|
try {
|
|
@@ -169,13 +172,34 @@ async function post(url, { headers, body }, name) {
|
|
|
169
172
|
} catch {
|
|
170
173
|
throw httpError(502, `${name} unreachable`);
|
|
171
174
|
}
|
|
172
|
-
if (!res.ok)
|
|
173
|
-
await res.text().catch(() => ''); // libera el socket
|
|
174
|
-
throw httpError(502, `${name} ${res.status}`);
|
|
175
|
-
}
|
|
175
|
+
if (!res.ok) throw providerError(name, res.status, await res.text().catch(() => ''));
|
|
176
176
|
return res;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Error de un proveedor de voz → mensaje que dice qué hacer. Formatos reales (2026-10-07):
|
|
181
|
+
* ElevenLabs { detail: { code: 'paid_plan_required' | 'quota_exceeded' | 'unauthorized', status, message } }
|
|
182
|
+
* xAI { code, error: 'Incorrect API key provided…' } (¡clave inválida = 400, no 401!)
|
|
183
|
+
* apuchat { code: 'invalid_token', reason } 401 · sin token 402 (x402)
|
|
184
|
+
*/
|
|
185
|
+
export function providerError(name, status, raw) {
|
|
186
|
+
let j = {};
|
|
187
|
+
try {
|
|
188
|
+
j = JSON.parse(raw);
|
|
189
|
+
} catch {}
|
|
190
|
+
const d = j && typeof j.detail === 'object' && j.detail ? j.detail : j || {};
|
|
191
|
+
const code = String(d.code || d.status || '').toLowerCase();
|
|
192
|
+
const said = String((typeof d.message === 'string' && d.message) || (typeof j.error === 'string' && j.error) || (typeof j.error?.message === 'string' && j.error.message) || j.reason || (typeof j.detail === 'string' && j.detail) || '');
|
|
193
|
+
const detail = said ? `: ${said.replace(/[\w.+-]+@[\w-]+(\.[\w-]+)+/g, '[email]').replace(/\s+/g, ' ').trim().slice(0, 180)}` : '';
|
|
194
|
+
const err = (key, vars = {}) => Object.assign(i18nError(502, `server.tts.${key}`, { provider: name, status, detail, ...vars }), { providerStatus: status });
|
|
195
|
+
if (name === 'apuchat' && status === 401) return err('apuchatToken');
|
|
196
|
+
if (name === 'apuchat' && status === 402) return err('apuchatPay');
|
|
197
|
+
if (name === 'ElevenLabs' && (status === 402 || /paid_plan|payment_required/.test(code))) return err('elevenPaid');
|
|
198
|
+
if (name === 'ElevenLabs' && /quota|credit/.test(code)) return err('elevenQuota');
|
|
199
|
+
if (status === 401 || status === 403 || /api key|invalid_api_key|unauthorized|authentication/i.test(`${code} ${said}`)) return err('badKey');
|
|
200
|
+
return err('failed');
|
|
201
|
+
}
|
|
202
|
+
|
|
179
203
|
// Idiomas que admite xAI TTS (docs.x.ai); el resto se deja en 'auto'.
|
|
180
204
|
const XAI_LANGS = ['en', 'ar-EG', 'ar-SA', 'ar-AE', 'bn', 'zh', 'fr', 'de', 'hi', 'id', 'it', 'ja', 'ko', 'pt-BR', 'pt-PT', 'ru', 'es-MX', 'es-ES', 'tr', 'vi'];
|
|
181
205
|
|
|
@@ -137,7 +137,7 @@ export class AvatarStage {
|
|
|
137
137
|
this._mouth = null;
|
|
138
138
|
this._face = null;
|
|
139
139
|
const ch = m.createCharacter3D(this.container, this.cfg.character, {
|
|
140
|
-
material: this.cfg.material
|
|
140
|
+
material: this.cfg.material || 'plush',
|
|
141
141
|
orbit: this.cfg.orbit === true,
|
|
142
142
|
quality: this.cfg.quality || 'high',
|
|
143
143
|
// escenario propio por encima del panel del widget (z-index 2147483000)
|
|
@@ -236,7 +236,7 @@ export class AvatarStage {
|
|
|
236
236
|
}
|
|
237
237
|
Object.assign(this.cfg, next);
|
|
238
238
|
if (isPlush) {
|
|
239
|
-
this._ch.update(next.character, { material: next.material
|
|
239
|
+
this._ch.update(next.character, { material: next.material || 'plush' });
|
|
240
240
|
if (next.mood) this.setMood(next.mood);
|
|
241
241
|
} else if (this.mode === '2d') {
|
|
242
242
|
if (this._ch && next.character && !next.image) this._ch.update(next.character);
|
package/src/avatar/three.js
CHANGED
|
@@ -42,13 +42,14 @@ export function loadThree() {
|
|
|
42
42
|
threeP ??= (async () => {
|
|
43
43
|
if (globalThis.__OTS_THREE__?.three) return globalThis.__OTS_THREE__;
|
|
44
44
|
const u = (p) => `${base()}/${p}/+esm`;
|
|
45
|
-
const [three, BufferGeometryUtils, RoomEnvironment, GLTFLoader] = await Promise.all([
|
|
45
|
+
const [three, BufferGeometryUtils, RoomEnvironment, GLTFLoader, RoundedBoxGeometry] = await Promise.all([
|
|
46
46
|
import(/* @vite-ignore */ /* webpackIgnore: true */ `${base()}/+esm`),
|
|
47
47
|
import(/* @vite-ignore */ /* webpackIgnore: true */ u('examples/jsm/utils/BufferGeometryUtils.js')),
|
|
48
48
|
import(/* @vite-ignore */ /* webpackIgnore: true */ u('examples/jsm/environments/RoomEnvironment.js')),
|
|
49
49
|
import(/* @vite-ignore */ /* webpackIgnore: true */ u('examples/jsm/loaders/GLTFLoader.js')),
|
|
50
|
+
import(/* @vite-ignore */ /* webpackIgnore: true */ u('examples/jsm/geometries/RoundedBoxGeometry.js')),
|
|
50
51
|
]);
|
|
51
|
-
return (globalThis.__OTS_THREE__ = { three, BufferGeometryUtils, RoomEnvironment, GLTFLoader });
|
|
52
|
+
return (globalThis.__OTS_THREE__ = { three, BufferGeometryUtils, RoomEnvironment, GLTFLoader, RoundedBoxGeometry });
|
|
52
53
|
})();
|
|
53
54
|
threeP.catch(() => { threeP = null; });
|
|
54
55
|
return threeP;
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
import { translator, detectLocale, getLocale, onLocaleChange, formatNumber } from '../i18n/index.js';
|
|
32
32
|
import { STYLES as ART_STYLES } from './styles.js';
|
|
33
33
|
import { loadCharacter3D } from '../avatar/three.js';
|
|
34
|
+
import { LOOK_MATERIALS } from '../identity/schema.js';
|
|
34
35
|
import { createTradingCard, CARD_FOILS } from './TradingCard.js';
|
|
35
36
|
|
|
36
37
|
const VIEW = [-20, -50, 240, 270];
|
|
@@ -39,7 +40,7 @@ const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '
|
|
|
39
40
|
|
|
40
41
|
const KINDS = ['character', 'plush', 'image'];
|
|
41
42
|
const RANDOM_N = 12;
|
|
42
|
-
const MATERIALS =
|
|
43
|
+
const MATERIALS = LOOK_MATERIALS;
|
|
43
44
|
|
|
44
45
|
const TABS = ['styles', 'shape', 'color', 'eyes', 'mouth', 'face', 'acc'];
|
|
45
46
|
const GESTURES = CHARACTER_GESTURES;
|
|
@@ -1458,4 +1458,4 @@ export function createCharacter(container, spec, opts = {}) {
|
|
|
1458
1458
|
export { SHAPES, EYES, BROWS, MOUTHS, CHEEKS, PATTERNS, FINISHES, TEXTURES, ACCESSORIES, PRESETS, BODY_POINTS };
|
|
1459
1459
|
export { ACCESSORY_GROUPS, partLabel } from './parts.js';
|
|
1460
1460
|
export { STYLES as CHARACTER_STYLES } from './styles.js';
|
|
1461
|
-
export { normalizeMods, normalizeMod, sanitizeSvg, modName, MOD_ANCHORS, MAX_MODS } from './mods.js';
|
|
1461
|
+
export { normalizeMods, normalizeMod, sanitizeSvg, modName, MOD_ANCHORS, MOD_SLOTS, MOD_FACE, MAX_MODS } from './mods.js';
|
|
@@ -17,6 +17,8 @@ const T = {
|
|
|
17
17
|
en: { stats: ['Energy', 'Wit', 'Charm', 'Chaos'], rar: ['Common', 'Rare', 'Epic', 'Legendary'] },
|
|
18
18
|
es: { stats: ['Energía', 'Ingenio', 'Encanto', 'Caos'], rar: ['Común', 'Rara', 'Épica', 'Legendaria'] },
|
|
19
19
|
pt: { stats: ['Energia', 'Engenho', 'Charme', 'Caos'], rar: ['Comum', 'Rara', 'Épica', 'Lendária'] },
|
|
20
|
+
zh: { stats: ['能量', '机智', '魅力', '混沌'], rar: ['普通', '稀有', '史诗', '传说'] },
|
|
21
|
+
hi: { stats: ['ऊर्जा', 'चतुराई', 'आकर्षण', 'उत्पात'], rar: ['साधारण', 'दुर्लभ', 'महाकाव्य', 'पौराणिक'] },
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
package/src/character/beat.js
CHANGED
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
* hype electrónica de cuatro en el piso funk bajo sincopado y guitarra rítmica
|
|
8
8
|
* chip 8 bits (cuadradas y triangular) trap 808 largo, hats con redobles
|
|
9
9
|
* entrance público que ruge, dos golpes con pirotecnia y un riff de rock (entradas tipo lucha libre)
|
|
10
|
+
* phonk (farmeo de aura) cowbell 808 en menor, 808 saturado que se desliza, hats en tresillo, medio tiempo
|
|
11
|
+
* montagem (farmeo de aura) funk brasileño: tamborzão, cowbell distorsionado repitiendo el riff
|
|
10
12
|
*
|
|
11
13
|
* playBeat(style, { ms, volume }) → { stop(), done: Promise, analyser } (solo en el navegador).
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
import { DANCE_BPM } from './motion.js';
|
|
15
17
|
|
|
16
|
-
export const BEAT_STYLES = ['hype', 'funk', 'chip', 'trap', 'entrance'];
|
|
18
|
+
export const BEAT_STYLES = ['hype', 'funk', 'chip', 'trap', 'entrance', 'phonk', 'montagem'];
|
|
17
19
|
|
|
18
20
|
const hz = (m) => 440 * 2 ** ((m - 69) / 12);
|
|
19
21
|
let shared = null;
|
|
@@ -61,6 +63,19 @@ function filt(ctx, type, f, q, dest) {
|
|
|
61
63
|
b.connect(dest);
|
|
62
64
|
return b;
|
|
63
65
|
}
|
|
66
|
+
/** Saturación (tanh) que se reusa por contexto y cantidad. */
|
|
67
|
+
function drive(ctx, amt, dest) {
|
|
68
|
+
const key = `__drive${amt}`;
|
|
69
|
+
if (!ctx[key]) {
|
|
70
|
+
const c = new Float32Array(1024);
|
|
71
|
+
for (let i = 0; i < c.length; i++) c[i] = Math.tanh(((i / c.length) * 2 - 1) * amt);
|
|
72
|
+
ctx[key] = c;
|
|
73
|
+
}
|
|
74
|
+
const ws = ctx.createWaveShaper();
|
|
75
|
+
ws.curve = ctx[key];
|
|
76
|
+
ws.connect(dest);
|
|
77
|
+
return ws;
|
|
78
|
+
}
|
|
64
79
|
const I = {
|
|
65
80
|
kick(ctx, out, t, v = 1, low = 45) {
|
|
66
81
|
const g = env(ctx, out, t, 0.9 * v, 0.003, 0.32);
|
|
@@ -125,6 +140,18 @@ const I = {
|
|
|
125
140
|
o.frequency.linearRampToValueAtTime(o.frequency.value * 1.3, s + 0.3);
|
|
126
141
|
}
|
|
127
142
|
},
|
|
143
|
+
// el cowbell de la 808: dos cuadradas desafinadas (≈ 540 y 800 Hz en el original), aquí afinado a la nota
|
|
144
|
+
cowbell(ctx, out, t, m, dur, v = 1, dist = 0) {
|
|
145
|
+
const g = env(ctx, out, t, 0.16 * v, 0.002, dur);
|
|
146
|
+
const bp = filt(ctx, 'bandpass', hz(m) * 1.8, 1.4, dist ? drive(ctx, dist, g) : g);
|
|
147
|
+
for (const k of [1, 1.48]) osc(ctx, 'square', hz(m) * k, t, dur, bp);
|
|
148
|
+
},
|
|
149
|
+
// 808 largo y saturado, con glide desde otra nota
|
|
150
|
+
bass808(ctx, out, t, m, dur, v = 1, from = null) {
|
|
151
|
+
const g = env(ctx, out, t, 0.5 * v, 0.004, dur);
|
|
152
|
+
const o = osc(ctx, 'sine', hz(from ?? m), t, dur, drive(ctx, 3.5, filt(ctx, 'lowpass', 900, 0.7, g)));
|
|
153
|
+
if (from != null) o.frequency.exponentialRampToValueAtTime(hz(m), t + 0.14);
|
|
154
|
+
},
|
|
128
155
|
boom(ctx, out, t, v = 1) {
|
|
129
156
|
I.kick(ctx, out, t, 1.2 * v, 30);
|
|
130
157
|
noise(ctx, t, 1.4, filt(ctx, 'lowpass', 900, 0.5, env(ctx, out, t, 0.5 * v, 0.005, 1.3)));
|
|
@@ -184,6 +211,39 @@ const STYLES = {
|
|
|
184
211
|
if (i === 0 && bar % 2 === 0) I.chord(ctx, out, t, [r + 12, r + 15, r + 19], sd * 30, 0.7, 'triangle');
|
|
185
212
|
},
|
|
186
213
|
},
|
|
214
|
+
// farmeo de aura: phonk de drift en medio tiempo (caja en el 3), el riff de cowbell va cambiando por compás
|
|
215
|
+
phonk: {
|
|
216
|
+
roots: [49, 49, 45, 47], // do#, do#, la, si (menor)
|
|
217
|
+
riff: [
|
|
218
|
+
[12, null, 12, null, 15, null, 12, null, 19, null, 17, 15, null, 12, null, null],
|
|
219
|
+
[12, null, 12, null, 15, null, 12, null, 10, null, 12, null, 7, null, null, null],
|
|
220
|
+
],
|
|
221
|
+
step(ctx, out, t, i, bar, sd) {
|
|
222
|
+
const r = this.roots[bar % 4];
|
|
223
|
+
if (on('x......xx.x.....', i)) (I.kick(ctx, out, t, 1.1, 40), I.bass808(ctx, out, t, r - 24, sd * (i === 0 ? 6 : 3), 1, i === 10 ? r - 19 : null));
|
|
224
|
+
if (i === 8) (I.clap(ctx, out, t, 1.2), I.snare(ctx, out, t, 0.6));
|
|
225
|
+
// hats en tresillo de corchea, más fuertes a contratiempo
|
|
226
|
+
if (i % 4 === 0) for (let k = 0; k < 3; k++) I.hat(ctx, out, t + (k * sd * 4) / 3, k === 1 ? 0.55 : 0.3);
|
|
227
|
+
const n = this.riff[bar % 2][i];
|
|
228
|
+
if (n != null) I.cowbell(ctx, out, t, r + n, sd * 1.6, 1);
|
|
229
|
+
if (i === 0 && bar % 4 === 0) I.chord(ctx, out, t, [r + 12, r + 15, r + 19], sd * 60, 0.45, 'triangle'); // colchón oscuro
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
// farmeo de aura: montagem (funk brasileño), tamborzão y el cowbell distorsionado repitiendo el mismo riff
|
|
233
|
+
montagem: {
|
|
234
|
+
roots: [50, 50, 53, 48],
|
|
235
|
+
riff: [0, null, 0, 3, null, 0, null, 7, null, 5, 3, null, 0, null, 3, null],
|
|
236
|
+
step(ctx, out, t, i, bar, sd) {
|
|
237
|
+
const r = this.roots[bar % 4];
|
|
238
|
+
if (on('x..x..x...x..x..', i)) I.kick(ctx, out, t, 1.15, 42); // tamborzão
|
|
239
|
+
if (on('x.....x...x.....', i)) I.bass808(ctx, out, t, r - 24, sd * 2.5, 0.8);
|
|
240
|
+
if (i === 4 || i === 12) I.clap(ctx, out, t, 1.1);
|
|
241
|
+
if (on('..x...x...x.x..x', i)) I.snare(ctx, out, t, 0.35);
|
|
242
|
+
if (i % 2) I.hat(ctx, out, t, 0.3);
|
|
243
|
+
const n = this.riff[i];
|
|
244
|
+
if (n != null) I.cowbell(ctx, out, t, r + 24 + n, sd * 1.2, 1.1, 4);
|
|
245
|
+
},
|
|
246
|
+
},
|
|
187
247
|
entrance: {
|
|
188
248
|
intro: 2.2, // s de público y golpes antes del riff
|
|
189
249
|
start(ctx, out, t) {
|
|
@@ -207,7 +267,7 @@ const STYLES = {
|
|
|
207
267
|
* Toca un estilo durante `ms`. Devuelve { stop(), done, analyser } o null sin Web Audio.
|
|
208
268
|
* `volume` 0..1. El primer paso cae en el instante en que se llama (con el gesto de baile).
|
|
209
269
|
*/
|
|
210
|
-
export function playBeat(style, { ms = 6000, volume = 0.5, bpm = DANCE_BPM, ctx = null } = {}) {
|
|
270
|
+
export function playBeat(style, { ms = 6000, volume = 0.5, bpm = DANCE_BPM, ctx = null, out = null } = {}) {
|
|
211
271
|
const AC = globalThis.AudioContext || globalThis.webkitAudioContext;
|
|
212
272
|
if (!AC) return null;
|
|
213
273
|
ctx ||= shared ||= new AC();
|
|
@@ -220,6 +280,8 @@ export function playBeat(style, { ms = 6000, volume = 0.5, bpm = DANCE_BPM, ctx
|
|
|
220
280
|
const analyser = ctx.createAnalyser();
|
|
221
281
|
analyser.fftSize = 256;
|
|
222
282
|
master.connect(comp).connect(analyser).connect(ctx.destination);
|
|
283
|
+
// out: otro destino además de los parlantes (p. ej. un MediaStreamDestination para grabar un clip)
|
|
284
|
+
if (out) analyser.connect(out);
|
|
223
285
|
const sd = 60 / bpm / 4; // un paso = semicorchea
|
|
224
286
|
const t0 = ctx.currentTime + 0.05;
|
|
225
287
|
const end = t0 + ms / 1000;
|