@idosgames/characters 0.1.4 → 0.1.5

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.
@@ -0,0 +1 @@
1
+ var l="en";function g(){return l}function p(t){l=t;}function f(t,e){let r=typeof t=="string"?t:t[l]??t.en;if(e)for(let[o,s]of Object.entries(e))r=r.split(`{${o}}`).join(String(s));return r}function O(t){let e=t.trim(),r=/```(?:json)?\s*([\s\S]*?)(?:```|$)/i.exec(e);r&&r[1]!==void 0&&(e=r[1]);let o=e.indexOf("{");if(o<0)return {ok:false,error:f({en:"the answer has no JSON object",ru:"\u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 JSON-\u043E\u0431\u044A\u0435\u043A\u0442\u0430"}),truncated:false};let s=0,a=false,u=false,c=-1;for(let i=o;i<e.length;i++){let n=e[i];if(a){u?u=false:n==="\\"?u=true:n==='"'&&(a=false);continue}if(n==='"')a=true;else if(n==="{"||n==="[")s++;else if((n==="}"||n==="]")&&(s--,s===0)){c=i;break}}if(c<0)return {ok:false,error:f({en:"the JSON is cut off",ru:"JSON \u043E\u0431\u043E\u0440\u0432\u0430\u043D"}),truncated:true};try{return {ok:!0,value:JSON.parse(e.slice(o,c+1))}}catch{return {ok:false,error:f({en:"invalid JSON",ru:"\u043D\u0435\u0432\u0430\u043B\u0438\u0434\u043D\u044B\u0439 JSON"}),truncated:false}}}export{g as a,p as b,f as c,O as d};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var E=["neutral","happy","sad","angry","surprised","scared","tired","hurt"];function j(e){return typeof e=="string"&&E.includes(e)}var b=["rest","A","E","O","MBP","FV"];function P(e){return typeof e=="string"&&b.includes(e)}var F=["idle","talk","walk","run","surprised","point","sit","wave","jump","fall","dance"],B=["handR","handL","head"],Y=["voxel-warm","flat-cartoon","chibi-2d","low-poly-3d","photo-sticker"];var k=new Set([..."a\u0430\u044F\xE4"]),L=new Set([..."eiy\u044D\u0435\u0438\u044B\u0439\u0451\xE9\xE8\xEA"]),O=new Set([..."ou\u043E\u0443\u044Ew\xF6\xFC"]),v=new Set([..."mbp\u043C\u0431\u043F"]),V=new Set([..."fv\u0444\u0432"]);function y(e){let t=e.toLowerCase();return k.has(t)?"A":L.has(t)?"E":O.has(t)?"O":v.has(t)?"MBP":V.has(t)?"FV":null}var S=e=>/\p{L}|\p{N}/u.test(e),w=e=>{let t=y(e);return t==="A"||t==="E"||t==="O"};function m(e){return S(e)?w(e)?1:.6:/[.!?…]/.test(e)?3:/[,;:—–-]/.test(e)?1.6:/\s/.test(e)?.35:0}function z(e,t,n){let o=Math.max(0,t),a=e.match(/\S+/g)??[];if(a.length===0||o===0)return {words:[],visemes:[{t:0,v:"rest"}]};let c=n&&n.length===a.length?n.map(r=>({...r})):A(e,o),s=[{t:0,v:"rest"}];for(let r of c){let i=[...r.text].filter(S),u=i.reduce((p,f)=>p+m(f),0)||1,g=r.start;for(let p of i){let f=y(p)??"E";s[s.length-1].v!==f&&s.push({t:l(g),v:f}),g+=(r.end-r.start)*m(p)/u;}s.push({t:l(r.end),v:"rest"});}return {words:c,visemes:T(s)}}function A(e,t){let n=[...e],o=n.reduce((r,i)=>r+m(i),0)||1,a=[],c=0,s=null;for(let r of n){let i=t*m(r)/o;/\s/.test(r)?(s&&a.push({text:s.text,start:l(s.start),end:l(c)}),s=null):s?s.text+=r:s={text:r,start:c},c+=i;}return s&&a.push({text:s.text,start:l(s.start),end:l(c)}),a.map(r=>{let i=/[^\p{L}\p{N}]+$/u.exec(r.text)?.[0].length??0;if(i===0)return r;let u=[...r.text],g=u.reduce((f,x)=>f+m(x),0)||1,p=u.slice(u.length-i).reduce((f,x)=>f+m(x),0);return {...r,end:l(r.end-(r.end-r.start)*p/g)}})}function G(e,t){let n="rest";for(let o of e){if(o.t>t)break;n=o.v;}return n}function H(e,t){for(let n=0;n<e.length;n++){let o=e[n];if(t>=o.start&&t<o.end)return n}return -1}var l=e=>Math.round(e*1e3)/1e3;function T(e){let t=[];for(let n of e){let o=t[t.length-1];o&&o.t===n.t?t[t.length-1]=n:(!o||o.v!==n.v)&&t.push(n);}return t}var M=["ru","kk","uk","be","ky","uz","tg"],I="idos:language",J="idos:language";function K(){try{let t=globalThis.localStorage?.getItem(I);if(t==="en"||t==="ru")return t}catch{}if(typeof navigator>"u")return "en";let e=(navigator.language||"").toLowerCase();return M.some(t=>e.startsWith(t))?"ru":"en"}var h=K();function N(){return h}function W(e){h=e;}typeof window<"u"&&window.addEventListener(J,e=>{let t=e.detail;(t==="en"||t==="ru")&&(h=t);});function d(e,t){let n=typeof e=="string"?e:e[h]??e.en;if(t)for(let[o,a]of Object.entries(t))n=n.split(`{${o}}`).join(String(a));return n}function C(e){let t=e>>>0;return function(){t|=0,t=t+1831565813|0;let n=Math.imul(t^t>>>15,1|t);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function _(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function R(e){let t=e.trim(),n=/```(?:json)?\s*([\s\S]*?)(?:```|$)/i.exec(t);n&&n[1]!==void 0&&(t=n[1]);let o=t.indexOf("{");if(o<0)return {ok:false,error:d({en:"the answer has no JSON object",ru:"\u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 JSON-\u043E\u0431\u044A\u0435\u043A\u0442\u0430"}),truncated:false};let a=0,c=false,s=false,r=-1;for(let i=o;i<t.length;i++){let u=t[i];if(c){s?s=false:u==="\\"?s=true:u==='"'&&(c=false);continue}if(u==='"')c=true;else if(u==="{"||u==="[")a++;else if((u==="}"||u==="]")&&(a--,a===0)){r=i;break}}if(r<0)return {ok:false,error:d({en:"the JSON is cut off",ru:"JSON \u043E\u0431\u043E\u0440\u0432\u0430\u043D"}),truncated:true};try{return {ok:!0,value:JSON.parse(t.slice(o,r+1))}}catch{return {ok:false,error:d({en:"invalid JSON",ru:"\u043D\u0435\u0432\u0430\u043B\u0438\u0434\u043D\u044B\u0439 JSON"}),truncated:false}}}exports.ACTOR_POSES=F;exports.ACTOR_SOCKETS=B;exports.EMOTIONS=E;exports.STYLE_FAMILIES=Y;exports.VISEMES=b;exports.extractJsonObject=R;exports.hashString=_;exports.isEmotion=j;exports.isViseme=P;exports.lang=N;exports.layoutSpeech=z;exports.mulberry32=C;exports.setLang=W;exports.tr=d;exports.visemeAt=G;exports.visemeOfLetter=y;exports.wordAt=H;
1
+ 'use strict';var b=["neutral","happy","sad","angry","surprised","scared","tired","hurt"];function W(e){return typeof e=="string"&&b.includes(e)}var O=["rest","A","E","O","MBP","FV"];function _(e){return typeof e=="string"&&O.includes(e)}var C=["idle","talk","walk","run","surprised","point","sit","wave","jump","fall","dance"],j=["handR","handL","head"],R=["voxel-warm","flat-cartoon","chibi-2d","low-poly-3d","photo-sticker"];var E=new Set([..."a\u0430\u044F\xE4"]),L=new Set([..."eiy\u044D\u0435\u0438\u044B\u0439\u0451\xE9\xE8\xEA"]),k=new Set([..."ou\u043E\u0443\u044Ew\xF6\xFC"]),v=new Set([..."mbp\u043C\u0431\u043F"]),V=new Set([..."fv\u0444\u0432"]);function S(e){let t=e.toLowerCase();return E.has(t)?"A":L.has(t)?"E":k.has(t)?"O":v.has(t)?"MBP":V.has(t)?"FV":null}var y=e=>/\p{L}|\p{N}/u.test(e),A=e=>{let t=S(e);return t==="A"||t==="E"||t==="O"};function m(e){return y(e)?A(e)?1:.6:/[.!?…]/.test(e)?3:/[,;:—–-]/.test(e)?1.6:/\s/.test(e)?.35:0}function F(e,t,r){let o=Math.max(0,t),c=e.match(/\S+/g)??[];if(c.length===0||o===0)return {words:[],visemes:[{t:0,v:"rest"}]};let a=r&&r.length===c.length?r.map(n=>({...n})):w(e,o),s=[{t:0,v:"rest"}];for(let n of a){let i=[...n.text].filter(y),u=i.reduce((p,f)=>p+m(f),0)||1,x=n.start;for(let p of i){let f=S(p)??"E";s[s.length-1].v!==f&&s.push({t:l(x),v:f}),x+=(n.end-n.start)*m(p)/u;}s.push({t:l(n.end),v:"rest"});}return {words:a,visemes:M(s)}}function w(e,t){let r=[...e],o=r.reduce((n,i)=>n+m(i),0)||1,c=[],a=0,s=null;for(let n of r){let i=t*m(n)/o;/\s/.test(n)?(s&&c.push({text:s.text,start:l(s.start),end:l(a)}),s=null):s?s.text+=n:s={text:n,start:a},a+=i;}return s&&c.push({text:s.text,start:l(s.start),end:l(a)}),c.map(n=>{let i=/[^\p{L}\p{N}]+$/u.exec(n.text)?.[0].length??0;if(i===0)return n;let u=[...n.text],x=u.reduce((f,g)=>f+m(g),0)||1,p=u.slice(u.length-i).reduce((f,g)=>f+m(g),0);return {...n,end:l(n.end-(n.end-n.start)*p/x)}})}function B(e,t){let r="rest";for(let o of e){if(o.t>t)break;r=o.v;}return r}function $(e,t){for(let r=0;r<e.length;r++){let o=e[r];if(t>=o.start&&t<o.end)return r}return -1}var l=e=>Math.round(e*1e3)/1e3;function M(e){let t=[];for(let r of e){let o=t[t.length-1];o&&o.t===r.t?t[t.length-1]=r:(!o||o.v!==r.v)&&t.push(r);}return t}var h="en";function T(){return h}function J(e){h=e;}function d(e,t){let r=typeof e=="string"?e:e[h]??e.en;if(t)for(let[o,c]of Object.entries(t))r=r.split(`{${o}}`).join(String(c));return r}function N(e){let t=e>>>0;return function(){t|=0,t=t+1831565813|0;let r=Math.imul(t^t>>>15,1|t);return r=r+Math.imul(r^r>>>7,61|r)^r,((r^r>>>14)>>>0)/4294967296}}function I(e){let t=2166136261;for(let r=0;r<e.length;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return t>>>0}function K(e){let t=e.trim(),r=/```(?:json)?\s*([\s\S]*?)(?:```|$)/i.exec(t);r&&r[1]!==void 0&&(t=r[1]);let o=t.indexOf("{");if(o<0)return {ok:false,error:d({en:"the answer has no JSON object",ru:"\u0432 \u043E\u0442\u0432\u0435\u0442\u0435 \u043D\u0435\u0442 JSON-\u043E\u0431\u044A\u0435\u043A\u0442\u0430"}),truncated:false};let c=0,a=false,s=false,n=-1;for(let i=o;i<t.length;i++){let u=t[i];if(a){s?s=false:u==="\\"?s=true:u==='"'&&(a=false);continue}if(u==='"')a=true;else if(u==="{"||u==="[")c++;else if((u==="}"||u==="]")&&(c--,c===0)){n=i;break}}if(n<0)return {ok:false,error:d({en:"the JSON is cut off",ru:"JSON \u043E\u0431\u043E\u0440\u0432\u0430\u043D"}),truncated:true};try{return {ok:!0,value:JSON.parse(t.slice(o,n+1))}}catch{return {ok:false,error:d({en:"invalid JSON",ru:"\u043D\u0435\u0432\u0430\u043B\u0438\u0434\u043D\u044B\u0439 JSON"}),truncated:false}}}exports.ACTOR_POSES=C;exports.ACTOR_SOCKETS=j;exports.EMOTIONS=b;exports.STYLE_FAMILIES=R;exports.VISEMES=O;exports.extractJsonObject=K;exports.hashString=I;exports.isEmotion=W;exports.isViseme=_;exports.lang=T;exports.layoutSpeech=F;exports.mulberry32=N;exports.setLang=J;exports.tr=d;exports.visemeAt=B;exports.visemeOfLetter=S;exports.wordAt=$;
package/dist/index.d.cts CHANGED
@@ -32,7 +32,7 @@ declare function wordAt(words: readonly SpokenWord[], t: number): number;
32
32
  type Lang = "en" | "ru";
33
33
  /** Текущий язык текстов пакета. */
34
34
  declare function lang(): Lang;
35
- /** Сменить язык в памяти (игра при своём выборе языка, тесты). */
35
+ /** Язык текстов пакета (игра: из языка приложения, тесты). */
36
36
  declare function setLang(l: Lang): void;
37
37
  /** Текст на двух языках; строка — один текст для обоих (числа, эмодзи, имена). */
38
38
  type Loc = string | {
package/dist/index.d.ts CHANGED
@@ -32,7 +32,7 @@ declare function wordAt(words: readonly SpokenWord[], t: number): number;
32
32
  type Lang = "en" | "ru";
33
33
  /** Текущий язык текстов пакета. */
34
34
  declare function lang(): Lang;
35
- /** Сменить язык в памяти (игра при своём выборе языка, тесты). */
35
+ /** Язык текстов пакета (игра: из языка приложения, тесты). */
36
36
  declare function setLang(l: Lang): void;
37
37
  /** Текст на двух языках; строка — один текст для обоих (числа, эмодзи, имена). */
38
38
  type Loc = string | {
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{e as ACTOR_POSES,f as ACTOR_SOCKETS,a as EMOTIONS,g as STYLE_FAMILIES,c as VISEMES,b as isEmotion,d as isViseme}from'./chunk-64D567CX.js';export{d as extractJsonObject,a as lang,b as setLang,c as tr}from'./chunk-WKHHFTK2.js';export{b as hashString,a as mulberry32}from'./chunk-CGF2TQVK.js';var k=new Set([..."a\u0430\u044F\xE4"]),E=new Set([..."eiy\u044D\u0435\u0438\u044B\u0439\u0451\xE9\xE8\xEA"]),W=new Set([..."ou\u043E\u0443\u044Ew\xF6\xFC"]),w=new Set([..."mbp\u043C\u0431\u043F"]),O=new Set([..."fv\u0444\u0432"]);function x(t){let e=t.toLowerCase();return k.has(e)?"A":E.has(e)?"E":W.has(e)?"O":w.has(e)?"MBP":O.has(e)?"FV":null}var g=t=>/\p{L}|\p{N}/u.test(t),A=t=>{let e=x(t);return e==="A"||e==="E"||e==="O"};function m(t){return g(t)?A(t)?1:.6:/[.!?…]/.test(t)?3:/[,;:—–-]/.test(t)?1.6:/\s/.test(t)?.35:0}function j(t,e,r){let o=Math.max(0,e),f=t.match(/\S+/g)??[];if(f.length===0||o===0)return {words:[],visemes:[{t:0,v:"rest"}]};let c=r&&r.length===f.length?r.map(n=>({...n})):K(t,o),s=[{t:0,v:"rest"}];for(let n of c){let i=[...n.text].filter(g),p=i.reduce((l,u)=>l+m(u),0)||1,d=n.start;for(let l of i){let u=x(l)??"E";s[s.length-1].v!==u&&s.push({t:a(d),v:u}),d+=(n.end-n.start)*m(l)/p;}s.push({t:a(n.end),v:"rest"});}return {words:c,visemes:M(s)}}function K(t,e){let r=[...t],o=r.reduce((n,i)=>n+m(i),0)||1,f=[],c=0,s=null;for(let n of r){let i=e*m(n)/o;/\s/.test(n)?(s&&f.push({text:s.text,start:a(s.start),end:a(c)}),s=null):s?s.text+=n:s={text:n,start:c},c+=i;}return s&&f.push({text:s.text,start:a(s.start),end:a(c)}),f.map(n=>{let i=/[^\p{L}\p{N}]+$/u.exec(n.text)?.[0].length??0;if(i===0)return n;let p=[...n.text],d=p.reduce((u,h)=>u+m(h),0)||1,l=p.slice(p.length-i).reduce((u,h)=>u+m(h),0);return {...n,end:a(n.end-(n.end-n.start)*l/d)}})}function C(t,e){let r="rest";for(let o of t){if(o.t>e)break;r=o.v;}return r}function F(t,e){for(let r=0;r<t.length;r++){let o=t[r];if(e>=o.start&&e<o.end)return r}return -1}var a=t=>Math.round(t*1e3)/1e3;function M(t){let e=[];for(let r of t){let o=e[e.length-1];o&&o.t===r.t?e[e.length-1]=r:(!o||o.v!==r.v)&&e.push(r);}return e}export{j as layoutSpeech,C as visemeAt,x as visemeOfLetter,F as wordAt};
1
+ export{e as ACTOR_POSES,f as ACTOR_SOCKETS,a as EMOTIONS,g as STYLE_FAMILIES,c as VISEMES,b as isEmotion,d as isViseme}from'./chunk-64D567CX.js';export{d as extractJsonObject,a as lang,b as setLang,c as tr}from'./chunk-YOAPVGXE.js';export{b as hashString,a as mulberry32}from'./chunk-CGF2TQVK.js';var k=new Set([..."a\u0430\u044F\xE4"]),E=new Set([..."eiy\u044D\u0435\u0438\u044B\u0439\u0451\xE9\xE8\xEA"]),W=new Set([..."ou\u043E\u0443\u044Ew\xF6\xFC"]),w=new Set([..."mbp\u043C\u0431\u043F"]),O=new Set([..."fv\u0444\u0432"]);function x(t){let e=t.toLowerCase();return k.has(e)?"A":E.has(e)?"E":W.has(e)?"O":w.has(e)?"MBP":O.has(e)?"FV":null}var g=t=>/\p{L}|\p{N}/u.test(t),A=t=>{let e=x(t);return e==="A"||e==="E"||e==="O"};function m(t){return g(t)?A(t)?1:.6:/[.!?…]/.test(t)?3:/[,;:—–-]/.test(t)?1.6:/\s/.test(t)?.35:0}function j(t,e,r){let o=Math.max(0,e),f=t.match(/\S+/g)??[];if(f.length===0||o===0)return {words:[],visemes:[{t:0,v:"rest"}]};let c=r&&r.length===f.length?r.map(n=>({...n})):K(t,o),s=[{t:0,v:"rest"}];for(let n of c){let i=[...n.text].filter(g),p=i.reduce((l,u)=>l+m(u),0)||1,d=n.start;for(let l of i){let u=x(l)??"E";s[s.length-1].v!==u&&s.push({t:a(d),v:u}),d+=(n.end-n.start)*m(l)/p;}s.push({t:a(n.end),v:"rest"});}return {words:c,visemes:M(s)}}function K(t,e){let r=[...t],o=r.reduce((n,i)=>n+m(i),0)||1,f=[],c=0,s=null;for(let n of r){let i=e*m(n)/o;/\s/.test(n)?(s&&f.push({text:s.text,start:a(s.start),end:a(c)}),s=null):s?s.text+=n:s={text:n,start:c},c+=i;}return s&&f.push({text:s.text,start:a(s.start),end:a(c)}),f.map(n=>{let i=/[^\p{L}\p{N}]+$/u.exec(n.text)?.[0].length??0;if(i===0)return n;let p=[...n.text],d=p.reduce((u,h)=>u+m(h),0)||1,l=p.slice(p.length-i).reduce((u,h)=>u+m(h),0);return {...n,end:a(n.end-(n.end-n.start)*l/d)}})}function C(t,e){let r="rest";for(let o of t){if(o.t>e)break;r=o.v;}return r}function F(t,e){for(let r=0;r<t.length;r++){let o=t[r];if(e>=o.start&&e<o.end)return r}return -1}var a=t=>Math.round(t*1e3)/1e3;function M(t){let e=[];for(let r of t){let o=e[e.length-1];o&&o.t===r.t?e[e.length-1]=r:(!o||o.v!==r.v)&&e.push(r);}return e}export{j as layoutSpeech,C as visemeAt,x as visemeOfLetter,F as wordAt};