md-face-engine 1.1.2 → 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.
@@ -0,0 +1,739 @@
1
+ import { useRef as V, useEffect as k, useState as G, useCallback as Y } from "react";
2
+ const q = {
3
+ smooth: { enabled: !0, radius: 4, passes: 2, opacity: 0.4 },
4
+ brightness: { enabled: !0, value: 0 },
5
+ contrast: { enabled: !0, value: 1 },
6
+ warmth: { enabled: !0, rPlus: 0, bMinus: 0, alpha: 0 }
7
+ };
8
+ class Q {
9
+ constructor(t = {}) {
10
+ 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();
11
+ }
12
+ init() {
13
+ const t = this.loadConfigurations();
14
+ (!t || Object.keys(t).length === 0) && this.products.length > 0 && this.initializeDefaultConfigurations();
15
+ }
16
+ setProducts(t = []) {
17
+ this.products = Array.isArray(t) ? t : [];
18
+ const o = this.loadConfigurations();
19
+ (!o || Object.keys(o).length === 0) && this.products.length > 0 && this.initializeDefaultConfigurations();
20
+ }
21
+ initializeDefaultConfigurations() {
22
+ try {
23
+ const t = {};
24
+ this.products.forEach((o) => {
25
+ t[o.id] = this.generateProductConfig(o);
26
+ }), this.saveConfigurations(t);
27
+ } catch (t) {
28
+ console.error("Error inicializando configuraciones:", t);
29
+ }
30
+ }
31
+ generateProductConfig(t = {}) {
32
+ return {
33
+ productId: t.id,
34
+ productName: t.name,
35
+ category: t.category,
36
+ filters: { ...q },
37
+ webglConfig: t.defaultWebglConfig ? { ...t.defaultWebglConfig } : {},
38
+ lastModified: (/* @__PURE__ */ new Date()).toISOString(),
39
+ version: "2.0"
40
+ };
41
+ }
42
+ getProductConfig(t) {
43
+ return this.loadConfigurations()[t] || null;
44
+ }
45
+ saveProductConfig(t, o) {
46
+ const r = this.loadConfigurations();
47
+ return r[t] = {
48
+ ...o,
49
+ lastModified: (/* @__PURE__ */ new Date()).toISOString()
50
+ }, this.saveConfigurations(r), !0;
51
+ }
52
+ getAllConfigurations() {
53
+ return this.loadConfigurations();
54
+ }
55
+ loadConfigurations() {
56
+ try {
57
+ const t = localStorage.getItem(this.storageKey);
58
+ return t ? JSON.parse(t) : {};
59
+ } catch (t) {
60
+ return console.error("Error cargando configuraciones:", t), {};
61
+ }
62
+ }
63
+ saveConfigurations(t) {
64
+ try {
65
+ return localStorage.setItem(this.storageKey, JSON.stringify(t)), this.createBackup(t), !0;
66
+ } catch (o) {
67
+ return console.error("Error guardando configuraciones:", o), !1;
68
+ }
69
+ }
70
+ createBackup(t = null) {
71
+ try {
72
+ const o = t || this.loadConfigurations(), r = {
73
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
74
+ configurations: o,
75
+ version: "2.0"
76
+ };
77
+ return localStorage.setItem(this.backupKey, JSON.stringify(r)), !0;
78
+ } catch (o) {
79
+ return console.error("Error creando backup:", o), !1;
80
+ }
81
+ }
82
+ restoreFromBackup() {
83
+ try {
84
+ const t = localStorage.getItem(this.backupKey);
85
+ if (t) {
86
+ const o = JSON.parse(t);
87
+ return this.saveConfigurations(o.configurations), !0;
88
+ }
89
+ return !1;
90
+ } catch (t) {
91
+ return console.error("Error restaurando backup:", t), !1;
92
+ }
93
+ }
94
+ exportConfigurations() {
95
+ const t = this.loadConfigurations(), o = {
96
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
97
+ configurations: t,
98
+ version: "2.0"
99
+ };
100
+ return JSON.stringify(o, null, 2);
101
+ }
102
+ importConfigurations(t) {
103
+ try {
104
+ const o = JSON.parse(t);
105
+ return o.configurations ? (this.saveConfigurations(o.configurations), !0) : !1;
106
+ } catch (o) {
107
+ return console.error("Error importando configuraciones:", o), !1;
108
+ }
109
+ }
110
+ resetToDefaults() {
111
+ try {
112
+ return localStorage.removeItem(this.storageKey), this.initializeDefaultConfigurations(), !0;
113
+ } catch (t) {
114
+ return console.error("Error reseteando configuraciones:", t), !1;
115
+ }
116
+ }
117
+ isAuthenticated() {
118
+ try {
119
+ const t = localStorage.getItem(this.authKey);
120
+ if (!t) return !1;
121
+ const o = JSON.parse(t);
122
+ return !!(o != null && o.authenticated);
123
+ } catch {
124
+ return !1;
125
+ }
126
+ }
127
+ authenticateAdmin(t, o) {
128
+ if (t === "admin" && o === "martiderm2024") {
129
+ const a = {
130
+ authenticated: !0,
131
+ username: t,
132
+ token: `adm-${Date.now()}`,
133
+ lastLogin: (/* @__PURE__ */ new Date()).toISOString()
134
+ };
135
+ return localStorage.setItem(this.authKey, JSON.stringify(a)), { success: !0, username: t };
136
+ }
137
+ return { success: !1, error: "Credenciales inválidas" };
138
+ }
139
+ getAuthenticatedUser() {
140
+ try {
141
+ const t = localStorage.getItem(this.authKey);
142
+ if (!t) return null;
143
+ const o = JSON.parse(t);
144
+ return o != null && o.authenticated ? { username: o.username } : null;
145
+ } catch {
146
+ return null;
147
+ }
148
+ }
149
+ logout() {
150
+ try {
151
+ return localStorage.removeItem(this.authKey), !0;
152
+ } catch {
153
+ return !1;
154
+ }
155
+ }
156
+ exportConfiguration() {
157
+ return this.exportConfigurations();
158
+ }
159
+ }
160
+ const F = new Q();
161
+ function ce(e) {
162
+ if (!e) throw new Error("Canvas WebGL inexistente");
163
+ const t = e.getContext("webgl", { premultipliedAlpha: !1, preserveDrawingBuffer: !0 }) || e.getContext("experimental-webgl");
164
+ if (!t) throw new Error("WebGL no disponible en este navegador");
165
+ return t;
166
+ }
167
+ function K(e, t, o) {
168
+ const r = e.createShader(t);
169
+ if (e.shaderSource(r, o), e.compileShader(r), !e.getShaderParameter(r, e.COMPILE_STATUS)) {
170
+ const i = e.getShaderInfoLog(r);
171
+ throw e.deleteShader(r), new Error(`Shader error: ${i}`);
172
+ }
173
+ return r;
174
+ }
175
+ function le(e, t, o) {
176
+ const r = K(e, e.VERTEX_SHADER, t), i = K(e, e.FRAGMENT_SHADER, o), a = e.createProgram();
177
+ if (e.attachShader(a, r), e.attachShader(a, i), e.linkProgram(a), !e.getProgramParameter(a, e.LINK_STATUS)) {
178
+ const f = e.getProgramInfoLog(a);
179
+ throw e.deleteProgram(a), new Error(`Program link error: ${f}`);
180
+ }
181
+ return a;
182
+ }
183
+ function he(e, t, o, r) {
184
+ const i = e.createTexture();
185
+ 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), r ? e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, e.RGBA, e.UNSIGNED_BYTE, r) : e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, t, o, 0, e.RGBA, e.UNSIGNED_BYTE, null), i;
186
+ }
187
+ function de(e, t) {
188
+ const o = e.createFramebuffer();
189
+ if (e.bindFramebuffer(e.FRAMEBUFFER, o), e.framebufferTexture2D(e.FRAMEBUFFER, e.COLOR_ATTACHMENT0, e.TEXTURE_2D, t, 0), e.checkFramebufferStatus(e.FRAMEBUFFER) !== e.FRAMEBUFFER_COMPLETE)
190
+ throw new Error("FBO incomplete");
191
+ return e.bindFramebuffer(e.FRAMEBUFFER, null), o;
192
+ }
193
+ function $(e, t, o) {
194
+ e.viewport(0, 0, t, o);
195
+ }
196
+ function me(e) {
197
+ const t = e.createBuffer();
198
+ e.bindBuffer(e.ARRAY_BUFFER, t);
199
+ const o = new Float32Array([-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1]);
200
+ e.bufferData(e.ARRAY_BUFFER, o, e.STATIC_DRAW);
201
+ const r = e.createBuffer();
202
+ e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, r);
203
+ const i = new Uint16Array([0, 1, 2, 2, 1, 3]);
204
+ return e.bufferData(e.ELEMENT_ARRAY_BUFFER, i, e.STATIC_DRAW), { vbo: t, ibo: r };
205
+ }
206
+ function Z(e) {
207
+ return e === "brightness" ? 1 : e === "spots" ? 2 : e === "acne" ? 3 : e === "firmness" ? 4 : 0;
208
+ }
209
+ const be = [
210
+ "attribute vec2 a_pos;",
211
+ "attribute vec2 a_uv;",
212
+ "varying vec2 v_uv;",
213
+ "void main() {",
214
+ " v_uv = a_uv;",
215
+ " gl_Position = vec4(a_pos, 0.0, 1.0);",
216
+ "}"
217
+ ].join(`
218
+ `), ge = [
219
+ "precision mediump float;",
220
+ "varying vec2 v_uv;",
221
+ "uniform sampler2D u_tex;",
222
+ "uniform vec2 u_texel;",
223
+ "uniform vec2 u_dir;",
224
+ "uniform float u_sigma;",
225
+ "float gaussian(float x, float s) { return exp(-(x*x)/(2.0*s*s)); }",
226
+ "void main() {",
227
+ " vec2 stepDir = u_dir * u_sigma;",
228
+ " vec4 col = texture2D(u_tex, v_uv) * gaussian(0.0, 1.0);",
229
+ " float wsum = gaussian(0.0, 1.0);",
230
+ " for (int i = 1; i <= 4; i++) {",
231
+ " float f = float(i);",
232
+ " float w = gaussian(f, 1.0);",
233
+ " vec2 off = stepDir * f * u_texel;",
234
+ " col += texture2D(u_tex, v_uv + off) * w;",
235
+ " col += texture2D(u_tex, v_uv - off) * w;",
236
+ " wsum += 2.0 * w;",
237
+ " }",
238
+ " gl_FragColor = col / wsum;",
239
+ "}"
240
+ ].join(`
241
+ `), we = [
242
+ "precision mediump float;",
243
+ "varying vec2 v_uv;",
244
+ "uniform sampler2D u_orig;",
245
+ "uniform sampler2D u_blur;",
246
+ "uniform sampler2D u_mask;",
247
+ "uniform float u_intensity;",
248
+ "uniform float u_brightness;",
249
+ "uniform float u_contrast;",
250
+ "uniform float u_warmthR;",
251
+ "uniform float u_warmthB;",
252
+ "uniform float u_warmthAlpha;",
253
+ "uniform int u_filterType;",
254
+ "void main() {",
255
+ " vec4 o = texture2D(u_orig, v_uv);",
256
+ " vec4 b = texture2D(u_blur, v_uv);",
257
+ " float a = clamp(texture2D(u_mask, v_uv).a, 0.0, 1.0);",
258
+ " float m = a * u_intensity;",
259
+ " vec4 blended = mix(o, b, m);",
260
+ " blended.rgb += u_brightness * a;",
261
+ " blended.rgb = clamp(blended.rgb, 0.0, 1.0);",
262
+ " gl_FragColor = blended;",
263
+ "if (u_filterType == 2) {",
264
+ "vec3 smoothed = mix(o.rgb, b.rgb, m * 0.7);",
265
+ "float origLum = dot(o.rgb, vec3(0.299, 0.587, 0.114));",
266
+ "float smoothLum = dot(smoothed, vec3(0.299, 0.587, 0.114));",
267
+ "float darkness = max(0.0, smoothLum - origLum);",
268
+ "smoothed.rgb += vec3(darkness * 0.4) * m;",
269
+ "float targetLum = dot(smoothed, vec3(0.299, 0.587, 0.114));",
270
+ "vec3 uniformTone = vec3(targetLum * 1.02);",
271
+ "smoothed.rgb = mix(smoothed.rgb, uniformTone, m * 0.35);",
272
+ "float avgChannel = (smoothed.r + smoothed.g + smoothed.b) / 3.0;",
273
+ "smoothed.r = mix(smoothed.r, avgChannel, m * 0.25);",
274
+ "smoothed.g = mix(smoothed.g, avgChannel, m * 0.15);",
275
+ "smoothed.b = mix(smoothed.b, avgChannel, m * 0.15);",
276
+ "float gray = dot(smoothed, vec3(0.299, 0.587, 0.114));",
277
+ "smoothed.rgb = mix(vec3(gray), smoothed.rgb, 0.85);",
278
+ "smoothed.rgb = pow(smoothed.rgb, vec3(0.96));",
279
+ "smoothed.rgb += vec3(0.02) * m;",
280
+ "float finalGray = dot(smoothed, vec3(0.299, 0.587, 0.114));",
281
+ "finalGray = pow(finalGray, 0.88);",
282
+ "blended.rgb = vec3(finalGray);",
283
+ "blended.rgb = clamp(blended.rgb, 0.0, 1.0);",
284
+ "}",
285
+ "if (u_filterType == 3) {",
286
+ "float origLum = dot(o.rgb, vec3(0.299, 0.587, 0.114));",
287
+ "float blurLum = dot(b.rgb, vec3(0.299, 0.587, 0.114));",
288
+ "float detail = origLum - blurLum;",
289
+ "vec3 smoothed = mix(o.rgb, b.rgb, m * 0.85);",
290
+ "float detailAmount = 0.25 * (1.0 - m * 0.5);",
291
+ "smoothed.rgb += detail * detailAmount * sign(detail);",
292
+ "float avgColor = (smoothed.r + smoothed.g + smoothed.b) / 3.0;",
293
+ "smoothed.r = mix(smoothed.r, avgColor, m * 0.35);",
294
+ "smoothed.g = mix(smoothed.g, avgColor, m * 0.15);",
295
+ "smoothed.b = mix(smoothed.b, avgColor, m * 0.1);",
296
+ "smoothed.rgb = mix(smoothed.rgb, vec3(blurLum), m * 0.2);",
297
+ "smoothed.rgb += vec3(0.05) * m;",
298
+ "blended.rgb = clamp(smoothed, 0.0, 1.0);",
299
+ "vec2 texelSize = vec2(1.0) / vec2(1024.0, 1024.0);",
300
+ "vec3 avgNeighbor = vec3(0.0);",
301
+ "float weightSum = 0.0;",
302
+ "for(int dx = -1; dx <= 1; dx++) {",
303
+ "for(int dy = -1; dy <= 1; dy++) {",
304
+ "vec2 offset = vec2(float(dx), float(dy)) * texelSize * 2.0;",
305
+ "vec3 neighbor = texture2D(u_blur, v_uv + offset).rgb;",
306
+ "float colorDiff = length(neighbor - blended.rgb);",
307
+ "float weight = exp(-colorDiff * 5.0) * a;",
308
+ "avgNeighbor += neighbor * weight;",
309
+ "weightSum += weight;",
310
+ "}",
311
+ "}",
312
+ "if(weightSum > 0.01) {",
313
+ "vec3 bilateralSmooth = avgNeighbor / weightSum;",
314
+ "blended.rgb = mix(blended.rgb, bilateralSmooth, m * 0.3);",
315
+ "}",
316
+ "}",
317
+ "if (u_filterType == 4) {",
318
+ "float lift = 0.02 * u_intensity;",
319
+ "vec2 off = vec2(0.0, -lift);",
320
+ "vec4 lifted = texture2D(u_orig, v_uv + off * a);",
321
+ "blended.rgb = mix(blended.rgb, lifted.rgb, 0.5 * m);",
322
+ "blended.rgb = pow(blended.rgb, vec3(1.0/(1.0 - 0.06 * u_intensity)));",
323
+ "blended.rgb += vec3(0.02 * u_intensity * a);",
324
+ "blended.rgb = clamp(blended.rgb, 0.0, 1.0);",
325
+ "}",
326
+ "blended.rgb = ((blended.rgb - 0.5) * u_contrast) + 0.5;",
327
+ "vec3 warm = blended.rgb;",
328
+ "warm.r += u_warmthR / 255.0;",
329
+ "warm.b = max(0.0, warm.b - (u_warmthB / 255.0));",
330
+ "blended.rgb = mix(blended.rgb, clamp(warm, 0.0, 1.0), u_warmthAlpha);",
331
+ "gl_FragColor = blended;",
332
+ "}"
333
+ ].join(`
334
+ `);
335
+ function X(e, t, o, r, i, a = "Error aplicando escala de grises") {
336
+ try {
337
+ const f = e.getImageData(t, o, r, i), n = f.data;
338
+ for (let l = 0; l < n.length; l += 4) {
339
+ const b = 0.299 * n[l] + 0.587 * n[l + 1] + 0.114 * n[l + 2];
340
+ n[l] = b, n[l + 1] = b, n[l + 2] = b;
341
+ }
342
+ e.putImageData(f, t, o);
343
+ } catch (f) {
344
+ console.error(a, f);
345
+ }
346
+ }
347
+ function J(e, t, o) {
348
+ const r = e.getAttribLocation(t, "a_pos"), i = e.getAttribLocation(t, "a_uv");
349
+ e.bindBuffer(e.ARRAY_BUFFER, o.vbo), e.enableVertexAttribArray(r), e.enableVertexAttribArray(i), e.vertexAttribPointer(r, 2, e.FLOAT, !1, 16, 0), e.vertexAttribPointer(i, 2, e.FLOAT, !1, 16, 8), e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, o.ibo);
350
+ }
351
+ function H(e, t, o, r) {
352
+ e.bindFramebuffer(e.FRAMEBUFFER, t), $(e, o, r), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.drawElements(e.TRIANGLES, 6, e.UNSIGNED_SHORT, 0);
353
+ }
354
+ function Ee({
355
+ gl: e,
356
+ image: t,
357
+ imgSize: o,
358
+ programs: r,
359
+ quad: i,
360
+ textures: a,
361
+ framebuffers: f,
362
+ params: n,
363
+ canvases: l,
364
+ callbacks: b = {}
365
+ }) {
366
+ if (!e || !t) {
367
+ const d = l == null ? void 0 : l.outCanvas;
368
+ if (d && t) {
369
+ const _ = d.getContext("2d"), L = o == null ? void 0 : o.w, W = o == null ? void 0 : o.h;
370
+ _ && L && W && (_.clearRect(0, 0, L, W), _.drawImage(t, 0, 0, L, W));
371
+ }
372
+ return;
373
+ }
374
+ const m = o == null ? void 0 : o.w, h = o == null ? void 0 : o.h;
375
+ if (!m || !h) return;
376
+ e.useProgram(r.blur), J(e, r.blur, i);
377
+ const M = e.getUniformLocation(r.blur, "u_texel"), P = e.getUniformLocation(r.blur, "u_dir"), D = e.getUniformLocation(r.blur, "u_sigma"), U = e.getUniformLocation(r.blur, "u_tex");
378
+ e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, a.orig), e.uniform1i(U, 0), e.uniform2f(M, 1 / m, 1 / h), e.uniform2f(P, 1, 0), e.uniform1f(D, n.sigma), H(e, f.ping, m, h), e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, a.ping), e.uniform1i(U, 0), e.uniform2f(M, 1 / m, 1 / h), e.uniform2f(P, 0, 1), e.uniform1f(D, n.sigma), H(e, f.pong, m, h), e.useProgram(r.compose), J(e, r.compose, i);
379
+ const T = e.getUniformLocation(r.compose, "u_orig"), p = e.getUniformLocation(r.compose, "u_blur"), g = e.getUniformLocation(r.compose, "u_mask"), w = e.getUniformLocation(r.compose, "u_intensity"), v = e.getUniformLocation(r.compose, "u_brightness"), S = e.getUniformLocation(r.compose, "u_contrast"), C = e.getUniformLocation(r.compose, "u_warmthR"), R = e.getUniformLocation(r.compose, "u_warmthB"), y = e.getUniformLocation(r.compose, "u_warmthAlpha"), A = e.getUniformLocation(r.compose, "u_filterType");
380
+ e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, a.orig), e.uniform1i(T, 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(g, 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, Z(n.filterType)), typeof b.onConfigApplied == "function" && b.onConfigApplied({
381
+ intensity: n.intensity,
382
+ sigma: n.sigma,
383
+ brightness: n.brightness,
384
+ contrast: n.contrast,
385
+ warmthR: n.warmthR,
386
+ warmthB: n.warmthB,
387
+ warmthA: n.warmthA,
388
+ filterType: n.filterType
389
+ }), e.bindFramebuffer(e.FRAMEBUFFER, null), $(e, m, h), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.drawElements(e.TRIANGLES, 6, e.UNSIGNED_SHORT, 0);
390
+ const I = l.glCanvas, B = l.outCanvas, j = l.maskCanvas, u = B && B.getContext("2d");
391
+ if (u) {
392
+ if (e.finish(), u.clearRect(0, 0, m, h), n.view === "before")
393
+ u.drawImage(t, 0, 0, m, h), n.filterType === "spots" && X(u, 0, 0, m, h, 'Error aplicando escala de grises en "antes":');
394
+ else if (n.view === "after")
395
+ !!I && I.width && I.height ? u.drawImage(I, 0, 0, m, h) : u.drawImage(t, 0, 0, m, h);
396
+ else if (n.view === "mask")
397
+ u.fillStyle = "#000000", u.fillRect(0, 0, m, h), u.drawImage(j, 0, 0, m, h);
398
+ else {
399
+ const d = Math.max(0, Math.min(1, n.splitPos)) * m;
400
+ if (n.mirrored) {
401
+ d > 0 && u.drawImage(I, 0, 0, d, h, 0, 0, d, h);
402
+ const _ = m - d;
403
+ _ > 0 && (u.drawImage(t, d, 0, _, h, d, 0, _, h), n.filterType === "spots" && X(
404
+ u,
405
+ d,
406
+ 0,
407
+ _,
408
+ h,
409
+ "Error aplicando B&N en split derecha (mirrored):"
410
+ ));
411
+ } else {
412
+ d > 0 && (u.drawImage(t, 0, 0, d, h, 0, 0, d, h), n.filterType === "spots" && X(u, 0, 0, d, h, "Error aplicando B&N en split izquierda:"));
413
+ const _ = m - d;
414
+ _ > 0 && u.drawImage(I, d, 0, _, h, d, 0, _, h);
415
+ }
416
+ u.save(), u.strokeStyle = "rgba(255,255,255,0.9)", u.lineWidth = 2, u.beginPath(), u.moveTo(Math.floor(d), 0), u.lineTo(Math.floor(d), h), u.stroke(), u.fillStyle = "rgba(0,0,0,0.15)", u.beginPath(), u.arc(Math.floor(d) + 2, h / 2 + 2, 14, 0, Math.PI * 2), u.fill(), u.fillStyle = "#ffffff", u.beginPath(), u.arc(Math.floor(d), h / 2, 14, 0, Math.PI * 2), u.fill(), u.strokeStyle = "rgba(0,0,0,0.25)", u.lineWidth = 1, u.beginPath(), u.arc(Math.floor(d), h / 2, 14, 0, Math.PI * 2), u.stroke(), u.restore();
417
+ }
418
+ if (typeof b.drawOverlay == "function" && b.drawOverlay(u, m, h), typeof b.onProcessed == "function" && B) {
419
+ const d = B.toDataURL("image/jpeg", 0.92);
420
+ d && b.onProcessed(d);
421
+ }
422
+ }
423
+ }
424
+ function pe(e) {
425
+ const t = V(null);
426
+ return k(() => {
427
+ let o = !1;
428
+ try {
429
+ if (t.current) return;
430
+ fe().then((r) => {
431
+ o || (t.current = r);
432
+ }).catch((r) => {
433
+ o || (console.warn("[md-face-engine] Landmark detector unavailable, using fallback mask.", r), t.current = null, typeof e == "function" && e(""));
434
+ });
435
+ } catch (r) {
436
+ console.warn("[md-face-engine] Landmark detector init failed, using fallback mask.", r), t.current = null, typeof e == "function" && e("");
437
+ }
438
+ return () => {
439
+ o = !0;
440
+ };
441
+ }, [e]), t;
442
+ }
443
+ const s = {
444
+ rightEyeUpper: [246, 161, 160, 159, 158, 157, 173],
445
+ rightEyeLower: [33, 7, 163, 144, 145, 153, 154, 155, 133],
446
+ leftEyeUpper: [466, 388, 387, 386, 385, 384, 398],
447
+ leftEyeLower: [263, 249, 390, 373, 374, 380, 381, 382, 362],
448
+ rightEyebrow: [70, 63, 105, 66, 107, 55, 65],
449
+ leftEyebrow: [300, 293, 334, 296, 336, 285, 295],
450
+ lipOutline: [61, 146, 91, 181, 84, 17, 314, 405, 321, 375, 291, 409, 270, 269, 267, 0, 37, 39, 40, 185],
451
+ 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],
452
+ forehead: [10, 338, 297, 332, 284, 251, 389, 356, 70, 63, 105, 66, 107, 336, 296, 334, 293, 300],
453
+ rightCheek: [50, 101, 100, 47, 117, 118, 119, 120, 121, 128, 129],
454
+ leftCheek: [280, 330, 329, 277, 346, 347, 348, 349, 350, 357, 358],
455
+ rightNasolabial: [36, 142, 126, 217, 174],
456
+ leftNasolabial: [266, 371, 355, 437, 399]
457
+ };
458
+ function O(e, t) {
459
+ let o = 0, r = 0;
460
+ return t.forEach((i) => {
461
+ o += e[i][0], r += e[i][1];
462
+ }), [o / t.length, r / t.length];
463
+ }
464
+ function N(e, t) {
465
+ let o = 1 / 0, r = 1 / 0, i = -1 / 0, a = -1 / 0;
466
+ return t.forEach((f) => {
467
+ const [n, l] = e[f];
468
+ o = Math.min(o, n), r = Math.min(r, l), i = Math.max(i, n), a = Math.max(a, l);
469
+ }), { x: o, y: r, width: i - o, height: a - r };
470
+ }
471
+ function c(e, t, o, r = 0.8, i = 1.5) {
472
+ const a = N(t, o), f = O(t, o), n = a.width * i, l = a.height * i, b = Math.max(n, l);
473
+ e.save(), e.translate(f[0], f[1]), e.scale(n / b, l / b);
474
+ const m = e.createRadialGradient(0, 0, b * 0.2, 0, 0, b);
475
+ m.addColorStop(0, `rgba(255, 255, 255, ${r})`), m.addColorStop(0.6, `rgba(255, 255, 255, ${r * 0.7})`), m.addColorStop(0.85, `rgba(255, 255, 255, ${r * 0.3})`), m.addColorStop(1, "rgba(255, 255, 255, 0)"), e.fillStyle = m, e.beginPath(), e.arc(0, 0, b, 0, Math.PI * 2), e.fill(), e.restore();
476
+ }
477
+ function E(e, t, o) {
478
+ e.globalCompositeOperation = "destination-out", e.beginPath(), o.forEach((r, i) => {
479
+ const [a, f] = t[r];
480
+ i === 0 ? e.moveTo(a, f) : e.lineTo(a, f);
481
+ }), e.closePath(), e.fillStyle = "rgba(255, 255, 255, 1)", e.fill(), e.globalCompositeOperation = "source-over";
482
+ }
483
+ function z(e, t) {
484
+ e.globalCompositeOperation = "source-over", c(e, t, s.forehead, 0.85, 1.3), c(e, t, [6, 197, 195, 5, 168, 8, 9], 0.75, 1), c(e, t, [33, 133, 155, 154, 153, 145, 144, 163], 0.8, 1.4), c(e, t, [263, 362, 382, 381, 380, 374, 373, 390], 0.8, 1.4), c(e, t, [133, 155, 154, 153, 145, 144, 163, 7], 0.7, 1.2), c(e, t, [362, 382, 381, 380, 374, 373, 390, 249], 0.7, 1.2), c(e, t, s.rightNasolabial, 0.75, 1.5), c(e, t, s.leftNasolabial, 0.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], 0.85, 1.4), c(e, t, [61, 146, 91, 181, 84, 17, 314, 405, 321, 375], 0.85, 1.6), c(e, t, [152, 377, 400, 378, 379, 365, 397, 288, 361], 0.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);
485
+ }
486
+ function ee(e, t) {
487
+ const o = O(t, s.faceOval), r = N(t, s.faceOval), i = r.width * 0.6, a = r.height * 0.7, f = Math.max(i, a);
488
+ e.save(), e.translate(o[0], o[1]), e.scale(i / f, a / f);
489
+ const n = e.createRadialGradient(0, 0, f * 0.3, 0, 0, f);
490
+ n.addColorStop(0, "rgba(255, 255, 255, 1)"), n.addColorStop(0.5, "rgba(255, 255, 255, 1)"), n.addColorStop(0.75, "rgba(255, 255, 255, 0.85)"), n.addColorStop(0.9, "rgba(255, 255, 255, 0.5)"), n.addColorStop(0.97, "rgba(255, 255, 255, 0.2)"), n.addColorStop(1, "rgba(255, 255, 255, 0)"), e.fillStyle = n, e.beginPath(), e.arc(0, 0, f, 0, Math.PI * 2), e.fill(), e.restore();
491
+ }
492
+ function te(e, t) {
493
+ const o = O(t, s.faceOval), r = N(t, s.faceOval), i = r.width * 0.72, a = r.height * 0.82, f = Math.max(i, a);
494
+ e.save(), e.translate(o[0], o[1]), e.scale(i / f, a / f);
495
+ const n = e.createRadialGradient(0, 0, f * 0.1, 0, 0, f);
496
+ n.addColorStop(0, "rgba(255, 255, 255, 0.95)"), n.addColorStop(0.6, "rgba(255, 255, 255, 0.92)"), n.addColorStop(0.8, "rgba(255, 255, 255, 0.7)"), n.addColorStop(0.92, "rgba(255, 255, 255, 0.4)"), n.addColorStop(1, "rgba(255, 255, 255, 0)"), e.fillStyle = n, e.beginPath(), e.arc(0, 0, f, 0, Math.PI * 2), e.fill(), e.restore(), c(e, t, s.forehead, 0.95, 1.3), c(e, t, s.rightCheek, 0.95, 1.4), c(e, t, s.leftCheek, 0.95, 1.4), c(e, t, [2, 98, 97, 99, 75, 60, 20, 242, 327, 326, 328, 305, 290, 250, 462], 0.9, 1.2), c(e, t, [205, 206, 207, 187, 123, 116, 111], 0.92, 1.2), c(e, t, [425, 426, 427, 411, 352, 345, 340], 0.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]);
497
+ }
498
+ function oe(e, t) {
499
+ const o = O(t, s.faceOval), r = N(t, s.faceOval), i = r.width * 0.75, a = r.height * 0.85, f = Math.max(i, a);
500
+ e.save(), e.translate(o[0], o[1]), e.scale(i / f, a / f);
501
+ const n = e.createRadialGradient(0, 0, f * 0.15, 0, 0, f);
502
+ n.addColorStop(0, "rgba(255, 255, 255, 1)"), n.addColorStop(0.5, "rgba(255, 255, 255, 0.98)"), n.addColorStop(0.7, "rgba(255, 255, 255, 0.92)"), n.addColorStop(0.85, "rgba(255, 255, 255, 0.6)"), n.addColorStop(0.95, "rgba(255, 255, 255, 0.3)"), n.addColorStop(1, "rgba(255, 255, 255, 0)"), e.fillStyle = n, e.beginPath(), e.arc(0, 0, f, 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], 0.98, 1.3), c(e, t, [152, 377, 400, 378, 379, 365, 397, 288, 361, 323, 454, 93], 0.98, 1.4), c(e, t, [8, 9, 168, 6, 197, 195, 5], 0.95, 1), c(e, t, [218, 126, 142, 36, 205, 206], 0.95, 1.2), c(e, t, [438, 355, 371, 266, 425, 426], 0.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]);
503
+ }
504
+ function re(e, t) {
505
+ c(e, t, s.rightCheek, 0.95, 1.4), c(e, t, s.leftCheek, 0.95, 1.4), c(e, t, s.rightEyeUpper.concat([70, 63, 105, 66, 107]), 0.9, 1.1), c(e, t, s.leftEyeUpper.concat([300, 293, 334, 296, 336]), 0.9, 1.1), c(e, t, s.rightNasolabial, 0.8, 1.3), c(e, t, s.leftNasolabial, 0.8, 1.3), c(e, t, [205, 206, 207, 187, 123], 0.85, 1), c(e, t, [425, 426, 427, 411, 352], 0.85, 1), c(e, t, [172, 136, 150, 149, 176, 148], 0.75, 1.2), c(e, t, [397, 365, 379, 378, 400, 377], 0.75, 1.2), E(e, t, s.rightEyeUpper.concat(s.rightEyeLower)), E(e, t, s.leftEyeUpper.concat(s.leftEyeLower));
506
+ }
507
+ function ye({
508
+ image: e,
509
+ faceMeshRef: t,
510
+ maskCanvasRef: o,
511
+ filterType: r,
512
+ syncMaskToGPU: i,
513
+ renderGL: a,
514
+ minimal: f,
515
+ forceAfter: n,
516
+ setView: l,
517
+ setProcessing: b
518
+ }) {
519
+ const [m, h] = G(!1), [M, P] = G(!1), D = Y(
520
+ async (T) => new Promise((p, g) => {
521
+ const w = t.current;
522
+ if (!w) {
523
+ g(new Error("FaceMesh no inicializado"));
524
+ return;
525
+ }
526
+ if (typeof w.onResults != "function" || typeof w.send != "function") {
527
+ g(new Error("FaceMesh inválido"));
528
+ return;
529
+ }
530
+ const v = document.createElement("canvas");
531
+ v.width = T.width, v.height = T.height;
532
+ const S = v.getContext("2d");
533
+ if (!S) {
534
+ g(new Error("No se pudo crear contexto temporal"));
535
+ return;
536
+ }
537
+ S.drawImage(T, 0, 0);
538
+ let C = !1;
539
+ const R = window.setTimeout(() => {
540
+ C || (C = !0, g(new Error("Timeout en detección facial")));
541
+ }, 1800);
542
+ w.onResults((y) => {
543
+ C || (C = !0, window.clearTimeout(R), p(y));
544
+ }), Promise.resolve(w.send({ image: v })).catch((y) => {
545
+ C || (C = !0, window.clearTimeout(R), g(y));
546
+ });
547
+ }),
548
+ [t]
549
+ ), U = Y(
550
+ async (T = 0) => {
551
+ if (!e) {
552
+ b(!1);
553
+ return;
554
+ }
555
+ if (!t.current) {
556
+ try {
557
+ const p = o.current;
558
+ if (!p) {
559
+ b(!1);
560
+ return;
561
+ }
562
+ const g = p.getContext("2d");
563
+ if (!g) {
564
+ b(!1);
565
+ return;
566
+ }
567
+ g.clearRect(0, 0, p.width, p.height), g.fillStyle = "rgba(255,255,255,1)", g.fillRect(0, 0, p.width, p.height), i(), a();
568
+ } finally {
569
+ b(!1);
570
+ }
571
+ return;
572
+ }
573
+ h(!0), b(!0);
574
+ try {
575
+ const p = await D(e);
576
+ if (!p.multiFaceLandmarks || p.multiFaceLandmarks.length === 0) {
577
+ if (T < 2) {
578
+ setTimeout(() => {
579
+ U(T + 1);
580
+ }, 500);
581
+ return;
582
+ }
583
+ const y = o.current, A = y && y.getContext("2d");
584
+ 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();
585
+ return;
586
+ }
587
+ const g = p.multiFaceLandmarks[0], w = o.current, v = w.getContext("2d");
588
+ v.clearRect(0, 0, w.width, w.height);
589
+ const S = w.width, C = w.height, R = g.map((y) => [y.x * S, y.y * C]);
590
+ r === "wrinkles" ? z(v, R) : r === "firmness" ? re(v, R) : r === "brightness" ? ee(v, R) : r === "spots" ? te(v, R) : r === "acne" && oe(v, R), i(), !f && !n && l("split"), a(), P(!0);
591
+ } catch (p) {
592
+ console.error("Error en detección:", p);
593
+ const g = o.current, w = g && g.getContext("2d");
594
+ w && (w.clearRect(0, 0, g.width, g.height), w.fillStyle = "rgba(255,255,255,1)", w.fillRect(0, 0, g.width, g.height)), i(), a();
595
+ } finally {
596
+ h(!1), b(!1);
597
+ }
598
+ },
599
+ [
600
+ D,
601
+ t,
602
+ r,
603
+ n,
604
+ e,
605
+ o,
606
+ f,
607
+ a,
608
+ b,
609
+ l,
610
+ i
611
+ ]
612
+ );
613
+ return { detectAndMaskFace: U, detectingFace: m, faceDetected: M };
614
+ }
615
+ function ve(e) {
616
+ const t = F.getProductConfig(e.id) || {}, o = e.filterType || t.webglConfig && t.webglConfig.filterType || "custom", r = e.defaultWebglConfig || {}, i = {
617
+ filterType: o,
618
+ intensity: e.defaultIntensity !== void 0 ? e.defaultIntensity : r.intensity ?? 0.5,
619
+ sigma: e.defaultSigma !== void 0 ? e.defaultSigma : r.sigma ?? 4,
620
+ brightness: e.defaultBrightness !== void 0 ? e.defaultBrightness : r.brightness ?? 0,
621
+ contrast: r.contrast ?? 1,
622
+ warmthR: r.warmthR ?? 0,
623
+ warmthB: r.warmthB ?? 0,
624
+ warmthA: r.warmthA ?? 0
625
+ }, a = t.webglConfig || {};
626
+ return { ...i, ...a, filterType: o };
627
+ }
628
+ const x = {
629
+ base: {
630
+ key: "base",
631
+ label: "Base",
632
+ defaults: { intensity: 0.5, sigma: 4, brightness: 0, contrast: 1, warmthR: 0, warmthB: 0, warmthA: 0 },
633
+ deep: {}
634
+ }
635
+ }, ne = ["base"];
636
+ function ie(e) {
637
+ return x[e] || null;
638
+ }
639
+ function ae(e = {}) {
640
+ var a;
641
+ const t = F.getProductConfig(e.id) || {}, o = e.filterType || ((a = t.webglConfig) == null ? void 0 : a.filterType) || "custom", r = e.defaultWebglConfig || x.base.defaults, i = t.webglConfig || {};
642
+ return {
643
+ filterType: o,
644
+ intensity: e.defaultIntensity !== void 0 ? e.defaultIntensity : r.intensity ?? 0.5,
645
+ sigma: e.defaultSigma !== void 0 ? e.defaultSigma : r.sigma ?? 4,
646
+ brightness: e.defaultBrightness !== void 0 ? e.defaultBrightness : r.brightness ?? 0,
647
+ contrast: r.contrast ?? 1,
648
+ warmthR: r.warmthR ?? 0,
649
+ warmthB: r.warmthB ?? 0,
650
+ warmthA: r.warmthA ?? 0,
651
+ ...i,
652
+ filterType: o
653
+ };
654
+ }
655
+ async function se({ token: e, products: t = [] } = {}) {
656
+ if (!e)
657
+ throw new Error("Falta token de licencia para activar md-face-engine.");
658
+ const { default: o } = await import("./MartidermEngine-lu2piGUl.js"), r = new o();
659
+ await r.activate(e), r.assertActivated();
660
+ const i = r.getFilterConfigManager();
661
+ return Array.isArray(t) && i.setProducts(t), {
662
+ engine: r,
663
+ FILTERS: r.getFilterRegistry(),
664
+ FILTER_ORDER: r.getFilterOrder(),
665
+ getFilter: (a) => r.getFilter(a),
666
+ filterConfigManager: i,
667
+ buildWebglConfigForProduct: (a) => r.buildWebglConfigForProduct(a)
668
+ };
669
+ }
670
+ async function _e({ token: e, products: t = [] } = {}) {
671
+ let o = null, r = null, i = !1;
672
+ if (e)
673
+ try {
674
+ o = await se({ token: e, products: t }), i = !0;
675
+ } catch (a) {
676
+ r = a, i = !1;
677
+ }
678
+ return !o && Array.isArray(t) && typeof (F == null ? void 0 : F.setProducts) == "function" && F.setProducts(t), {
679
+ engine: (o == null ? void 0 : o.engine) || null,
680
+ FILTERS: (o == null ? void 0 : o.FILTERS) || x,
681
+ FILTER_ORDER: (o == null ? void 0 : o.FILTER_ORDER) || ne,
682
+ getFilter: (o == null ? void 0 : o.getFilter) || ie,
683
+ filterConfigManager: (o == null ? void 0 : o.filterConfigManager) || F,
684
+ buildWebglConfigForProduct: (o == null ? void 0 : o.buildWebglConfigForProduct) || ae,
685
+ license: {
686
+ active: i,
687
+ error: r,
688
+ mode: i ? "licensed" : "unlicensed"
689
+ }
690
+ };
691
+ }
692
+ async function fe(e = {}) {
693
+ const t = e.locateFile || ((a) => `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh@0.4.1633559619/${a}`), o = {
694
+ maxNumFaces: 1,
695
+ refineLandmarks: !0,
696
+ minDetectionConfidence: 0.5,
697
+ minTrackingConfidence: 0.5,
698
+ ...e.detectorOptions || {}
699
+ };
700
+ let r = typeof window < "u" ? window.FaceMesh : void 0;
701
+ if (!r && typeof window < "u") {
702
+ const a = document.querySelector('script[data-md-face-mesh="1"]');
703
+ a ? window.FaceMesh || await new Promise((f, n) => {
704
+ a.addEventListener("load", f, { once: !0 }), a.addEventListener(
705
+ "error",
706
+ () => n(new Error("No se pudo cargar MediaPipe FaceMesh")),
707
+ { once: !0 }
708
+ );
709
+ }) : await new Promise((f, n) => {
710
+ const l = document.createElement("script");
711
+ 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 = f, l.onerror = () => n(new Error("No se pudo cargar MediaPipe FaceMesh")), document.head.appendChild(l);
712
+ }), r = window.FaceMesh;
713
+ }
714
+ if (!r)
715
+ throw new Error("No se pudo inicializar el detector de landmarks");
716
+ const i = new r({ locateFile: t });
717
+ return i.setOptions(o), i;
718
+ }
719
+ export {
720
+ _e as a,
721
+ ve as b,
722
+ se as c,
723
+ X as d,
724
+ ge as e,
725
+ F as f,
726
+ we as g,
727
+ de as h,
728
+ ce as i,
729
+ fe as j,
730
+ le as k,
731
+ he as l,
732
+ Z as m,
733
+ me as n,
734
+ pe as o,
735
+ be as q,
736
+ Ee as r,
737
+ $ as s,
738
+ ye as u
739
+ };