md-face-engine 1.1.1 → 1.1.3
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/dist/MartidermEngine-ZSpNzcN-.cjs +4 -0
- package/dist/MartidermEngine-lu2piGUl.js +123 -0
- package/dist/client-DSvAftv8.cjs +4 -0
- package/dist/client-Rdsk7P-r.js +739 -0
- package/dist/client.cjs +1 -1
- package/dist/client.js +19 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -9
- package/dist/MartidermEngine-O4mYSfhg.cjs +0 -4
- package/dist/MartidermEngine-OvpT3v9z.js +0 -202
- package/dist/face_mesh-CA6iJyns.cjs +0 -18
- package/dist/face_mesh-Ctt6fZlf.js +0 -4207
- package/dist/index-Bdxo13gP.js +0 -420
- package/dist/index-DA_YlCTl.cjs +0 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./client-DSvAftv8.cjs"),v={base:{key:"base",label:"Base",defaults:{intensity:.5,sigma:4,brightness:0,contrast:1,warmthR:0,warmthB:0,warmthA:0},deep:{}}};function p(r){return v[r]||null}const w=["base"],g="mdfe2_",h="md-face-engine",s=`-----BEGIN PUBLIC KEY-----
|
|
2
|
+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEW9CHbTVvVXcm09wZIj6GKGaq8ae1
|
|
3
|
+
XGQAum9LBLgoT3+4q3xPc7W9KSw1z4xgfOByTi8OzdjbjEaF3VrHjzl05w==
|
|
4
|
+
-----END PUBLIC KEY-----`;let c=null;function E(r){const e=r.replace(/-/g,"+").replace(/_/g,"/"),t=e+"=".repeat((4-e.length%4)%4);return atob(t)}function b(r){const e=E(r),t=new Uint8Array(e.length);for(let a=0;a<e.length;a+=1)t[a]=e.charCodeAt(a);return t}function C(r){const e=r.replace(/-----BEGIN PUBLIC KEY-----/g,"").replace(/-----END PUBLIC KEY-----/g,"").replace(/\s+/g,""),t=atob(e),a=new Uint8Array(t.length);for(let i=0;i<t.length;i+=1)a[i]=t.charCodeAt(i);return a.buffer}async function A(r=s){if(r===s&&c)return c;const e=C(r),t=await crypto.subtle.importKey("spki",e,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]);return r===s&&(c=t),t}async function m(r,e={}){const{now:t=Date.now(),publicKeyPem:a=s,allowExpired:i=!1}=e;if(!r||typeof r!="string")return{valid:!1,reason:"Token vacío o inválido"};if(!r.startsWith(g))return{valid:!1,reason:"Prefijo de token inválido"};const d=r.slice(g.length).split(".");if(d.length!==2)return{valid:!1,reason:"Formato de token inválido"};const[u,y]=d;let n;try{n=JSON.parse(E(u))}catch{return{valid:!1,reason:"Payload de licencia inválido"}}try{const o=await A(a);if(!await crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},o,b(y),new TextEncoder().encode(u)))return{valid:!1,reason:"Firma de licencia inválida"}}catch{return{valid:!1,reason:"Error verificando firma de licencia"}}return n.productCode!==h?{valid:!1,reason:"Licencia de otro producto"}:!i&&(typeof n.exp!="number"||n.exp<t)?{valid:!1,reason:"Licencia vencida",payload:n}:{valid:!0,reason:null,payload:n}}class l{constructor(){this.license=null,this.activated=!1}async activate(e){const t=await m(e);if(!t.valid)throw this.license=null,this.activated=!1,new Error(`Licencia inválida: ${t.reason}`);return this.license=t.payload,this.activated=!0,t.payload}isActivated(){return this.activated}assertActivated(){if(!this.activated)throw new Error("md-face-engine no está activado. Configura VITE_MD_FACE_ENGINE_TOKEN.")}getLicense(){return this.assertActivated(),this.license}getProductCode(){return h}getFilterRegistry(){return this.assertActivated(),v}getFilterOrder(){return this.assertActivated(),w}getFilter(e){return this.assertActivated(),p(e)}getFilterConfigManager(){return this.assertActivated(),f.filterConfigManager}buildWebglConfigForProduct(e){return this.assertActivated(),f.buildWebglConfigForProduct(e)}}exports.MartidermEngine=l;exports.MdFaceEngine=l;exports.default=l;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { f as E, b as y } from "./client-Rdsk7P-r.js";
|
|
2
|
+
const f = {
|
|
3
|
+
base: {
|
|
4
|
+
key: "base",
|
|
5
|
+
label: "Base",
|
|
6
|
+
defaults: { intensity: 0.5, sigma: 4, brightness: 0, contrast: 1, warmthR: 0, warmthB: 0, warmthA: 0 },
|
|
7
|
+
deep: {}
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function p(a) {
|
|
11
|
+
return f[a] || null;
|
|
12
|
+
}
|
|
13
|
+
const w = ["base"], u = "mdfe2_", g = "md-face-engine", s = `-----BEGIN PUBLIC KEY-----
|
|
14
|
+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEW9CHbTVvVXcm09wZIj6GKGaq8ae1
|
|
15
|
+
XGQAum9LBLgoT3+4q3xPc7W9KSw1z4xgfOByTi8OzdjbjEaF3VrHjzl05w==
|
|
16
|
+
-----END PUBLIC KEY-----`;
|
|
17
|
+
let c = null;
|
|
18
|
+
function v(a) {
|
|
19
|
+
const e = a.replace(/-/g, "+").replace(/_/g, "/"), t = e + "=".repeat((4 - e.length % 4) % 4);
|
|
20
|
+
return atob(t);
|
|
21
|
+
}
|
|
22
|
+
function C(a) {
|
|
23
|
+
const e = v(a), t = new Uint8Array(e.length);
|
|
24
|
+
for (let r = 0; r < e.length; r += 1)
|
|
25
|
+
t[r] = e.charCodeAt(r);
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
function b(a) {
|
|
29
|
+
const e = a.replace(/-----BEGIN PUBLIC KEY-----/g, "").replace(/-----END PUBLIC KEY-----/g, "").replace(/\s+/g, ""), t = atob(e), r = new Uint8Array(t.length);
|
|
30
|
+
for (let i = 0; i < t.length; i += 1)
|
|
31
|
+
r[i] = t.charCodeAt(i);
|
|
32
|
+
return r.buffer;
|
|
33
|
+
}
|
|
34
|
+
async function m(a = s) {
|
|
35
|
+
if (a === s && c)
|
|
36
|
+
return c;
|
|
37
|
+
const e = b(a), t = await crypto.subtle.importKey(
|
|
38
|
+
"spki",
|
|
39
|
+
e,
|
|
40
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
41
|
+
!1,
|
|
42
|
+
["verify"]
|
|
43
|
+
);
|
|
44
|
+
return a === s && (c = t), t;
|
|
45
|
+
}
|
|
46
|
+
async function A(a, e = {}) {
|
|
47
|
+
const {
|
|
48
|
+
now: t = Date.now(),
|
|
49
|
+
publicKeyPem: r = s,
|
|
50
|
+
allowExpired: i = !1
|
|
51
|
+
} = e;
|
|
52
|
+
if (!a || typeof a != "string")
|
|
53
|
+
return { valid: !1, reason: "Token vacío o inválido" };
|
|
54
|
+
if (!a.startsWith(u))
|
|
55
|
+
return { valid: !1, reason: "Prefijo de token inválido" };
|
|
56
|
+
const l = a.slice(u.length).split(".");
|
|
57
|
+
if (l.length !== 2)
|
|
58
|
+
return { valid: !1, reason: "Formato de token inválido" };
|
|
59
|
+
const [d, h] = l;
|
|
60
|
+
let n;
|
|
61
|
+
try {
|
|
62
|
+
n = JSON.parse(v(d));
|
|
63
|
+
} catch {
|
|
64
|
+
return { valid: !1, reason: "Payload de licencia inválido" };
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const o = await m(r);
|
|
68
|
+
if (!await crypto.subtle.verify(
|
|
69
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
70
|
+
o,
|
|
71
|
+
C(h),
|
|
72
|
+
new TextEncoder().encode(d)
|
|
73
|
+
))
|
|
74
|
+
return { valid: !1, reason: "Firma de licencia inválida" };
|
|
75
|
+
} catch {
|
|
76
|
+
return { valid: !1, reason: "Error verificando firma de licencia" };
|
|
77
|
+
}
|
|
78
|
+
return n.productCode !== g ? { valid: !1, reason: "Licencia de otro producto" } : !i && (typeof n.exp != "number" || n.exp < t) ? { valid: !1, reason: "Licencia vencida", payload: n } : { valid: !0, reason: null, payload: n };
|
|
79
|
+
}
|
|
80
|
+
class B {
|
|
81
|
+
constructor() {
|
|
82
|
+
this.license = null, this.activated = !1;
|
|
83
|
+
}
|
|
84
|
+
async activate(e) {
|
|
85
|
+
const t = await A(e);
|
|
86
|
+
if (!t.valid)
|
|
87
|
+
throw this.license = null, this.activated = !1, new Error(`Licencia inválida: ${t.reason}`);
|
|
88
|
+
return this.license = t.payload, this.activated = !0, t.payload;
|
|
89
|
+
}
|
|
90
|
+
isActivated() {
|
|
91
|
+
return this.activated;
|
|
92
|
+
}
|
|
93
|
+
assertActivated() {
|
|
94
|
+
if (!this.activated)
|
|
95
|
+
throw new Error("md-face-engine no está activado. Configura VITE_MD_FACE_ENGINE_TOKEN.");
|
|
96
|
+
}
|
|
97
|
+
getLicense() {
|
|
98
|
+
return this.assertActivated(), this.license;
|
|
99
|
+
}
|
|
100
|
+
getProductCode() {
|
|
101
|
+
return g;
|
|
102
|
+
}
|
|
103
|
+
getFilterRegistry() {
|
|
104
|
+
return this.assertActivated(), f;
|
|
105
|
+
}
|
|
106
|
+
getFilterOrder() {
|
|
107
|
+
return this.assertActivated(), w;
|
|
108
|
+
}
|
|
109
|
+
getFilter(e) {
|
|
110
|
+
return this.assertActivated(), p(e);
|
|
111
|
+
}
|
|
112
|
+
getFilterConfigManager() {
|
|
113
|
+
return this.assertActivated(), E;
|
|
114
|
+
}
|
|
115
|
+
buildWebglConfigForProduct(e) {
|
|
116
|
+
return this.assertActivated(), y(e);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
B as MartidermEngine,
|
|
121
|
+
B as MdFaceEngine,
|
|
122
|
+
B as default
|
|
123
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";const D=require("react"),q={smooth:{enabled:!0,radius:4,passes:2,opacity:.4},brightness:{enabled:!0,value:0},contrast:{enabled:!0,value:1},warmth:{enabled:!0,rPlus:0,bMinus:0,alpha:0}};class Q{constructor(t={}){this.storageKey="martiderm_filter_configs",this.authKey="martiderm_admin_auth",this.backupKey="martiderm_config_backup",this.products=Array.isArray(t.products)?t.products:[],this.init()}init(){const t=this.loadConfigurations();(!t||Object.keys(t).length===0)&&this.products.length>0&&this.initializeDefaultConfigurations()}setProducts(t=[]){this.products=Array.isArray(t)?t:[];const r=this.loadConfigurations();(!r||Object.keys(r).length===0)&&this.products.length>0&&this.initializeDefaultConfigurations()}initializeDefaultConfigurations(){try{const t={};this.products.forEach(r=>{t[r.id]=this.generateProductConfig(r)}),this.saveConfigurations(t)}catch(t){console.error("Error inicializando configuraciones:",t)}}generateProductConfig(t={}){return{productId:t.id,productName:t.name,category:t.category,filters:{...q},webglConfig:t.defaultWebglConfig?{...t.defaultWebglConfig}:{},lastModified:new Date().toISOString(),version:"2.0"}}getProductConfig(t){return this.loadConfigurations()[t]||null}saveProductConfig(t,r){const o=this.loadConfigurations();return o[t]={...r,lastModified:new Date().toISOString()},this.saveConfigurations(o),!0}getAllConfigurations(){return this.loadConfigurations()}loadConfigurations(){try{const t=localStorage.getItem(this.storageKey);return t?JSON.parse(t):{}}catch(t){return console.error("Error cargando configuraciones:",t),{}}}saveConfigurations(t){try{return localStorage.setItem(this.storageKey,JSON.stringify(t)),this.createBackup(t),!0}catch(r){return console.error("Error guardando configuraciones:",r),!1}}createBackup(t=null){try{const r=t||this.loadConfigurations(),o={timestamp:new Date().toISOString(),configurations:r,version:"2.0"};return localStorage.setItem(this.backupKey,JSON.stringify(o)),!0}catch(r){return console.error("Error creando backup:",r),!1}}restoreFromBackup(){try{const t=localStorage.getItem(this.backupKey);if(t){const r=JSON.parse(t);return this.saveConfigurations(r.configurations),!0}return!1}catch(t){return console.error("Error restaurando backup:",t),!1}}exportConfigurations(){const t=this.loadConfigurations(),r={timestamp:new Date().toISOString(),configurations:t,version:"2.0"};return JSON.stringify(r,null,2)}importConfigurations(t){try{const r=JSON.parse(t);return r.configurations?(this.saveConfigurations(r.configurations),!0):!1}catch(r){return console.error("Error importando configuraciones:",r),!1}}resetToDefaults(){try{return localStorage.removeItem(this.storageKey),this.initializeDefaultConfigurations(),!0}catch(t){return console.error("Error reseteando configuraciones:",t),!1}}isAuthenticated(){try{const t=localStorage.getItem(this.authKey);if(!t)return!1;const r=JSON.parse(t);return!!(r!=null&&r.authenticated)}catch{return!1}}authenticateAdmin(t,r){if(t==="admin"&&r==="martiderm2024"){const a={authenticated:!0,username:t,token:`adm-${Date.now()}`,lastLogin:new Date().toISOString()};return localStorage.setItem(this.authKey,JSON.stringify(a)),{success:!0,username:t}}return{success:!1,error:"Credenciales inválidas"}}getAuthenticatedUser(){try{const t=localStorage.getItem(this.authKey);if(!t)return null;const r=JSON.parse(t);return r!=null&&r.authenticated?{username:r.username}:null}catch{return null}}logout(){try{return localStorage.removeItem(this.authKey),!0}catch{return!1}}exportConfiguration(){return this.exportConfigurations()}}const T=new Q;function Z(e){if(!e)throw new Error("Canvas WebGL inexistente");const t=e.getContext("webgl",{premultipliedAlpha:!1,preserveDrawingBuffer:!0})||e.getContext("experimental-webgl");if(!t)throw new Error("WebGL no disponible en este navegador");return t}function K(e,t,r){const o=e.createShader(t);if(e.shaderSource(o,r),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS)){const i=e.getShaderInfoLog(o);throw e.deleteShader(o),new Error(`Shader error: ${i}`)}return o}function z(e,t,r){const o=K(e,e.VERTEX_SHADER,t),i=K(e,e.FRAGMENT_SHADER,r),a=e.createProgram();if(e.attachShader(a,o),e.attachShader(a,i),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS)){const u=e.getProgramInfoLog(a);throw e.deleteProgram(a),new Error(`Program link error: ${u}`)}return a}function ee(e,t,r,o){const i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),o?e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,o):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),i}function te(e,t){const r=e.createFramebuffer();if(e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)throw new Error("FBO incomplete");return e.bindFramebuffer(e.FRAMEBUFFER,null),r}function G(e,t,r){e.viewport(0,0,t,r)}function re(e){const t=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,t);const r=new Float32Array([-1,-1,0,0,1,-1,1,0,-1,1,0,1,1,1,1,1]);e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW);const o=e.createBuffer();e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,o);const i=new Uint16Array([0,1,2,2,1,3]);return e.bufferData(e.ELEMENT_ARRAY_BUFFER,i,e.STATIC_DRAW),{vbo:t,ibo:o}}function V(e){return e==="brightness"?1:e==="spots"?2:e==="acne"?3:e==="firmness"?4:0}const oe=["attribute vec2 a_pos;","attribute vec2 a_uv;","varying vec2 v_uv;","void main() {"," v_uv = a_uv;"," gl_Position = vec4(a_pos, 0.0, 1.0);","}"].join(`
|
|
2
|
+
`),ne=["precision mediump float;","varying vec2 v_uv;","uniform sampler2D u_tex;","uniform vec2 u_texel;","uniform vec2 u_dir;","uniform float u_sigma;","float gaussian(float x, float s) { return exp(-(x*x)/(2.0*s*s)); }","void main() {"," vec2 stepDir = u_dir * u_sigma;"," vec4 col = texture2D(u_tex, v_uv) * gaussian(0.0, 1.0);"," float wsum = gaussian(0.0, 1.0);"," for (int i = 1; i <= 4; i++) {"," float f = float(i);"," float w = gaussian(f, 1.0);"," vec2 off = stepDir * f * u_texel;"," col += texture2D(u_tex, v_uv + off) * w;"," col += texture2D(u_tex, v_uv - off) * w;"," wsum += 2.0 * w;"," }"," gl_FragColor = col / wsum;","}"].join(`
|
|
3
|
+
`),ie=["precision mediump float;","varying vec2 v_uv;","uniform sampler2D u_orig;","uniform sampler2D u_blur;","uniform sampler2D u_mask;","uniform float u_intensity;","uniform float u_brightness;","uniform float u_contrast;","uniform float u_warmthR;","uniform float u_warmthB;","uniform float u_warmthAlpha;","uniform int u_filterType;","void main() {"," vec4 o = texture2D(u_orig, v_uv);"," vec4 b = texture2D(u_blur, v_uv);"," float a = clamp(texture2D(u_mask, v_uv).a, 0.0, 1.0);"," float m = a * u_intensity;"," vec4 blended = mix(o, b, m);"," blended.rgb += u_brightness * a;"," blended.rgb = clamp(blended.rgb, 0.0, 1.0);"," gl_FragColor = blended;","if (u_filterType == 2) {","vec3 smoothed = mix(o.rgb, b.rgb, m * 0.7);","float origLum = dot(o.rgb, vec3(0.299, 0.587, 0.114));","float smoothLum = dot(smoothed, vec3(0.299, 0.587, 0.114));","float darkness = max(0.0, smoothLum - origLum);","smoothed.rgb += vec3(darkness * 0.4) * m;","float targetLum = dot(smoothed, vec3(0.299, 0.587, 0.114));","vec3 uniformTone = vec3(targetLum * 1.02);","smoothed.rgb = mix(smoothed.rgb, uniformTone, m * 0.35);","float avgChannel = (smoothed.r + smoothed.g + smoothed.b) / 3.0;","smoothed.r = mix(smoothed.r, avgChannel, m * 0.25);","smoothed.g = mix(smoothed.g, avgChannel, m * 0.15);","smoothed.b = mix(smoothed.b, avgChannel, m * 0.15);","float gray = dot(smoothed, vec3(0.299, 0.587, 0.114));","smoothed.rgb = mix(vec3(gray), smoothed.rgb, 0.85);","smoothed.rgb = pow(smoothed.rgb, vec3(0.96));","smoothed.rgb += vec3(0.02) * m;","float finalGray = dot(smoothed, vec3(0.299, 0.587, 0.114));","finalGray = pow(finalGray, 0.88);","blended.rgb = vec3(finalGray);","blended.rgb = clamp(blended.rgb, 0.0, 1.0);","}","if (u_filterType == 3) {","float origLum = dot(o.rgb, vec3(0.299, 0.587, 0.114));","float blurLum = dot(b.rgb, vec3(0.299, 0.587, 0.114));","float detail = origLum - blurLum;","vec3 smoothed = mix(o.rgb, b.rgb, m * 0.85);","float detailAmount = 0.25 * (1.0 - m * 0.5);","smoothed.rgb += detail * detailAmount * sign(detail);","float avgColor = (smoothed.r + smoothed.g + smoothed.b) / 3.0;","smoothed.r = mix(smoothed.r, avgColor, m * 0.35);","smoothed.g = mix(smoothed.g, avgColor, m * 0.15);","smoothed.b = mix(smoothed.b, avgColor, m * 0.1);","smoothed.rgb = mix(smoothed.rgb, vec3(blurLum), m * 0.2);","smoothed.rgb += vec3(0.05) * m;","blended.rgb = clamp(smoothed, 0.0, 1.0);","vec2 texelSize = vec2(1.0) / vec2(1024.0, 1024.0);","vec3 avgNeighbor = vec3(0.0);","float weightSum = 0.0;","for(int dx = -1; dx <= 1; dx++) {","for(int dy = -1; dy <= 1; dy++) {","vec2 offset = vec2(float(dx), float(dy)) * texelSize * 2.0;","vec3 neighbor = texture2D(u_blur, v_uv + offset).rgb;","float colorDiff = length(neighbor - blended.rgb);","float weight = exp(-colorDiff * 5.0) * a;","avgNeighbor += neighbor * weight;","weightSum += weight;","}","}","if(weightSum > 0.01) {","vec3 bilateralSmooth = avgNeighbor / weightSum;","blended.rgb = mix(blended.rgb, bilateralSmooth, m * 0.3);","}","}","if (u_filterType == 4) {","float lift = 0.02 * u_intensity;","vec2 off = vec2(0.0, -lift);","vec4 lifted = texture2D(u_orig, v_uv + off * a);","blended.rgb = mix(blended.rgb, lifted.rgb, 0.5 * m);","blended.rgb = pow(blended.rgb, vec3(1.0/(1.0 - 0.06 * u_intensity)));","blended.rgb += vec3(0.02 * u_intensity * a);","blended.rgb = clamp(blended.rgb, 0.0, 1.0);","}","blended.rgb = ((blended.rgb - 0.5) * u_contrast) + 0.5;","vec3 warm = blended.rgb;","warm.r += u_warmthR / 255.0;","warm.b = max(0.0, warm.b - (u_warmthB / 255.0));","blended.rgb = mix(blended.rgb, clamp(warm, 0.0, 1.0), u_warmthAlpha);","gl_FragColor = blended;","}"].join(`
|
|
4
|
+
`);function N(e,t,r,o,i,a="Error aplicando escala de grises"){try{const u=e.getImageData(t,r,o,i),n=u.data;for(let l=0;l<n.length;l+=4){const g=.299*n[l]+.587*n[l+1]+.114*n[l+2];n[l]=g,n[l+1]=g,n[l+2]=g}e.putImageData(u,t,r)}catch(u){console.error(a,u)}}function J(e,t,r){const o=e.getAttribLocation(t,"a_pos"),i=e.getAttribLocation(t,"a_uv");e.bindBuffer(e.ARRAY_BUFFER,r.vbo),e.enableVertexAttribArray(o),e.enableVertexAttribArray(i),e.vertexAttribPointer(o,2,e.FLOAT,!1,16,0),e.vertexAttribPointer(i,2,e.FLOAT,!1,16,8),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r.ibo)}function H(e,t,r,o){e.bindFramebuffer(e.FRAMEBUFFER,t),G(e,r,o),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.drawElements(e.TRIANGLES,6,e.UNSIGNED_SHORT,0)}function ae({gl:e,image:t,imgSize:r,programs:o,quad:i,textures:a,framebuffers:u,params:n,canvases:l,callbacks:g={}}){if(!e||!t){const d=l==null?void 0:l.outCanvas;if(d&&t){const _=d.getContext("2d"),X=r==null?void 0:r.w,x=r==null?void 0:r.h;_&&X&&x&&(_.clearRect(0,0,X,x),_.drawImage(t,0,0,X,x))}return}const m=r==null?void 0:r.w,h=r==null?void 0:r.h;if(!m||!h)return;e.useProgram(o.blur),J(e,o.blur,i);const P=e.getUniformLocation(o.blur,"u_texel"),B=e.getUniformLocation(o.blur,"u_dir"),M=e.getUniformLocation(o.blur,"u_sigma"),U=e.getUniformLocation(o.blur,"u_tex");e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,a.orig),e.uniform1i(U,0),e.uniform2f(P,1/m,1/h),e.uniform2f(B,1,0),e.uniform1f(M,n.sigma),H(e,u.ping,m,h),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,a.ping),e.uniform1i(U,0),e.uniform2f(P,1/m,1/h),e.uniform2f(B,0,1),e.uniform1f(M,n.sigma),H(e,u.pong,m,h),e.useProgram(o.compose),J(e,o.compose,i);const F=e.getUniformLocation(o.compose,"u_orig"),p=e.getUniformLocation(o.compose,"u_blur"),b=e.getUniformLocation(o.compose,"u_mask"),w=e.getUniformLocation(o.compose,"u_intensity"),v=e.getUniformLocation(o.compose,"u_brightness"),S=e.getUniformLocation(o.compose,"u_contrast"),C=e.getUniformLocation(o.compose,"u_warmthR"),R=e.getUniformLocation(o.compose,"u_warmthB"),y=e.getUniformLocation(o.compose,"u_warmthAlpha"),A=e.getUniformLocation(o.compose,"u_filterType");e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,a.orig),e.uniform1i(F,0),e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,a.pong),e.uniform1i(p,1),e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,a.mask),e.uniform1i(b,2),e.uniform1f(w,n.intensity),e.uniform1f(v,n.brightness),e.uniform1f(S,n.contrast),e.uniform1f(C,n.warmthR),e.uniform1f(R,n.warmthB),e.uniform1f(y,n.warmthA),e.uniform1i(A,V(n.filterType)),typeof g.onConfigApplied=="function"&&g.onConfigApplied({intensity:n.intensity,sigma:n.sigma,brightness:n.brightness,contrast:n.contrast,warmthR:n.warmthR,warmthB:n.warmthB,warmthA:n.warmthA,filterType:n.filterType}),e.bindFramebuffer(e.FRAMEBUFFER,null),G(e,m,h),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT),e.drawElements(e.TRIANGLES,6,e.UNSIGNED_SHORT,0);const I=l.glCanvas,O=l.outCanvas,j=l.maskCanvas,f=O&&O.getContext("2d");if(f){if(e.finish(),f.clearRect(0,0,m,h),n.view==="before")f.drawImage(t,0,0,m,h),n.filterType==="spots"&&N(f,0,0,m,h,'Error aplicando escala de grises en "antes":');else if(n.view==="after")!!I&&I.width&&I.height?f.drawImage(I,0,0,m,h):f.drawImage(t,0,0,m,h);else if(n.view==="mask")f.fillStyle="#000000",f.fillRect(0,0,m,h),f.drawImage(j,0,0,m,h);else{const d=Math.max(0,Math.min(1,n.splitPos))*m;if(n.mirrored){d>0&&f.drawImage(I,0,0,d,h,0,0,d,h);const _=m-d;_>0&&(f.drawImage(t,d,0,_,h,d,0,_,h),n.filterType==="spots"&&N(f,d,0,_,h,"Error aplicando B&N en split derecha (mirrored):"))}else{d>0&&(f.drawImage(t,0,0,d,h,0,0,d,h),n.filterType==="spots"&&N(f,0,0,d,h,"Error aplicando B&N en split izquierda:"));const _=m-d;_>0&&f.drawImage(I,d,0,_,h,d,0,_,h)}f.save(),f.strokeStyle="rgba(255,255,255,0.9)",f.lineWidth=2,f.beginPath(),f.moveTo(Math.floor(d),0),f.lineTo(Math.floor(d),h),f.stroke(),f.fillStyle="rgba(0,0,0,0.15)",f.beginPath(),f.arc(Math.floor(d)+2,h/2+2,14,0,Math.PI*2),f.fill(),f.fillStyle="#ffffff",f.beginPath(),f.arc(Math.floor(d),h/2,14,0,Math.PI*2),f.fill(),f.strokeStyle="rgba(0,0,0,0.25)",f.lineWidth=1,f.beginPath(),f.arc(Math.floor(d),h/2,14,0,Math.PI*2),f.stroke(),f.restore()}if(typeof g.drawOverlay=="function"&&g.drawOverlay(f,m,h),typeof g.onProcessed=="function"&&O){const d=O.toDataURL("image/jpeg",.92);d&&g.onProcessed(d)}}}function se(e){const t=D.useRef(null);return D.useEffect(()=>{let r=!1;try{if(t.current)return;k().then(o=>{r||(t.current=o)}).catch(o=>{r||(console.warn("[md-face-engine] Landmark detector unavailable, using fallback mask.",o),t.current=null,typeof e=="function"&&e(""))})}catch(o){console.warn("[md-face-engine] Landmark detector init failed, using fallback mask.",o),t.current=null,typeof e=="function"&&e("")}return()=>{r=!0}},[e]),t}const s={rightEyeUpper:[246,161,160,159,158,157,173],rightEyeLower:[33,7,163,144,145,153,154,155,133],leftEyeUpper:[466,388,387,386,385,384,398],leftEyeLower:[263,249,390,373,374,380,381,382,362],rightEyebrow:[70,63,105,66,107,55,65],leftEyebrow:[300,293,334,296,336,285,295],lipOutline:[61,146,91,181,84,17,314,405,321,375,291,409,270,269,267,0,37,39,40,185],faceOval:[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109],forehead:[10,338,297,332,284,251,389,356,70,63,105,66,107,336,296,334,293,300],rightCheek:[50,101,100,47,117,118,119,120,121,128,129],leftCheek:[280,330,329,277,346,347,348,349,350,357,358],rightNasolabial:[36,142,126,217,174],leftNasolabial:[266,371,355,437,399]};function L(e,t){let r=0,o=0;return t.forEach(i=>{r+=e[i][0],o+=e[i][1]}),[r/t.length,o/t.length]}function W(e,t){let r=1/0,o=1/0,i=-1/0,a=-1/0;return t.forEach(u=>{const[n,l]=e[u];r=Math.min(r,n),o=Math.min(o,l),i=Math.max(i,n),a=Math.max(a,l)}),{x:r,y:o,width:i-r,height:a-o}}function c(e,t,r,o=.8,i=1.5){const a=W(t,r),u=L(t,r),n=a.width*i,l=a.height*i,g=Math.max(n,l);e.save(),e.translate(u[0],u[1]),e.scale(n/g,l/g);const m=e.createRadialGradient(0,0,g*.2,0,0,g);m.addColorStop(0,`rgba(255, 255, 255, ${o})`),m.addColorStop(.6,`rgba(255, 255, 255, ${o*.7})`),m.addColorStop(.85,`rgba(255, 255, 255, ${o*.3})`),m.addColorStop(1,"rgba(255, 255, 255, 0)"),e.fillStyle=m,e.beginPath(),e.arc(0,0,g,0,Math.PI*2),e.fill(),e.restore()}function E(e,t,r){e.globalCompositeOperation="destination-out",e.beginPath(),r.forEach((o,i)=>{const[a,u]=t[o];i===0?e.moveTo(a,u):e.lineTo(a,u)}),e.closePath(),e.fillStyle="rgba(255, 255, 255, 1)",e.fill(),e.globalCompositeOperation="source-over"}function ue(e,t){e.globalCompositeOperation="source-over",c(e,t,s.forehead,.85,1.3),c(e,t,[6,197,195,5,168,8,9],.75,1),c(e,t,[33,133,155,154,153,145,144,163],.8,1.4),c(e,t,[263,362,382,381,380,374,373,390],.8,1.4),c(e,t,[133,155,154,153,145,144,163,7],.7,1.2),c(e,t,[362,382,381,380,374,373,390,249],.7,1.2),c(e,t,s.rightNasolabial,.75,1.5),c(e,t,s.leftNasolabial,.75,1.5),c(e,t,[2,98,97,99,75,60,20,242,97,98,2,327,326,328,305,290,250,462,1,10,164,393],.85,1.4),c(e,t,[61,146,91,181,84,17,314,405,321,375],.85,1.6),c(e,t,[152,377,400,378,379,365,397,288,361],.65,1.3),E(e,t,s.rightEyeUpper.concat(s.rightEyeLower)),E(e,t,s.leftEyeUpper.concat(s.leftEyeLower)),E(e,t,s.rightEyebrow),E(e,t,s.leftEyebrow),E(e,t,s.lipOutline)}function fe(e,t){const r=L(t,s.faceOval),o=W(t,s.faceOval),i=o.width*.6,a=o.height*.7,u=Math.max(i,a);e.save(),e.translate(r[0],r[1]),e.scale(i/u,a/u);const n=e.createRadialGradient(0,0,u*.3,0,0,u);n.addColorStop(0,"rgba(255, 255, 255, 1)"),n.addColorStop(.5,"rgba(255, 255, 255, 1)"),n.addColorStop(.75,"rgba(255, 255, 255, 0.85)"),n.addColorStop(.9,"rgba(255, 255, 255, 0.5)"),n.addColorStop(.97,"rgba(255, 255, 255, 0.2)"),n.addColorStop(1,"rgba(255, 255, 255, 0)"),e.fillStyle=n,e.beginPath(),e.arc(0,0,u,0,Math.PI*2),e.fill(),e.restore()}function ce(e,t){const r=L(t,s.faceOval),o=W(t,s.faceOval),i=o.width*.72,a=o.height*.82,u=Math.max(i,a);e.save(),e.translate(r[0],r[1]),e.scale(i/u,a/u);const n=e.createRadialGradient(0,0,u*.1,0,0,u);n.addColorStop(0,"rgba(255, 255, 255, 0.95)"),n.addColorStop(.6,"rgba(255, 255, 255, 0.92)"),n.addColorStop(.8,"rgba(255, 255, 255, 0.7)"),n.addColorStop(.92,"rgba(255, 255, 255, 0.4)"),n.addColorStop(1,"rgba(255, 255, 255, 0)"),e.fillStyle=n,e.beginPath(),e.arc(0,0,u,0,Math.PI*2),e.fill(),e.restore(),c(e,t,s.forehead,.95,1.3),c(e,t,s.rightCheek,.95,1.4),c(e,t,s.leftCheek,.95,1.4),c(e,t,[2,98,97,99,75,60,20,242,327,326,328,305,290,250,462],.9,1.2),c(e,t,[205,206,207,187,123,116,111],.92,1.2),c(e,t,[425,426,427,411,352,345,340],.92,1.2),E(e,t,s.rightEyeUpper.concat(s.rightEyeLower)),E(e,t,s.leftEyeUpper.concat(s.leftEyeLower)),E(e,t,s.rightEyebrow),E(e,t,s.leftEyebrow),E(e,t,[61,185,40,39,37,0,267,269,270,409,291,146,91,181,84,17,314,405,321,375])}function le(e,t){const r=L(t,s.faceOval),o=W(t,s.faceOval),i=o.width*.75,a=o.height*.85,u=Math.max(i,a);e.save(),e.translate(r[0],r[1]),e.scale(i/u,a/u);const n=e.createRadialGradient(0,0,u*.15,0,0,u);n.addColorStop(0,"rgba(255, 255, 255, 1)"),n.addColorStop(.5,"rgba(255, 255, 255, 0.98)"),n.addColorStop(.7,"rgba(255, 255, 255, 0.92)"),n.addColorStop(.85,"rgba(255, 255, 255, 0.6)"),n.addColorStop(.95,"rgba(255, 255, 255, 0.3)"),n.addColorStop(1,"rgba(255, 255, 255, 0)"),e.fillStyle=n,e.beginPath(),e.arc(0,0,u,0,Math.PI*2),e.fill(),e.restore(),c(e,t,s.forehead,1,1.4),c(e,t,s.rightCheek,1,1.5),c(e,t,s.leftCheek,1,1.5),c(e,t,[6,197,195,5,4,1,19,94,2],.98,1.3),c(e,t,[152,377,400,378,379,365,397,288,361,323,454,93],.98,1.4),c(e,t,[8,9,168,6,197,195,5],.95,1),c(e,t,[218,126,142,36,205,206],.95,1.2),c(e,t,[438,355,371,266,425,426],.95,1.2),E(e,t,s.rightEyeUpper.concat(s.rightEyeLower)),E(e,t,s.leftEyeUpper.concat(s.leftEyeLower)),E(e,t,s.rightEyebrow),E(e,t,s.leftEyebrow),E(e,t,[61,185,40,39,37,0,267,269,270,409,291,146,91,181,84,17,314,405,321,375])}function he(e,t){c(e,t,s.rightCheek,.95,1.4),c(e,t,s.leftCheek,.95,1.4),c(e,t,s.rightEyeUpper.concat([70,63,105,66,107]),.9,1.1),c(e,t,s.leftEyeUpper.concat([300,293,334,296,336]),.9,1.1),c(e,t,s.rightNasolabial,.8,1.3),c(e,t,s.leftNasolabial,.8,1.3),c(e,t,[205,206,207,187,123],.85,1),c(e,t,[425,426,427,411,352],.85,1),c(e,t,[172,136,150,149,176,148],.75,1.2),c(e,t,[397,365,379,378,400,377],.75,1.2),E(e,t,s.rightEyeUpper.concat(s.rightEyeLower)),E(e,t,s.leftEyeUpper.concat(s.leftEyeLower))}function de({image:e,faceMeshRef:t,maskCanvasRef:r,filterType:o,syncMaskToGPU:i,renderGL:a,minimal:u,forceAfter:n,setView:l,setProcessing:g}){const[m,h]=D.useState(!1),[P,B]=D.useState(!1),M=D.useCallback(async F=>new Promise((p,b)=>{const w=t.current;if(!w){b(new Error("FaceMesh no inicializado"));return}if(typeof w.onResults!="function"||typeof w.send!="function"){b(new Error("FaceMesh inválido"));return}const v=document.createElement("canvas");v.width=F.width,v.height=F.height;const S=v.getContext("2d");if(!S){b(new Error("No se pudo crear contexto temporal"));return}S.drawImage(F,0,0);let C=!1;const R=window.setTimeout(()=>{C||(C=!0,b(new Error("Timeout en detección facial")))},1800);w.onResults(y=>{C||(C=!0,window.clearTimeout(R),p(y))}),Promise.resolve(w.send({image:v})).catch(y=>{C||(C=!0,window.clearTimeout(R),b(y))})}),[t]),U=D.useCallback(async(F=0)=>{if(!e){g(!1);return}if(!t.current){try{const p=r.current;if(!p){g(!1);return}const b=p.getContext("2d");if(!b){g(!1);return}b.clearRect(0,0,p.width,p.height),b.fillStyle="rgba(255,255,255,1)",b.fillRect(0,0,p.width,p.height),i(),a()}finally{g(!1)}return}h(!0),g(!0);try{const p=await M(e);if(!p.multiFaceLandmarks||p.multiFaceLandmarks.length===0){if(F<2){setTimeout(()=>{U(F+1)},500);return}const y=r.current,A=y&&y.getContext("2d");A&&(A.clearRect(0,0,y.width,y.height),A.fillStyle="rgba(255,255,255,1)",A.fillRect(0,0,y.width,y.height)),i(),a();return}const b=p.multiFaceLandmarks[0],w=r.current,v=w.getContext("2d");v.clearRect(0,0,w.width,w.height);const S=w.width,C=w.height,R=b.map(y=>[y.x*S,y.y*C]);o==="wrinkles"?ue(v,R):o==="firmness"?he(v,R):o==="brightness"?fe(v,R):o==="spots"?ce(v,R):o==="acne"&&le(v,R),i(),!u&&!n&&l("split"),a(),B(!0)}catch(p){console.error("Error en detección:",p);const b=r.current,w=b&&b.getContext("2d");w&&(w.clearRect(0,0,b.width,b.height),w.fillStyle="rgba(255,255,255,1)",w.fillRect(0,0,b.width,b.height)),i(),a()}finally{h(!1),g(!1)}},[M,t,o,n,e,r,u,a,g,l,i]);return{detectAndMaskFace:U,detectingFace:m,faceDetected:P}}function me(e){const t=T.getProductConfig(e.id)||{},r=e.filterType||t.webglConfig&&t.webglConfig.filterType||"custom",o=e.defaultWebglConfig||{},i={filterType:r,intensity:e.defaultIntensity!==void 0?e.defaultIntensity:o.intensity??.5,sigma:e.defaultSigma!==void 0?e.defaultSigma:o.sigma??4,brightness:e.defaultBrightness!==void 0?e.defaultBrightness:o.brightness??0,contrast:o.contrast??1,warmthR:o.warmthR??0,warmthB:o.warmthB??0,warmthA:o.warmthA??0},a=t.webglConfig||{};return{...i,...a,filterType:r}}const Y={base:{key:"base",label:"Base",defaults:{intensity:.5,sigma:4,brightness:0,contrast:1,warmthR:0,warmthB:0,warmthA:0},deep:{}}},ge=["base"];function be(e){return Y[e]||null}function we(e={}){var a;const t=T.getProductConfig(e.id)||{},r=e.filterType||((a=t.webglConfig)==null?void 0:a.filterType)||"custom",o=e.defaultWebglConfig||Y.base.defaults,i=t.webglConfig||{};return{filterType:r,intensity:e.defaultIntensity!==void 0?e.defaultIntensity:o.intensity??.5,sigma:e.defaultSigma!==void 0?e.defaultSigma:o.sigma??4,brightness:e.defaultBrightness!==void 0?e.defaultBrightness:o.brightness??0,contrast:o.contrast??1,warmthR:o.warmthR??0,warmthB:o.warmthB??0,warmthA:o.warmthA??0,...i,filterType:r}}async function $({token:e,products:t=[]}={}){if(!e)throw new Error("Falta token de licencia para activar md-face-engine.");const{default:r}=await Promise.resolve().then(()=>require("./MartidermEngine-ZSpNzcN-.cjs")),o=new r;await o.activate(e),o.assertActivated();const i=o.getFilterConfigManager();return Array.isArray(t)&&i.setProducts(t),{engine:o,FILTERS:o.getFilterRegistry(),FILTER_ORDER:o.getFilterOrder(),getFilter:a=>o.getFilter(a),filterConfigManager:i,buildWebglConfigForProduct:a=>o.buildWebglConfigForProduct(a)}}async function Ee({token:e,products:t=[]}={}){let r=null,o=null,i=!1;if(e)try{r=await $({token:e,products:t}),i=!0}catch(a){o=a,i=!1}return!r&&Array.isArray(t)&&typeof(T==null?void 0:T.setProducts)=="function"&&T.setProducts(t),{engine:(r==null?void 0:r.engine)||null,FILTERS:(r==null?void 0:r.FILTERS)||Y,FILTER_ORDER:(r==null?void 0:r.FILTER_ORDER)||ge,getFilter:(r==null?void 0:r.getFilter)||be,filterConfigManager:(r==null?void 0:r.filterConfigManager)||T,buildWebglConfigForProduct:(r==null?void 0:r.buildWebglConfigForProduct)||we,license:{active:i,error:o,mode:i?"licensed":"unlicensed"}}}async function k(e={}){const t=e.locateFile||(a=>`https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh@0.4.1633559619/${a}`),r={maxNumFaces:1,refineLandmarks:!0,minDetectionConfidence:.5,minTrackingConfidence:.5,...e.detectorOptions||{}};let o=typeof window<"u"?window.FaceMesh:void 0;if(!o&&typeof window<"u"){const a=document.querySelector('script[data-md-face-mesh="1"]');a?window.FaceMesh||await new Promise((u,n)=>{a.addEventListener("load",u,{once:!0}),a.addEventListener("error",()=>n(new Error("No se pudo cargar MediaPipe FaceMesh")),{once:!0})}):await new Promise((u,n)=>{const l=document.createElement("script");l.src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh@0.4.1633559619/face_mesh.js",l.async=!0,l.dataset.mdFaceMesh="1",l.onload=u,l.onerror=()=>n(new Error("No se pudo cargar MediaPipe FaceMesh")),document.head.appendChild(l)}),o=window.FaceMesh}if(!o)throw new Error("No se pudo inicializar el detector de landmarks");const i=new o({locateFile:t});return i.setOptions(r),i}exports.applyGrayscaleInRegion=N;exports.blurFS=ne;exports.buildWebglConfigForProduct=me;exports.composeFS=ie;exports.createFBO=te;exports.createGL=Z;exports.createLandmarkDetector=k;exports.createMdFaceEngineClient=$;exports.createMdFaceEngineRuntime=Ee;exports.createProgram=z;exports.createTexture=ee;exports.filterConfigManager=T;exports.getFilterTypeId=V;exports.makeFullscreenQuad=re;exports.quadVS=oe;exports.renderWebglFrame=ae;exports.setViewport=G;exports.useFaceMasking=de;exports.useLandmarkDetector=se;
|