import { ai as M, a7 as ce, aj as ue, ak as de, al as le, am as fe } from "./index-d46d84f5.js";
import { defineComponent as me, inject as U, ref as g, computed as X, watch as w, nextTick as G, onBeforeUnmount as ve, resolveDirective as pe, openBlock as L, createElementBlock as k, createElementVNode as F, normalizeClass as q, unref as C, withDirectives as xe, withModifiers as he, createVNode as _e, createCommentVNode as H } from "vue";
import be from "axios";
import { isArray as ge } from "lodash-es";
import "@vueuse/core";
import "vue-i18n";
function ye({ isLuminance: e = !1 } = {}) {
  return {
    vertex: {
      attribute: {
        a_alphaMaskTexCoord: "vec2"
      },
      main: `
    v_alphaMaskTexCoord = a_alphaMaskTexCoord;`
    },
    fragment: {
      uniform: {
        u_alphaMaskEnabled: "bool",
        u_alphaMaskIsLuminance: "bool",
        u_mask: "sampler2D"
      },
      main: `
    if (u_alphaMaskEnabled) {
        vec4 alphaMaskPixel = texture2D(u_mask, v_alphaMaskTexCoord);

        if (u_alphaMaskIsLuminance) {
            alpha *= dot(lumcoeff, alphaMaskPixel.rgb) * alphaMaskPixel.a;
        }
        else {
            alpha *= alphaMaskPixel.a;
        }
    }`
    },
    get disabled() {
      return !this.uniforms[0].data[0];
    },
    set disabled(a) {
      this.uniforms[0].data[0] = +!a;
    },
    get mask() {
      return this.textures[0].data;
    },
    set mask(a) {
      this.textures[0].data = a;
    },
    get isLuminance() {
      return !!this.uniforms[2].data[0];
    },
    set isLuminance(a) {
      this.uniforms[2].data[0] = +a, this.textures[0].format = a ? "RGBA" : "ALPHA";
    },
    varying: {
      v_alphaMaskTexCoord: "vec2"
    },
    uniforms: [
      {
        name: "u_alphaMaskEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_mask",
        type: "i",
        data: [1]
      },
      {
        name: "u_alphaMaskIsLuminance",
        type: "i",
        data: [+!!e]
      }
    ],
    attributes: [
      {
        name: "a_alphaMaskTexCoord",
        extends: "a_texCoord"
      }
    ],
    textures: [
      {
        format: e ? "RGBA" : "ALPHA"
      }
    ]
  };
}
const m = {
  blend_luminosity: `float blend_luminosity (vec3 c) {
    return dot(c, blendLum);
}`,
  blend_saturation: `float blend_saturation (vec3 c) {
    return max(max(c.r, c.g), c.b) - min(min(c.r, c.g), c.b);
}`,
  blend_set_luminosity: `vec3 blend_clip_color (vec3 c) {
    float l = blend_luminosity(c);
    float cMin = min(min(c.r, c.g), c.b);
    float cMax = max(max(c.r, c.g), c.b);

    if (cMin < 0.0)
        return l + (((c - l) * l) / (l - cMin));
    if (cMax > 1.0)
        return l + (((c - l) * (1.0 - l)) / (cMax - l));

    return c;
}

vec3 blend_set_luminosity (vec3 c, float l) {
    vec3 delta = vec3(l - blend_luminosity(c));

    return blend_clip_color(vec3(c.rgb + delta.rgb));
}`,
  blend_set_saturation: `
float getBlendMid (vec3 c) {
    float bigger = max(c.r, c.g);

    if (bigger < c.b) {
        return bigger;
    }

    float smaller = min(c.r, c.g);

    if (c.b < smaller) {
        return smaller;
    }

    return c.b;
}

vec3 blend_set_saturation (vec3 c, float s) {
    if (s == 0.0) return vec3(0.0);

    float cMax = max(max(c.r, c.g), c.b);
    float cMid = getBlendMid(c);
    float cMin = min(min(c.r, c.g), c.b);
    float r, g, b;

    cMid = (((cMid - cMin) * s) / (cMax - cMin));
    cMax = s;
    cMin = 0.0;

    if (c.r > c.g) {
        // r > g
        if (c.b > c.r) {
            // g < r < b
            g = cMin;
            r = cMid;
            b = cMax;
        }
        else if (c.g > c.b) {
            // b < g < r
            b = cMin;
            g = cMid;
            r = cMax;
        }
        else {
            // g < b < r
            g = cMin;
            b = cMid;
            r = cMax;
        }
    }
    // g > r
    else if (c.g > c.b) {
        // g > b
        if (c.b > c.r) {
            // r < b < g
            r = cMin;
            b = cMid;
            g = cMax;
        }
        else {
            // b < r < g
            b = cMin;
            r = cMid;
            g = cMax;
        }
    }
    else {
        // r < g < b
        r = cMin;
        g = cMid;
        b = cMax;
    }

    return vec3(r, g, b);
}`
}, Ee = {
  normal: "",
  multiply: "",
  screen: "",
  overlay: `float blend_overlay (float b, float c) {
    if (b <= 0.5)
        return 2.0 * b * c;
    else
        return 1.0 - 2.0 * ((1.0 - b) * (1.0 - c));
}`,
  darken: "",
  lighten: "",
  colorDodge: `float blend_colorDodge (float b, float c) {
    if (b == 0.0)
        return 0.0;
    else if (c == 1.0)
        return 1.0;
    else
        return min(1.0, b / (1.0 - c));
}`,
  colorBurn: `float blend_colorBurn (float b, float c) {
    if (b == 1.0) {
        return 1.0;
    }
    else if (c == 0.0) {
        return 0.0;
    }
    else {
        return 1.0 - min(1.0, (1.0 - b) / c);
    }
}`,
  hardLight: `float blend_hardLight (float b, float c) {
    if (c <= 0.5) {
        return 2.0 * b * c;
    }
    else {
        return 1.0 - 2.0 * ((1.0 - b) * (1.0 - c));
    }
}`,
  softLight: `float blend_softLight (float b, float c) {
    if (c <= 0.5) {
        return b - (1.0 - 2.0 * c) * b * (1.0 - b);
    }
    else {
        float d;

        if (b <= 0.25) {
            d = ((16.0 * b - 12.0) * b + 4.0) * b;
        }
        else {
            d = sqrt(b);
        }

        return b + (2.0 * c - 1.0) * (d - b);
    }
}`,
  difference: `float blend_difference (float b, float c) {
    return abs(b - c);
}`,
  exclusion: `float blend_exclusion (float b, float c) {
    return b + c - 2.0 * b * c;
}`,
  hue: `${m.blend_luminosity}
${m.blend_saturation}
${m.blend_set_saturation}
${m.blend_set_luminosity}`,
  saturation: `${m.blend_luminosity}
${m.blend_saturation}
${m.blend_set_saturation}
${m.blend_set_luminosity}`,
  color: `${m.blend_luminosity}
${m.blend_set_luminosity}`,
  luminosity: `${m.blend_luminosity}
${m.blend_set_luminosity}`
};
function y(e) {
  return `vec3(${e}(backdrop.r, source.r), ${e}(backdrop.g, source.g), ${e}(backdrop.b, source.b))`;
}
const W = {
  normal: "source",
  multiply: "source * backdrop",
  screen: "backdrop + source - backdrop * source",
  overlay: y("blend_overlay"),
  darken: y("min"),
  lighten: y("max"),
  colorDodge: y("blend_colorDodge"),
  colorBurn: y("blend_colorBurn"),
  hardLight: y("blend_hardLight"),
  softLight: y("blend_softLight"),
  difference: y("blend_difference"),
  exclusion: y("blend_exclusion"),
  hue: "blend_set_luminosity(blend_set_saturation(source, blend_saturation(backdrop)), blend_luminosity(backdrop))",
  saturation: "blend_set_luminosity(blend_set_saturation(backdrop, blend_saturation(source)), blend_luminosity(backdrop))",
  color: "blend_set_luminosity(source, blend_luminosity(backdrop))",
  luminosity: "blend_set_luminosity(backdrop, blend_luminosity(source))"
};
function Ce({
  mode: e = "normal",
  color: a = [0, 0, 0, 1]
} = {}) {
  return {
    vertex: {
      attribute: {
        a_blendImageTexCoord: "vec2"
      },
      main: `
    v_blendImageTexCoord = a_blendImageTexCoord;`
    },
    fragment: {
      uniform: {
        u_blendEnabled: "bool",
        u_blendColorEnabled: "bool",
        u_blendImageEnabled: "bool",
        u_blendColor: "vec4",
        u_blendImage: "sampler2D"
      },
      constant: `const vec3 blendLum = vec3(0.3, 0.59, 0.11);
${Ee[e]}`,
      main: `
    if (u_blendEnabled) {
        vec3 backdrop = vec3(0.0);
        float backdropAlpha = 1.0;

        if (u_blendColorEnabled) {
            backdrop = u_blendColor.rgb;
            backdropAlpha = u_blendColor.a;
        }
        if (u_blendImageEnabled) {
            vec4 blendBackdropPixel = texture2D(u_blendImage, v_blendImageTexCoord);
            if (u_blendColorEnabled) {
                vec3 source = blendBackdropPixel.rgb;
                float sourceAlpha = blendBackdropPixel.a;
                backdrop = (1.0 - backdropAlpha) * source + backdropAlpha * clamp(${W[e]}, 0.0, 1.0);
                backdropAlpha = sourceAlpha + backdropAlpha * (1.0 - sourceAlpha);
            }
            else {
                backdrop = blendBackdropPixel.rgb;
                backdropAlpha = blendBackdropPixel.a;
            }
        }
        vec3 source = vec3(color.rgb);
        color = (1.0 - backdropAlpha) * source + backdropAlpha * clamp(${W[e]}, 0.0, 1.0);
        alpha = alpha + backdropAlpha * (1.0 - alpha);
    }`
    },
    get color() {
      return this.uniforms[1].data.slice(0);
    },
    set color(t) {
      !t || !t.length ? this.uniforms[2].data[0] = 0 : (this.uniforms[2].data[0] = 1, t.forEach((o, r) => {
        Number.isNaN(o) || (this.uniforms[1].data[r] = o);
      }));
    },
    get image() {
      return this.textures[0].data;
    },
    set image(t) {
      t ? (this.uniforms[4].data[0] = 1, this.textures[0].data = t) : this.uniforms[4].data[0] = 0;
    },
    get disabled() {
      return !this.uniforms[0].data[0];
    },
    set disabled(t) {
      this.uniforms[0].data[0] = +!t;
    },
    varying: {
      v_blendImageTexCoord: "vec2"
    },
    uniforms: [
      {
        name: "u_blendEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_blendColor",
        type: "f",
        data: a
      },
      {
        name: "u_blendColorEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_blendImage",
        type: "i",
        data: [1]
      },
      {
        name: "u_blendImageEnabled",
        type: "i",
        data: [0]
      }
    ],
    attributes: [
      {
        name: "a_blendImageTexCoord",
        extends: "a_texCoord"
      }
    ],
    textures: [
      {
        format: "RGBA"
      }
    ]
  };
}
function Te({ brightness: e = 1, contrast: a = 1 } = {}) {
  return {
    fragment: {
      uniform: {
        u_brEnabled: "bool",
        u_ctEnabled: "bool",
        u_contrast: "float",
        u_brightness: "float"
      },
      constant: "const vec3 half3 = vec3(0.5);",
      main: `
    if (u_brEnabled) {
        color *= u_brightness;
    }

    if (u_ctEnabled) {
        color = (color - half3) * u_contrast + half3;
    }

    color = clamp(color, 0.0, 1.0);`
    },
    get brightness() {
      return this.uniforms[2].data[0];
    },
    set brightness(t) {
      this.uniforms[2].data[0] = parseFloat(Math.max(0, t));
    },
    get contrast() {
      return this.uniforms[3].data[0];
    },
    set contrast(t) {
      this.uniforms[3].data[0] = parseFloat(Math.max(0, t));
    },
    get brightnessDisabled() {
      return !this.uniforms[0].data[0];
    },
    set brightnessDisabled(t) {
      this.uniforms[0].data[0] = +!t;
    },
    get contrastDisabled() {
      return !this.uniforms[1].data[0];
    },
    set contrastDisabled(t) {
      this.uniforms[1].data[0] = +!t;
    },
    uniforms: [
      {
        name: "u_brEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_ctEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_brightness",
        type: "f",
        data: [e]
      },
      {
        name: "u_contrast",
        type: "f",
        data: [a]
      }
    ]
  };
}
function ze({ hue: e = 0, saturation: a = 1 } = {}) {
  return {
    vertex: {
      uniform: {
        u_hue: "float",
        u_saturation: "float"
      },
      // for implementation see: https://www.w3.org/TR/SVG11/filters.html#feColorMatrixElement
      constant: `
const mat3 lummat = mat3(
    lumcoeff,
    lumcoeff,
    lumcoeff
);
const mat3 cosmat = mat3(
    vec3(0.787, -0.715, -0.072),
    vec3(-0.213, 0.285, -0.072),
    vec3(-0.213, -0.715, 0.928)
);
const mat3 sinmat = mat3(
    vec3(-0.213, -0.715, 0.928),
    vec3(0.143, 0.140, -0.283),
    vec3(-0.787, 0.715, 0.072)
);
const mat3 satmat = mat3(
    vec3(0.787, -0.715, -0.072),
    vec3(-0.213, 0.285, -0.072),
    vec3(-0.213, -0.715, 0.928)
);`,
      main: `
    float angle = (u_hue / 180.0) * 3.14159265358979323846264;
    v_hueRotation = lummat + cos(angle) * cosmat + sin(angle) * sinmat;
    v_saturation = lummat + satmat * u_saturation;`
    },
    fragment: {
      uniform: {
        u_hueEnabled: "bool",
        u_satEnabled: "bool",
        u_hue: "float",
        u_saturation: "float"
      },
      main: `
    if (u_hueEnabled) {
        color = vec3(
            dot(color, v_hueRotation[0]),
            dot(color, v_hueRotation[1]),
            dot(color, v_hueRotation[2])
        );
    }

    if (u_satEnabled) {
        color = vec3(
            dot(color, v_saturation[0]),
            dot(color, v_saturation[1]),
            dot(color, v_saturation[2])
        );
    }

    color = clamp(color, 0.0, 1.0);`
    },
    varying: {
      v_hueRotation: "mat3",
      v_saturation: "mat3"
    },
    get hue() {
      return this.uniforms[2].data[0];
    },
    set hue(t) {
      this.uniforms[2].data[0] = parseFloat(t);
    },
    get saturation() {
      return this.uniforms[3].data[0];
    },
    set saturation(t) {
      this.uniforms[3].data[0] = parseFloat(Math.max(0, t));
    },
    get hueDisabled() {
      return !this.uniforms[0].data[0];
    },
    set hueDisabled(t) {
      this.uniforms[0].data[0] = +!t;
    },
    get saturationDisabled() {
      return !this.uniforms[1].data[0];
    },
    set saturationDisabled(t) {
      this.uniforms[1].data[0] = +!t;
    },
    uniforms: [
      {
        name: "u_hueEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_satEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_hue",
        type: "f",
        data: [e]
      },
      {
        name: "u_saturation",
        type: "f",
        data: [a]
      }
    ]
  };
}
function Pe({
  dark: e = [0.7411764706, 0.0431372549, 0.568627451, 1],
  light: a = [0.9882352941, 0.7333333333, 0.05098039216, 1]
} = {}) {
  return {
    fragment: {
      uniform: {
        u_duotoneEnabled: "bool",
        u_light: "vec4",
        u_dark: "vec4"
      },
      main: `
    if (u_duotoneEnabled) {
        vec3 gray = vec3(dot(lumcoeff, color));
        color = mix(u_dark.rgb, u_light.rgb, gray);
    }`
    },
    get light() {
      return this.uniforms[1].data.slice(0);
    },
    set light(t) {
      t.forEach((o, r) => {
        Number.isNaN(o) || (this.uniforms[1].data[r] = o);
      });
    },
    get dark() {
      return this.uniforms[2].data.slice(0);
    },
    set dark(t) {
      t.forEach((o, r) => {
        Number.isNaN(o) || (this.uniforms[2].data[r] = o);
      });
    },
    get disabled() {
      return !this.uniforms[0].data[0];
    },
    set disabled(t) {
      this.uniforms[0].data[0] = +!t;
    },
    uniforms: [
      {
        name: "u_duotoneEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_light",
        type: "f",
        data: a
      },
      {
        name: "u_dark",
        type: "f",
        data: e
      }
    ]
  };
}
function K({
  wrap: e = R.CLAMP,
  scale: a
} = {}) {
  const { x: t, y: o } = a || { x: 0, y: 0 };
  return {
    vertex: {
      attribute: {
        a_displacementMapTexCoord: "vec2"
      },
      main: `
    v_displacementMapTexCoord = a_displacementMapTexCoord;`
    },
    fragment: {
      uniform: {
        u_displacementEnabled: "bool",
        u_dispMap: "sampler2D",
        u_dispScale: "vec2"
      },
      source: `
    if (u_displacementEnabled) {
        vec3 dispMap = texture2D(u_dispMap, v_displacementMapTexCoord).rgb - 0.5;
        vec2 dispVec = vec2(sourceCoord.x + u_dispScale.x * dispMap.r, sourceCoord.y + u_dispScale.y * dispMap.g);
        ${e}
        sourceCoord = dispVec;
    }`
    },
    get disabled() {
      return !this.uniforms[0].data[0];
    },
    set disabled(r) {
      this.uniforms[0].data[0] = +!r;
    },
    get scale() {
      const [r, n] = this.uniforms[2].data;
      return { x: r, y: n };
    },
    set scale({ x: r, y: n }) {
      typeof r < "u" && (this.uniforms[2].data[0] = r), typeof n < "u" && (this.uniforms[2].data[1] = n);
    },
    get map() {
      return this.textures[0].data;
    },
    set map(r) {
      this.textures[0].data = r;
    },
    varying: {
      v_displacementMapTexCoord: "vec2"
    },
    uniforms: [
      {
        name: "u_displacementEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_dispMap",
        type: "i",
        data: [1]
      },
      {
        name: "u_dispScale",
        type: "f",
        data: [t, o]
      }
    ],
    attributes: [
      {
        name: "a_displacementMapTexCoord",
        extends: "a_texCoord"
      }
    ],
    textures: [
      {
        format: "RGB"
      }
    ]
  };
}
const R = {
  CLAMP: "dispVec = clamp(dispVec, 0.0, 1.0);",
  DISCARD: "if (dispVec.x < 0.0 || dispVec.x > 1.0 || dispVec.y > 1.0 || dispVec.y < 0.0) { discard; }",
  WRAP: "dispVec = mod(dispVec, 1.0);"
};
K.CLAMP = R.CLAMP;
K.DISCARD = R.DISCARD;
K.WRAP = R.WRAP;
/*!
 * GLSL textureless classic 3D noise "cnoise",
 * with an RSL-style periodic variant "pnoise".
 * Author:  Stefan Gustavson (stefan.gustavson@liu.se)
 * Version: 2011-10-11
 *
 * Many thanks to Ian McEwan of Ashima Arts for the
 * ideas for permutation and gradient selection.
 *
 * Copyright (c) 2011 Stefan Gustavson. All rights reserved.
 * Distributed under the MIT license. See LICENSE file.
 * https://github.com/ashima/webgl-noise
 */
var De = `
vec3 mod289 (vec3 x) {
    return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec4 mod289 (vec4 x) {
    return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec4 permute (vec4 x) {
    return mod289(((x*34.0)+1.0)*x);
}

vec4 taylorInvSqrt (vec4 r) {
    return 1.79284291400159 - 0.85373472095314 * r;
}

vec3 fade (vec3 t) {
    return t*t*t*(t*(t*6.0-15.0)+10.0);
}

// Classic Perlin noise
float noise (vec3 P) {
    vec3 Pi0 = floor(P); // Integer part for indexing
    vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1
    Pi0 = mod289(Pi0);
    Pi1 = mod289(Pi1);
    vec3 Pf0 = fract(P); // Fractional part for interpolation
    vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
    vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
    vec4 iy = vec4(Pi0.yy, Pi1.yy);
    vec4 iz0 = Pi0.zzzz;
    vec4 iz1 = Pi1.zzzz;

    vec4 ixy = permute(permute(ix) + iy);
    vec4 ixy0 = permute(ixy + iz0);
    vec4 ixy1 = permute(ixy + iz1);

    vec4 gx0 = ixy0 * (1.0 / 7.0);
    vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
    gx0 = fract(gx0);
    vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
    vec4 sz0 = step(gz0, vec4(0.0));
    gx0 -= sz0 * (step(0.0, gx0) - 0.5);
    gy0 -= sz0 * (step(0.0, gy0) - 0.5);

    vec4 gx1 = ixy1 * (1.0 / 7.0);
    vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
    gx1 = fract(gx1);
    vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
    vec4 sz1 = step(gz1, vec4(0.0));
    gx1 -= sz1 * (step(0.0, gx1) - 0.5);
    gy1 -= sz1 * (step(0.0, gy1) - 0.5);

    vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
    vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
    vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
    vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
    vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
    vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
    vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
    vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);

    vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
    g000 *= norm0.x;
    g010 *= norm0.y;
    g100 *= norm0.z;
    g110 *= norm0.w;
    vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
    g001 *= norm1.x;
    g011 *= norm1.y;
    g101 *= norm1.z;
    g111 *= norm1.w;

    float n000 = dot(g000, Pf0);
    float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
    float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
    float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
    float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
    float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
    float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
    float n111 = dot(g111, Pf1);

    vec3 fade_xyz = fade(Pf0);
    vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
    vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
    float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); 
    return 2.2 * n_xyz;
}`;
/*!
 * Cellular noise ("Worley noise") in 3D in GLSL.
 * Author:  Stefan Gustavson (stefan.gustavson@liu.se)
 * Version: Stefan Gustavson 2011-04-19
 *
 * Many thanks to Ian McEwan of Ashima Arts for the
 * ideas for permutation and gradient selection.
 *
 * Copyright (c) 2011 Stefan Gustavson. All rights reserved.
 * Distributed under the MIT license. See LICENSE file.
 * https://github.com/ashima/webgl-noise
 */
var Me = `
  vec3 mod289(vec3 x) {
    return x - floor(x * (1.0 / 289.0)) * 289.0;
  }

  // Modulo 7 without a division
  vec3 mod7(vec3 x) {
    return x - floor(x * (1.0 / 7.0)) * 7.0;
  }

  // Permutation polynomial: (34x^2 + x) mod 289
  vec3 permute(vec3 x) {
    return mod289((34.0 * x + 1.0) * x);
  }

  float noise(vec3 P) {
    #define K 0.142857142857 // 1/7
    #define Ko 0.428571428571 // 1/2-K/2
    #define K2 0.020408163265306 // 1/(7*7)
    #define Kz 0.166666666667 // 1/6
    #define Kzo 0.416666666667 // 1/2-1/6*2
    #define jitter 1.0 // smaller jitter gives more regular pattern

    vec3 Pi = mod289(floor(P));
    vec3 Pf = fract(P) - 0.5;

    vec3 Pfx = Pf.x + vec3(1.0, 0.0, -1.0);
    vec3 Pfy = Pf.y + vec3(1.0, 0.0, -1.0);
    vec3 Pfz = Pf.z + vec3(1.0, 0.0, -1.0);

    vec3 p = permute(Pi.x + vec3(-1.0, 0.0, 1.0));
    vec3 p1 = permute(p + Pi.y - 1.0);
    vec3 p2 = permute(p + Pi.y);
    vec3 p3 = permute(p + Pi.y + 1.0);

    vec3 p11 = permute(p1 + Pi.z - 1.0);
    vec3 p12 = permute(p1 + Pi.z);
    vec3 p13 = permute(p1 + Pi.z + 1.0);

    vec3 p21 = permute(p2 + Pi.z - 1.0);
    vec3 p22 = permute(p2 + Pi.z);
    vec3 p23 = permute(p2 + Pi.z + 1.0);

    vec3 p31 = permute(p3 + Pi.z - 1.0);
    vec3 p32 = permute(p3 + Pi.z);
    vec3 p33 = permute(p3 + Pi.z + 1.0);

    vec3 ox11 = fract(p11*K) - Ko;
    vec3 oy11 = mod7(floor(p11*K))*K - Ko;
    vec3 oz11 = floor(p11*K2)*Kz - Kzo; // p11 < 289 guaranteed

    vec3 ox12 = fract(p12*K) - Ko;
    vec3 oy12 = mod7(floor(p12*K))*K - Ko;
    vec3 oz12 = floor(p12*K2)*Kz - Kzo;

    vec3 ox13 = fract(p13*K) - Ko;
    vec3 oy13 = mod7(floor(p13*K))*K - Ko;
    vec3 oz13 = floor(p13*K2)*Kz - Kzo;

    vec3 ox21 = fract(p21*K) - Ko;
    vec3 oy21 = mod7(floor(p21*K))*K - Ko;
    vec3 oz21 = floor(p21*K2)*Kz - Kzo;

    vec3 ox22 = fract(p22*K) - Ko;
    vec3 oy22 = mod7(floor(p22*K))*K - Ko;
    vec3 oz22 = floor(p22*K2)*Kz - Kzo;

    vec3 ox23 = fract(p23*K) - Ko;
    vec3 oy23 = mod7(floor(p23*K))*K - Ko;
    vec3 oz23 = floor(p23*K2)*Kz - Kzo;

    vec3 ox31 = fract(p31*K) - Ko;
    vec3 oy31 = mod7(floor(p31*K))*K - Ko;
    vec3 oz31 = floor(p31*K2)*Kz - Kzo;

    vec3 ox32 = fract(p32*K) - Ko;
    vec3 oy32 = mod7(floor(p32*K))*K - Ko;
    vec3 oz32 = floor(p32*K2)*Kz - Kzo;

    vec3 ox33 = fract(p33*K) - Ko;
    vec3 oy33 = mod7(floor(p33*K))*K - Ko;
    vec3 oz33 = floor(p33*K2)*Kz - Kzo;

    vec3 dx11 = Pfx + jitter*ox11;
    vec3 dy11 = Pfy.x + jitter*oy11;
    vec3 dz11 = Pfz.x + jitter*oz11;

    vec3 dx12 = Pfx + jitter*ox12;
    vec3 dy12 = Pfy.x + jitter*oy12;
    vec3 dz12 = Pfz.y + jitter*oz12;

    vec3 dx13 = Pfx + jitter*ox13;
    vec3 dy13 = Pfy.x + jitter*oy13;
    vec3 dz13 = Pfz.z + jitter*oz13;

    vec3 dx21 = Pfx + jitter*ox21;
    vec3 dy21 = Pfy.y + jitter*oy21;
    vec3 dz21 = Pfz.x + jitter*oz21;

    vec3 dx22 = Pfx + jitter*ox22;
    vec3 dy22 = Pfy.y + jitter*oy22;
    vec3 dz22 = Pfz.y + jitter*oz22;

    vec3 dx23 = Pfx + jitter*ox23;
    vec3 dy23 = Pfy.y + jitter*oy23;
    vec3 dz23 = Pfz.z + jitter*oz23;

    vec3 dx31 = Pfx + jitter*ox31;
    vec3 dy31 = Pfy.z + jitter*oy31;
    vec3 dz31 = Pfz.x + jitter*oz31;

    vec3 dx32 = Pfx + jitter*ox32;
    vec3 dy32 = Pfy.z + jitter*oy32;
    vec3 dz32 = Pfz.y + jitter*oz32;

    vec3 dx33 = Pfx + jitter*ox33;
    vec3 dy33 = Pfy.z + jitter*oy33;
    vec3 dz33 = Pfz.z + jitter*oz33;

    vec3 d11 = dx11 * dx11 + dy11 * dy11 + dz11 * dz11;
    vec3 d12 = dx12 * dx12 + dy12 * dy12 + dz12 * dz12;
    vec3 d13 = dx13 * dx13 + dy13 * dy13 + dz13 * dz13;
    vec3 d21 = dx21 * dx21 + dy21 * dy21 + dz21 * dz21;
    vec3 d22 = dx22 * dx22 + dy22 * dy22 + dz22 * dz22;
    vec3 d23 = dx23 * dx23 + dy23 * dy23 + dz23 * dz23;
    vec3 d31 = dx31 * dx31 + dy31 * dy31 + dz31 * dz31;
    vec3 d32 = dx32 * dx32 + dy32 * dy32 + dz32 * dz32;
    vec3 d33 = dx33 * dx33 + dy33 * dy33 + dz33 * dz33;

    vec3 d1 = min(min(d11,d12), d13);
    vec3 d2 = min(min(d21,d22), d23);
    vec3 d3 = min(min(d31,d32), d33);
    vec3 d = min(min(d1,d2), d3);
    d.x = min(min(d.x,d.y),d.z);

    return sqrt(d.x);
  }
`;
/*!
 * Description : Array and textureless GLSL 2D/3D/4D simplex
 *               noise functions.
 *      Author : Ian McEwan, Ashima Arts.
 *  Maintainer : stegu
 *     Lastmod : 20110822 (ijm)
 *     License : Copyright (C) 2011 Ashima Arts. All rights reserved.
 *               Distributed under the MIT License. See LICENSE file.
 *               https://github.com/ashima/webgl-noise
 *               https://github.com/stegu/webgl-noise
 */
var we = `
vec3 mod289 (vec3 x) {
    return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec4 mod289 (vec4 x) {
    return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec4 permute (vec4 x) {
    return mod289(((x*34.0)+1.0)*x);
}

vec4 taylorInvSqrt (vec4 r) {
    return 1.79284291400159 - 0.85373472095314 * r;
}

float noise (vec3 v) { 
    const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
    const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);

    // First corner
    vec3 i  = floor(v + dot(v, C.yyy) );
    vec3 x0 =   v - i + dot(i, C.xxx) ;

    // Other corners
    vec3 g = step(x0.yzx, x0.xyz);
    vec3 l = 1.0 - g;
    vec3 i1 = min( g.xyz, l.zxy );
    vec3 i2 = max( g.xyz, l.zxy );

    //   x0 = x0 - 0.0 + 0.0 * C.xxx;
    //   x1 = x0 - i1  + 1.0 * C.xxx;
    //   x2 = x0 - i2  + 2.0 * C.xxx;
    //   x3 = x0 - 1.0 + 3.0 * C.xxx;
    vec3 x1 = x0 - i1 + C.xxx;
    vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
    vec3 x3 = x0 - D.yyy;      // -1.0+3.0*C.x = -0.5 = -D.y

    // Permutations
    i = mod289(i); 
    vec4 p = permute( permute( permute( 
                 i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
               + i.y + vec4(0.0, i1.y, i2.y, 1.0 )) 
               + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));

    // Gradients: 7x7 points over a square, mapped onto an octahedron.
    // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
    float n_ = 0.142857142857; // 1.0/7.0
    vec3  ns = n_ * D.wyz - D.xzx;

    vec4 j = p - 49.0 * floor(p * ns.z * ns.z);  //  mod(p,7*7)

    vec4 x_ = floor(j * ns.z);
    vec4 y_ = floor(j - 7.0 * x_ );    // mod(j,N)

    vec4 x = x_ *ns.x + ns.yyyy;
    vec4 y = y_ *ns.x + ns.yyyy;
    vec4 h = 1.0 - abs(x) - abs(y);

    vec4 b0 = vec4( x.xy, y.xy );
    vec4 b1 = vec4( x.zw, y.zw );

    //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
    //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
    vec4 s0 = floor(b0)*2.0 + 1.0;
    vec4 s1 = floor(b1)*2.0 + 1.0;
    vec4 sh = -step(h, vec4(0.0));

    vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
    vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;

    vec3 p0 = vec3(a0.xy,h.x);
    vec3 p1 = vec3(a0.zw,h.y);
    vec3 p2 = vec3(a1.xy,h.z);
    vec3 p3 = vec3(a1.zw,h.w);

    //Normalise gradients
    vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
    p0 *= norm.x;
    p1 *= norm.y;
    p2 *= norm.z;
    p3 *= norm.w;

    // Mix final noise value
    vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
    m = m * m;
    return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), 
                                    dot(p2,x2), dot(p3,x3) ) );
}`;
function V({
  noise: e,
  output: a = O.COLOR,
  frequency: t,
  octaves: o = 1,
  isFractal: r = !1,
  time: n = 0
}) {
  const { x: i, y: s } = t || { x: 0, y: 0 };
  return {
    fragment: {
      uniform: {
        u_turbulenceEnabled: "bool",
        u_turbulenceFrequency: "vec2",
        u_turbulenceOctaves: "int",
        u_isFractal: "bool",
        u_time: "float"
      },
      constant: `
${e}

const int MAX_OCTAVES = 9;

float turbulence (vec3 seed, vec2 frequency, int numOctaves, bool isFractal) {
    float sum = 0.0;
    vec3 position = vec3(0.0);
    position.x = seed.x * frequency.x;
    position.y = seed.y * frequency.y;
    position.z = seed.z;
    float ratio = 1.0;

    for (int octave = 0; octave <= MAX_OCTAVES; octave++) {
        if (octave > numOctaves) {
            break;
        }

        if (isFractal) {
            sum += noise(position) / ratio;
        }
        else {
            sum += abs(noise(position)) / ratio;
        }
        position.x *= 2.0;
        position.y *= 2.0;
        ratio *= 2.0;
    }

    if (isFractal) {
        sum = (sum + 1.0) / 2.0;
    }

    return clamp(sum, 0.0, 1.0);
}`,
      main: `
    vec3 turbulenceSeed = vec3(gl_FragCoord.xy, u_time * 0.0001);
    float turbulenceValue = turbulence(turbulenceSeed, u_turbulenceFrequency, u_turbulenceOctaves, u_isFractal);
    ${a || ""}`
    },
    get frequency() {
      const [c, l] = this.uniforms[0].data;
      return { x: c, y: l };
    },
    set frequency({ x: c, y: l }) {
      typeof c < "u" && (this.uniforms[0].data[0] = c), typeof l < "u" && (this.uniforms[0].data[1] = l);
    },
    get octaves() {
      return this.uniforms[1].data[0];
    },
    set octaves(c) {
      this.uniforms[1].data[0] = Math.max(0, parseInt(c));
    },
    get isFractal() {
      return !!this.uniforms[2].data[0];
    },
    set isFractal(c) {
      this.uniforms[2].data[0] = +c;
    },
    get time() {
      return this.uniforms[3].data[0];
    },
    set time(c) {
      this.uniforms[3].data[0] = Math.max(0, parseFloat(c));
    },
    uniforms: [
      {
        name: "u_turbulenceFrequency",
        type: "f",
        data: [i, s]
      },
      {
        name: "u_turbulenceOctaves",
        type: "i",
        data: [o]
      },
      {
        name: "u_isFractal",
        type: "i",
        data: [+!!r]
      },
      {
        name: "u_time",
        type: "f",
        data: [n]
      }
    ]
  };
}
const O = {
  COLOR: "color = vec3(turbulenceValue);",
  ALPHA: "alpha = turbulenceValue;"
};
V.COLOR = O.COLOR;
V.ALPHA = O.ALPHA;
function Ae() {
  return {
    vertex: {
      attribute: {
        a_transitionToTexCoord: "vec2"
      },
      main: `
    v_transitionToTexCoord = a_transitionToTexCoord;`
    },
    fragment: {
      uniform: {
        u_transitionEnabled: "bool",
        u_transitionProgress: "float",
        u_transitionTo: "sampler2D"
      },
      main: `
    if (u_transitionEnabled) {
        vec4 targetPixel = texture2D(u_transitionTo, v_transitionToTexCoord);
        color = mix(color, targetPixel.rgb, u_transitionProgress);
        alpha = mix(alpha, targetPixel.a, u_transitionProgress);
    }`
    },
    get disabled() {
      return !this.uniforms[0].data[0];
    },
    set disabled(e) {
      this.uniforms[0].data[0] = +!e;
    },
    get progress() {
      return this.uniforms[2].data[0];
    },
    set progress(e) {
      this.uniforms[2].data[0] = e;
    },
    get to() {
      return this.textures[0].data;
    },
    set to(e) {
      this.textures[0].data = e;
    },
    varying: {
      v_transitionToTexCoord: "vec2"
    },
    uniforms: [
      {
        name: "u_transitionEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_transitionTo",
        type: "i",
        data: [1]
      },
      {
        name: "u_transitionProgress",
        type: "f",
        data: [0]
      }
    ],
    attributes: [
      {
        name: "a_transitionToTexCoord",
        extends: "a_texCoord"
      }
    ],
    textures: [
      {
        format: "RGBA",
        update: !0
      }
    ]
  };
}
function Se({ sourceScale: e, toScale: a } = {}) {
  const { x: t, y: o } = e || { x: 0, y: 0 }, { x: r, y: n } = a || { x: 0, y: 0 };
  return {
    vertex: {
      attribute: {
        a_transitionToTexCoord: "vec2",
        a_transitionDispMapTexCoord: "vec2"
      },
      main: `
    v_transitionToTexCoord = a_transitionToTexCoord;
    v_transitionDispMapTexCoord = a_transitionDispMapTexCoord;`
    },
    fragment: {
      uniform: {
        u_transitionEnabled: "bool",
        u_transitionTo: "sampler2D",
        u_transitionDispMap: "sampler2D",
        u_transitionProgress: "float",
        u_sourceDispScale: "vec2",
        u_toDispScale: "vec2"
      },
      source: `
    vec3 transDispMap = vec3(1.0);
    vec2 transDispVec = vec2(0.0);

    if (u_transitionEnabled) {
        // read the displacement texture once and create the displacement map
        transDispMap = texture2D(u_transitionDispMap, v_transitionDispMapTexCoord).rgb - 0.5;

        // prepare the source coordinates for sampling
        transDispVec = vec2(u_sourceDispScale.x * transDispMap.r, u_sourceDispScale.y * transDispMap.g);
        sourceCoord = clamp(sourceCoord + transDispVec * u_transitionProgress, 0.0, 1.0);
    }`,
      main: `
    if (u_transitionEnabled) {
        // prepare the target coordinates for sampling
        transDispVec = vec2(u_toDispScale.x * transDispMap.r, u_toDispScale.y * transDispMap.g);
        vec2 targetCoord = clamp(v_transitionToTexCoord + transDispVec * (1.0 - u_transitionProgress), 0.0, 1.0);

        // sample the target
        vec4 targetPixel = texture2D(u_transitionTo, targetCoord);

        // mix the results of source and target
        color = mix(color, targetPixel.rgb, u_transitionProgress);
        alpha = mix(alpha, targetPixel.a, u_transitionProgress);
    }`
    },
    get disabled() {
      return !this.uniforms[0].data[0];
    },
    set disabled(i) {
      this.uniforms[0].data[0] = +!i;
    },
    get progress() {
      return this.uniforms[3].data[0];
    },
    set progress(i) {
      this.uniforms[3].data[0] = i;
    },
    get sourceScale() {
      const [i, s] = this.uniforms[4].data;
      return { x: i, y: s };
    },
    set sourceScale({ x: i, y: s }) {
      typeof i < "u" && (this.uniforms[4].data[0] = i), typeof s < "u" && (this.uniforms[4].data[1] = s);
    },
    get toScale() {
      const [i, s] = this.uniforms[5].data;
      return { x: i, y: s };
    },
    set toScale({ x: i, y: s }) {
      typeof i < "u" && (this.uniforms[5].data[0] = i), typeof s < "u" && (this.uniforms[5].data[1] = s);
    },
    get to() {
      return this.textures[0].data;
    },
    set to(i) {
      this.textures[0].data = i;
    },
    get map() {
      return this.textures[1].data;
    },
    set map(i) {
      this.textures[1].data = i;
    },
    varying: {
      v_transitionToTexCoord: "vec2",
      v_transitionDispMapTexCoord: "vec2"
    },
    uniforms: [
      {
        name: "u_transitionEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_transitionTo",
        type: "i",
        data: [1]
      },
      {
        name: "u_transitionDispMap",
        type: "i",
        data: [2]
      },
      {
        name: "u_transitionProgress",
        type: "f",
        data: [0]
      },
      {
        name: "u_sourceDispScale",
        type: "f",
        data: [t, o]
      },
      {
        name: "u_toDispScale",
        type: "f",
        data: [r, n]
      }
    ],
    attributes: [
      {
        name: "a_transitionToTexCoord",
        extends: "a_texCoord"
      },
      {
        name: "a_transitionDispMapTexCoord",
        extends: "a_texCoord"
      }
    ],
    textures: [
      {
        format: "RGBA",
        update: !0
      },
      {
        format: "RGB"
      }
    ]
  };
}
function Ke({
  low: e = 0,
  high: a = 0.01,
  color: t = [0, 0, 0, 0],
  textureEnabled: o = !0
} = {}) {
  return {
    vertex: {
      attribute: {
        a_transitionToTexCoord: "vec2",
        a_transitionDissolveMapTexCoord: "vec2"
      },
      main: `
    v_transitionToTexCoord = a_transitionToTexCoord;
    v_transitionDissolveMapTexCoord = a_transitionDissolveMapTexCoord;`
    },
    fragment: {
      uniform: {
        u_transitionEnabled: "bool",
        u_dissolveToTextureEnabled: "bool",
        u_transitionProgress: "float",
        u_dissolveLowEdge: "float",
        u_dissolveHighEdge: "float",
        u_transitionColorTo: "vec4",
        u_transitionTo: "sampler2D",
        u_transitionDissolveMap: "sampler2D"
      },
      main: `
    if (u_transitionEnabled) {
        vec4 targetPixel = u_transitionColorTo;

        if (u_dissolveToTextureEnabled) {
            targetPixel = texture2D(u_transitionTo, v_transitionToTexCoord);
        }

        vec3 transDissolveMapColor = texture2D(u_transitionDissolveMap, v_transitionDissolveMapTexCoord).rgb;
        float transDissolveMapAlpha = dot(transDissolveMapColor, lumcoeff);
        vec4 transDissolveMap = vec4(transDissolveMapColor, transDissolveMapAlpha);

        float edgeDelta = u_dissolveHighEdge - u_dissolveLowEdge;
        float dissolveProgress = u_transitionProgress * (1.0 + edgeDelta);
        vec4 dissolveVector = smoothstep(u_dissolveLowEdge, u_dissolveHighEdge, clamp(transDissolveMap - 1.0 + dissolveProgress , 0.0, 1.0));

        // color = dissolveVector.rgb; // debug
        color = mix(color, targetPixel.rgb, dissolveVector.rgb);
        alpha = mix(alpha, targetPixel.a, dissolveVector.a);
    }`
    },
    get disabled() {
      return !this.uniforms[0].data[0];
    },
    set disabled(r) {
      this.uniforms[0].data[0] = +!r;
    },
    get textureEnabled() {
      return !this.uniforms[7].data[0];
    },
    set textureEnabled(r) {
      this.uniforms[7].data[0] = +!!r;
    },
    get progress() {
      return this.uniforms[3].data[0];
    },
    set progress(r) {
      this.uniforms[3].data[0] = Math.min(Math.max(r, 0), 1);
    },
    get color() {
      return this.uniforms[6].data.slice();
    },
    set color(r) {
      r.forEach((n, i) => {
        Number.isNaN(n) || (this.uniforms[6].data[i] = n);
      });
    },
    get to() {
      return this.textures[0].data;
    },
    set to(r) {
      this.textures[0].data = r;
    },
    get map() {
      return this.textures[1].data;
    },
    set map(r) {
      this.textures[1].data = r;
    },
    get low() {
      return this.uniforms[4].data[0];
    },
    set low(r) {
      this.uniforms[4].data[0] = Math.min(Math.max(r, 0), this.high);
    },
    get high() {
      return this.uniforms[5].data[0];
    },
    set high(r) {
      this.uniforms[5].data[0] = Math.min(Math.max(r, this.low), 1);
    },
    varying: {
      v_transitionToTexCoord: "vec2",
      v_transitionDissolveMapTexCoord: "vec2"
    },
    uniforms: [
      {
        name: "u_transitionEnabled",
        type: "i",
        data: [1]
      },
      {
        name: "u_transitionTo",
        type: "i",
        data: [1]
      },
      {
        name: "u_transitionDissolveMap",
        type: "i",
        data: [2]
      },
      {
        name: "u_transitionProgress",
        type: "f",
        data: [0]
      },
      {
        name: "u_dissolveLowEdge",
        type: "f",
        data: [e]
      },
      {
        name: "u_dissolveHighEdge",
        type: "f",
        data: [a]
      },
      {
        name: "u_transitionColorTo",
        type: "f",
        data: t
      },
      {
        name: "u_dissolveToTextureEnabled",
        type: "i",
        data: [+!!o]
      }
    ],
    attributes: [
      {
        name: "a_transitionToTexCoord",
        extends: "a_texCoord"
      },
      {
        name: "a_transitionDissolveMapTexCoord",
        extends: "a_texCoord"
      }
    ],
    textures: [
      {
        format: "RGBA",
        update: !0
      },
      {
        format: "RGB",
        update: !1
      }
    ]
  };
}
const Re = ({
  uniform: e = "",
  attribute: a = "",
  varying: t = "",
  constant: o = "",
  main: r = ""
}) => `
precision highp float;
${e}
${a}
attribute vec2 a_position;
${t}

const vec3 lumcoeff = vec3(0.2125, 0.7154, 0.0721);
${o}
void main() {
    ${r}
    gl_Position = vec4(a_position.xy, 0.0, 1.0);
}`, Le = ({
  uniform: e = "",
  attribute: a = "",
  varying: t = "",
  constant: o = "",
  main: r = ""
}) => `
precision highp float;
${e}
${a}
attribute vec2 a_texCoord;
attribute vec2 a_position;
${t}
varying vec2 v_texCoord;

const vec3 lumcoeff = vec3(0.2125, 0.7154, 0.0721);
${o}
void main() {
    v_texCoord = a_texCoord;
    ${r}
    gl_Position = vec4(a_position.xy, 0.0, 1.0);
}`, ke = ({
  uniform: e = "",
  varying: a = "",
  constant: t = "",
  main: o = "",
  source: r = ""
}) => `
precision highp float;
${a}
${e}

const vec3 lumcoeff = vec3(0.2125, 0.7154, 0.0721);
${t}
void main() {
    ${r}
    vec3 color = vec3(0.0);
    float alpha = 1.0;
    ${o}
    gl_FragColor = vec4(color, 1.0) * alpha;
}`, Fe = ({
  uniform: e = "",
  varying: a = "",
  constant: t = "",
  main: o = "",
  source: r = ""
}) => `
precision highp float;
${a}
varying vec2 v_texCoord;
${e}
uniform sampler2D u_source;

const vec3 lumcoeff = vec3(0.2125, 0.7154, 0.0721);
${t}
void main() {
    vec2 sourceCoord = v_texCoord;
    ${r}
    vec4 pixel = texture2D(u_source, sourceCoord);
    vec3 color = pixel.rgb;
    float alpha = pixel.a;
    ${o}
    gl_FragColor = vec4(color, 1.0) * alpha;
}`, Y = {
  stretch: "CLAMP_TO_EDGE",
  repeat: "REPEAT",
  mirror: "MIRRORED_REPEAT"
}, I = {
  vertex: "VERTEX",
  fragment: "FRAGMENT"
};
function Ie({ gl: e, plane: a, effects: t, dimensions: o, noSource: r }) {
  const n = je(e, a, t, r);
  return { gl: e, data: n, dimensions: o || {} };
}
let J = !1;
function Q(e) {
  let a;
  const t = {
    preserveDrawingBuffer: !1,
    // should improve performance - https://stackoverflow.com/questions/27746091/preservedrawingbuffer-false-is-it-worth-the-effort
    antialias: !1,
    // should improve performance
    depth: !1,
    // turn off for explicitness - and in some cases perf boost
    stencil: !1
    // turn off for explicitness - and in some cases perf boost
  };
  if (a = e.getContext("webgl", t), a)
    J = !0;
  else if (!J)
    a = e.getContext("experimental-webgl", t);
  else
    return null;
  return a;
}
function Ve(e, a) {
  const t = e.canvas, o = 1, { width: r, height: n } = a || {};
  let i, s;
  r && n ? (i = r, s = n) : (i = Math.floor(t.clientWidth * o), s = Math.floor(t.clientHeight * o)), (t.width !== i || t.height !== s) && (t.width = i, t.height = s), e.viewport(0, 0, e.drawingBufferWidth, e.drawingBufferHeight);
}
function Oe(e, a = {}, t, o, r) {
  const { program: n, source: i, attributes: s, uniforms: c, textures: l, extensions: u, vao: d } = o, { xSegments: f = 1, ySegments: b = 1 } = a;
  t && i && i.texture && (e.bindTexture(e.TEXTURE_2D, i.texture), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, e.RGBA, e.UNSIGNED_BYTE, t)), e.useProgram(n), d ? u.vao.bindVertexArrayOES(d) : ie(e, s), We(e, c);
  let p = e.TEXTURE0;
  if (i && (e.activeTexture(p), e.bindTexture(e.TEXTURE_2D, i.texture), p = e.TEXTURE1), l)
    for (let x = 0; x < l.length; x++) {
      e.activeTexture(p + x);
      const h = l[x];
      e.bindTexture(e.TEXTURE_2D, h.texture), h.update && e.texImage2D(e.TEXTURE_2D, 0, e[h.format], e[h.format], e.UNSIGNED_BYTE, h.data);
    }
  e.drawArrays(e.TRIANGLES, 0, 6 * f * b);
}
function $e(e, a) {
  const { program: t, vertexShader: o, fragmentShader: r, source: n, attributes: i, extensions: s, vao: c } = a;
  (i || []).forEach((l) => e.deleteBuffer(l.buffer)), c && s.vao.deleteVertexArrayOES(c), n && n.texture && e.deleteTexture(n.texture), e.deleteProgram(t), e.deleteShader(o), e.deleteShader(r);
}
function je(e, a, t, o = !1) {
  const r = o ? null : {
    texture: ne(e).texture,
    buffer: null
  };
  r && (e.bindTexture(e.TEXTURE_2D, r.texture), e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL, !0));
  const n = Be(a, t, o), i = ee(n.vertex, o ? Re : Le), s = ee(n.fragment, o ? ke : Fe), { program: c, vertexShader: l, fragmentShader: u, error: d, type: f } = Ue(e, i, s);
  if (d)
    throw new Error(`${f} error:: ${d}
${f === I.fragment ? s : i}`);
  let b, p;
  try {
    b = e.getExtension("OES_vertex_array_object"), p = b.createVertexArrayOES(), b.bindVertexArrayOES(p);
  } catch {
  }
  const x = qe(e, c, n.attributes);
  p && (ie(e, x), b.bindVertexArrayOES(null));
  const h = He(e, c, n.uniforms);
  return {
    extensions: {
      vao: b
    },
    program: c,
    vertexShader: l,
    fragmentShader: u,
    source: r,
    attributes: x,
    uniforms: h,
    textures: n.textures,
    vao: p
  };
}
function Be(e, a, t = !1) {
  return a.reduce((o, r) => {
    const { attributes: n = [], uniforms: i = [], textures: s = [], varying: c = {} } = r, l = (u) => Object.keys(r[u] || {}).forEach((d) => {
      d === "constant" || d === "main" || d === "source" ? o[u][d] += r[u][d] + `
` : o[u][d] = { ...o[u][d], ...r[u][d] };
    });
    return l("vertex"), l("fragment"), n.forEach((u) => {
      o.attributes.some((f) => {
        if (f.name === u.name)
          return Object.assign(f, u), !0;
      }) || o.attributes.push(u);
    }), o.attributes.forEach((u) => {
      if (u.extends && !o.attributes.some((f) => {
        if (f.name === u.extends)
          return Object.assign(u, f, { name: u.name }), !0;
      }))
        throw new Error(`Could not find attribute ${u.extends} to extend`);
    }), o.uniforms.push(...i), o.textures.push(...s), Object.assign(o.vertex.varying, c), Object.assign(o.fragment.varying, c), o;
  }, Ne(e, t));
}
function Z({ xEnd: e, yEnd: a, factor: t }, o = {}) {
  const { xSegments: r = 1, ySegments: n = 1 } = o, i = [];
  for (let s = 0; s < r; s++)
    for (let c = 0; c < n; c++)
      i.push(
        e * s / r - t,
        a * c / n - t
      ), i.push(
        e * s / r - t,
        a * (c + 1) / n - t
      ), i.push(
        e * (s + 1) / r - t,
        a * c / n - t
      ), i.push(
        e * (s + 1) / r - t,
        a * c / n - t
      ), i.push(
        e * s / r - t,
        a * (c + 1) / n - t
      ), i.push(
        e * (s + 1) / r - t,
        a * (c + 1) / n - t
      );
  return i;
}
function Ne(e, a) {
  const t = a ? [] : [
    {
      name: "u_source",
      type: "i",
      data: [0]
    }
  ], o = [
    {
      name: "a_position",
      data: new Float32Array(Z({ xEnd: 2, yEnd: 2, factor: 1 }, e)),
      size: 2,
      type: "FLOAT"
    }
  ];
  return a || o.push({
    name: "a_texCoord",
    data: new Float32Array(Z({ xEnd: 1, yEnd: 1, factor: 0 }, e)),
    size: 2,
    type: "FLOAT"
  }), {
    vertex: {
      uniform: {},
      attribute: {},
      varying: {},
      constant: "",
      main: ""
    },
    fragment: {
      uniform: {},
      varying: {},
      constant: "",
      main: "",
      source: ""
    },
    attributes: o,
    uniforms: t,
    /*
     * Default textures
     */
    textures: []
  };
}
function ee(e, a) {
  const t = Object.entries(e).reduce((o, [r, n]) => (["uniform", "attribute", "varying"].includes(r) ? o[r] = Object.entries(n).reduce(
    (i, [s, c]) => i + `${r} ${c} ${s};
`,
    ""
  ) : o[r] = n, o), {});
  return a(t);
}
function Ue(e, a, t) {
  const o = te(e, e.VERTEX_SHADER, a), r = te(e, e.FRAGMENT_SHADER, t);
  return o.error ? o : r.error ? r : Xe(e, o, r);
}
function Xe(e, a, t) {
  const o = e.createProgram();
  if (e.attachShader(o, a), e.attachShader(o, t), e.linkProgram(o), e.getProgramParameter(o, e.LINK_STATUS))
    return { program: o, vertexShader: a, fragmentShader: t };
  const n = {
    error: e.getProgramInfoLog(o),
    type: "program"
  };
  return e.deleteProgram(o), n;
}
function te(e, a, t) {
  const o = e.createShader(a);
  if (e.shaderSource(o, t), e.compileShader(o), e.getShaderParameter(o, e.COMPILE_STATUS))
    return o;
  const n = {
    error: e.getShaderInfoLog(o),
    type: a === e.VERTEX_SHADER ? I.vertex : I.fragment
  };
  return e.deleteShader(o), n;
}
function ne(e, { width: a = 1, height: t = 1, data: o = null, format: r = "RGBA", wrap: n = "stretch" } = {}) {
  const i = e.createTexture();
  return e.bindTexture(e.TEXTURE_2D, i), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_S, e[ae(n.x || n)]), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_WRAP_T, e[ae(n.y || n)]), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MIN_FILTER, e.NEAREST), e.texParameteri(e.TEXTURE_2D, e.TEXTURE_MAG_FILTER, e.NEAREST), o ? e.texImage2D(e.TEXTURE_2D, 0, e[r], e[r], e.UNSIGNED_BYTE, o) : e.texImage2D(e.TEXTURE_2D, 0, e[r], a, t, 0, e[r], e.UNSIGNED_BYTE, null), { texture: i, width: a, height: t, format: r };
}
function Ge(e, a, t, o) {
  const r = e.getAttribLocation(a, t), n = e.createBuffer();
  return e.bindBuffer(e.ARRAY_BUFFER, n), e.bufferData(e.ARRAY_BUFFER, o, e.STATIC_DRAW), { location: r, buffer: n };
}
function qe(e, a, t) {
  return (t || []).map((o) => {
    const { location: r, buffer: n } = Ge(e, a, o.name, o.data);
    return {
      name: o.name,
      location: r,
      buffer: n,
      type: o.type,
      size: o.size
    };
  });
}
function He(e, a, t) {
  return (t || []).map((o) => ({
    location: e.getUniformLocation(a, o.name),
    size: o.size || o.data.length,
    type: o.type,
    data: o.data
  }));
}
function We(e, a) {
  (a || []).forEach((t) => {
    let { size: o, type: r, location: n, data: i } = t;
    r === "i" && (i = new Int32Array(i)), e[`uniform${o}${r}v`](n, i);
  });
}
function ie(e, a) {
  (a || []).forEach((t) => {
    const { location: o, buffer: r, size: n, type: i } = t;
    e.enableVertexAttribArray(o), e.bindBuffer(e.ARRAY_BUFFER, r), e.vertexAttribPointer(o, n, e[i], !1, 0, 0);
  });
}
function ae(e) {
  return Y[e] || Y.stretch;
}
let Ye = class z {
  /**
   * @constructor
   */
  constructor(a) {
    if (!a || !a.target)
      throw new Error("A target canvas was not provided");
    if (z.preventContextCreation)
      throw new Error("Context creation is prevented");
    if (this._contextCreationError = function() {
      z.preventContextCreation = !0, a && a.onContextCreationError && a.onContextCreationError.call(this, a);
    }, a.target.addEventListener("webglcontextcreationerror", this._contextCreationError, !1), !this.init(a))
      throw new Error("Could not create context");
    this._restoreContext = (o) => (o && o.preventDefault(), this.config.target.removeEventListener("webglcontextrestored", this._restoreContext, !0), this.init() ? (this._source && this.setSource(this._source), delete this._source, a && a.onContextRestored && a.onContextRestored.call(this, a), !0) : !1), this._loseContext = (o) => {
      o.preventDefault(), this.gl && this.gl.isContextLost() && (this.lostContext = !0, this.config.target.addEventListener("webglcontextrestored", this._restoreContext, !0), this.destroy(!0), a && a.onContextLost && a.onContextLost.call(this, a));
    }, this.config.target.addEventListener("webglcontextlost", this._loseContext, !0);
  }
  /**
   * Initializes a Kampos instance.
   * This is called inside the constructor,
   * but can be called again after effects have changed
   * or after {@link Kampos#destroy}.
   *
   * @param {kamposConfig} [config] defaults to `this.config`
   * @return {boolean} success whether initializing of the context and program were successful
   */
  init(a) {
    a = a || this.config;
    let { target: t, plane: o, effects: r, ticker: n, noSource: i } = a;
    if (z.preventContextCreation)
      return !1;
    this.lostContext = !1;
    let s = Q(t);
    if (!s || s.isContextLost() && (!this.restoreContext() || (s = Q(this.config.target), !s)))
      return !1;
    const { x: c = 1, y: l = 1 } = o && o.segments ? typeof o.segments == "object" ? o.segments : { x: o.segments, y: o.segments } : {};
    this.plane = {
      xSegments: c,
      ySegments: l
    };
    const { data: u } = Ie({ gl: s, plane: this.plane, effects: r, dimensions: this.dimensions, noSource: i });
    return this.gl = s, this.data = u, this.config = a, n && (this.ticker = n, n.add(this)), !0;
  }
  /**
   * Set the source config.
   *
   * @param {ArrayBufferView|ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|ImageBitmap|kamposSource} source
   * @example
   * const media = document.querySelector('#video');
   * kampos.setSource(media);
   */
  setSource(a) {
    if (!a || this.lostContext && !this.restoreContext())
      return;
    let t, o, r;
    Object.prototype.toString.call(a) === "[object Object]" ? { media: t, width: o, height: r } = a : t = a, o && r && (this.dimensions = { width: o, height: r }), Ve(this.gl, this.dimensions), this._createTextures(), this.media = t;
  }
  /**
   * Draw current scene.
   *
   * @param {number} time
   */
  draw(a) {
    if (this.lostContext && !this.restoreContext())
      return;
    const t = this.config.beforeDraw;
    t && t(a) === !1 || Oe(this.gl, this.plane, this.media, this.data, this.dimensions);
  }
  /**
   * Starts the animation loop.
   *
   * If a {@link Ticker} is used, this instance will be added to that {@link Ticker}.
   *
   * @param {function} beforeDraw function to run before each draw call
   */
  play(a) {
    if (this.config.beforeDraw = a, this.ticker)
      this.animationFrameId && this.stop(), this.playing || (this.playing = !0, this.ticker.add(this));
    else if (!this.animationFrameId) {
      const t = (o) => {
        this.animationFrameId = window.requestAnimationFrame(t), this.draw(o);
      };
      this.animationFrameId = window.requestAnimationFrame(t);
    }
  }
  /**
   * Stops the animation loop.
   *
   * If a {@link Ticker} is used, this instance will be removed from that {@link Ticker}.
   */
  stop() {
    this.animationFrameId && (window.cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.playing && (this.playing = !1, this.ticker.remove(this));
  }
  /**
   * Stops the animation loop and frees all resources.
   *
   * @param {boolean} keepState for internal use.
   */
  destroy(a) {
    if (this.stop(), this.gl && this.data && $e(this.gl, this.data), a) {
      const t = this.dimensions || {};
      this._source = this._source || {
        media: this.media,
        width: t.width,
        height: t.height
      };
    } else
      this.config && (this.config.target.removeEventListener("webglcontextlost", this._loseContext, !0), this.config.target.removeEventListener("webglcontextcreationerror", this._contextCreationError, !1)), this.config = null, this.dimensions = null;
    this.gl = null, this.data = null, this.media = null;
  }
  /**
   * Restore a lost WebGL context fot the given target.
   * This will replace canvas DOM element with a fresh clone.
   *
   * @return {boolean} success whether forcing a context restore was successful
   */
  restoreContext() {
    if (z.preventContextCreation)
      return !1;
    const a = this.config.target, t = this.config.target.cloneNode(!0), o = a.parentNode;
    return o && o.replaceChild(t, a), this.config.target = t, a.removeEventListener("webglcontextlost", this._loseContext, !0), a.removeEventListener("webglcontextrestored", this._restoreContext, !0), a.removeEventListener("webglcontextcreationerror", this._contextCreationError, !1), t.addEventListener("webglcontextlost", this._loseContext, !0), t.addEventListener("webglcontextcreationerror", this._contextCreationError, !1), this.lostContext ? this._restoreContext() : !0;
  }
  _createTextures() {
    this.data && this.data.textures.forEach((a, t) => {
      const o = this.data.textures[t];
      o.texture = ne(this.gl, {
        width: this.dimensions.width,
        height: this.dimensions.height,
        format: a.format,
        data: a.data,
        wrap: a.wrap
      }).texture, o.format = a.format, o.update = a.update;
    });
  }
};
class Je {
  constructor() {
    this.pool = [];
  }
  /**
   * Starts the animation loop.
   */
  start() {
    if (!this.animationFrameId) {
      const a = (t) => {
        this.animationFrameId = window.requestAnimationFrame(a), this.draw(t);
      };
      this.animationFrameId = window.requestAnimationFrame(a);
    }
  }
  /**
   * Stops the animation loop.
   */
  stop() {
    window.cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null;
  }
  /**
   * Invoke `.draw()` on all instances in the pool.
   *
   * @param {number} time
   */
  draw(a) {
    this.pool.forEach((t) => t.draw(a));
  }
  /**
   * Add an instance to the pool.
   *
   * @param {Kampos} instance
   */
  add(a) {
    ~this.pool.indexOf(a) || (this.pool.push(a), a.playing = !0);
  }
  /**
   * Remove an instance form the pool.
   *
   * @param {Kampos} instance
   */
  remove(a) {
    const t = this.pool.indexOf(a);
    ~t && (this.pool.splice(t, 1), a.playing = !1);
  }
}
const Qe = {
  alphaMask: ye,
  blend: Ce,
  brightnessContrast: Te,
  hueSaturation: ze,
  duotone: Pe,
  displacement: K,
  turbulence: V
}, Ze = {
  fade: Ae,
  displacement: Se,
  dissolve: Ke
}, et = {
  perlinNoise: De,
  simplex: we,
  cellular: Me
}, tt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  Kampos: Ye,
  Ticker: Je,
  effects: Qe,
  noise: et,
  transitions: Ze
}, Symbol.toStringTag, { value: "Module" })), { Kampos: S } = tt, A = {
  brightnessContrast({ brightness: e = 1, contrast: a = 1 } = {}) {
    return {
      fragment: {
        uniform: {
          u_brEnabled: "bool",
          u_ctEnabled: "bool",
          u_contrast: "float",
          u_brightness: "float"
        },
        constant: "const vec3 half3 = vec3(0.5);",
        main: `
    if (u_brEnabled) {
        color *= u_brightness;
    }

    if (u_ctEnabled) {
        color = (color - half3) * u_contrast + half3;
    }

    color = clamp(color, 0.0, 1.0);`
      },
      get brightness() {
        return this.uniforms[2].data[0];
      },
      set brightness(t) {
        this.uniforms[2].data[0] = M(Math.max(0, t), 0);
      },
      get contrast() {
        return this.uniforms[3].data[0];
      },
      set contrast(t) {
        this.uniforms[3].data[0] = M(Math.max(0, t), 0);
      },
      get brightnessDisabled() {
        return !this.uniforms[0].data[0];
      },
      set brightnessDisabled(t) {
        this.uniforms[0].data[0] = +!t;
      },
      get contrastDisabled() {
        return !this.uniforms[1].data[0];
      },
      set contrastDisabled(t) {
        this.uniforms[1].data[0] = +!t;
      },
      uniforms: [{
        name: "u_brEnabled",
        type: "i",
        data: [1]
      }, {
        name: "u_ctEnabled",
        type: "i",
        data: [1]
      }, {
        name: "u_brightness",
        type: "f",
        data: [e]
      }, {
        name: "u_contrast",
        type: "f",
        data: [a]
      }]
    };
  },
  hueSaturation({ hue: e = 0, saturation: a = 1 } = {}) {
    return {
      vertex: {
        uniform: {
          u_hue: "float",
          u_saturation: "float"
        },
        constant: `
const mat3 lummat = mat3(
    lumcoeff,
    lumcoeff,
    lumcoeff
);
const mat3 cosmat = mat3(
    vec3(0.787, -0.715, -0.072),
    vec3(-0.213, 0.285, -0.072),
    vec3(-0.213, -0.715, 0.928)
);
const mat3 sinmat = mat3(
    vec3(-0.213, -0.715, 0.928),
    vec3(0.143, 0.140, -0.283),
    vec3(-0.787, 0.715, 0.072)
);
const mat3 satmat = mat3(
    vec3(0.787, -0.715, -0.072),
    vec3(-0.213, 0.285, -0.072),
    vec3(-0.213, -0.715, 0.928)
);`,
        main: `
    float angle = (u_hue / 180.0) * 3.14159265358979323846264;
    v_hueRotation = lummat + cos(angle) * cosmat + sin(angle) * sinmat;
    v_saturation = lummat + satmat * u_saturation;`
      },
      fragment: {
        uniform: {
          u_hueEnabled: "bool",
          u_satEnabled: "bool",
          u_hue: "float",
          u_saturation: "float"
        },
        main: `
    if (u_hueEnabled) {
        color = vec3(
            dot(color, v_hueRotation[0]),
            dot(color, v_hueRotation[1]),
            dot(color, v_hueRotation[2])
        );
    }

    if (u_satEnabled) {
        color = vec3(
            dot(color, v_saturation[0]),
            dot(color, v_saturation[1]),
            dot(color, v_saturation[2])
        );
    }

    color = clamp(color, 0.0, 1.0);`
      },
      varying: {
        v_hueRotation: "mat3",
        v_saturation: "mat3"
      },
      get hue() {
        return this.uniforms[2].data[0];
      },
      set hue(t) {
        this.uniforms[2].data[0] = M(t, 0);
      },
      get saturation() {
        return this.uniforms[3].data[0];
      },
      set saturation(t) {
        this.uniforms[3].data[0] = M(Math.max(0, t), 0);
      },
      get hueDisabled() {
        return !this.uniforms[0].data[0];
      },
      set hueDisabled(t) {
        this.uniforms[0].data[0] = +!t;
      },
      get saturationDisabled() {
        return !this.uniforms[1].data[0];
      },
      set saturationDisabled(t) {
        this.uniforms[1].data[0] = +!t;
      },
      uniforms: [{
        name: "u_hueEnabled",
        type: "i",
        data: [1]
      }, {
        name: "u_satEnabled",
        type: "i",
        data: [1]
      }, {
        name: "u_hue",
        type: "f",
        data: [e]
      }, {
        name: "u_saturation",
        type: "f",
        data: [a]
      }]
    };
  },
  duotone({ dark: e = [0.7411764706, 0.0431372549, 0.568627451, 1], light: a = [0.9882352941, 0.7333333333, 0.05098039216, 1] } = {}) {
    return {
      fragment: {
        uniform: {
          u_duotoneEnabled: "bool",
          u_light: "vec4",
          u_dark: "vec4"
        },
        main: `
    if (u_duotoneEnabled) {
        vec3 gray = vec3(dot(lumcoeff, color));
        color = mix(u_dark.rgb, u_light.rgb, gray);
    }`
      },
      get light() {
        return this.uniforms[1].data.slice(0);
      },
      set light(t) {
        t.forEach(
          (o, r) => {
            Number.isNaN(o) || (this.uniforms[1].data[r] = o);
          }
        );
      },
      get dark() {
        return this.uniforms[2].data.slice(0);
      },
      set dark(t) {
        t.forEach(
          (o, r) => {
            Number.isNaN(o) || (this.uniforms[2].data[r] = o);
          }
        );
      },
      get disabled() {
        return !this.uniforms[0].data[0];
      },
      set disabled(t) {
        this.uniforms[0].data[0] = +!t;
      },
      uniforms: [{
        name: "u_duotoneEnabled",
        type: "i",
        data: [1]
      }, {
        name: "u_light",
        type: "f",
        data: a
      }, {
        name: "u_dark",
        type: "f",
        data: e
      }]
    };
  },
  transparentVideo() {
    return {
      vertex: {
        uniform: {
          u_texOffset: "vec2"
        },
        main: "v_texAlphaCoord = v_texCoord + u_texOffset;"
      },
      fragment: {
        uniform: {
          u_tvEnabled: "bool"
        },
        main: `
    if (u_tvEnabled) {
        alpha *= dot(lumcoeff, texture2D(u_source, v_texAlphaCoord).rgb);

        // transform alpha values from sRGB source to linearRGB - this cleans up the rim from the result
        float linear;
        if (alpha <= 0.04045) {
            linear = alpha / 12.92;
        }
        else {
            linear = pow((alpha + 0.055) / 1.055, 2.4);
        }

        alpha = linear;

        if (alpha < 0.04) {
            alpha = 0.0;
        }
        else if (alpha > 0.96) {
            alpha = 1.0;
        }
    }`
      },
      get disabled() {
        return !this.uniforms[0].data[0];
      },
      set disabled(e) {
        this.uniforms[0].data[0] = +!e;
      },
      varying: {
        v_texAlphaCoord: "vec2"
      },
      uniforms: [{
        name: "u_tvEnabled",
        type: "i",
        data: [1]
      }, {
        name: "u_texOffset",
        type: "f",
        data: [0, -0.5]
      }],
      attributes: [{
        name: "a_texCoord",
        data: new Float32Array([0, 0.5, 0, 1, 1, 0.5, 1, 0.5, 0, 1, 1, 1]),
        size: 2,
        type: "FLOAT"
      }]
    };
  }
};
S.prototype.getRequestFrame = function() {
  return "requestVideoFrameCallback" in HTMLVideoElement.prototype ? (a) => this.media.requestVideoFrameCallback(a) : window.requestAnimationFrame;
};
S.prototype.play = function() {
  if (!this.animationFrameId) {
    const a = this.getRequestFrame(), t = () => {
      const o = this.media;
      this.animationFrameId = a(t), o && o.readyState >= o.HAVE_CURRENT_DATA && (!(o.paused || o.ended) || this._needsRedraw) && (this._needsRedraw = !1, this.draw());
    };
    this.animationFrameId = a(t);
  }
};
const at = (e) => ({
  width: e && e.videoWidth || 0,
  height: e && e.videoHeight / 2 || 0,
  media: e
});
function oe(e) {
  const a = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
  return a ? [
    parseInt(a[1], 16) / 255,
    parseInt(a[2], 16) / 255,
    parseInt(a[3], 16) / 255,
    1
  ] : e;
}
const ot = (e = {}) => {
  const a = [A.transparentVideo()], t = "brightness" in e, o = "contrast" in e;
  if (t || o) {
    const i = A.brightnessContrast();
    t && (i.brightness = e.brightness), o && (i.contrast = e.contrast), a.push(i);
  }
  if (e.duotoneDark && e.duotoneLight) {
    const i = A.duotone();
    i.dark = oe(e.duotoneDark), i.light = oe(e.duotoneLight), a.push(i);
  }
  const r = "hue" in e, n = "saturation" in e;
  if (r || n) {
    const i = A.hueSaturation();
    r && (i.hue = e.hue), n && (i.saturation = e.saturation), a.push(i);
  }
  return a;
}, re = (e) => e.readyState >= e.HAVE_CURRENT_DATA, rt = 8, v = {
  count: 0,
  set: /* @__PURE__ */ new Set(),
  add(e) {
    return v.set.has(e) ? !0 : v.set.size < rt ? (v.set.add(e), v.count = v.set.size, !0) : !1;
  },
  remove(e) {
    v.set.delete(e), v.count = v.set.size;
  }
};
function nt({
  filterEffect: e,
  playerRef: a,
  videoRef: t,
  canvasRef: o,
  contextRef: r,
  kampos: n,
  setCanPlayTV: i
}) {
  let s = !1, c = !1;
  function l() {
    t.value && a.value && (t.value.removeEventListener("seeked", l), a.value.dataset.showCanvas = "", c = !0);
  }
  const u = {
    initKampos() {
      try {
        n.value = new S({
          target: o.value,
          effects: ot(e || {}),
          onContextLost: () => {
            const f = n.value._source && n.value._source.media;
            f && (f.ended || f.paused) && (n.value._needsRedraw = !0), this.stopKampos(), s && this.playKampos();
          }
        }), n.value.hasContext = !0;
      } catch {
        v.remove(r), i(!1), c && u.showPoster();
        return;
      }
      if (!t.value)
        return;
      const d = () => {
        t.value && (n.value.setSource(
          at(t.value)
        ), u.playKampos(), t.value.removeEventListener(
          "loadeddata",
          d,
          !1
        ));
      };
      re(t.value) ? d() : t.value.addEventListener(
        "loadeddata",
        d,
        !1
      );
    },
    playKampos() {
      if (!a.value || !o.value)
        return;
      let d;
      if (n.value ? d = n.value.hasContext || v.add(r) : d = S.preventContextCreation ? !1 : v.add(r), !d) {
        c && u.showPoster();
        return;
      }
      !n.value || !n.value.config ? u.initKampos() : (n.value.lostContext && n.value.restoreContext(), n.value.hasContext = !0, n.value.play(), !c && n.value.media && re(n.value.media) && "playing" in a.value.dataset && u.removePoster());
    },
    stopKampos() {
      v.remove(r), n.value.hasContext = !1, n.value.stop();
    },
    killKampos() {
      var d;
      n.value && (u.stopKampos(), n.value.destroy()), (d = t.value) == null || d.removeEventListener("seeked", l);
    },
    removePoster() {
      const d = t.value, f = a.value;
      c || !(f && d && n.value) || ((d.paused || d.ended || n.value._needsRedraw) && (n.value._needsRedraw = !1, n.value.draw()), d.addEventListener("seeked", l), d.currentTime = 0);
    },
    showPoster() {
      a.value && t.value && (delete a.value.dataset.showCanvas, c = !1);
    },
    onViewEnter() {
      s = !0, u.playKampos();
    },
    onViewLeave() {
      s = !1, n.value && n.value.hasContext && u.stopKampos();
    }
  };
  return u;
}
const it = ["poster", "controls", "loop", "volume", "muted"], st = {
  key: 1,
  class: "kapix-video-loading ka-center-middle"
}, ct = /* @__PURE__ */ F("div", { class: "kapix-loading-icon" }, null, -1), ut = [
  ct
], xt = /* @__PURE__ */ me({
  __name: "KapixTransparentVideoPlayer",
  props: {
    src: {
      type: [String, Array],
      default: void 0
    },
    alt: {
      type: String,
      default: void 0
    },
    autoplay: {
      type: Boolean,
      default: !1
    },
    controls: {
      type: Boolean,
      default: !1
    },
    loop: {
      type: Boolean,
      default: !1
    },
    volume: {
      type: Number,
      default: 0
    },
    fit: {
      type: String,
      default: "cover"
    },
    poster: {
      type: String,
      default: void 0
    },
    deactivated: {
      type: Boolean,
      default: !1
    }
  },
  setup(e) {
    ce("KapixVideoPlayer", ue);
    const a = new fe({
      maxAge: 60 * 60 * 1e3
      // 60min
    }), t = e, o = U("collectionContext", null), r = U("tippyParent", null), n = g(!1), i = g(!1), s = g(!1), c = g(), l = g(), u = g(), d = g(), f = g(), b = g(), p = X(() => de.isClient ? ge(t.src) ? t.src[0] : t.src : void 0), x = X(() => o != null && o.scrolling || r && !r.internalVisible ? !0 : t.deactivated), h = nt({
      filterEffect: {},
      playerRef: l,
      videoRef: u,
      canvasRef: d,
      contextRef: f,
      kampos: b,
      setCanPlayTV: () => {
      }
    });
    function $() {
      P();
    }
    function se() {
      s.value && (u.value && (u.value.load(), u.value.srcObject = null), s.value = !1);
    }
    async function j(_ = !0) {
      const D = p.value;
      if (u.value && D)
        try {
          i.value = !0;
          const T = await a.executePromiseWithCache(D, async () => {
            try {
              const E = await be.get(D, { responseType: "blob" });
              return E ? E.data : null;
            } catch (E) {
              console.error(E);
            }
            return null;
          });
          if (T) {
            const E = { type: "video/mp4" };
            try {
              u.value.srcObject = new Blob([T], E);
            } catch (N) {
              if (N.name !== "TypeError")
                throw N;
              u.value.src = URL.createObjectURL(T);
            }
            _ ? await u.value.play() : await u.value.load();
          }
        } finally {
          i.value = !1, s.value = !0;
        }
    }
    async function P() {
      u.value && !x.value && !c.value && (c.value = j(), await c.value, c.value = null);
    }
    async function B() {
      u.value && s.value && (c.value && await c.value, n.value = !0, c.value = null, u.value.pause());
    }
    return w(() => p.value, async (_) => {
      !u.value && await G(), se(), _ && (t.autoplay ? P() : t.poster || j(!1));
    }, { immediate: !0 }), w(() => x.value, (_) => {
      (s.value || !_ && t.autoplay) && (_ ? B() : P());
    }), w(() => t.autoplay, async (_) => {
      await G(), _ ? P() : B();
    }, { immediate: !0 }), w(() => d.value, () => {
      h.onViewEnter();
    }), ve(() => {
      h.killKampos();
    }), (_, D) => {
      const T = le, E = pe("tippy");
      return L(), k("div", {
        ref_key: "player",
        ref: l,
        class: "kapix-video-player-container"
      }, [
        F("video", {
          ref_key: "video",
          ref: u,
          class: q(["kapix-transparent-video-player", [`ka-fit-${e.fit || "none"}`]]),
          poster: e.poster,
          controls: C(s) && !C(x) && e.controls,
          loop: e.loop,
          volume: e.volume,
          muted: e.volume === 0,
          playsinline: ""
        }, null, 10, it),
        F("canvas", {
          ref_key: "canvas",
          ref: d,
          class: q([[`ka-fit-${e.fit || "none"}`], "kapix-video-canvas"])
        }, null, 2),
        !e.autoplay && !C(s) && !C(i) ? xe((L(), k("span", {
          key: 0,
          class: "kapix-video-icon ka-center-middle",
          onClick: he($, ["stop"])
        }, [
          _e(T)
        ])), [
          [E, { content: _.$t("components.videoPlayer.startVideo", "Start video") }]
        ]) : H("", !0),
        !C(s) && C(i) ? (L(), k("span", st, ut)) : H("", !0)
      ], 512);
    };
  }
});
export {
  xt as default
};
