From f3126a1da14dd2626b61ec32f2e4290c5c421ad0 Mon Sep 17 00:00:00 2001 From: George Hastings Date: Tue, 14 Jul 2026 21:23:21 -0400 Subject: [PATCH] bump 2.2.7 --- package-lock.json | 4 +- package.json | 2 +- src/shared/constants.ts | 2 +- vendor/unicornstudio/unicornStudio.umd.js | 8963 +-------------------- 4 files changed, 5 insertions(+), 8966 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0fe6bb0..a470f0a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "unicornstudio-react", - "version": "2.2.6", + "version": "2.2.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "unicornstudio-react", - "version": "2.2.6", + "version": "2.2.7", "license": "MIT", "devDependencies": { "@testing-library/jest-dom": "^6.9.1", diff --git a/package.json b/package.json index b80e4f4..77d9d82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unicornstudio-react", - "version": "2.2.6", + "version": "2.2.7", "description": "React component for embedding Unicorn.Studio interactive scenes with TypeScript support. Compatible with React (Vite) and Next.js.", "keywords": [ "react", diff --git a/src/shared/constants.ts b/src/shared/constants.ts index c617d8f..c6fb952 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -3,7 +3,7 @@ import type { ValidFPS, ScaleRange } from "./types"; /** * Current version of the Unicorn Studio SDK being used. */ -export const UNICORN_STUDIO_VERSION = "2.2.6"; +export const UNICORN_STUDIO_VERSION = "2.2.7"; /** * Official CDN URL for the Unicorn Studio SDK script. diff --git a/vendor/unicornstudio/unicornStudio.umd.js b/vendor/unicornstudio/unicornStudio.umd.js index 5d280cf..fbd56e0 100644 --- a/vendor/unicornstudio/unicornStudio.umd.js +++ b/vendor/unicornstudio/unicornStudio.umd.js @@ -1,8962 +1 @@ -!(function (e, t) { - "object" == typeof exports && "undefined" != typeof module - ? t(exports) - : "function" == typeof define && define.amd - ? define(["exports"], t) - : t( - ((e = - "undefined" != typeof globalThis - ? globalThis - : e || self).UnicornStudio = {}), - ); -})(this, function (e) { - "use strict"; - var t = Object.defineProperty, - i = (e, i, r) => - ((e, i, r) => - i in e - ? t(e, i, { - enumerable: !0, - configurable: !0, - writable: !0, - value: r, - }) - : (e[i] = r))(e, "symbol" != typeof i ? i + "" : i, r), - r = - "undefined" != typeof globalThis - ? globalThis - : "undefined" != typeof window - ? window - : "undefined" != typeof global - ? global - : "undefined" != typeof self - ? self - : {}, - a = { exports: {} }; - !(function (e, t) { - function i(e, t, r) { - return ( - (i = - "undefined" != typeof Reflect && Reflect.get - ? Reflect.get - : function (e, t, i) { - var r = (function (e, t) { - for ( - ; - !Object.prototype.hasOwnProperty.call(e, t) && - null !== (e = n(e)); - ); - return e; - })(e, t); - if (r) { - var a = Object.getOwnPropertyDescriptor(r, t); - return a.get ? a.get.call(i) : a.value; - } - }), - i(e, t, r || e) - ); - } - function a(e, t) { - return (a = - Object.setPrototypeOf || - function (e, t) { - return ((e.__proto__ = t), e); - })(e, t); - } - function s(e) { - var t = (function () { - if ("undefined" == typeof Reflect || !Reflect.construct) return !1; - if (Reflect.construct.sham) return !1; - if ("function" == typeof Proxy) return !0; - try { - return ( - Boolean.prototype.valueOf.call( - Reflect.construct(Boolean, [], function () {}), - ), - !0 - ); - } catch (e) { - return !1; - } - })(); - return function () { - var i, - r = n(e); - if (t) { - var a = n(this).constructor; - i = Reflect.construct(r, arguments, a); - } else i = r.apply(this, arguments); - return (function (e, t) { - if (t && ("object" === m(t) || "function" == typeof t)) return t; - if (void 0 !== t) - throw new TypeError( - "Derived constructors may only return object or undefined", - ); - return (function (e) { - if (void 0 === e) - throw new ReferenceError( - "this hasn't been initialised - super() hasn't been called", - ); - return e; - })(e); - })(this, i); - }; - } - function n(e) { - return (n = Object.setPrototypeOf - ? Object.getPrototypeOf - : function (e) { - return e.__proto__ || Object.getPrototypeOf(e); - })(e); - } - function l(e) { - return ( - (function (e) { - if (Array.isArray(e)) return u(e); - })(e) || - (function (e) { - if ( - ("undefined" != typeof Symbol && null != e[Symbol.iterator]) || - null != e["@@iterator"] - ) - return Array.from(e); - })(e) || - o(e) || - (function () { - throw new TypeError( - "Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", - ); - })() - ); - } - function o(e, t) { - if (e) { - if ("string" == typeof e) return u(e, t); - var i = Object.prototype.toString.call(e).slice(8, -1); - return ( - "Object" === i && e.constructor && (i = e.constructor.name), - "Map" === i || "Set" === i - ? Array.from(e) - : "Arguments" === i || - /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i) - ? u(e, t) - : void 0 - ); - } - } - function u(e, t) { - (null == t || t > e.length) && (t = e.length); - for (var i = 0, r = new Array(t); i < t; i++) r[i] = e[i]; - return r; - } - function d(e, t) { - var i = Object.keys(e); - if (Object.getOwnPropertySymbols) { - var r = Object.getOwnPropertySymbols(e); - (t && - (r = r.filter(function (t) { - return Object.getOwnPropertyDescriptor(e, t).enumerable; - })), - i.push.apply(i, r)); - } - return i; - } - function c(e) { - for (var t = 1; t < arguments.length; t++) { - var i = null != arguments[t] ? arguments[t] : {}; - t % 2 - ? d(Object(i), !0).forEach(function (t) { - h(e, t, i[t]); - }) - : Object.getOwnPropertyDescriptors - ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(i)) - : d(Object(i)).forEach(function (t) { - Object.defineProperty( - e, - t, - Object.getOwnPropertyDescriptor(i, t), - ); - }); - } - return e; - } - function h(e, t, i) { - return ( - t in e - ? Object.defineProperty(e, t, { - value: i, - enumerable: !0, - configurable: !0, - writable: !0, - }) - : (e[t] = i), - e - ); - } - function f(e, t) { - if (!(e instanceof t)) - throw new TypeError("Cannot call a class as a function"); - } - function p(e, t, i) { - return ( - t && - (function (e, t) { - for (var i = 0; i < t.length; i++) { - var r = t[i]; - ((r.enumerable = r.enumerable || !1), - (r.configurable = !0), - "value" in r && (r.writable = !0), - Object.defineProperty(e, r.key, r)); - } - })(e.prototype, t), - e - ); - } - function m(e) { - return (m = - "function" == typeof Symbol && "symbol" == typeof Symbol.iterator - ? function (e) { - return typeof e; - } - : function (e) { - return e && - "function" == typeof Symbol && - e.constructor === Symbol && - e !== Symbol.prototype - ? "symbol" - : typeof e; - })(e); - } - var v, g; - ((v = r), - (g = function (e) { - var t = new Uint8Array([0, 0, 0, 0]), - r = new Float32Array([ - 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, - ]), - u = (function () { - function e(t) { - var i, - r, - a, - s = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : {}; - (f(this, e), - (this.curtains = t), - (this.gl = null == t ? void 0 : t.gl), - (this.type = "Texture"), - (this.userData = {}), - (this.shouldUpdate = !1), - (this._samplerName = s.sampler || "uTexture"), - (this._source = s.source || null), - (this.source = this._source), - (this.sourceType = this._source - ? "source" - : s.fromTexture - ? "copy" - : "empty"), - (this._copiedFrom = null), - (this._videoFrameCallbackID = null), - (this._videoFrameCallback = null), - (this._videoFallbackRAF = null), - (this._sourceLoaded = !1), - (this._uploaded = !1), - (this._canDraw = !1), - (this._size = { width: 1, height: 1 }), - (this._globalParameters = this.gl - ? ((r = this.gl), - (a = s.floatingPoint), - r instanceof WebGL2RenderingContext - ? "half-float" === a - ? { - internalFormat: r.RGBA16F, - format: r.RGBA, - type: r.HALF_FLOAT, - } - : "float" === a - ? { - internalFormat: r.RGBA32F, - format: r.RGBA, - type: r.FLOAT, - } - : { - internalFormat: r.RGBA8, - format: r.RGBA, - type: r.UNSIGNED_BYTE, - } - : { - internalFormat: r.RGBA, - format: r.RGBA, - type: r.UNSIGNED_BYTE, - }) - : { internalFormat: 0, format: 0, type: 0 }), - (this._sampler = { - texture: this.gl ? this.gl.createTexture() : null, - }), - (this._premultiplyAlpha = - null !== (i = s.premultiplyAlpha) && void 0 !== i && i), - this.gl && this._sampler.texture && this._initState(), - s.fromTexture - ? this.copy(s.fromTexture) - : this._source - ? this.setSource(this._source) - : this._uploadFallback()); - } - return ( - p(e, [ - { - key: "_bind", - value: function () { - this.gl.bindTexture( - this.gl.TEXTURE_2D, - this._sampler.texture, - ); - }, - }, - { - key: "_initState", - value: function () { - var e = this.gl; - (this._bind(), - e.pixelStorei( - e.UNPACK_PREMULTIPLY_ALPHA_WEBGL, - this._premultiplyAlpha ? 1 : 0, - ), - 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, - ), - e.texParameteri( - e.TEXTURE_2D, - e.TEXTURE_MIN_FILTER, - e.LINEAR, - ), - e.texParameteri( - e.TEXTURE_2D, - e.TEXTURE_MAG_FILTER, - e.LINEAR, - ), - e.bindTexture(e.TEXTURE_2D, null)); - }, - }, - { - key: "_uploadFallback", - value: function () { - if (this.gl && this._sampler.texture && !this._copiedFrom) { - var e = this.gl; - (this._bind(), - this._globalParameters.type === e.UNSIGNED_BYTE - ? e.texImage2D( - e.TEXTURE_2D, - 0, - this._globalParameters.internalFormat, - 1, - 1, - 0, - this._globalParameters.format, - this._globalParameters.type, - t, - ) - : e.texImage2D( - e.TEXTURE_2D, - 0, - this._globalParameters.internalFormat, - 1, - 1, - 0, - this._globalParameters.format, - this._globalParameters.type, - null, - ), - (this._uploaded = !0), - (this._canDraw = !0), - e.bindTexture(e.TEXTURE_2D, null)); - } - }, - }, - { - key: "_scheduleVideoRender", - value: function () { - this.curtains && - !this._copiedFrom && - ((this.shouldUpdate = !0), - "function" == typeof this.curtains.requestRender - ? this.curtains.requestRender() - : "function" == typeof this.curtains.render && - this.curtains.render()); - }, - }, - { - key: "_stopVideoFrameUpdates", - value: function () { - var e = this._source; - e && - e instanceof HTMLVideoElement && - (null !== this._videoFrameCallbackID && - "function" == typeof e.cancelVideoFrameCallback && - e.cancelVideoFrameCallback(this._videoFrameCallbackID), - (this._videoFrameCallbackID = null), - (this._videoFrameCallback = null), - null !== this._videoFallbackRAF && - (cancelAnimationFrame(this._videoFallbackRAF), - (this._videoFallbackRAF = null))); - }, - }, - { - key: "_startVideoFrameUpdates", - value: function () { - var e = this, - t = this._source; - t && - t instanceof HTMLVideoElement && - !this._copiedFrom && - (this._stopVideoFrameUpdates(), - "function" == typeof t.requestVideoFrameCallback - ? ((this._videoFrameCallback = function () { - (e._scheduleVideoRender(), - (e._videoFrameCallbackID = - t.requestVideoFrameCallback( - e._videoFrameCallback, - ))); - }), - (this._videoFrameCallbackID = - t.requestVideoFrameCallback( - this._videoFrameCallback, - ))) - : (this._videoFallbackRAF = requestAnimationFrame( - function i() { - e._source === t - ? (!t.paused && - !t.ended && - t.readyState >= t.HAVE_CURRENT_DATA && - e._scheduleVideoRender(), - (e._videoFallbackRAF = - requestAnimationFrame(i))) - : (e._videoFallbackRAF = null); - }, - ))); - }, - }, - { - key: "_uploadSource", - value: function (e) { - if (this.gl && this._sampler.texture && !this._copiedFrom) { - var t = this.gl, - i = e.videoWidth || e.naturalWidth || e.width || 1, - r = e.videoHeight || e.naturalHeight || e.height || 1; - ((this._size = { width: i, height: r }), - this._bind(), - t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), - t.pixelStorei( - t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, - this._premultiplyAlpha ? 1 : 0, - ), - t instanceof WebGL2RenderingContext - ? t.texImage2D( - t.TEXTURE_2D, - 0, - this._globalParameters.internalFormat, - this._globalParameters.format, - this._globalParameters.type, - e, - ) - : t.texImage2D( - t.TEXTURE_2D, - 0, - this._globalParameters.format, - this._globalParameters.format, - this._globalParameters.type, - e, - ), - t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 0), - (this._sourceLoaded = !0), - (this._uploaded = !0), - (this._canDraw = !0), - (this.sourceType = - e instanceof HTMLVideoElement - ? "video" - : e instanceof HTMLCanvasElement - ? "canvas" - : "image"), - t.bindTexture(t.TEXTURE_2D, null)); - } - }, - }, - { - key: "setSource", - value: function (e) { - return ( - this._stopVideoFrameUpdates(), - (this._source = e), - (this.source = e), - (this._copiedFrom = null), - this._uploadSource(e), - e instanceof HTMLVideoElement && - this._startVideoFrameUpdates(), - this - ); - }, - }, - { - key: "copy", - value: function (e) { - return e - ? (this._stopVideoFrameUpdates(), - (this._source = e._source || null), - (this.source = this._source), - (this._copiedFrom = e), - (this.sourceType = e.sourceType || "copy"), - (this._sourceLoaded = !!e._sourceLoaded), - (this._uploaded = !!e._uploaded), - (this._canDraw = !1 !== e._canDraw), - (this._sampler.texture = e._sampler.texture), - (this._size = c({}, e._size)), - (this._globalParameters = c({}, e._globalParameters)), - (this.shouldUpdate = !!e.shouldUpdate), - this) - : this; - }, - }, - { - key: "update", - value: function () { - this._source && - !this._copiedFrom && - this._uploadSource(this._source); - }, - }, - { - key: "needUpdate", - value: function () { - this._copiedFrom || - (this.update(), - this.curtains && - "function" == typeof this.curtains.requestRender - ? this.curtains.requestRender() - : this.curtains && - "function" == typeof this.curtains.render && - this.curtains.render()); - }, - }, - { - key: "remove", - value: function () { - (this._stopVideoFrameUpdates(), - this.gl && - this._sampler.texture && - !this._copiedFrom && - this.gl.deleteTexture(this._sampler.texture)); - }, - }, - ]), - e - ); - })(), - d = (function () { - function e(t) { - var i, - r, - a, - s, - n, - l = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : {}; - (f(this, e), - (this.curtains = t), - (this.gl = null == t ? void 0 : t.gl), - (this.type = "RenderTarget"), - (this.userData = {}), - (this._depth = !!l.depth), - (this._clear = void 0 === l.clear || !!l.clear)); - var o = - (null == t || null === (i = t.canvas) || void 0 === i - ? void 0 - : i.width) || 1, - d = - (null == t || null === (r = t.canvas) || void 0 === r - ? void 0 - : r.height) || 1; - ((this._scaleWithCanvas = - void 0 === l.scaleWithCanvas || !!l.scaleWithCanvas), - (this._widthScale = - void 0 !== l.maxWidth && o > 0 ? l.maxWidth / o : null), - (this._heightScale = - void 0 !== l.maxHeight && d > 0 ? l.maxHeight / d : null), - (this._baseMaxSize = { - width: Math.max(1, Math.round(l.maxWidth || o)), - height: Math.max(1, Math.round(l.maxHeight || d)), - }), - (this._minSize = { - width: Math.max(1, Math.round(l.minWidth || 1)), - height: Math.max(1, Math.round(l.minHeight || 1)), - }), - (this._maxSize = { - width: this._baseMaxSize.width, - height: this._baseMaxSize.height, - }), - (this._size = { - width: this._baseMaxSize.width, - height: this._baseMaxSize.height, - }), - this._setSize(), - (this.index = -1), - (this._frameBuffer = null), - (this._depthBuffer = null)); - var c = - (null === (a = l.texturesOptions) || void 0 === a - ? void 0 - : a.sampler) || "uTexture", - h = l.texturesOptions && l.texturesOptions.floatingPoint; - ((this.textures = [ - new u(t, { - sampler: c, - premultiplyAlpha: - null !== - (s = - null === (n = l.texturesOptions) || void 0 === n - ? void 0 - : n.premultiplyAlpha) && - void 0 !== s && - s, - floatingPoint: h, - }), - ]), - null != t && - t.renderTargets && - !t.renderTargets.includes(this) && - (t.renderTargets.push(this), - t.renderTargets.forEach(function (e, t) { - e.index = t; - })), - this._initRenderTarget()); - } - return ( - p(e, [ - { - key: "_setSize", - value: function () { - var e, - t, - i = - 1 * - ((null === this.curtains || - void 0 === this.curtains || - null === (e = this.curtains.canvas) || - void 0 === e - ? void 0 - : e.width) || 1), - r = - 1 * - ((null === this.curtains || - void 0 === this.curtains || - null === (t = this.curtains.canvas) || - void 0 === t - ? void 0 - : t.height) || 1), - a = this._baseMaxSize.width, - s = this._baseMaxSize.height; - (this._scaleWithCanvas && - (null !== this._widthScale && - (a = Math.max(1, Math.round(i * this._widthScale))), - null !== this._heightScale && - (s = Math.max(1, Math.round(r * this._heightScale)))), - (this._maxSize = { width: a, height: s }), - (this._size = { - width: Math.min( - this._maxSize.width, - Math.max(this._minSize.width, i), - ), - height: Math.min( - this._maxSize.height, - Math.max(this._minSize.height, r), - ), - })); - }, - }, - { - key: "_initRenderTarget", - value: function () { - if (this.gl) { - var e = this.gl; - (this._setSize(), - this._frameBuffer || - (this._frameBuffer = e.createFramebuffer())); - var t = this.getTexture(); - t && - (e.bindFramebuffer(e.FRAMEBUFFER, this._frameBuffer), - e.bindTexture(e.TEXTURE_2D, t._sampler.texture), - e.texImage2D( - e.TEXTURE_2D, - 0, - t._globalParameters.internalFormat, - this._size.width, - this._size.height, - 0, - t._globalParameters.format, - t._globalParameters.type, - null, - ), - (t._size = c({}, this._size)), - (t._sourceLoaded = !0), - (t._uploaded = !0), - (t._canDraw = !0), - (t.sourceType = "fbo"), - e.framebufferTexture2D( - e.FRAMEBUFFER, - e.COLOR_ATTACHMENT0, - e.TEXTURE_2D, - t._sampler.texture, - 0, - ), - this._depth && - (this._depthBuffer || - (this._depthBuffer = e.createRenderbuffer()), - e.bindRenderbuffer(e.RENDERBUFFER, this._depthBuffer), - e.renderbufferStorage( - e.RENDERBUFFER, - e.DEPTH_COMPONENT16, - this._size.width, - this._size.height, - ), - e.framebufferRenderbuffer( - e.FRAMEBUFFER, - e.DEPTH_ATTACHMENT, - e.RENDERBUFFER, - this._depthBuffer, - ), - e.bindRenderbuffer(e.RENDERBUFFER, null)), - e.bindTexture(e.TEXTURE_2D, null), - e.bindFramebuffer(e.FRAMEBUFFER, null)); - } - }, - }, - { - key: "resize", - value: function () { - if (this.gl) { - var e = this._size.width, - t = this._size.height; - if ( - (this._setSize(), - e !== this._size.width || - t !== this._size.height || - !this._frameBuffer) - ) - if (this._frameBuffer) { - var i = this.getTexture(); - if (i) { - var r = this.gl; - (r.bindFramebuffer( - r.FRAMEBUFFER, - this._frameBuffer, - ), - r.bindTexture(r.TEXTURE_2D, i._sampler.texture), - r.texImage2D( - r.TEXTURE_2D, - 0, - i._globalParameters.internalFormat, - this._size.width, - this._size.height, - 0, - i._globalParameters.format, - i._globalParameters.type, - null, - ), - (i._size = c({}, this._size)), - (i._sourceLoaded = !0), - (i._uploaded = !0), - (i._canDraw = !0), - (i.sourceType = "fbo"), - r.framebufferTexture2D( - r.FRAMEBUFFER, - r.COLOR_ATTACHMENT0, - r.TEXTURE_2D, - i._sampler.texture, - 0, - ), - this._depth && - (this._depthBuffer || - (this._depthBuffer = r.createRenderbuffer()), - r.bindRenderbuffer( - r.RENDERBUFFER, - this._depthBuffer, - ), - r.renderbufferStorage( - r.RENDERBUFFER, - r.DEPTH_COMPONENT16, - this._size.width, - this._size.height, - ), - r.framebufferRenderbuffer( - r.FRAMEBUFFER, - r.DEPTH_ATTACHMENT, - r.RENDERBUFFER, - this._depthBuffer, - ), - r.bindRenderbuffer(r.RENDERBUFFER, null)), - r.bindTexture(r.TEXTURE_2D, null), - this.curtains && this.curtains.renderer - ? this.curtains.renderer.bindFrameBuffer(null) - : r.bindFramebuffer(r.FRAMEBUFFER, null)); - } - } else this._initRenderTarget(); - } - }, - }, - { - key: "getTexture", - value: function () { - return this.textures[0] || null; - }, - }, - { - key: "remove", - value: function () { - var e, - t = this; - this.gl && - (this._depthBuffer && - (this.gl.deleteRenderbuffer(this._depthBuffer), - (this._depthBuffer = null)), - this._frameBuffer && - (this.gl.deleteFramebuffer(this._frameBuffer), - (this._frameBuffer = null)), - this.textures.forEach(function (e) { - return e.remove(); - }), - null !== (e = this.curtains) && - void 0 !== e && - e.renderTargets && - ((this.curtains.renderTargets = - this.curtains.renderTargets.filter(function (e) { - return e !== t; - })), - this.curtains.renderTargets.forEach(function (e, t) { - e.index = t; - }))); - }, - }, - ]), - e - ); - })(), - h = (function () { - function e() { - var t, - i, - r, - a = this, - s = - arguments.length > 0 && void 0 !== arguments[0] - ? arguments[0] - : {}; - (f(this, e), - (this.type = "Curtains"), - (this.options = c({}, s)), - (this.container = (r = s.container) - ? "string" == typeof r - ? document.querySelector(r) - : r - : null), - (this.canvas = document.createElement("canvas")), - (this.canvas.style.display = "block"), - (this.canvas.style.width = "100%"), - (this.canvas.style.height = "100%"), - this.container && - !this.container.contains(this.canvas) && - this.container.appendChild(this.canvas)); - var n = { - alpha: !0, - antialias: null !== (t = s.antialias) && void 0 !== t && t, - premultipliedAlpha: - null === (i = s.premultipliedAlpha) || void 0 === i || i, - preserveDrawingBuffer: !1, - }; - ((this.gl = - this.canvas.getContext("webgl2", n) || - this.canvas.getContext("webgl", n)), - this.gl instanceof WebGL2RenderingContext - ? (this.gl.getExtension("EXT_color_buffer_float"), - this.gl.getExtension("OES_texture_float_linear")) - : (this.gl.getExtension("OES_texture_half_float"), - this.gl.getExtension("OES_texture_half_float_linear"), - this.gl.getExtension("OES_texture_float"), - this.gl.getExtension("OES_texture_float_linear")), - (this.planes = []), - (this.renderTargets = []), - (this.pixelRatio = s.pixelRatio || 1), - (this.renderingScale = s.renderingScale || 1), - (this._renderRequestID = null), - (this._errorCallbacks = []), - (this._contextLostCallbacks = []), - (this._contextRestoredCallbacks = [])); - var l = { - currentProgramID: null, - currentGeometryID: null, - forceBufferUpdate: !1, - depthTest: null, - blending: null, - cullFace: null, - frameBufferID: null, - activeTexture: null, - flipY: null, - premultiplyAlpha: null, - }; - ((this.renderer = { - gl: this.gl, - premultipliedAlpha: n.premultipliedAlpha, - state: l, - nextRender: { execute: function () {} }, - setDepthTest: function (e) { - a.gl && - (e && !l.depthTest - ? ((l.depthTest = e), a.gl.enable(a.gl.DEPTH_TEST)) - : !e && - l.depthTest && - ((l.depthTest = e), a.gl.disable(a.gl.DEPTH_TEST))); - }, - setDepthFunc: function () { - a.gl && a.gl.depthFunc(a.gl.LEQUAL); - }, - setBlending: function () { - var e = - arguments.length > 0 && - void 0 !== arguments[0] && - arguments[0]; - a.gl && - (e && !l.blending - ? ((l.blending = e), a.gl.enable(a.gl.BLEND)) - : !e && - l.blending && - ((l.blending = e), a.gl.disable(a.gl.BLEND))); - }, - setBlendFunc: function () { - a.gl && - (a.gl.enable(a.gl.BLEND), - this.premultipliedAlpha - ? a.gl.blendFuncSeparate( - a.gl.ONE, - a.gl.ONE_MINUS_SRC_ALPHA, - a.gl.ONE, - a.gl.ONE_MINUS_SRC_ALPHA, - ) - : a.gl.blendFuncSeparate( - a.gl.SRC_ALPHA, - a.gl.ONE_MINUS_SRC_ALPHA, - a.gl.ONE, - a.gl.ONE_MINUS_SRC_ALPHA, - )); - }, - setFaceCulling: function (e) { - if (a.gl && l.cullFace !== e) - if (((l.cullFace = e), "none" === e)) - a.gl.disable(a.gl.CULL_FACE); - else { - var t = "front" === e ? a.gl.FRONT : a.gl.BACK; - (a.gl.enable(a.gl.CULL_FACE), a.gl.cullFace(t)); - } - }, - useProgram: function (e) { - if (a.gl && e) { - var t = void 0 !== e.id ? e.id : e, - i = e.program || e; - (null !== l.currentProgramID && l.currentProgramID === t) || - (a.gl.useProgram(i), (l.currentProgramID = t)); - } - }, - bindFrameBuffer: function (e) { - var t = - arguments.length > 1 && - void 0 !== arguments[1] && - arguments[1]; - if (a.gl) { - e && t && !e._frameBuffer && e._initRenderTarget(); - var i = e - ? void 0 !== e.index - ? e.index - : e._frameBuffer - : null; - i !== l.frameBufferID && - (a.gl.bindFramebuffer( - a.gl.FRAMEBUFFER, - e ? e._frameBuffer : null, - ), - (l.frameBufferID = i)); - } - }, - }), - this.renderer.setBlendFunc(), - this.renderer.setDepthFunc(), - this.renderer.setDepthTest(!1), - (this._onContextLost = function (e) { - (e.preventDefault(), - a._contextLostCallbacks.forEach(function (t) { - return t(e); - })); - }), - (this._onContextRestored = function () { - a._contextRestoredCallbacks.forEach(function (e) { - return e(); - }); - }), - this.canvas.addEventListener( - "webglcontextlost", - this._onContextLost, - !1, - ), - this.canvas.addEventListener( - "webglcontextrestored", - this._onContextRestored, - !1, - ), - this.resize()); - } - return ( - p(e, [ - { - key: "_emitError", - value: function (e) { - this._errorCallbacks.forEach(function (t) { - return t(e); - }); - }, - }, - { - key: "onError", - value: function (e) { - return ( - "function" == typeof e && this._errorCallbacks.push(e), - this - ); - }, - }, - { - key: "onContextLost", - value: function (e) { - return ( - "function" == typeof e && - this._contextLostCallbacks.push(e), - this - ); - }, - }, - { - key: "onContextRestored", - value: function (e) { - return ( - "function" == typeof e && - this._contextRestoredCallbacks.push(e), - this - ); - }, - }, - { - key: "restoreContext", - value: function () { - return this; - }, - }, - { - key: "createRenderTarget", - value: function () { - return new d( - this, - arguments.length > 0 && void 0 !== arguments[0] - ? arguments[0] - : {}, - ); - }, - }, - { - key: "requestRender", - value: function () { - var e = this; - this.gl && - null === this._renderRequestID && - (this._renderRequestID = requestAnimationFrame( - function () { - ((e._renderRequestID = null), e.render()); - }, - )); - }, - }, - { - key: "resize", - value: function () { - if (this.container) { - var e = Math.max( - 1, - Math.round( - this.container.clientWidth * - this.pixelRatio * - this.renderingScale, - ), - ), - t = Math.max( - 1, - Math.round( - this.container.clientHeight * - this.pixelRatio * - this.renderingScale, - ), - ); - ((this.canvas.width = e), - (this.canvas.height = t), - this.gl && this.gl.viewport(0, 0, e, t), - this.renderTargets.slice().forEach(function (e) { - e && "function" == typeof e.resize && e.resize(); - })); - } - }, - }, - { - key: "render", - value: function () { - if (this.gl) { - this.renderer.nextRender.execute(); - var e = this.gl; - e.clear(e.COLOR_BUFFER_BIT | e.DEPTH_BUFFER_BIT); - var t = l(this.planes) - .filter(function (e) { - return !1 !== e.visible; - }) - .sort(function (e, t) { - return (e.renderOrder || 0) - (t.renderOrder || 0); - }), - i = t.filter(function (e) { - return "PingPongPlane" === e.type; - }), - r = t.filter(function (e) { - return "PingPongPlane" !== e.type; - }), - a = r - .filter(function (e) { - return !!e.target; - }) - .sort(function (e, t) { - var i = - e.target && void 0 !== e.target.index - ? e.target.index - : Number.MAX_SAFE_INTEGER, - r = - t.target && void 0 !== t.target.index - ? t.target.index - : Number.MAX_SAFE_INTEGER; - return i !== r - ? i - r - : (e.renderOrder || 0) - (t.renderOrder || 0); - }), - s = r.filter(function (e) { - return !e.target; - }); - (e.disable(e.DEPTH_TEST), - e.enable(e.BLEND), - e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA), - i.forEach(function (e) { - !1 !== e._canDraw && e._render(); - }), - a.forEach(function (e) { - !1 !== e._canDraw && e._render(); - }), - s.forEach(function (e) { - !1 !== e._canDraw && e._render(); - })); - } - }, - }, - { - key: "dispose", - value: function () { - (null !== this._renderRequestID && - (cancelAnimationFrame(this._renderRequestID), - (this._renderRequestID = null)), - this.planes.slice().forEach(function (e) { - return e.remove(); - }), - this.renderTargets.slice().forEach(function (e) { - return e.remove(); - }), - this.canvas && - (this.canvas.removeEventListener( - "webglcontextlost", - this._onContextLost, - ), - this.canvas.removeEventListener( - "webglcontextrestored", - this._onContextRestored, - )), - (this.planes = []), - (this.renderTargets = [])); - }, - }, - ]), - e - ); - })(); - function v(e, t, i) { - var r = e.createShader(t); - if ( - (e.shaderSource(r, i), - e.compileShader(r), - !e.getShaderParameter(r, e.COMPILE_STATUS)) - ) { - var a = e.getShaderInfoLog(r) || "Unknown shader compile error"; - throw (e.deleteShader(r), new Error(a)); - } - return r; - } - var g = (function () { - function e(t, i) { - var r = this, - a = - arguments.length > 2 && void 0 !== arguments[2] - ? arguments[2] - : {}; - (f(this, e), - (this.type = "Plane"), - (this.curtains = t), - (this.gl = null == t ? void 0 : t.gl), - (this.htmlElement = - i || (null == t ? void 0 : t.container) || null), - (this.userData = {}), - (this.visible = !0), - (this.renderOrder = 0), - (this.target = null), - (this._canDraw = !0), - (this.textures = []), - (this.videos = []), - (this.uniforms = (function () { - var e = - arguments.length > 0 && void 0 !== arguments[0] - ? arguments[0] - : {}, - t = {}; - return ( - Object.keys(e).forEach(function (i) { - t[i] = c({}, e[i]); - }), - t - ); - })(a.uniforms)), - (this._readyCallbacks = []), - (this._renderCallbacks = []), - (this._afterRenderCallbacks = []), - (this._uniformLocations = new Map()), - (this._vertexShader = - a.vertexShader || - "\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nvarying vec2 vTextureCoord;\n\nvoid main() {\n gl_Position = vec4(aVertexPosition, 1.0);\n vTextureCoord = aTextureCoord;\n}\n"), - (this._fragmentShader = - a.fragmentShader || - "\nprecision mediump float;\n\nuniform sampler2D uTexture;\nvarying vec2 vTextureCoord;\n\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTextureCoord);\n}\n"), - (this._geometry = null), - (this._program = null), - (this._positionLocation = -1), - (this._uvLocation = -1), - (this._mvMatrixLocation = null), - (this._pMatrixLocation = null), - this._init(a), - null == t || t.planes.push(this), - requestAnimationFrame(function () { - r._readyCallbacks.forEach(function (e) { - return e(r); - }); - })); - } - return ( - p(e, [ - { - key: "_init", - value: function (e) { - if (this.gl) - try { - ((this._program = (function (e, t, i) { - var r = v(e, e.VERTEX_SHADER, t), - a = v(e, e.FRAGMENT_SHADER, i), - s = e.createProgram(); - if ( - (e.attachShader(s, r), - e.attachShader(s, a), - e.linkProgram(s), - e.deleteShader(r), - e.deleteShader(a), - !e.getProgramParameter(s, e.LINK_STATUS)) - ) { - var n = - e.getProgramInfoLog(s) || - "Unknown program link error"; - throw (e.deleteProgram(s), new Error(n)); - } - return s; - })(this.gl, this._vertexShader, this._fragmentShader)), - (this._positionLocation = this.gl.getAttribLocation( - this._program, - "aVertexPosition", - )), - (this._uvLocation = this.gl.getAttribLocation( - this._program, - "aTextureCoord", - )), - (this._geometry = (function (e) { - for ( - var t = - arguments.length > 1 && - void 0 !== arguments[1] - ? arguments[1] - : 1, - i = - arguments.length > 2 && - void 0 !== arguments[2] - ? arguments[2] - : 1, - r = Math.max(1, Math.floor(t)), - a = Math.max(1, Math.floor(i)), - s = (r + 1) * (a + 1), - n = new Float32Array(3 * s), - l = new Float32Array(2 * s), - o = 0, - u = 0, - d = 0; - d <= a; - d++ - ) - for ( - var c = d / a, h = 1 - 2 * c, f = 0; - f <= r; - f++ - ) { - var p = f / r, - m = 2 * p - 1; - ((n[o++] = m), - (n[o++] = h), - (n[o++] = 0), - (l[u++] = p), - (l[u++] = 1 - c)); - } - for ( - var v = r * a * 6, - g = s > 65535, - y = g ? new Uint32Array(v) : new Uint16Array(v), - x = 0, - b = 0; - b < a; - b++ - ) - for (var _ = 0; _ < r; _++) { - var P = b * (r + 1) + _, - T = P + 1, - E = (b + 1) * (r + 1) + _, - w = E + 1; - ((y[x++] = P), - (y[x++] = E), - (y[x++] = T), - (y[x++] = T), - (y[x++] = E), - (y[x++] = w)); - } - var k = e.createBuffer(); - (e.bindBuffer(e.ARRAY_BUFFER, k), - e.bufferData(e.ARRAY_BUFFER, n, e.STATIC_DRAW)); - var R = e.createBuffer(); - (e.bindBuffer(e.ARRAY_BUFFER, R), - e.bufferData(e.ARRAY_BUFFER, l, e.STATIC_DRAW)); - var M = e.createBuffer(); - return ( - e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, M), - e.bufferData( - e.ELEMENT_ARRAY_BUFFER, - y, - e.STATIC_DRAW, - ), - e.bindBuffer(e.ARRAY_BUFFER, null), - e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, null), - { - positionBuffer: k, - uvBuffer: R, - indexBuffer: M, - indexCount: v, - indexType: g - ? e.UNSIGNED_INT - : e.UNSIGNED_SHORT, - } - ); - })(this.gl, e.widthSegments, e.heightSegments)), - (this._mvMatrixLocation = this.gl.getUniformLocation( - this._program, - "uMVMatrix", - )), - (this._pMatrixLocation = this.gl.getUniformLocation( - this._program, - "uPMatrix", - )), - (this._texMatrixLocation = this.gl.getUniformLocation( - this._program, - "uTextureMatrix", - ))); - } catch (r) { - var t, i; - (null === (t = this.curtains) || - void 0 === t || - null === (i = t._emitError) || - void 0 === i || - i.call(t, r), - (this._canDraw = !1)); - } - }, - }, - { - key: "_bindAttributes", - value: function () { - var e = this.gl, - t = this._geometry; - t && - (this._positionLocation >= 0 && - (e.bindBuffer(e.ARRAY_BUFFER, t.positionBuffer), - e.enableVertexAttribArray(this._positionLocation), - e.vertexAttribPointer( - this._positionLocation, - 3, - e.FLOAT, - !1, - 0, - 0, - )), - this._uvLocation >= 0 && - (e.bindBuffer(e.ARRAY_BUFFER, t.uvBuffer), - e.enableVertexAttribArray(this._uvLocation), - e.vertexAttribPointer( - this._uvLocation, - 2, - e.FLOAT, - !1, - 0, - 0, - )), - e.bindBuffer(e.ELEMENT_ARRAY_BUFFER, t.indexBuffer)); - }, - }, - { - key: "_bindUniforms", - value: function () { - var e = this; - if (this._program) { - var t = this.gl; - (t.useProgram(this._program), - Object.keys(this.uniforms).forEach(function (i) { - var r = e.uniforms[i]; - if (r) { - var a = e._uniformLocations.get(i); - (void 0 === a && - ((a = t.getUniformLocation( - e._program, - r.name || i, - )), - e._uniformLocations.set(i, a)), - (function (e, t, i, r) { - if (null != t && null != r) { - var a = - r && - "object" === m(r) && - "x" in r && - "y" in r, - s = a && "z" in r; - switch (i) { - case "1f": - e.uniform1f(t, Number(r)); - break; - case "2f": - e.uniform2f( - t, - a ? r.x : r[0], - a ? r.y : r[1], - ); - break; - case "3f": - e.uniform3f( - t, - s ? r.x : r[0], - s ? r.y : r[1], - s ? r.z : r[2], - ); - break; - case "4f": - e.uniform4f(t, r[0], r[1], r[2], r[3]); - break; - case "1i": - e.uniform1i(t, Number(r)); - break; - case "2i": - e.uniform2i(t, r[0], r[1]); - break; - case "3i": - e.uniform3i(t, r[0], r[1], r[2]); - break; - case "4i": - e.uniform4i(t, r[0], r[1], r[2], r[3]); - break; - case "1fv": - e.uniform1fv(t, r); - break; - case "2fv": - e.uniform2fv(t, r); - break; - case "3fv": - e.uniform3fv(t, r); - break; - case "4fv": - e.uniform4fv(t, r); - break; - case "mat3": - e.uniformMatrix3fv(t, !1, r); - break; - case "mat4": - e.uniformMatrix4fv(t, !1, r); - break; - default: - s - ? e.uniform3f(t, r.x, r.y, r.z) - : a - ? e.uniform2f(t, r.x, r.y) - : Array.isArray(r) || - ArrayBuffer.isView(r) - ? 16 === r.length - ? e.uniformMatrix4fv(t, !1, r) - : 9 === r.length - ? e.uniformMatrix3fv(t, !1, r) - : 4 === r.length - ? e.uniform4fv(t, r) - : 3 === r.length - ? e.uniform3fv(t, r) - : 2 === r.length - ? e.uniform2fv(t, r) - : 1 === r.length && - e.uniform1f(t, r[0]) - : e.uniform1f(t, Number(r)); - } - } - })(t, a, r.type, r.value)); - } - })); - } - }, - }, - { - key: "_bindTextures", - value: function () { - var e, - t = this.gl, - i = 0, - r = (function (e, t) { - var i = - ("undefined" != typeof Symbol && - e[Symbol.iterator]) || - e["@@iterator"]; - if (!i) { - if (Array.isArray(e) || (i = o(e)) || t) { - i && (e = i); - var r = 0, - a = function () {}; - return { - s: a, - n: function () { - return r >= e.length - ? { done: !0 } - : { done: !1, value: e[r++] }; - }, - e: function (e) { - throw e; - }, - f: a, - }; - } - throw new TypeError( - "Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", - ); - } - var s, - n = !0, - l = !1; - return { - s: function () { - i = i.call(e); - }, - n: function () { - var e = i.next(); - return ((n = e.done), e); - }, - e: function (e) { - ((l = !0), (s = e)); - }, - f: function () { - try { - n || null == i.return || i.return(); - } finally { - if (l) throw s; - } - }, - }; - })(this.textures); - try { - for (r.s(); !(e = r.n()).done; ) { - var a, - s = e.value; - if ( - null != s && - null !== (a = s._sampler) && - void 0 !== a && - a.texture - ) { - (t.activeTexture(t.TEXTURE0 + i), - s._copiedFrom && s.copy(s._copiedFrom), - s.shouldUpdate && s.update()); - var n = t.getUniformLocation( - this._program, - s._samplerName, - ); - null != n && - (t.bindTexture(t.TEXTURE_2D, s._sampler.texture), - t.uniform1i(n, i), - i++); - } - } - } catch (l) { - r.e(l); - } finally { - r.f(); - } - }, - }, - { - key: "_prepareRenderTarget", - value: function (e) { - var t, i; - if (!e || !this.gl) - return ( - this.curtains.renderer.bindFrameBuffer(null), - void this.gl.viewport( - 0, - 0, - this.curtains.canvas.width, - this.curtains.canvas.height, - ) - ); - this.curtains.renderer.bindFrameBuffer(e, !0); - var r = - (null === (t = e._size) || void 0 === t - ? void 0 - : t.width) || this.curtains.canvas.width, - a = - (null === (i = e._size) || void 0 === i - ? void 0 - : i.height) || this.curtains.canvas.height; - (this.gl.viewport(0, 0, r, a), - !1 !== e._clear && - (this.gl.clearColor(0, 0, 0, 0), - this.gl.clear( - this.gl.COLOR_BUFFER_BIT | - (e._depth ? this.gl.DEPTH_BUFFER_BIT : 0), - ))); - }, - }, - { - key: "_render", - value: function () { - var e = this; - this.gl && - this._program && - this._geometry && - (this._renderCallbacks.forEach(function (t) { - return t(e); - }), - this._prepareRenderTarget(this.target), - this.gl.useProgram(this._program), - this._mvMatrixLocation && - this.gl.uniformMatrix4fv(this._mvMatrixLocation, !1, r), - this._pMatrixLocation && - this.gl.uniformMatrix4fv(this._pMatrixLocation, !1, r), - this._texMatrixLocation && - this.gl.uniformMatrix4fv( - this._texMatrixLocation, - !1, - r, - ), - this._bindAttributes(), - this._bindUniforms(), - this._bindTextures(), - this.gl.drawElements( - this.gl.TRIANGLES, - this._geometry.indexCount, - this._geometry.indexType, - 0, - ), - this.curtains.renderer.bindFrameBuffer(null), - this.gl.viewport( - 0, - 0, - this.curtains.canvas.width, - this.curtains.canvas.height, - ), - this._afterRenderCallbacks.forEach(function (t) { - return t(e); - })); - }, - }, - { - key: "onReady", - value: function (e) { - return ( - "function" == typeof e && this._readyCallbacks.push(e), - this - ); - }, - }, - { - key: "onRender", - value: function (e) { - return ( - "function" == typeof e && this._renderCallbacks.push(e), - this - ); - }, - }, - { - key: "onAfterRender", - value: function (e) { - return ( - "function" == typeof e && - this._afterRenderCallbacks.push(e), - this - ); - }, - }, - { - key: "setRenderOrder", - value: function () { - var e = - arguments.length > 0 && void 0 !== arguments[0] - ? arguments[0] - : 0; - return ((this.renderOrder = e), this); - }, - }, - { - key: "setRenderTarget", - value: function (e) { - var t; - return ( - (this.target = e), - e && - null !== (t = this.curtains) && - void 0 !== t && - t.renderTargets && - !this.curtains.renderTargets.includes(e) && - (this.curtains.renderTargets.push(e), - this.curtains.renderTargets.forEach(function (e, t) { - e.index = t; - })), - this - ); - }, - }, - { - key: "createTexture", - value: function () { - var e, - t = - arguments.length > 0 && void 0 !== arguments[0] - ? arguments[0] - : {}, - i = t.sampler || "uTexture", - r = this.textures.find(function (e) { - return e._samplerName === i; - }); - if (r && t.fromTexture) return (r.copy(t.fromTexture), r); - var a = new u(this.curtains, { - sampler: i, - premultiplyAlpha: - null !== (e = t.premultiplyAlpha) && void 0 !== e && e, - fromTexture: t.fromTexture, - }); - if (r) { - var s = this.textures.indexOf(r); - return ((this.textures[s] = a), a); - } - return (this.textures.push(a), a); - }, - }, - { - key: "addTexture", - value: function (e) { - if (!e) return null; - var t = e._samplerName || "uTexture", - i = this.textures.findIndex(function (e) { - return e._samplerName === t; - }); - return ( - i >= 0 ? (this.textures[i] = e) : this.textures.push(e), - e - ); - }, - }, - { - key: "loadCanvas", - value: function (e) { - var t = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : {}, - i = arguments.length > 2 ? arguments[2] : void 0, - r = arguments.length > 3 ? arguments[3] : void 0; - try { - var a, - s = new u(this.curtains, { - sampler: t.sampler || "uTexture", - source: e, - premultiplyAlpha: - null !== (a = t.premultiplyAlpha) && - void 0 !== a && - a, - }); - return ( - (s.shouldUpdate = !0), - this.addTexture(s), - "function" == typeof i && i(s), - s - ); - } catch (n) { - return ("function" == typeof r && r(n), null); - } - }, - }, - { - key: "loadVideo", - value: function (e) { - var t, - i, - r = this, - a = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : {}, - s = arguments.length > 2 ? arguments[2] : void 0, - n = arguments.length > 3 ? arguments[3] : void 0; - (e instanceof HTMLVideoElement - ? (t = e) - : (((t = document.createElement("video")).crossOrigin = - "anonymous"), - (t.src = e)), - (t.preload = "auto"), - (t.muted = !0), - (t.loop = !0), - t.setAttribute("playsinline", ""), - t.crossOrigin || (t.crossOrigin = "anonymous")); - var l = new u(r.curtains, { - sampler: a.sampler || "uVideoTexture", - premultiplyAlpha: - null !== (i = a.premultiplyAlpha) && void 0 !== i && i, - }); - ((l.shouldUpdate = !0), r.addTexture(l)); - var o = function () { - try { - (l.setSource(t), - (l.shouldUpdate = !0), - r.videos.push(t), - "function" == typeof s && s(l)); - } catch (e) { - "function" == typeof n && n(e); - } - }; - return ( - t.readyState >= t.HAVE_CURRENT_DATA - ? o() - : (t.addEventListener("loadeddata", o, { once: !0 }), - t.addEventListener( - "error", - function (e) { - "function" == typeof n && n(e); - }, - { once: !0 }, - ), - e instanceof HTMLVideoElement || t.load()), - t - ); - }, - }, - { - key: "remove", - value: function () { - var e, - t = this; - this.gl && - (this.textures.forEach(function (e) { - return e.remove(); - }), - this._geometry && - (this.gl.deleteBuffer(this._geometry.positionBuffer), - this.gl.deleteBuffer(this._geometry.uvBuffer), - this.gl.deleteBuffer(this._geometry.indexBuffer)), - this._program && this.gl.deleteProgram(this._program), - null !== (e = this.curtains) && - void 0 !== e && - e.planes && - (this.curtains.planes = this.curtains.planes.filter( - function (e) { - return e !== t; - }, - ))); - }, - }, - ]), - e - ); - })(), - y = (function () { - function e(t) { - (f(this, e), (this.curtains = t), (this.cache = new Map())); - } - return ( - p(e, [ - { - key: "loadImage", - value: function (e) { - var t = this, - i = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : {}, - r = arguments.length > 2 ? arguments[2] : void 0, - a = arguments.length > 3 ? arguments[3] : void 0; - if (!e) - return ( - "function" == typeof a && - a(new Error("Missing image src")), - null - ); - var s = this.cache.get(e), - n = function (e) { - var a, - s = new u(t.curtains, { - sampler: i.sampler || "uTexture", - source: e, - premultiplyAlpha: - null !== (a = i.premultiplyAlpha) && - void 0 !== a && - a, - }); - "function" == typeof r && r(s); - }; - if (null != s && s.loaded && s.image) - return (n(s.image), s.image); - var l = (null == s ? void 0 : s.image) || new Image(); - l.crossOrigin = "anonymous"; - var o = s || { image: l, loaded: !1 }; - this.cache.set(e, o); - var d = function () { - ((o.loaded = !0), n(l)); - }; - return l.complete && l.naturalWidth > 0 - ? (d(), l) - : (l.addEventListener("load", d, { once: !0 }), - l.addEventListener( - "error", - function (e) { - "function" == typeof a && a(e); - }, - { once: !0 }, - ), - l.src || (l.src = e), - l); - }, - }, - { - key: "loadCanvas", - value: function (e) { - var t = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : {}, - i = arguments.length > 2 ? arguments[2] : void 0, - r = arguments.length > 3 ? arguments[3] : void 0; - try { - var a, - s = new u(this.curtains, { - sampler: t.sampler || "uTexture", - source: e, - premultiplyAlpha: - null !== (a = t.premultiplyAlpha) && - void 0 !== a && - a, - }); - return ( - (s.shouldUpdate = !0), - "function" == typeof i && i(s), - s - ); - } catch (n) { - return ("function" == typeof r && r(n), null); - } - }, - }, - ]), - e - ); - })(), - x = (function () { - function e() { - var t = - arguments.length > 0 && void 0 !== arguments[0] - ? arguments[0] - : 0, - i = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : t; - (f(this, e), - (this.type = "Vec2"), - (this._x = Number.isFinite(t) ? t : 0), - (this._y = Number.isFinite(i) ? i : 0)); - } - return ( - p(e, [ - { - key: "x", - get: function () { - return this._x; - }, - set: function (e) { - this._x = Number.isFinite(e) ? e : this._x; - }, - }, - { - key: "y", - get: function () { - return this._y; - }, - set: function (e) { - this._y = Number.isFinite(e) ? e : this._y; - }, - }, - { - key: "equals", - value: function (e) { - return !!e && this._x === e.x && this._y === e.y; - }, - }, - ]), - e - ); - })(), - b = (function () { - function e() { - var t = - arguments.length > 0 && void 0 !== arguments[0] - ? arguments[0] - : 0, - i = - arguments.length > 1 && void 0 !== arguments[1] - ? arguments[1] - : t, - r = - arguments.length > 2 && void 0 !== arguments[2] - ? arguments[2] - : t; - (f(this, e), - (this.type = "Vec3"), - (this._x = Number.isFinite(t) ? t : 0), - (this._y = Number.isFinite(i) ? i : 0), - (this._z = Number.isFinite(r) ? r : 0)); - } - return ( - p(e, [ - { - key: "x", - get: function () { - return this._x; - }, - set: function (e) { - this._x = Number.isFinite(e) ? e : this._x; - }, - }, - { - key: "y", - get: function () { - return this._y; - }, - set: function (e) { - this._y = Number.isFinite(e) ? e : this._y; - }, - }, - { - key: "z", - get: function () { - return this._z; - }, - set: function (e) { - this._z = Number.isFinite(e) ? e : this._z; - }, - }, - ]), - e - ); - })(), - _ = (function (e) { - !(function (e, t) { - if ("function" != typeof t && null !== t) - throw new TypeError( - "Super expression must either be null or a function", - ); - ((e.prototype = Object.create(t && t.prototype, { - constructor: { value: e, writable: !0, configurable: !0 }, - })), - t && a(e, t)); - })(r, e); - var t = s(r); - function r(e, i) { - var a, - s = - arguments.length > 2 && void 0 !== arguments[2] - ? arguments[2] - : {}; - (f(this, r), - ((a = t.call(this, e, i, s)).type = "PingPongPlane")); - var n = Object.assign({}, s.texturesOptions, { - sampler: s.sampler || "uPingPongTexture", - }); - return ( - void 0 === n.premultiplyAlpha && (n.premultiplyAlpha = !1), - (a._targets = [ - new d(e, { - clear: !1, - maxWidth: e.canvas.width, - maxHeight: e.canvas.height, - texturesOptions: n, - }), - new d(e, { - clear: !1, - maxWidth: e.canvas.width, - maxHeight: e.canvas.height, - texturesOptions: n, - }), - ]), - (a._readIndex = 0), - (a._sampler = s.sampler || "uPingPongTexture"), - a.createTexture({ - sampler: a._sampler, - fromTexture: a._targets[a._readIndex].getTexture(), - }), - a.setRenderTarget(a._targets[a._readIndex]), - a - ); - } - return ( - p(r, [ - { - key: "getTexture", - value: function () { - return ( - this.textures.find(function (e) { - return e._samplerName === this._sampler; - }, this) || this._targets[this._readIndex].getTexture() - ); - }, - }, - { - key: "_render", - value: function () { - var e = 0 === this._readIndex ? 1 : 0; - (this.setRenderTarget(this._targets[e]), - i(n(r.prototype), "_render", this).call(this), - (this._readIndex = e)); - var t = this._targets[this._readIndex].getTexture(), - a = this.textures.find(function (e) { - return e._samplerName === this._sampler; - }, this); - a && t && a.copy(t); - }, - }, - { - key: "remove", - value: function () { - (this._targets.forEach(function (e) { - return e.remove(); - }), - i(n(r.prototype), "remove", this).call(this)); - }, - }, - ]), - r - ); - })(g); - ((e.Curtains = h), - (e.PingPongPlane = _), - (e.Plane = g), - (e.RenderTarget = d), - (e.TextureLoader = y), - (e.Vec2 = x), - (e.Vec3 = b), - Object.defineProperty(e, "__esModule", { value: !0 })); - }), - "object" === m(t) - ? g(t) - : g( - ((v = - "undefined" != typeof globalThis - ? globalThis - : v || self).window = v.window || {}), - )); - })(0, a.exports); - var s = a.exports; - function n(e, t, i = {}) { - return (function ( - e, - { includeRuntimeLocalId: t = !1, includeNames: i = !0 } = {}, - ) { - var r; - const a = [null == e ? void 0 : e.id, null == e ? void 0 : e.publicId]; - return ( - i && - a.push(null == e ? void 0 : e.layerName, null == e ? void 0 : e.name), - t && a.push(null == (r = null == e ? void 0 : e.local) ? void 0 : r.id), - a.filter((e) => null != e && "" !== e) - ); - })(e, i).includes(t); - } - function l(e) { - return e && "function" == typeof e.clone - ? e.clone() - : e && "object" == typeof e - ? JSON.parse(JSON.stringify(e)) - : e; - } - function o(e) { - return String(e || "").trim(); - } - function u(e = "var") { - return `${e}_${Math.random().toString(36).slice(2, 10)}`; - } - function d() { - return new Date().toISOString(); - } - function c(e, t, i, r) { - null == r || - r( - `Invalid value for Unicorn Studio variable "${e.name}". Expected ${t}; received ${(function ( - e, - ) { - if (null === e) return "null"; - if (void 0 === e) return "undefined"; - if ("object" == typeof e) - try { - return JSON.stringify(e); - } catch (t) { - return Object.prototype.toString.call(e); - } - return `${typeof e} ${JSON.stringify(e)}`; - })(i)}.`, - ); - } - function h(e) { - return e && "object" == typeof e ? e.src : e; - } - function f(e) { - const t = Number(e); - return Number.isFinite(t) ? t : null; - } - function p(e, t = {}) { - const i = Number.isFinite(Number(t.min)) ? Number(t.min) : -1 / 0, - r = Number.isFinite(Number(t.max)) ? Number(t.max) : 1 / 0; - return Math.min(r, Math.max(i, e)); - } - function m(e, t) { - if (!e || "object" != typeof e) return null; - const i = 2 === t ? "Vec2" : "Vec3"; - if (e.type && e.type !== i) return null; - const r = f(e.x ?? e._x), - a = f(e.y ?? e._y), - s = 3 === t ? f(e.z ?? e._z) : 0; - return null === r || null === a || (3 === t && null === s) - ? null - : { type: i, x: r, y: a, ...(3 === t ? { z: s } : {}) }; - } - function v(e) { - return ( - "string" == typeof e && - /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e) - ); - } - function g(e) { - return Array.isArray(e) && e.length > 0 && e.every((e) => v(e)); - } - function y(e, t, i) { - const r = e.validation || {}, - a = Array.isArray(r.options) ? r.options : null; - if (a && !a.includes(t)) - return (c(e, `one of: ${a.join(", ")}`, t, i), { valid: !1, value: t }); - if ("number" === e.type) { - const a = f(t); - if (null === a) - return (c(e, "a finite number", t, i), { valid: !1, value: t }); - return { - valid: !0, - value: p("integer" === r.output ? Math.round(a) : a, r), - }; - } - if ("boolean" === e.type) - return "boolean" == typeof t - ? { valid: !0, value: t } - : "true" === t || "false" === t - ? { valid: !0, value: "true" === t } - : (c(e, "a boolean", t, i), { valid: !1, value: t }); - if ("string" === e.type) - return "string" == typeof t - ? { valid: !0, value: t } - : ("number" == typeof t && Number.isFinite(t)) || "boolean" == typeof t - ? { valid: !0, value: String(t) } - : (c(e, "a string", t, i), { valid: !1, value: t }); - if ("color" === e.type) { - if (v(t)) return { valid: !0, value: t }; - const r = m(t, 3); - return r - ? { valid: !0, value: r } - : (c(e, "a hex color or Vec3 color object", t, i), - { valid: !1, value: t }); - } - if ("vec2" === e.type || "vec3" === e.type) { - const r = "vec2" === e.type ? 2 : 3, - a = m(t, r); - return a - ? { valid: !0, value: a } - : (c(e, `{ type: 'Vec${r}', x, y${3 === r ? ", z" : ""} }`, t, i), - { valid: !1, value: t }); - } - return "texture" === e.type - ? "string" == typeof t && t.trim() - ? { valid: !0, value: t } - : t && "object" == typeof t && "string" == typeof t.src && t.src.trim() - ? { valid: !0, value: l(t) } - : (c(e, "a texture URL string or object with a src", t, i), - { valid: !1, value: t }) - : { valid: !0, value: t }; - } - function x(e = {}) { - return Object.entries(e || {}).reduce((e, [t, i]) => { - const r = o(t); - return r ? ((e[r] = l(i)), e) : e; - }, {}); - } - function b(e) { - const t = o(null == e ? void 0 : e.name); - return t - ? { - id: e.id || u("preset"), - name: t, - description: e.description || "", - values: x(e.values), - createdAt: e.createdAt || "", - updatedAt: e.updatedAt || e.createdAt || "", - } - : null; - } - function _(e) { - return e ? { ...e, values: x(e.values) } : null; - } - function P(e = [], t = new Set(), { keepEmpty: i = !1 } = {}) { - return (e || []) - .map((e) => { - const r = (function (e = {}, t = new Set()) { - return Object.entries(e || {}).reduce( - (e, [i, r]) => (t.has(i) && (e[i] = l(r)), e), - {}, - ); - })(e.values, t); - return i || Object.keys(r).length ? { ...e, values: r } : null; - }) - .filter(Boolean); - } - function T(e) { - return "Vec2" === (null == e ? void 0 : e.type) - ? "vec2" - : "Vec3" === (null == e ? void 0 : e.type) - ? "vec3" - : "number" == typeof e - ? "number" - : "boolean" == typeof e - ? "boolean" - : ("string" == typeof e && - /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)) || - g(e) - ? "color" - : "string" == typeof e - ? "string" - : e && "object" == typeof e && (e.src || e.sampler) - ? "texture" - : "value"; - } - const E = new Set([ - "number", - "boolean", - "string", - "color", - "vec2", - "vec3", - "texture", - ]); - function w(e, t = 140) { - const i = o(e); - return i ? i.slice(0, t) : ""; - } - function k(e = {}) { - const t = w(e.layerId), - i = w(e.target || e.property || e.prop), - r = w(e.layerName), - a = void 0 !== e.defaultValue ? l(e.defaultValue) : 0, - s = (function (e, t) { - if (E.has(e)) return e; - const i = T(t); - return E.has(i) ? i : "number"; - })(e.type, a), - n = - w(e.name) || - (function (e, t) { - const i = `${e || "Layer"} ${t || "Value"}` - .replace(/([a-z0-9])([A-Z])/g, "$1 $2") - .replace(/[^a-zA-Z0-9]+/g, " ") - .trim() - .split(/\s+/) - .filter(Boolean); - return i.length - ? i.map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" ") - : "Layer Value"; - })(r || t, i), - o = w(e.description, 500); - return { - version: 1, - action: "createVariable", - name: n, - type: s, - defaultValue: a, - ...(o ? { description: o } : {}), - ...(t ? { layerId: t } : {}), - ...(r ? { layerName: r } : {}), - ...(i ? { target: i } : {}), - ...(e.kind ? { kind: w(e.kind, 24) } : {}), - ...(e.canvasId ? { canvasId: w(e.canvasId) } : {}), - }; - } - function R(e) { - return (function (e) { - if ("undefined" != typeof Buffer) - return Buffer.from(e, "utf8").toString("base64url"); - const t = new TextEncoder().encode(e), - i = Array.from(t, (e) => String.fromCharCode(e)).join(""); - return btoa(i) - .replace(/\+/g, "-") - .replace(/\//g, "_") - .replace(/=+$/g, ""); - })(JSON.stringify(k(e))); - } - function M(e) { - var t, i, r; - return (null == e ? void 0 : e.isModel) - ? null == (t = null == e ? void 0 : e.default) - ? void 0 - : t.call(e, e) - : null == - (r = - null == (i = null == e ? void 0 : e.getParams) ? void 0 : i.call(e)) - ? void 0 - : r.properties; - } - function I(e, t) { - var i; - return !(function (e = null) { - return !( - !e || - (!0 !== e.variableDisabled && (!e.options || e.radio || e.classic)) - ); - })(null == (i = M(e)) ? void 0 : i[t]); - } - const F = ["relative", "fixed", "auto"]; - function S(e, t) { - const i = null == t ? void 0 : t.mode; - if (!i) return null == t ? void 0 : t.output; - const r = ((a = null == e ? void 0 : e[i]), F.includes(a) ? a : F[a] || a); - var a; - return "fixed" === r - ? "px" - : "relative" === r - ? "percent" - : null == t - ? void 0 - : t.output; - } - function A(e) { - return "pixels" === e ? "px" : e; - } - function V(e, t) { - var i; - const r = null == (i = M(e)) ? void 0 : i[t]; - if (!r) return; - const a = A(S(e, r)); - return a ? { output: a } : void 0; - } - function L(e, t) { - var i; - const r = null == (i = M(e)) ? void 0 : i[t]; - return "color" === (null == r ? void 0 : r.type) || - "color" === (null == r ? void 0 : r.output) || - v(null == e ? void 0 : e[t]) || - g(null == e ? void 0 : e[t]) - ? "color" - : void 0; - } - function O(e, t, i, r) { - var a, s, n; - if ( - "texture" === (null == e ? void 0 : e.type) && - "string" == typeof (null == t ? void 0 : t[i]) - ) - return h(r); - if ("color" !== (null == e ? void 0 : e.type)) return r; - const l = null == t ? void 0 : t[i]; - if (Array.isArray(l)) { - const e = Array.isArray(r) - ? r[0] - : (function (e) { - const t = m(e, 3); - return t - ? `#${[t.x, t.y, t.z] - .map((e) => - Math.max(0, Math.min(255, Math.round(255 * e))) - .toString(16) - .padStart(2, "0"), - ) - .join("")}` - : null; - })(r) || r; - return void 0 === e ? r : [e]; - } - if ( - "Vec3" === (null == l ? void 0 : l.type) || - "3f" === - (null == - (n = - null == - (s = null == (a = null == t ? void 0 : t.data) ? void 0 : a.uniforms) - ? void 0 - : s[i]) - ? void 0 - : n.type) - ) { - if ("Vec3" === (null == r ? void 0 : r.type)) return r; - return ( - (function (e) { - if ("string" != typeof e) return null; - const t = /^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e); - if (!t) return null; - let i = t[1]; - return ( - 3 === i.length - ? (i = i - .split("") - .map((e) => e + e) - .join("")) - : 8 === i.length && (i = i.slice(0, 6)), - { - type: "Vec3", - x: parseInt(i.slice(0, 2), 16) / 255, - y: parseInt(i.slice(2, 4), 16) / 255, - z: parseInt(i.slice(4, 6), 16) / 255, - } - ); - })(Array.isArray(r) ? r[0] : r) || r - ); - } - return Array.isArray(r) ? r[0] : r; - } - function D(e, t, i = "") { - if (e) - return "Vec2" === (null == t ? void 0 : t.type) || - "Vec3" === (null == t ? void 0 : t.type) - ? ((e.value = e.value || {}), - (e.value.x = t.x ?? t._x ?? 0), - (e.value.y = - "pos" === i || i.endsWith("_pos") - ? 1 - (t.y ?? t._y ?? 0) - : (t.y ?? t._y ?? 0)), - void ("Vec3" === t.type && (e.value.z = t.z ?? t._z ?? 0))) - : void (e.value = t); - } - function B(e, t, i) { - var r, a, s, n, l, o, u, d, c, f, p, m, v, g, y, x, b; - const _ = null == (r = null == e ? void 0 : e.state) ? void 0 : r.call(e), - P = null == i ? void 0 : i.texture, - T = (null == i ? void 0 : i.target) || t.target, - E = (null == i ? void 0 : i.src) || h(null == i ? void 0 : i.value), - w = (function (e) { - var t, i; - const r = - (null == e ? void 0 : e.source) || (null == e ? void 0 : e._source), - a = - (null == (t = null == e ? void 0 : e._size) ? void 0 : t.width) || - (null == r ? void 0 : r.naturalWidth) || - (null == r ? void 0 : r.width) || - (null == r ? void 0 : r.videoWidth) || - 0, - s = - (null == (i = null == e ? void 0 : e._size) ? void 0 : i.height) || - (null == r ? void 0 : r.naturalHeight) || - (null == r ? void 0 : r.height) || - (null == r ? void 0 : r.videoHeight) || - 0; - return a && s ? { width: a, height: s } : null; - })(P); - if (w && "image" === (null == e ? void 0 : e.layerType)) { - const t = { - type: "Vec2", - x: w.width, - y: w.height, - _x: w.width, - _y: w.height, - }, - r = w.width / w.height; - ((e.naturalWidth = w.width), - (e.naturalHeight = w.height), - (e.imageNaturalSize = t), - (e.aspectRatio = r), - D( - null == - (s = - null == (a = null == i ? void 0 : i.plane) ? void 0 : a.uniforms) - ? void 0 - : s.imageNaturalSize, - t, - "imageNaturalSize", - ), - D( - null == - (l = - null == (n = null == i ? void 0 : i.plane) ? void 0 : n.uniforms) - ? void 0 - : l.aspectRatio, - r, - "aspectRatio", - )); - } - if (null == e ? void 0 : e.isFlattened) { - const t = - null == (u = null == (o = e.data) ? void 0 : o.textures) - ? void 0 - : u.find((e) => (null == e ? void 0 : e.sampler) === T); - t && - ((t.src = E), - Number.isInteger(t.sublayerIndex) && - ((e.local.sourceTextures = e.local.sourceTextures || {}), - (e.local.sourceTextures[t.sublayerIndex] = P))); - const r = - "image" === (null == t ? void 0 : t.type) && - Number.isInteger(t.sublayerIndex) - ? null == (d = e.sublayers) - ? void 0 - : d.find((e) => e.sublayerIndex === t.sublayerIndex) - : null; - if (w && "image" === (null == r ? void 0 : r.layerType)) { - const a = { - type: "Vec2", - x: w.width, - y: w.height, - _x: w.width, - _y: w.height, - }, - s = w.width / w.height, - n = `L${t.sublayerIndex}_imageNaturalSize`, - l = `L${t.sublayerIndex}_aspectRatio`; - ((r.src = E), - (r.imageNaturalSize = a), - (r.aspectRatio = s), - (null == (f = null == (c = e.data) ? void 0 : c.uniforms) - ? void 0 - : f[n]) && (e.data.uniforms[n].value = a), - (null == (m = null == (p = e.data) ? void 0 : p.uniforms) - ? void 0 - : m[l]) && (e.data.uniforms[l].value = s), - D( - null == - (g = - null == (v = null == i ? void 0 : i.plane) - ? void 0 - : v.uniforms) - ? void 0 - : g[n], - a, - n, - ), - D( - null == - (x = - null == (y = null == i ? void 0 : i.plane) - ? void 0 - : y.uniforms) - ? void 0 - : x[l], - s, - l, - )); - } - } - "function" == typeof (null == _ ? void 0 : _.requestLayerRender) - ? _.requestLayerRender(e) - : null == (b = null == _ ? void 0 : _.requestSceneRender) || b.call(_); - } - function C(e = {}) { - e = e || {}; - const t = Array.isArray(e.definitions) - ? e.definitions - .map((e) => { - const t = o(e.name); - return t - ? { - id: e.id || u("var"), - name: t, - type: e.type || T(e.defaultValue), - defaultValue: l(e.defaultValue), - description: e.description || "", - validation: e.validation || {}, - } - : null; - }) - .filter(Boolean) - : [], - i = Array.isArray(e.bindings) - ? e.bindings - .map((e) => { - var i; - const r = o(e.layerId), - a = o(e.target || e.prop || e.property), - s = - e.variableId || - (null == (i = t.find((t) => t.name === e.variableName)) - ? void 0 - : i.id); - return r && a && s - ? { - id: e.id || u("bind"), - layerId: r, - kind: ["source", "texture"].includes(e.kind) - ? e.kind - : "prop", - target: a, - variableId: s, - enabled: !1 !== e.enabled, - } - : null; - }) - .filter(Boolean) - : [], - r = new Set(t.map((e) => e.id)), - a = Array.isArray(e.presets) - ? P(e.presets.map(b).filter(Boolean), r, { keepEmpty: !0 }) - : []; - return { definitions: t, bindings: i, presets: a }; - } - class U { - constructor({ - variables: e = {}, - getLayer: t, - onChange: i, - warn: r = console.warn, - } = {}) { - ((this.getLayer = t || (() => null)), - (this.onChange = i || (() => {})), - (this.warn = r), - (this.state = C(e)), - (this.values = {}), - this.state.definitions.forEach((e) => { - this.values[e.name] = l(e.defaultValue); - })); - } - serialize() { - return C({ - definitions: this.getDefinitions(), - bindings: this.state.bindings, - presets: this.state.presets, - }); - } - getDefinitions() { - return this.state.definitions.map((e) => ({ - ...e, - defaultValue: l(e.defaultValue), - validation: { ...this.getInferredValidation(e), ...e.validation }, - })); - } - getBindings() { - return this.state.bindings.map((e) => ({ ...e })); - } - getPresets() { - return this.state.presets.map(_); - } - has(e) { - return !!this.getDefinition(e); - } - getDefinition(e) { - return ( - this.state.definitions.find((t) => t.id === e || t.name === e) || null - ); - } - getPreset(e) { - return _( - this.state.presets.find((t) => t.id === e || t.name === e) || null, - ); - } - getInferredValidation(e) { - return ( - (e && - this.state.bindings - .filter((t) => !1 !== t.enabled && t.variableId === e.id) - .map((e) => V(this.getLayer(e.layerId, e), e.target)) - .find((e) => (null == e ? void 0 : e.output))) || - {} - ); - } - getValue(e) { - const t = this.getDefinition(e); - if (t) return l(this.values[t.name]); - } - getValues() { - return this.state.definitions.reduce( - (e, t) => ((e[t.name] = l(this.values[t.name])), e), - {}, - ); - } - add(e, t, i, r = "prop", a = void 0, s = {}) { - const n = { kind: r, target: i }, - l = t && i ? this.getLayer(t, n) : null, - o = n.target, - u = this.createVariable(e, { - defaultValue: a, - type: s.type || L(l, o), - description: s.description, - validation: s.validation || V(l, o), - notify: !1, - }); - return (this.bind(u.id, t, i, r, { notify: !1 }), this.notify(), u); - } - createVariable(e, t = {}) { - const i = o(e); - if (!i) throw new Error("Variable name is required."); - if (this.state.definitions.some((e) => e.name === i)) - throw new Error(`Variable "${i}" already exists.`); - const r = { - id: t.id || u("var"), - name: i, - type: t.type || T(t.defaultValue), - defaultValue: l(t.defaultValue), - description: t.description || "", - validation: t.validation || {}, - }; - return ( - this.state.definitions.push(r), - (this.values[r.name] = l(r.defaultValue)), - !1 !== t.notify && this.notify(), - r - ); - } - getCurrentPresetValues() { - return this.state.definitions.reduce( - (e, t) => ((e[t.id] = l(this.values[t.name])), e), - {}, - ); - } - createPreset(e, t = {}) { - const i = o(e); - if (!i) throw new Error("Preset name is required."); - if (this.state.presets.some((e) => e.name === i)) - throw new Error(`Preset "${i}" already exists.`); - const r = d(), - a = { - id: t.id || u("preset"), - name: i, - description: t.description || "", - values: x(t.values || this.getCurrentPresetValues()), - createdAt: t.createdAt || r, - updatedAt: t.updatedAt || r, - }; - return ( - this.state.presets.push(a), - !1 !== t.notify && this.notify(), - _(a) - ); - } - updatePreset(e, t = {}) { - const i = this.state.presets.find((t) => t.id === e || t.name === e); - if (!i) return !1; - if (void 0 !== t.name) { - const e = o(t.name); - if (!e) throw new Error("Preset name is required."); - if (this.state.presets.some((t) => t.id !== i.id && t.name === e)) - throw new Error(`Preset "${e}" already exists.`); - i.name = e; - } - return ( - void 0 !== t.description && (i.description = t.description || ""), - Object.prototype.hasOwnProperty.call(t, "values") && - (i.values = x(t.values)), - (i.updatedAt = t.updatedAt || d()), - !1 !== t.notify && this.notify(), - _(i) - ); - } - deletePreset(e, t = {}) { - const i = this.state.presets.findIndex((t) => t.id === e || t.name === e); - return ( - -1 !== i && - (this.state.presets.splice(i, 1), !1 !== t.notify && this.notify(), !0) - ); - } - applyPreset(e, t = {}) { - var i; - const r = this.state.presets.find((t) => t.id === e || t.name === e); - if (!r) - return ( - null == (i = this.warn) || - i.call(this, `Unknown Unicorn Studio preset "${e}".`), - [] - ); - const a = []; - return ( - Object.entries(r.values || {}).forEach(([e, i]) => { - var s; - const n = this.getDefinition(e); - n - ? this.setValue(n.name, i, { - persistDefault: !!t.persistDefault, - notify: !1, - }) && a.push(n.name) - : null == (s = this.warn) || - s.call( - this, - `Preset "${r.name}" references missing variable "${e}".`, - ); - }), - t.persistDefault && a.length && this.notify(), - a - ); - } - bind(e, t, i, r = "prop", a = {}) { - var s, n, l; - const o = this.getDefinition(e); - if (!o) throw new Error(`Variable "${e}" does not exist.`); - const d = ["source", "texture"].includes(r) ? r : "prop", - c = { kind: d, target: i }, - h = t && i ? this.getLayer(t, c) : null, - f = c.target; - if ("prop" === d && !I(h, f)) - return ( - null == (s = this.warn) || - s.call(this, `Variable binding is disabled for "${i}".`), - null - ); - const p = { - ...o, - validation: { ...this.getInferredValidation(o), ...o.validation }, - }; - if ( - "prop" === d && - !(function (e, t, i) { - var r, a; - const s = A( - null == (r = null == e ? void 0 : e.validation) ? void 0 : r.output, - ); - if (!s) return !0; - const n = A(null == (a = V(t, i)) ? void 0 : a.output); - return !n || s === n || ("integer" === s && "number" === n); - })(p, h, f) - ) { - const e = null == (n = V(h, f)) ? void 0 : n.output; - return ( - null == (l = this.warn) || - l.call( - this, - `Unable to bind variable "${o.name}" to "${i}". Expected ${p.validation.output}, target uses ${e}.`, - ), - null - ); - } - const m = this.state.bindings.find( - (e) => - e.variableId === o.id && - e.layerId === t && - e.kind === d && - e.target === i, - ); - if (m) return m; - const v = { - id: a.id || u("bind"), - variableId: o.id, - layerId: t, - kind: d, - target: i, - enabled: !1 !== a.enabled, - }; - return ( - this.state.bindings.push(v), - this.applyBinding(v, this.values[o.name]), - !1 !== a.notify && this.notify(), - v - ); - } - unbind(e, t = {}) { - const i = this.state.bindings.findIndex((t) => t.id === e); - if (-1 === i) return !1; - const [r] = this.state.bindings.splice(i, 1); - return (this.clearBinding(r), !1 !== t.notify && this.notify(), !0); - } - deleteVariable(e) { - const t = this.getDefinition(e); - return ( - !!t && - (this.state.bindings - .filter((e) => e.variableId === t.id) - .forEach((e) => this.clearBinding(e)), - (this.state.definitions = this.state.definitions.filter( - (e) => e.id !== t.id, - )), - (this.state.bindings = this.state.bindings.filter( - (e) => e.variableId !== t.id, - )), - (this.state.presets = P( - this.state.presets, - new Set(this.state.definitions.map((e) => e.id)), - { keepEmpty: !0 }, - )), - delete this.values[t.name], - this.notify(), - !0) - ); - } - renameVariable(e, t) { - const i = this.getDefinition(e), - r = o(t); - if (!i || !r || i.name === r) return !1; - if (this.state.definitions.some((e) => e.id !== i.id && e.name === r)) - throw new Error(`Variable "${r}" already exists.`); - const a = this.values[i.name]; - return ( - delete this.values[i.name], - (i.name = r), - (this.values[i.name] = a), - this.notify(), - !0 - ); - } - updateVariable(e, t = {}) { - const i = this.getDefinition(e); - if (!i) return !1; - const r = void 0 !== t.name ? o(t.name) : i.name; - if (!r) throw new Error("Variable name is required."); - if (this.state.definitions.some((e) => e.id !== i.id && e.name === r)) - throw new Error(`Variable "${r}" already exists.`); - const a = { - ...i, - name: r, - type: void 0 !== t.type ? t.type : i.type, - description: - void 0 !== t.description ? t.description || "" : i.description, - validation: - void 0 !== t.validation ? t.validation || {} : i.validation, - }, - s = Object.prototype.hasOwnProperty.call(t, "defaultValue"), - n = y(a, s ? t.defaultValue : this.values[i.name], this.warn); - return ( - !!n.valid && - (i.name !== r && delete this.values[i.name], - (i.name = r), - (i.type = a.type), - (i.description = a.description), - (i.validation = a.validation), - s && (i.defaultValue = l(n.value)), - (this.values[i.name] = l(n.value)), - this.applyVariable(i), - !1 !== t.notify && this.notify(), - !0) - ); - } - setValue(e, t, i = {}) { - var r; - const a = this.getDefinition(e); - if (!a) { - const t = - this.state.definitions.map((e) => e.name).join(", ") || "none"; - return ( - null == (r = this.warn) || - r.call( - this, - `Unknown Unicorn Studio variable "${e}". Available variables: ${t}.`, - ), - !1 - ); - } - const s = y(a, t, this.warn); - return ( - !!s.valid && - ((this.values[a.name] = l(s.value)), - this.applyVariable(a), - i.persistDefault && - ((a.defaultValue = l(s.value)), !1 !== i.notify && this.notify()), - !0) - ); - } - setValues(e = {}, t = {}) { - const i = []; - return ( - Object.entries(e || {}).forEach(([e, r]) => { - this.setValue(e, r, { ...t, notify: !1 }) && i.push(e); - }), - t.persistDefault && this.notify(), - i - ); - } - applyInitialValues(e = {}) { - Object.entries(e || {}).forEach(([e, t]) => this.setValue(e, t)); - } - applyAll() { - this.state.definitions.forEach((e) => this.applyVariable(e)); - } - applyVariable(e) { - this.state.bindings - .filter((t) => !1 !== t.enabled && t.variableId === e.id) - .forEach((t) => this.applyBinding(t, this.values[e.name])); - } - applyBinding(e, t) { - var i, r, a, s, n, l, o; - const u = this.getLayer(e.layerId, e); - if (!u) { - const t = this.getDefinition(e.variableId); - return void ( - null == (i = this.warn) || - i.call( - this, - `Unable to apply Unicorn Studio variable binding for "${(null == t ? void 0 : t.name) || e.variableId}". Layer "${e.layerId}" was not found. Target: ${e.kind || "prop"}:${e.target}.`, - ) - ); - } - const d = this.getDefinition(e.variableId); - if (!d) - return void ( - null == (r = this.warn) || - r.call( - this, - `Unable to apply Unicorn Studio variable binding. Variable "${e.variableId}" was not found for layer "${e.layerId}" target "${e.target}".`, - ) - ); - if ("prop" === (e.kind || "prop") && !I(u, e.target)) - return void ( - null == (a = this.warn) || - a.call( - this, - `Skipping variable binding for "${e.target}" because variables are disabled for that property.`, - ) - ); - const c = O(d, u, e.target, t); - if ("source" === e.kind) { - const t = h(c); - if ("function" == typeof u.setSource) - u.setSource(t, { onLoad: (t) => B(u, e, t) }); - else if ("function" == typeof u.replaceSource) { - const i = c && "object" == typeof c ? c.thumb || c.src : t; - (null == (s = u.setRuntimeOverride) || - s.call(u, e.target || "src", t), - u.replaceSource(t, i || u.thumb, u.naturalWidth, u.naturalHeight)); - } else - "function" == typeof u.setProp - ? u.setProp(e.target || "src", t, { runtimeOverride: !0 }) - : null == (n = this.warn) || - n.call( - this, - `Unable to apply source variable "${d.name}". Layer "${e.layerId}" does not support source updates.`, - ); - return; - } - "texture" !== e.kind - ? "function" == typeof u.setPropertySource - ? u.setPropertySource(e.target, "runtime", c, { owner: "variable" }) - : "function" == typeof u.setRuntimeOverride - ? u.setRuntimeOverride(e.target, c, { source: "variable" }) - : "function" == typeof u.setProp - ? u.setProp(e.target, c, { runtimeOverride: !0 }) - : Object.prototype.hasOwnProperty.call(u, e.target) - ? (u[e.target] = c) - : null == (o = this.warn) || - o.call( - this, - `Unable to apply prop variable "${d.name}". Layer "${e.layerId}" does not expose target "${e.target}".`, - ) - : "function" == typeof u.setTexture - ? u.setTexture(e.target, c, { onLoad: (t) => B(u, e, t) }) - : "function" == typeof u.setProp - ? u.setProp(e.target, c, { runtimeOverride: !0 }) - : null == (l = this.warn) || - l.call( - this, - `Unable to apply texture variable "${d.name}". Layer "${e.layerId}" does not support texture target "${e.target}".`, - ); - } - clearBinding(e) { - const t = this.getLayer(e.layerId, e); - if (t && "function" == typeof t.clearRuntimeOverride) { - if ("source" === e.kind) - return ( - t.clearRuntimeOverride(e.target || "src"), - void ( - "function" == typeof t.replaceSource && - t.replaceSource(t.src, t.thumb, t.naturalWidth, t.naturalHeight) - ) - ); - if ("texture" === e.kind) { - const i = - Object.keys(t).find((i) => { - var r; - return (null == (r = t[i]) ? void 0 : r.sampler) === e.target; - }) || "texture"; - return void t.clearRuntimeOverride(i); - } - t.clearRuntimeOverride(e.target); - } - } - getManifest() { - return this.getDefinitions().map((e) => { - const t = this.state.bindings.filter((t) => t.variableId === e.id); - return { - ...e, - currentValue: l(this.values[e.name]), - bindingCount: t.length, - bindings: t.map((e) => ({ - layerId: e.layerId, - kind: e.kind, - target: e.target, - enabled: e.enabled, - })), - }; - }); - } - notify() { - this.onChange(this.serialize()); - } - } - const N = ["base", "breakpoint", "runtime", "event", "preview"], - z = { - runtime: "runtimeOverrides", - event: "stateEffectProps", - preview: "previewProps", - }, - j = ["Desktop", "Tablet", "Mobile"]; - function H(e, t) { - return !!e && Object.prototype.hasOwnProperty.call(e, t); - } - function W(e) { - return e && "function" == typeof e.clone - ? e.clone() - : Array.isArray(e) - ? e.map(W) - : e && "object" == typeof e - ? JSON.parse(JSON.stringify(e)) - : e; - } - function $(e) { - return Array.isArray(e) - ? e - : Array.isArray(null == e ? void 0 : e.breakpoints) - ? e.breakpoints - : []; - } - function q(e, t = {}) { - const i = $(e); - if (!i.length) return {}; - if (!t.breakpointName && !H(t, "width")) return {}; - const r = t.breakpointName - ? (function (e, t, i = {}) { - const r = $(e), - a = (function (e, t) { - return Array.isArray(t) && t.length - ? t - .map((e) => - "string" == typeof e ? e : null == e ? void 0 : e.name, - ) - .filter(Boolean) - : e.map((e) => (null == e ? void 0 : e.name)).filter(Boolean); - })(r, i.breakpointOrder), - s = a.indexOf(t); - if (-1 === s) return {}; - const n = {}; - for (let l = s; l >= 0; l--) { - const e = r.find((e) => (null == e ? void 0 : e.name) === a[l]); - (null == e ? void 0 : e.props) && - Object.keys(e.props).forEach((t) => { - H(n, t) || (n[t] = e.props[t]); - }); - } - return n; - })(i, t.breakpointName, t) - : (function (e, t, i = {}) { - const r = $(e); - if (!r.length) return {}; - const a = Number.isFinite(Number(t)) ? Number(t) : 0, - s = [...r].sort( - (e, t) => - ((null == t ? void 0 : t.min) ?? 0) - - ((null == e ? void 0 : e.min) ?? 0), - ), - n = {}; - for (let u = s.length - 1; u >= 0; u--) { - const e = s[u]; - (null == e ? void 0 : e.props) && - (null === e.max || a <= e.max) && - Object.keys(e.props).forEach((t) => { - H(n, t) || (n[t] = e.props[t]); - }); - } - const l = i.baseBreakpointName || "Desktop", - o = r.find((e) => (null == e ? void 0 : e.name) === l); - (null == o ? void 0 : o.props) && - Object.keys(o.props).forEach((e) => { - H(n, e) || (n[e] = o.props[e]); - }); - return n; - })(i, t.width, t); - return (function (e, t) { - return Array.isArray(t) - ? t.reduce((t, i) => (H(e, i) && (t[i] = e[i]), t), {}) - : e; - })(r, t.props); - } - function G(e, t, i, r, a = {}) { - if (!e || !t) return !1; - const s = a.cloneValue || W; - if ("base" === i) - return ( - (function (e, t, i) { - const r = null == e ? void 0 : e[t]; - if (r && (null == i ? void 0 : i.type)) { - const e = i.x ?? i._x, - t = i.y ?? i._y, - a = i.z ?? i._z; - return ( - void 0 !== e && (r.x = e), - void 0 !== t && (r.y = t), - void 0 !== a && (r.z = a), - void 0 !== e && (r._x = e), - void 0 !== t && (r._y = t), - void 0 !== a && (r._z = a), - r - ); - } - e[t] = i; - })(e, t, s(r)), - !0 - ); - if ("breakpoint" === i) { - const i = a.breakpointName, - n = $(e).find((e) => (null == e ? void 0 : e.name) === i); - return !!n && ((n.props = n.props || {}), (n.props[t] = s(r)), !0); - } - const n = z[i]; - if (!n) return !1; - if ( - ((e.local = e.local || {}), - (e.local[n] = e.local[n] || {}), - "runtime" === i && - ((e.local.runtimeOverrideBaseValues = - e.local.runtimeOverrideBaseValues || {}), - !H(e.local[n], t))) - ) { - const i = H(a, "baseValue") ? a.baseValue : e[t]; - e.local.runtimeOverrideBaseValues[t] = s(i); - } - return ((e.local[n][t] = s(r)), !0); - } - function Y(e, t, i, r = {}) { - if (!e || !t) return; - if ("breakpoint" === i) { - const i = $(e).find( - (e) => (null == e ? void 0 : e.name) === r.breakpointName, - ); - if (!(null == i ? void 0 : i.props) || !H(i.props, t)) return; - const a = i.props[t]; - return (delete i.props[t], a); - } - if (!e.local) return; - const a = z[i]; - if (!a || !e.local[a] || !H(e.local[a], t)) return; - const s = e.local[a][t]; - if ( - (delete e.local[a][t], - "runtime" === i && e.local.runtimeOverrideBaseValues) - ) { - const i = e.local.runtimeOverrideBaseValues[t]; - return (delete e.local.runtimeOverrideBaseValues[t], i); - } - return s; - } - function X(e, t, i = {}) { - var r, a, s, n, l, o; - const u = i.breakpointProps || q(e, i), - d = { - base: H(i, "baseValue") ? i.baseValue : null == e ? void 0 : e[t], - breakpoint: H(u, t) ? u[t] : void 0, - runtime: - null == - (a = - null == (r = null == e ? void 0 : e.local) - ? void 0 - : r.runtimeOverrides) - ? void 0 - : a[t], - event: - null == - (n = - null == (s = null == e ? void 0 : e.local) - ? void 0 - : s.stateEffectProps) - ? void 0 - : n[t], - preview: - null == - (o = - null == (l = null == e ? void 0 : e.local) - ? void 0 - : l.previewProps) - ? void 0 - : o[t], - }, - c = i.sources || N; - for (let h = c.length - 1; h >= 0; h--) { - const e = c[h]; - if (void 0 !== d[e]) - return { prop: t, source: e, value: d[e], sources: d }; - } - return { prop: t, source: "base", value: d.base, sources: d }; - } - function J(e, t, i, r = null == e ? void 0 : e[t]) { - if (!e || !i) return r; - const a = e.responsiveProps, - s = j.indexOf(i); - if (-1 === s) { - const e = null == a ? void 0 : a[i]; - return e && H(e, t) ? e[t] : r; - } - for (let n = s; n >= 0; n--) { - const e = null == a ? void 0 : a[j[n]]; - if (e && H(e, t)) return e[t]; - } - return r; - } - let K, - Q, - Z, - ee, - te = !1, - ie = window.innerHeight || document.documentElement.clientHeight, - re = window.innerWidth || document.documentElement.clientWidth, - ae = null, - se = ye(), - ne = 0, - le = 0, - oe = 0, - ue = 0, - de = null; - const ce = 0.001, - he = ["relative", "fixed", "auto"], - fe = ["relative", "fixed"], - pe = { enterTime: null, movePos: { x: 0.5, y: 0.5 } }, - me = ["lightColor", "ambientLightColor", "fillLightColor"]; - let ve = "2.2.6"; - function ge(e) { - if (null == e || "" === e) return null; - if ("string" == typeof e && "" === e.trim()) return null; - const t = Number(e); - return Number.isFinite(t) ? t : null; - } - function ye() { - return null !== ae ? ae : window.scrollY || window.pageYOffset || 0; - } - function xe(e = ye()) { - const t = ge(e); - return null !== t && ((se = t), (le = se - ne), (ne = se), !0); - } - function be(e) { - if (!e || "string" != typeof e) return null; - 9 === e.length - ? (e = e.substring(0, 7)) - : 8 === e.length && "#" !== e[0] && (e = "#" + e.substring(0, 6)); - e = e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (e, t, i, r) { - return t + t + i + i + r + r; - }); - const t = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e); - return t - ? [parseInt(t[1], 16), parseInt(t[2], 16), parseInt(t[3], 16)] - : null; - } - function _e(e) { - const t = be(e); - return t ? new s.Vec3(...t.map((e) => e / 255)) : null; - } - void 0 !== document.hidden - ? ((K = "hidden"), (Q = "visibilitychange")) - : void 0 !== document.msHidden - ? ((K = "msHidden"), (Q = "msvisibilitychange")) - : void 0 !== document.webkitHidden && - ((K = "webkitHidden"), (Q = "webkitvisibilitychange")); - const Pe = new Set(["gradient", "gradientMap", "gradientFill"]); - function Te(e) { - return window.atob(e); - } - function Ee(e) { - return fe.includes(e) ? e : (fe[e ?? 0] ?? fe[0]); - } - function we() { - return ( - "id-" + - Math.random().toString(36).substring(2, 15) + - Math.random().toString(36).substring(2, 15) - ); - } - function ke(e) { - const t = { - linear: (e) => e, - easeInQuad: (e) => e * e, - easeOutQuad: (e) => 1 - (1 - e) * (1 - e), - easeInOutQuad: (e) => - e < 0.5 ? 2 * e * e : 1 - Math.pow(-2 * e + 2, 2) / 2, - easeInCubic: (e) => e * e * e, - easeOutCubic: (e) => 1 - Math.pow(1 - e, 3), - easeInOutCubic: (e) => - e < 0.5 ? 4 * e * e * e : 1 - Math.pow(-2 * e + 2, 3) / 2, - easeInQuart: (e) => e ** 4, - easeOutQuart: (e) => 1 - Math.pow(1 - e, 4), - easeInOutQuart: (e) => - e < 0.5 ? 8 * e ** 4 : 1 - Math.pow(-2 * e + 2, 4) / 2, - easeInQuint: (e) => e ** 5, - easeOutQuint: (e) => 1 - Math.pow(1 - e, 5), - easeInOutQuint: (e) => - e < 0.5 ? 16 * e ** 5 : 1 - Math.pow(-2 * e + 2, 5) / 2, - easeOutElastic: (e) => { - const t = (2 * Math.PI) / 3; - return 0 === e - ? 0 - : 1 === e - ? 1 - : Math.pow(2, -10 * e) * Math.sin((10 * e - 0.75) * t) + 1; - }, - easeInElastic: (e) => { - const t = (2 * Math.PI) / 3; - return 0 === e - ? 0 - : 1 === e - ? 1 - : -Math.pow(2, 10 * e - 10) * Math.sin((10 * e - 10.75) * t); - }, - easeInOutElastic: (e) => { - const t = (2 * Math.PI) / 4.5; - return 0 === e - ? 0 - : 1 === e - ? 1 - : e < 0.5 - ? (-Math.pow(2, 20 * e - 10) * Math.sin((20 * e - 11.125) * t)) / - 2 - : (Math.pow(2, -20 * e + 10) * Math.sin((20 * e - 11.125) * t)) / - 2 + - 1; - }, - easeOutSpringSoft: (e) => - 0 === e || 1 === e - ? e - : 1 - Math.exp(-5 * e) * Math.cos(3 * e * Math.PI), - easeOutSpring: (e) => - 0 === e || 1 === e - ? e - : 1 - Math.exp(-6 * e) * Math.cos(4.5 * e * Math.PI), - easeInSpring: (e) => { - if (0 === e || 1 === e) return e; - const t = 1 - e; - return Math.exp(-6 * t) * Math.cos(4.5 * t * Math.PI); - }, - easeInOutSpring: (e) => { - if (0 === e || 1 === e) return e; - if (e < 0.5) { - const t = 1 - 2 * e; - return (Math.exp(-6 * t) * Math.cos(4.5 * t * Math.PI)) / 2; - } - const t = 2 * e - 1; - return 1 - (Math.exp(-6 * t) * Math.cos(4.5 * t * Math.PI)) / 2; - }, - easeInSine: (e) => 1 - Math.cos((e * Math.PI) / 2), - easeOutSine: (e) => Math.sin((e * Math.PI) / 2), - easeInOutSine: (e) => -(Math.cos(Math.PI * e) - 1) / 2, - easeInCirc: (e) => 1 - Math.sqrt(1 - e ** 2), - easeOutCirc: (e) => Math.sqrt(1 - Math.pow(e - 1, 2)), - easeInOutCirc: (e) => - e < 0.5 - ? (1 - Math.sqrt(1 - (2 * e) ** 2)) / 2 - : (Math.sqrt(1 - Math.pow(-2 * e + 2, 2)) + 1) / 2, - easeInExpo: (e) => (0 === e ? 0 : Math.pow(2, 10 * e - 10)), - easeOutExpo: (e) => (1 === e ? 1 : 1 - Math.pow(2, -10 * e)), - easeInOutExpo: (e) => - 0 === e - ? 0 - : 1 === e - ? 1 - : e < 0.5 - ? Math.pow(2, 20 * e - 10) / 2 - : (2 - Math.pow(2, -20 * e + 10)) / 2, - easeInBack: (e) => { - const t = 1.70158; - return (t + 1) * e * e * e - t * e * e; - }, - easeOutBack: (e) => { - const t = 1.70158; - return 1 + (t + 1) * Math.pow(e - 1, 3) + t * Math.pow(e - 1, 2); - }, - easeInOutBack: (e) => { - const t = 2.5949095; - return e < 0.5 - ? (Math.pow(2 * e, 2) * (7.189819 * e - t)) / 2 - : (Math.pow(2 * e - 2, 2) * ((t + 1) * (2 * e - 2) + t) + 2) / 2; - }, - }; - if ("string" == typeof e && (e.includes("=>") || e.includes("function"))); - else if (t[e]) return t[e]; - return t.easeInOutQuad; - } - function Re(e) { - return (e && "string" == typeof e && (e = JSON.parse(e)), Object.values(e)); - } - function Me(e, t, i) { - for (let r = 0; r < i; r++) e = (e + t) / 2; - return +((e + t) / 2).toFixed(4); - } - function Ie(e, t, i, r, a) { - return { - value: - e + - (i = - (i + - (t - e) * (0.05 + 0.35 * (1 - Math.max(0, Math.min(1, r ?? 0))))) * - (0.5 + 0.32 * a)), - velocity: i, - }; - } - let Fe = null; - function Se() { - return ( - null === Fe && - (Fe = - /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( - navigator.userAgent, - )), - Fe - ); - } - function Ae(e, t) { - return e.getAttribute(t); - } - function Ve(e) { - var t, i, r, a; - if (void 0 !== e.local.isDynamicCache) return e.local.isDynamicCache; - if (e.isFlattened) { - const a = - e.states && - [ - ...e.states.appear, - ...e.states.scroll, - ...e.states.hover, - ...e.states.mousemove, - ].length > 0, - s = - Array.isArray(null == (t = e.data) ? void 0 : t.timeUniforms) && - e.data.timeUniforms.some( - (e) => - !1 !== (null == e ? void 0 : e.animating) && - Math.abs(Number((null == e ? void 0 : e.speed) ?? 0)) > 1e-5, - ), - n = !!(null == (i = e.data) ? void 0 : i.hasMouseTracking), - l = !!(null == (r = e.data) ? void 0 : r.hasVideoSublayers), - o = - Array.isArray(e.sublayers) && - e.sublayers.some( - (e) => - !!e && - ("video" === e.type || - (("effect" === e.layerType || "model" === e.layerType) && - !!e.animating)), - ), - u = a || s || n || l || o; - return ((e.local.isDynamicCache = u), u); - } - const s = [ - "trackMouse", - "axisTilt", - "trackMouseMove", - "rotationTracking", - "lightTracking", - ].some((t) => e.hasOwnProperty(t) && 0 !== e[t]), - n = - e.states && - [ - ...e.states.appear, - ...e.states.scroll, - ...e.states.hover, - ...e.states.mousemove, - ].length > 0, - l = - ("effect" === e.layerType || e.isModel) && - (e.animating || e.usesPingPong), - o = "video" === e.type, - u = - Array.isArray(null == (a = e.data) ? void 0 : a.textures) && - e.data.textures.some( - (e) => - "video" === (null == e ? void 0 : e.type) && - (null == e ? void 0 : e.src), - ), - d = s || n || l || o || u; - return ((e.local.isDynamicCache = d), d); - } - function Le(e, t) { - var i, r, a, s; - if (e.noTextAsHtml) return; - if (!t) return; - const n = (function (e) { - if (!e || "string" != typeof e) return ""; - const t = e.trim(); - if (!t || /[\u0000-\u001F\u007F]/.test(t)) return ""; - const i = t.match(/^([a-z][a-z0-9+.-]*):/i); - if (i) { - const e = i[1].toLowerCase(); - return ["http", "https", "mailto", "tel"].includes(e) ? t : ""; - } - if ( - t.startsWith("/") || - t.startsWith("#") || - t.startsWith("?") || - t.startsWith("./") || - t.startsWith("../") - ) - return t; - if (t.startsWith("//")) return t; - return ""; - })(e.href), - l = Ee(e.leftMode), - o = Ee(e.topMode); - let u = "fixed" === e.widthMode ? e.width : e.width * t.offsetWidth, - d = e.height, - c = "fixed" === e.fontSizeMode ? e.fontSize : e.fontSize * t.offsetWidth, - h = "fixed" === e.fontSizeMode ? e.lineHeight : e.lineHeight * c, - f = "fixed" === e.fontSizeMode ? e.letterSpacing : e.letterSpacing * c, - p = "fixed" === o ? e.top : e.top * t.offsetHeight, - m = "fixed" === l ? e.left : e.left * t.offsetWidth, - v = nt(e.anchorPoint); - ((m -= v.x * u), (p -= v.y * d), (p += t.offsetTop), (m += t.offsetLeft)); - let g = t.querySelector(`[data-us-text="${e.local.id}"]`); - const y = n ? "a" : "div"; - let x = !g; - (g && g.tagName.toLowerCase() !== y && (g.remove(), (g = null), (x = !0)), - (g = g || document.createElement(y))); - const b = Array.isArray(e.fill) ? e.fill : [], - _ = { - MULTIPLY: "multiply", - SCREEN: "screen", - OVERLAY: "overlay", - DARKEN: "darken", - LIGHTEN: "lighten", - COLOR_DODGE: "color-dodge", - COLOR_BURN: "color-burn", - HARD_LIGHT: "hard-light", - SOFT_LIGHT: "soft-light", - DIFFERENCE: "difference", - EXCLUSION: "exclusion", - }[ - e.blendMode && 0 !== e.blendMode - ? String(e.blendMode).toUpperCase() - : "NORMAL" - ], - P = - (null == (r = null == (i = e.local) ? void 0 : i.stateEffectProps) - ? void 0 - : r.opacity) ?? - e.opacity ?? - (null == (a = e.data) ? void 0 : a.elementOpacity) ?? - 1; - let T = "color:transparent;"; - (e.htmlOnly && (T = `color:${b[0] || "#000000"};`), - g.setAttribute("data-us-text", e.local.id), - n - ? (g.setAttribute("href", n), - g.setAttribute("target", "_blank"), - g.setAttribute("rel", "noopener noreferrer")) - : (g.removeAttribute("href"), - g.removeAttribute("target"), - g.removeAttribute("rel")), - (g.style.cssText = `width:${u}px;top:${p}px;left:${m}px;font-size:${c}px;line-height:${h}px;letter-spacing:${f}px;font-family:${e.fontFamily};font-style:${(null == (s = e.fontStyle) ? void 0 : s.includes("italic")) ? "italic" : "normal"};font-weight:${e.fontWeight};text-align:${e.textAlign};position:absolute;word-break:break-word;white-space:pre-wrap;transform:rotateZ(${Math.round(360 * e.rotation)}deg);opacity:${P};z-index:${e.htmlOnly ? 100 + (e.htmlRenderOrder ?? 0) : 2};display:block;text-decoration:none;pointer-events:${n ? "auto" : "none"};cursor:${n ? "pointer" : "inherit"};${_ ? `mix-blend-mode:${_};` : ""}${T}`), - (g.innerText = e.textContent), - x && t.appendChild(g)); - } - function Oe(e) { - const t = e.split(",").map((e) => e.trim()), - i = /^((?!chrome|android).)*safari/i.test(navigator.userAgent), - r = /iPad|iPhone|iPod/.test(navigator.userAgent); - if (i || r) { - const e = t.find((e) => e.endsWith(".mov") || e.endsWith(".mp4")); - if (e) return e; - } - const a = t.find((e) => e.endsWith(".webm")); - return a || t[0]; - } - function De() { - Rt.filter((e) => !document.body.contains(e.element)).forEach((e) => { - e.curtain && e.curtain.dispose(); - const t = Rt.indexOf(e); - -1 !== t && Rt.splice(t, 1); - }); - } - function Be(e) { - return ( - e && - e.renderer && - e.renderer.nextRender && - "function" == typeof e.renderer.nextRender.execute - ); - } - function Ce() { - cancelAnimationFrame(Z); - let e = Rt.filter((e) => !e.destroyed && e.getDynamicLayers().length > 0); - const t = (i) => { - let r = !1; - (e.forEach((e) => { - if (!e.destroyed) - if (e.isInView && e.initialized) { - e.rendering = !0; - const t = i - (e.lastTime || 0); - ((e.lastTime && !(t >= e.frameDuration)) || - e.paused || - (e.renderFrame(), - (e.lastTime = e.lastTime ? i - (t % e.frameDuration) : i)), - (r = !0)); - } else e.rendering = !1; - }), - (!oe || i - oe > 64) && - (xe(), (oe = i), (le > 1e3 || (le < 0 && !ne && !se)) && xt()), - r - ? (!(function () { - var e, t, i, r; - let a = performance.now(); - const s = Se(); - for (let n = 0; n < Rt.length; n++) { - const l = Rt[n]; - if (l.isInView && Et(l)) - if ( - (s && - (null == - (t = null == (e = l.interactivity) ? void 0 : e.mouse) - ? void 0 - : t.disableMobile)) || - (null == - (r = null == (i = l.interactivity) ? void 0 : i.mouse) - ? void 0 - : r.disabled) - ); - else { - ((l.mouse.pos.y = l.mouse.movePos.y), - (l.mouse.pos.x = l.mouse.movePos.x), - (l.mouse.lastPos.x = l.mouse.pos.x), - (l.mouse.lastPos.y = l.mouse.pos.y)); - let e = l.isFixed ? l.bbox.top : l.bbox.top + l.scrollY, - t = l.bbox.left; - l.mouse.page.x > t && - l.mouse.page.y > e && - l.mouse.page.x < l.lastBbox.width + t && - l.mouse.page.y < l.lastBbox.height + e - ? l.mouse.enterTime || (l.mouse.enterTime = a) - : (l.mouse.enterTime = null); - } - } - })(), - (Z = requestAnimationFrame(t))) - : cancelAnimationFrame(Z)); - }; - e.length ? (Z = requestAnimationFrame(t)) : cancelAnimationFrame(Z); - } - function Ue(e, t, i) { - return "Vec3" === (null == e ? void 0 : e.type) && - "Vec3" === (null == t ? void 0 : t.type) - ? { - type: "Vec3", - x: e._x + (t._x - e._x) * i, - y: e._y + (t._y - e._y) * i, - z: e._z + (t._z - e._z) * i, - } - : "Vec2" === (null == e ? void 0 : e.type) && - "Vec2" === (null == t ? void 0 : t.type) - ? { - type: "Vec2", - x: e._x + (t._x - e._x) * i, - y: e._y + (t._y - e._y) * i, - } - : e + (t - e) * i; - } - function Ne(e, t) { - return ( - "Vec2" === e.type - ? (e = new s.Vec2(e._x, e._y)) - : "Vec3" === e.type && (e = new s.Vec3(e._x, e._y, e._z)), - e - ); - } - function ze(e, t, i) { - if ( - (null == e ? void 0 : e.type) && - ("Vec2" === (null == e ? void 0 : e.type) || - "Vec3" === (null == e ? void 0 : e.type)) - ) { - const r = e.x ?? e._x ?? 0, - a = e.y ?? e._y ?? 0, - s = e.z ?? e._z ?? 0; - ((t.value.x = r), - "pos" === i || i.endsWith("_pos") - ? (t.value.y = 1 - a) - : (t.value.y = a), - "Vec3" === e.type && (t.value.z = s)); - } else t.value = e; - } - function je(e) { - return e && "function" == typeof e.clone - ? e.clone() - : e && "object" == typeof e - ? JSON.parse(JSON.stringify(e)) - : e; - } - function He(e, t, i) { - const r = e[t]; - return "Vec2" === (null == r ? void 0 : r.type) && i && "object" == typeof i - ? ((r.x = i.x ?? i._x ?? r.x), void (r.y = i.y ?? i._y ?? r.y)) - : "Vec3" === (null == r ? void 0 : r.type) && i && "object" == typeof i - ? ((r.x = i.x ?? i._x ?? r.x), - (r.y = i.y ?? i._y ?? r.y), - void (r.z = i.z ?? i._z ?? r.z)) - : void (e[t] = i); - } - function We(e, t, i) { - var r, a, n, l; - if ("shape" !== e.layerType) return !1; - if ("stroke" === i) { - const i = _e(Array.isArray(e.stroke) ? e.stroke[0] : e.stroke); - return ( - i && - (null == (r = t.uniforms) ? void 0 : r.strokeColor) && - ze(i, t.uniforms.strokeColor, "strokeColor"), - !0 - ); - } - if ("fill" !== i) return !1; - const o = Array.isArray(e.fill) ? e.fill : [e.fill || "#777777"], - u = Math.min(o.length, 16); - if ( - ((null == (a = t.uniforms) ? void 0 : a.count) && - (t.uniforms.count.value = u), - null == (n = t.uniforms) ? void 0 : n.fillAlpha) - ) { - const e = o.map((e) => - (function (e) { - if ("transparent" === e) return 0; - if ("string" != typeof e) return 1; - const t = /^#(?:[0-9a-f]{6})([0-9a-f]{2})$/i.exec(e); - return t ? parseInt(t[1], 16) / 255 : 1; - })(e), - ); - t.uniforms.fillAlpha.value = e.length ? Math.max(...e) : 1; - } - for (let d = 0; d < 16; d++) { - const e = null == (l = t.uniforms) ? void 0 : l[`color${d}`]; - if (!e) continue; - const i = d < u ? _e(o[d]) : new s.Vec3(0); - i && ze(i, e, `color${d}`); - } - return !0; - } - function $e(e) { - if (!e) return {}; - if ("object" == typeof e) return e; - try { - return JSON.parse(e); - } catch (t) { - return {}; - } - } - let qe = null; - function Ge() { - return new URLSearchParams(window.location.search).get("preset") || ""; - } - function Ye(e) { - return !0 === e || 1 === e || "1" === e || "true" === e; - } - function Xe(e = {}) { - return e.controls && "object" == typeof e.controls ? e.controls : {}; - } - function Je(e, t = {}) { - var i; - return ( - Xe(t).title || - t.controlsTitle || - (null == (i = null == e ? void 0 : e.editMetadata) - ? void 0 - : i.sceneName) || - (null == e ? void 0 : e.name) || - "Controls" - ); - } - function Ke(e, t = {}) { - if (!1 === t.controls) return !1; - const i = Xe(t); - if (Object.prototype.hasOwnProperty.call(i, "enabled")) - return Ye(i.enabled); - const r = Ae(e, "data-us-controls"); - return ( - Ye(t.controls) || - (function () { - const e = new URLSearchParams(window.location.search).get("controls"); - return "1" === e || "true" === e; - })() || - (null !== r && "false" !== r) - ); - } - function Qe(e, t, i = {}) { - if (!Ke(e, i)) return; - const r = Xe(i); - var a, s; - ((a = r.src || i.controlsSrc || Ae(e, "data-us-controls-src")), - (null == (s = window.UnicornStudioControls) ? void 0 : s.initControls) - ? Promise.resolve(window.UnicornStudioControls) - : qe || - ((qe = new Promise((e, t) => { - const i = document.createElement("script"); - ((i.src = - a || "https://assets.unicorn.studio/controls/controls.umd.js"), - (i.async = !0), - (i.onload = () => { - var i; - ( - null == (i = window.UnicornStudioControls) - ? void 0 - : i.initControls - ) - ? e(window.UnicornStudioControls) - : t( - new Error( - "UnicornStudioControls loaded without initControls().", - ), - ); - }), - (i.onerror = () => - t( - new Error( - `Unable to load Unicorn Studio controls from ${i.src}.`, - ), - )), - (document.head || document.body).appendChild(i)); - })), - qe)) - .then((a) => - a.initControls({ - ...r, - scene: t, - element: e, - title: Je(t, i), - draggable: r.draggable ?? i.controlsDraggable ?? !0, - }), - ) - .catch((e) => {}); - } - function Ze(e, t, i) { - var r, a; - i && - (null == (r = null == e ? void 0 : e.target) ? void 0 : r.getTexture) && - i === e.target.getTexture() && - (i = null); - const s = - null == (a = e.textures) ? void 0 : a.find((e) => e._samplerName === t); - if (s) { - if (i && s._copiedFrom !== i) return (s.copy(i), s); - if (!i && s._copiedFrom) { - (s._dispose(), (e.textures = e.textures.filter((e) => e !== s))); - const i = e.createTexture({ sampler: t, premultiplyAlpha: !0 }); - return ( - (function (e) { - var t; - null == (t = e.textures) || - t.forEach((t, i) => { - var r; - ((t.index = i), - (null == (r = e._program) ? void 0 : r.compiled) && - t._setTextureUniforms()); - }); - })(e), - i - ); - } - return s; - } - return e.createTexture({ - sampler: t, - premultiplyAlpha: !0, - fromTexture: i, - }); - } - function et(e) { - return e && "object" == typeof e ? JSON.parse(JSON.stringify(e)) : {}; - } - class tt { - constructor({ - prop: e, - value: t, - endValue: r, - transition: a, - breakpoints: s, - uniformData: n, - loop: l = "none", - loopDelay: o = 0, - responsiveProps: u, - }) { - (i(this, "id", we()), - (this.prop = e), - (this.transition = a), - (this.complete = !1), - (this.progress = 0), - (this.uniformData = n), - (this.value = Ne(t)), - (this.endValue = void 0 !== r ? Ne(r || 0) : null), - (this.responsiveProps = et(u)), - (this.lastTick = void 0), - (this.initialized = !1), - (this.startTime = null), - (this.breakpoints = s || []), - (this.loop = l), - (this.loopDelay = o), - (this.easeFunction = ke(this.transition.ease))); - } - updateEffect(e, t) { - const i = J(this, "value", this.activeBreakpointName, this.value); - if ( - void 0 === - (e = J(this, "endValue", this.activeBreakpointName, this.endValue ?? e)) - ) - return !1; - const r = performance.now(), - a = r - ((this.startTime || t) + this.transition.delay); - if (a < 0) return !1; - if ("none" !== this.loop) { - const t = this.transition.duration + this.loopDelay, - s = a % t; - if (s > this.transition.duration) return !1; - const n = s / this.transition.duration, - l = Math.floor(a / t); - let o = n; - return ( - "reverse" === this.loop && l % 2 == 1 && (o = 1 - n), - (this.progress = this.easeFunction(o)), - (this.lastTick = r), - Ue(i, e, this.progress) - ); - } - const s = Math.max(0, Math.min(1, a / this.transition.duration)); - return ( - (this.progress = this.easeFunction(s)), - 0 !== this.progress && - (s >= 1 - ? ((this.complete = !0), (this.progress = 0), e) - : ((this.lastTick = r), !this.complete && Ue(i, e, this.progress))) - ); - } - resetState() { - ((this.progress = 0), - (this.complete = !1), - (this.lastTick = void 0), - (this.initialized = !1)); - } - } - class it { - constructor({ - prop: e, - value: t, - range: r, - offset: a, - momentum: s, - spring: n, - uniformData: l, - mode: o = "scrollIntoView", - delta: u = 0.01, - absScrollValue: d = !0, - breakpoints: c = [], - responsiveProps: h, - }) { - (i(this, "id", we()), - (this.prop = e), - (this.progress = 0), - (this.momentum = s), - (this.spring = n ?? 0), - (this._velocity = 0), - (this.range = r), - (this.offset = a), - (this.mode = o), - (this.delta = u), - (this.absScrollValue = d), - (this.uniformData = l), - (this.value = Ne(t)), - (this.responsiveProps = et(h)), - (this.lastTick = void 0), - (this.breakpoints = c || [])); - } - updateEffect(e, { top: t, height: i, isFixed: r }) { - if (void 0 === e) return !1; - if ((r && (t -= se), "scrollIntoView" === this.mode)) { - const r = t + se - ie * this.offset, - a = r + (ie + i) * this.range; - let s = (se - r) / (a - r), - n = Math.max(0, Math.min(1, s)); - if (void 0 !== this.lastTick) { - if (this.spring > 0) { - const e = Ie( - this.lastTick, - n, - this._velocity, - this.momentum, - this.spring, - ); - ((n = e.value), (this._velocity = e.velocity)); - } else n = Me(n, this.lastTick, 2 * this.momentum); - if (Math.abs(this.lastTick - n) < ce && Math.abs(this._velocity) < ce) - return !1; - } - return ( - (this.lastTick = n), - Ue(e, J(this, "value", this.activeBreakpointName, this.value), n) - ); - } - if ("whileScrolling" === this.mode) { - let t = le * this.delta; - if ( - (this.absScrollValue && (t = Math.abs(t)), void 0 !== this.lastTick) - ) { - if (this.spring > 0) { - const e = Ie( - this.lastTick, - t, - this._velocity, - this.momentum, - this.spring, - ); - ((t = e.value), (this._velocity = e.velocity)); - } else t = Me(t, this.lastTick, 2 * this.momentum); - if (Math.abs(t) < ce && Math.abs(this._velocity) < ce) return !1; - } - return ( - (this.lastScrollPos = se), - (this.lastTick = t), - Ue(e, J(this, "value", this.activeBreakpointName, this.value), t) - ); - } - return !1; - } - resetState() { - this.lastTick = void 0; - } - } - class rt { - constructor({ - prop: e, - value: t, - transition: r, - breakpoints: a, - uniformData: s, - triggerOnElement: n, - responsiveProps: l, - }) { - (i(this, "id", we()), - (this.prop = e), - (this.transition = r), - (this.progress = 0), - (this.rawProgress = 0), - (this.lastProgress = null), - (this.value = Ne(t)), - (this.responsiveProps = et(l)), - (this.uniformData = s), - (this.triggerOnElement = void 0 !== n ? n : 1), - (this.breakpoints = a || []), - (this.easeFunction = ke(this.transition.ease))); - } - updateEffect(e, t, i) { - var r; - if (void 0 === e) return !1; - const a = - null == (r = null == i ? void 0 : i.getParent) ? void 0 : r.call(i), - s = performance.now(); - if ( - this.triggerOnElement && - ((null == i ? void 0 : i.isElement) || - (null == i ? void 0 : i.isModel) || - (null == i ? void 0 : i.isFlattened) || - a) - ) { - let e = (a || i).isHovered(this.prop); - t = e && !this.lastEnterTime ? s : e ? this.lastEnterTime : null; - } - const n = null === t, - l = - (s - (n ? this.lastTick || s : t + this.transition.delay)) / - this.transition.duration, - o = Math.max(0, Math.min(1, l)); - n - ? (this.rawProgress = Math.max(0, this.rawProgress - o)) - : (this.lastEnterTime !== t && - (this.lastProgress = this.rawProgress || 0), - (this.rawProgress = Math.min(1, this.lastProgress + o))); - const u = this.easeFunction(this.rawProgress), - d = Math.abs(this.progress - u) > ce; - return ( - (this.progress = u), - !(!t && !d) && - (!t && - this.transition.forwardsOnly && - ((this.progress = 0), (this.rawProgress = 0)), - (this.lastTick = s), - (this.lastEnterTime = t), - !!d && - Ue( - e, - J(this, "value", this.activeBreakpointName, this.value), - this.progress, - )) - ); - } - resetState() { - this.progress = 0; - } - } - class at { - constructor({ - prop: e, - value: t, - sensitivity: r, - momentum: a, - spring: s, - delay: n, - mode: l, - axisMode: o, - point: u, - breakpoints: d, - uniformData: c, - responsiveProps: h, - }) { - (i(this, "id", we()), - (this.prop = e), - (this.progress = 0), - (this.sensitivity = r ?? 0.5), - (this.momentum = a ?? 0.25), - (this.spring = s ?? 0), - (this._velocity = 0), - (this.delay = n ?? 0), - (this.mode = l ?? "velocity"), - (this.axisMode = o ?? "both"), - (this.point = u ?? { x: 0.5, y: 0.5 }), - (this.value = Ne(t)), - (this.responsiveProps = et(h)), - (this.uniformData = c), - (this.lastMousePos = null), - (this.lastMoveTime = null), - (this.breakpoints = d || [])); - } - updateEffect(e, t, i) { - if (void 0 === e) return !1; - const r = performance.now(); - let a = 0; - if (null !== this.lastMousePos && t) { - const e = t.x - this.lastMousePos.x, - i = t.y - this.lastMousePos.y; - ((a = - "x" === this.axisMode - ? Math.abs(e) - : "y" === this.axisMode - ? Math.abs(i) - : Math.sqrt(e * e + i * i)), - a > 1e-4 && (this.lastMoveTime = r)); - } - t && (this.lastMousePos = { x: t.x, y: t.y }); - let s, - n = this.progress; - if ("proximity" === this.mode) { - if (!t) return !1; - const e = 0.5 * ((null == i ? void 0 : i.canvasWidth) || 0), - r = 0.5 * ((null == i ? void 0 : i.canvasHeight) || 0); - if (!e || !r) return !1; - const a = this.point.x * e, - s = this.point.y * r; - let l = t.x - a, - o = t.y - s, - u = Math.sqrt(e * e + r * r); - "x" === this.axisMode - ? ((o = 0), (u = e)) - : "y" === this.axisMode && ((l = 0), (u = r)); - const d = Math.sqrt(l * l + o * o), - c = 1 - Math.min(1, d / u), - h = 1 + 4 * this.sensitivity; - n = Math.pow(c, h); - } else { - (this.lastMoveTime ? r - this.lastMoveTime : 1 / 0) > this.delay - ? (n = 0) - : a > 0 && - (n = Math.min(1, this.progress + a * (this.sensitivity / 500))); - } - if (this.spring > 0) { - const e = Ie( - this.progress, - n, - this._velocity, - this.momentum, - this.spring, - ); - ((s = e.value), (this._velocity = e.velocity)); - } else s = Me(n, this.progress, this.momentum); - return Math.abs(s - this.progress) < ce && - Math.abs(this._velocity) < ce && - Math.abs(s) < ce - ? (0 !== this.progress && ((this.progress = 0), (this._velocity = 0)), - Ue(e, J(this, "value", this.activeBreakpointName, this.value), 0)) - : ((this.progress = s), - Ue(e, J(this, "value", this.activeBreakpointName, this.value), s)); - } - resetState() { - ((this.progress = 0), - (this._velocity = 0), - (this.lastMousePos = null), - (this.lastMoveTime = null)); - } - } - class st { - constructor(e, t, r) { - var a; - (i(this, "local", { - id: "", - projectId: "", - lastMousePos: { x: 0.5, y: 0.5 }, - createdAt: null, - }), - (this.initOptions = r), - (this.aspectRatio = e.aspectRatio || 1), - (this.layerName = e.layerName || e.publicId || e.id), - (this.data = e.data || {}), - (this.userDownsample = e.userDownsample || 1), - (this.visible = !1 !== e.visible), - (this.breakpoints = - ((a = e.breakpoints || []).forEach((e) => { - var t, i; - for (let r in e.props) - "Vec2" === (null == (t = e.props[r]) ? void 0 : t.type) - ? (e.props[r] = new s.Vec2(e.props[r]._x, e.props[r]._y)) - : "Vec3" === (null == (i = e.props[r]) ? void 0 : i.type) - ? (e.props[r] = new s.Vec3( - e.props[r]._x, - e.props[r]._y, - e.props[r]._z, - )) - : "object" == typeof e.props[r] && - (e.props[r] = Re(e.props[r])); - }), - a)), - (this.local.sceneId = t), - (this.id = e.id || we()), - (this.publicId = e.publicId || this.id), - (this.hasPublishedPublicId = Object.prototype.hasOwnProperty.call( - e, - "publicId", - )), - (this.local.id = this.id), - (this.editorLayerId = e.editorLayerId), - (this.compiledFragmentShaders = e.compiledFragmentShaders || []), - (this.compiledVertexShaders = e.compiledVertexShaders || []), - (this.states = { - appear: - e.states && e.states.appear - ? e.states.appear.map((e) => new tt(e)) - : [], - scroll: - e.states && e.states.scroll - ? e.states.scroll.map((e) => new it(e)) - : [], - hover: - e.states && e.states.hover - ? e.states.hover.map((e) => new rt(e)) - : [], - mousemove: - e.states && e.states.mousemove - ? e.states.mousemove.map((e) => new at(e)) - : [], - }), - (function (e) { - const t = {}; - ((e.breakpoints || []).forEach((e) => { - Object.assign(t, e.props || {}); - }), - Object.keys(t).forEach((i) => { - Object.prototype.hasOwnProperty.call(e, i) || (e[i] = je(t[i])); - })); - })(this)); - } - state() { - return Rt.find((e) => e.id === this.local.sceneId) || this.initOptions; - } - getIndex() { - return this.state() - .layers.map((e) => e.local.id) - .indexOf(this.local.id); - } - getPixelRatio() { - const e = this.state(); - return e.dpi * e.scale * this.userDownsample; - } - getPlane() { - var e, t, i; - return null == - (i = - null == (t = null == (e = this.state()) ? void 0 : e.curtain) - ? void 0 - : t.planes) - ? void 0 - : i.find( - (e) => - "PingPongPlane" !== e.type && e.userData.id === this.local.id, - ); - } - getPlanes() { - var e, t, i; - return ( - (null == - (i = - null == (t = null == (e = this.state()) ? void 0 : e.curtain) - ? void 0 - : t.planes) - ? void 0 - : i.filter( - (e) => - "PingPongPlane" !== e.type && e.userData.id === this.local.id, - )) || [] - ); - } - getMaskedItem() { - return ( - !!this.mask && - this.state().layers.filter((e) => !e.parentLayer)[this.getIndex() - 1] - ); - } - getChildEffectItems() { - if (this.effects && this.effects.length) { - const e = this.state(); - if (!e || !e.layers) return []; - const t = e.layers.filter((e) => this.effects.includes(e.parentLayer)); - return this.effects - .map((e) => t.find((t) => t.parentLayer === e)) - .filter((e) => void 0 !== e); - } - return []; - } - setVisible(e = !this.visible) { - var t, i; - const r = !1 !== e; - return ( - this.visible === r || - ((this.visible = r), - this.invalidatePerformanceCaches(), - null == - (i = - null == (t = this.state()) ? void 0 : t.applyLayerVisibility) || - i.call(t)), - this - ); - } - show() { - return this.setVisible(!0); - } - hide() { - return this.setVisible(!1); - } - setProp(e, t, i = {}) { - return i.runtimeOverride - ? this.setRuntimeOverride(e, t, i) - : this.applyRuntimeProp(e, t); - } - hasRuntimePropTarget(e) { - var t, i; - return ( - !( - !this.local.stateEffectProps || - !Object.prototype.hasOwnProperty.call(this.local.stateEffectProps, e) - ) || - !!(null == (i = null == (t = this.data) ? void 0 : t.uniforms) - ? void 0 - : i[e]) || - !!this.getPlanes().some((t) => { - var i; - return null == (i = t.uniforms) ? void 0 : i[e]; - }) || - !(!this.isText || !Object.prototype.hasOwnProperty.call(this, e)) - ); - } - warnMissingRuntimeProp(e, t) { - var i, r; - const a = null == (i = this.state) ? void 0 : i.call(this); - null == (r = null == a ? void 0 : a.getCreateVariableUrl) || - r.call(a, { layer: this, target: e, defaultValue: t, kind: "prop" }); - } - setRuntimeOverride(e, t, i = {}) { - return ( - "scene.setProp" !== i.source || - this.hasRuntimePropTarget(e) || - this.warnMissingRuntimeProp(e, t), - G(this, e, "runtime", t, { cloneValue: je }), - this.applyRuntimeProp(e, t) - ); - } - clearRuntimeOverride(e) { - if ( - !this.local.runtimeOverrides || - !Object.prototype.hasOwnProperty.call(this.local.runtimeOverrides, e) - ) - return this; - const t = Y(this, e, "runtime"); - return (void 0 !== t && this.applyRuntimeProp(e, t), this); - } - setPropertySource(e, t, i) { - return "runtime" === t - ? this.setRuntimeOverride(e, i) - : "event" === t - ? (this.updateStateEffectProperty(e, i), this) - : (G(this, e, t, i, { cloneValue: je }), this); - } - clearPropertySource(e, t, i = {}) { - return "runtime" === t - ? this.clearRuntimeOverride(e) - : "event" === t - ? (Y(this, e, "event"), this) - : (Y(this, e, t, i), this); - } - applyRuntimeOverrides() { - Object.entries(this.local.runtimeOverrides || {}).forEach(([e, t]) => { - this.applyRuntimeProp(e, t); - }); - } - applyRuntimeProp(e, t) { - return (He(this, e, je(t)), this.syncRuntimeProp(e), this); - } - syncRuntimeProp(e) { - var t, i, r, a; - const s = this.state(); - this.local.stateEffectProps && - Object.prototype.hasOwnProperty.call(this.local.stateEffectProps, e) - ? null == (t = null == s ? void 0 : s.requestLayerRender) || - t.call(s, this) - : (this.getPlanes().forEach((t) => { - var i; - (We(this, t, e), - (function (e, t, i) { - var r, a, s, n; - if ("fill" !== i || !Pe.has(e.type)) return !1; - const l = Array.isArray(e.fill) - ? e.fill - : [e.fill || "#777777"], - o = Math.min(l.length, 16), - u = Math.max(o - 1, 1); - (null == (r = t.uniforms) ? void 0 : r.count) && - (t.uniforms.count.value = o); - for (let d = 0; d < 16; d++) { - const i = null == (a = t.uniforms) ? void 0 : a[`color${d}`]; - if (i && d < o) { - const e = _e(l[d]); - e && ze(e, i, `color${d}`); - } - const r = null == (s = t.uniforms) ? void 0 : s[`stop${d}`]; - r && - d < o && - (r.value = - (null == (n = e.stops) ? void 0 : n[d]) ?? d / u); - } - })(this, t, e), - (null == (i = t.uniforms) ? void 0 : i[e]) && - ze(this[e], t.uniforms[e], e)); - }), - this.isText && - "function" == typeof this.render && - (this.render(), - null == - (r = - null == (i = this.preloadedCanvasTexture) - ? void 0 - : i.needUpdate) || r.call(i), - Le(this, null == s ? void 0 : s.element)), - null == (a = null == s ? void 0 : s.requestLayerRender) || - a.call(s, this)); - } - setSource(e, t = {}) { - var i, r, a; - const s = e && "object" == typeof e ? e.src : e; - if (!s) return this; - this.setRuntimeOverride("src", s); - const n = this.state(); - if (!n) return this; - if ( - ((this.local.sourceTexture = null), - (this.local.sourceTextureLoading = !1), - "image" === this.layerType) - ) { - const e = null == (i = this.getPlane) ? void 0 : i.call(this); - n.preloadImage(s, "uSourceImage", (i) => { - var r, a, l; - if (!i) return; - ((this.local.sourceTexture = i), (this.local.imageReady = !0)); - const o = - null == (r = null == e ? void 0 : e.textures) - ? void 0 - : r.find((e) => "uSourceImage" === e._samplerName); - ((null == o ? void 0 : o.copy) - ? (o.copy(i), null == (a = o.needUpdate) || a.call(o)) - : e && e.addTexture(i), - null == (l = t.onLoad) || - l.call(t, { - layer: this, - target: "uSourceImage", - value: s, - texture: i, - plane: e, - src: s, - }), - n.requestSceneRender()); - }); - } else if ("video" === this.type) { - const e = null == (r = this.getPlane) ? void 0 : r.call(this); - if (e) { - ((e.videos = []), - (e.textures = e.textures.filter((e) => "video" !== e.sourceType))); - const t = (null == (a = s.includes) ? void 0 : a.call(s, ", ")) - ? Oe(s) - : s; - e.loadVideo( - t, - { sampler: "uVideoTexture", premultipliedAlpha: !1 }, - () => n.requestSceneRender(), - ); - } - } - return this; - } - setTexture(e, t, i = {}) { - var r, a, s, n, l; - if ( - !new Set( - [ - null == (r = this.texture) ? void 0 : r.sampler, - null == (s = null == (a = this.data) ? void 0 : a.texture) - ? void 0 - : s.sampler, - ...((null == (n = this.data) ? void 0 : n.textures) || []).map( - (e) => (null == e ? void 0 : e.sampler), - ), - ...this.getPlanes().flatMap((e) => - (e.textures || []).map((e) => e._samplerName), - ), - ].filter(Boolean), - ).has(e) - ) - return this; - const o = - "string" == typeof t - ? { src: t, sampler: e } - : { ...(t || {}), sampler: e }, - u = - Object.keys(this).find((t) => { - var i; - return (null == (i = this[t]) ? void 0 : i.sampler) === e; - }) || "texture"; - this.setRuntimeOverride(u, o); - const d = o.src, - c = null == (l = this.getPlane) ? void 0 : l.call(this), - h = this.state(); - return d && c && (null == h ? void 0 : h.preloadImage) - ? (h.preloadImage( - d, - e, - (t) => { - var r, a; - if (!t) return; - const s = c.textures.find((t) => t._samplerName === e); - ((null == s ? void 0 : s.copy) - ? (s.copy(t), null == (r = s.needUpdate) || r.call(s)) - : c.addTexture(t), - null == (a = i.onLoad) || - a.call(i, { - layer: this, - target: e, - value: o, - texture: t, - plane: c, - src: d, - }), - h.requestSceneRender()); - }, - !1, - ), - this) - : this; - } - setBreakpointValues(e = null) { - var t, i; - const r = null == (t = this.state) ? void 0 : t.call(this), - a = - (null == (i = null == r ? void 0 : r.getBreakpointWidth) - ? void 0 - : i.call(r)) || (null == r ? void 0 : r.breakpointWidth), - s = e || a || re, - n = [...this.breakpoints].sort((e, t) => t.min - e.min); - if (1 === n.length && "Desktop" === n[0].name) return; - if (n.length >= 1 && !n.find((e) => "Desktop" === e.name)) - throw new Error("Malfored breakpoint data, missing Desktop"); - const l = (e) => { - for (let t in e) - if (Object.prototype.hasOwnProperty.call(this, t)) { - let i = e[t]; - (null == i ? void 0 : i.type) - ? ((this[t].x = i._x), - (this[t].y = i._y), - void 0 !== i._z && (this[t].z = i._z)) - : (this[t] = i); - } - }; - l(q(this, { breakpointName: "Desktop" })); - const o = q(this, { width: s }); - (l(o), - (this.local.bpProps = o), - Object.keys(this.local.runtimeOverrides || {}).forEach((e) => { - ((this.local.runtimeOverrideBaseValues = - this.local.runtimeOverrideBaseValues || {}), - (this.local.runtimeOverrideBaseValues[e] = je(this[e]))); - }), - this.applyRuntimeOverrides()); - } - updateStateEffects() { - var e, t, i, r, a; - if ( - (!this.states.appear.some((e) => !e.complete) && - !(null == (e = this.states) ? void 0 : e.scroll.length) && - !(null == (t = this.states) ? void 0 : t.hover.length) && - !(null == (i = this.states) ? void 0 : i.mousemove.length)) || - (this.isModel && !this.local.modelLoaded) - ) - return; - (this.local.uniformUpdatesPool || (this.local.uniformUpdatesPool = {}), - this.local.updatedProps - ? this.local.updatedProps.clear() - : (this.local.updatedProps = new Set()), - (this.local.hasUpdates = !1)); - const s = this.state() || {}, - n = s.mouse || pe; - let l = performance.now(); - (this.local.cachedBreakpoint && - this.local.cachedBreakpoint === - (null == (r = s.currentBreakpoint) ? void 0 : r.name)) || - (this.local.cachedBreakpoint = - null == (a = s.currentBreakpoint) ? void 0 : a.name); - const o = (e) => - !e.breakpoints || - 0 === e.breakpoints.length || - e.breakpoints.find((e) => e === this.local.cachedBreakpoint); - (s.isInView && - (null === this.local.createdAt && (this.local.createdAt = l), - this.states.appear - .filter((e) => !e.complete) - .forEach((e) => { - if (((e.activeBreakpointName = this.local.cachedBreakpoint), !o(e))) - return void ( - this.local.stateEffectProps && - this.local.stateEffectProps[e.prop] && - delete this.local.stateEffectProps[e.prop] - ); - let t = e.startTime || this.local.createdAt; - if (!e.initialized) { - const i = [ - ...this.states.appear.filter((t) => t.prop === e.prop), - ].sort( - (e, t) => (e.transition.delay || 0) - (t.transition.delay || 0), - )[0]; - ((null == i ? void 0 : i.id) === e.id && - ((this.local.uniformUpdatesPool[e.prop] = J( - e, - "value", - this.local.cachedBreakpoint, - )), - (this.local.hasUpdates = !0), - this.local.updatedProps.add(e.prop)), - (e.initialized = !0), - t || (e.startTime = l)); - } - (null == s ? void 0 : s.pauseTime) && - (t += Math.abs(null == s ? void 0 : s.pauseTime)); - const i = this.getEventValue - ? this.getEventValue(e.prop, this[e.prop]) - : this[e.prop]; - e.activeBreakpointName = this.local.cachedBreakpoint; - const r = e.updateEffect(i, t); - (!1 !== r && - ((this.local.uniformUpdatesPool[e.prop] = r), - (this.local.hasUpdates = !0), - this.local.updatedProps.add(e.prop)), - this.isText && - e.complete && - this.local.stateEffectProps && - this.local.stateEffectProps[e.prop] && - delete this.local.stateEffectProps[e.prop]); - })), - this.states.hover.forEach((e) => { - if (!o(e)) - return void ( - this.local.stateEffectProps && - this.local.stateEffectProps[e.prop] && - delete this.local.stateEffectProps[e.prop] - ); - const t = this.getEventValue - ? this.getEventValue(e.prop, this[e.prop]) - : this[e.prop]; - e.activeBreakpointName = this.local.cachedBreakpoint; - const i = e.updateEffect(t, n.enterTime, this); - !1 !== i && - ((this.local.uniformUpdatesPool[e.prop] = i), - (this.local.hasUpdates = !0), - this.local.updatedProps.add(e.prop)); - }), - this.states.scroll.forEach((e) => { - var t; - if (!o(e)) - return void ( - this.local.stateEffectProps && - this.local.stateEffectProps[e.prop] && - delete this.local.stateEffectProps[e.prop] - ); - const i = s.bbox; - if (!i) return; - const r = this.getEventValue - ? this.getEventValue(e.prop, this[e.prop]) - : this[e.prop]; - e.activeBreakpointName = this.local.cachedBreakpoint; - const a = e.updateEffect(r, { - top: s.isFixed ? 0 : null == (t = s.bbox) ? void 0 : t.top, - height: i.height / 2, - isFixed: s.isFixed, - }); - !1 !== a && - ((this.local.uniformUpdatesPool[e.prop] = a), - (this.local.hasUpdates = !0), - this.local.updatedProps.add(e.prop)); - }), - this.states.mousemove.forEach((e) => { - if (!o(e)) - return void ( - this.local.stateEffectProps && - this.local.stateEffectProps[e.prop] && - delete this.local.stateEffectProps[e.prop] - ); - const t = this.getEventValue - ? this.getEventValue(e.prop, this[e.prop]) - : this[e.prop]; - e.activeBreakpointName = this.local.cachedBreakpoint; - const i = e.updateEffect(t, n.movePos, s); - !1 !== i && - ((this.local.uniformUpdatesPool[e.prop] = i), - (this.local.hasUpdates = !0), - this.local.updatedProps.add(e.prop)); - }), - this.local.hasUpdates && - (this.getPlanes().forEach((e) => { - var t; - for (let i of this.local.updatedProps) { - const r = this.local.uniformUpdatesPool[i]; - void 0 !== r && - (null == (t = e.uniforms[i]) ? void 0 : t.lastValue) !== r && - (e.uniforms[i] && ze(r, e.uniforms[i], i), - this.updateStateEffectProperty( - i, - this.fromEventValue ? this.fromEventValue(i, r) : r, - )); - } - }), - this.isText && - this.local.stateEffectProps && - Object.keys(this.local.stateEffectProps).length && - this.render())); - } - updateStateEffectProperty(e, t) { - G(this, e, "event", t, { cloneValue: je }); - } - invalidatePerformanceCaches() { - ((this.local.isDynamicCache = void 0), - (this.local.cachedBreakpoint = void 0), - (this.local.lastCalculatedMousePos = void 0), - (this.local.lastCalculatedMouseValues = void 0)); - } - dispose() { - this.invalidatePerformanceCaches(); - } - } - function nt(e) { - const t = { - topLeft: { x: 0, y: 0 }, - topCenter: { x: 0.5, y: 0 }, - topRight: { x: 1, y: 0 }, - rightCenter: { x: 1, y: 0.5 }, - bottomRight: { x: 1, y: 1 }, - bottomCenter: { x: 0.5, y: 1 }, - bottomLeft: { x: 0, y: 1 }, - leftCenter: { x: 0, y: 0.5 }, - center: { x: 0.5, y: 0.5 }, - }; - return t[e] ? t[e] : Object.values(t)[e]; - } - function lt(e, t, i, r) { - const a = e.left ?? 0.5, - s = e.top ?? 0.5, - n = "fixed" === Ee(e.leftMode) ? a : a * t, - l = "fixed" === Ee(e.topMode) ? s : s * i, - o = he.includes(e.widthMode) ? e.widthMode : he[e.widthMode ?? 1], - u = he.includes(e.heightMode) ? e.heightMode : he[e.heightMode ?? 1], - d = - e.aspectRatio || - (e.imageNaturalSize - ? e.imageNaturalSize._x / e.imageNaturalSize._y - : 1); - let c, h; - return ( - "auto" === o && "auto" === u - ? ((c = e.width ?? 0), (h = e.height ?? 0)) - : ("auto" !== o && - (c = "fixed" === o ? (e.width ?? 0) : (e.width ?? 0) * t), - (h = - "auto" === u - ? c / (d || 1) - : "fixed" === u - ? (e.height ?? 0) - : (e.height ?? 0) * i), - "auto" === o && (c = h * (d || 1))), - (function (e, t, i, r, a, s) { - const n = nt(a ?? "center"); - (i < 0 && (i = Math.abs(i)), r < 0 && ((t += r), (r = Math.abs(r)))); - const l = e - n.x * i, - o = t - n.y * r; - return ( - 2 * s.x >= l && 2 * s.x <= l + i && 2 * s.y >= o && 2 * s.y <= o + r - ); - })(n, l, c, h, e.anchorPoint, r) - ); - } - function ot(e, t = {}) { - const i = Number(t.maskDepth ?? e.maskDepth ?? 0), - r = Number.isFinite(i) ? i : 0, - a = Number(t.maskDepthLayer ?? e.maskDepthLayer ?? 1), - s = Number.isFinite(a) ? Math.max(0, Math.floor(a)) : 1; - ((e.maskInvert = Object.prototype.hasOwnProperty.call(t, "maskInvert") - ? t.maskInvert - : (e.maskInvert ?? 0)), - (e.maskDepth = 1 === r ? 1 : 0), - (e.maskDepthLayer = 1 === r ? s : 0)); - } - class ut extends st { - constructor(e, t) { - (super(e, t), - i(this, "isElement", !0), - i(this, "isGpuElement", !1), - (this.width = e.width || 0), - (this.height = e.height || 0), - (this.widthMode = e.widthMode ?? "fixed"), - (this.heightMode = e.heightMode ?? "fixed"), - (this.anchorPoint = e.anchorPoint ?? "center"), - (this.left = e.left || 0), - (this.top = e.top || 0), - (this.leftMode = e.leftMode ?? "relative"), - (this.topMode = e.topMode ?? "relative"), - (this.effects = e.effects || []), - (this.trackMouse = e.trackMouse || 0), - (this.trackAxes = e.trackAxes || "xy"), - (this.axisTilt = e.axisTilt || 0), - (this.mouseMomentum = e.mouseMomentum || 0), - (this.mask = e.mask || 0), - (this.maskAlpha = e.maskAlpha || 0), - (this.maskBackground = e.maskBackground || new s.Vec3(0)), - ot(this, e)); - } - unpackage() { - this.effects = Re(this.effects); - for (let e in this) - this[e] && - this[e].type && - ("Vec2" === this[e].type - ? (this[e] = new s.Vec2(this[e]._x, this[e]._y)) - : "Vec3" === this[e].type && - (this[e] = new s.Vec3(this[e]._x, this[e]._y, this[e]._z))); - return this; - } - dispose() { - (this.local.canvas && - ((this.local.canvas.width = 1), - (this.local.canvas.height = 1), - (this.local.canvas = null)), - this.local.ctx && (this.local.ctx = null), - super.dispose()); - } - box() { - const e = nt(this.anchorPoint), - { width: t, height: i } = this.getAbsoluteDimensions(), - { left: r, top: a } = this.getAbsolutePosition(); - return { - anchor: { x: r + t * (0.5 - e.x), y: a + i * (0.5 - e.y) }, - center: { x: r + t / 2, y: a + i / 2 }, - left: r, - top: a, - width: t, - height: i, - }; - } - getAbsolutePosition() { - var e, t, i, r; - const a = this.state(), - s = a.canvasWidth, - n = a.canvasHeight; - let l = - (null == (t = null == (e = this.local) ? void 0 : e.stateEffectProps) - ? void 0 - : t.left) ?? this.left, - o = - (null == (r = null == (i = this.local) ? void 0 : i.stateEffectProps) - ? void 0 - : r.top) ?? this.top; - let u = "fixed" === Ee(this.leftMode) ? l : l * s, - d = "fixed" === Ee(this.topMode) ? o : o * n; - return ((u = +u.toFixed(1)), (d = +d.toFixed(1)), { left: u, top: d }); - } - getAbsoluteDimensions() { - var e, t, i, r; - const a = this.state(); - let s, n; - const l = a.canvasWidth, - o = a.canvasHeight; - let u = - (null == (t = null == (e = this.local) ? void 0 : e.stateEffectProps) - ? void 0 - : t.width) ?? this.width, - d = - (null == (r = null == (i = this.local) ? void 0 : i.stateEffectProps) - ? void 0 - : r.height) ?? this.height, - c = he.includes(this.widthMode) ? this.widthMode : he[this.widthMode], - h = he.includes(this.heightMode) - ? this.heightMode - : he[this.heightMode]; - return ( - "auto" !== c && - ((s = "fixed" === c ? u : u * l), - "auto" === h && - ((n = s / (this.aspectRatio || 1)), - (this.height = "fixed" === c ? n : n / o))), - "auto" !== h && - ((n = "fixed" === this.heightMode ? d : d * o), - "auto" === c && - ((s = n * (this.aspectRatio || 1)), - (this.width = "fixed" === c ? s : s / l))), - "text" === this.layerType && (n = this.height), - { width: s, height: n } - ); - } - isHovered() { - const e = this.state(); - return lt(this, e.canvasWidth, e.canvasHeight, e.mouse.movePos); - } - } - class dt extends ut { - constructor(e, t, r) { - (super(e, t), - i(this, "layerType", "shape"), - i(this, "isElement", !0), - i(this, "isGpuElement", !0), - (this.initOptions = r)); - for (let i in e) i in this || (this[i] = e[i]); - (ot(this, e), this.breakpoints.length && this.setBreakpointValues()); - } - } - class ct extends st { - constructor(e, t, r) { - (super(e, t), - i(this, "layerType", "effect"), - (this.initOptions = r), - (this.type = e.type || "sine"), - (this.usesPingPong = e.usesPingPong || !1), - (this.speed = e.speed ?? 0.5), - (this.parentLayer = e.parentLayer || !1), - (this.animating = e.animating || !1), - (this.isMask = e.isMask || 0), - (this.texture = e.texture || null), - (this.mouseMomentum = e.mouseMomentum || 0)); - for (let i in e) this[i] || (this[i] = e[i]); - this.breakpoints.length && this.setBreakpointValues(); - } - unpackage() { - for (let e in this) - this[e] && - this[e].type && - ("Vec2" === this[e].type - ? (this[e] = new s.Vec2(this[e]._x, this[e]._y)) - : "Vec3" === this[e].type && - (this[e] = new s.Vec3(this[e]._x, this[e]._y, this[e]._z))); - return this; - } - getParent() { - return this.state() - .layers.filter((e) => e.effects && e.effects.length) - .find((e) => e.effects.includes(this.parentLayer)); - } - } - class ht extends st { - constructor(e, t, r) { - var a, s, n, l; - (super(e, t), - i(this, "layerType", "flattened"), - i(this, "isFlattened", !0), - (this.initOptions = r), - (this.sublayers = e.sublayers || []), - (this.visible = !1 !== e.visible), - (this.consumedMaskId = e.consumedMaskId || null), - (this.mask = e.mask || 0), - (this.maskDepthLayer = e.maskDepthLayer ?? 0), - (this.maskInvert = e.maskInvert || 0), - (this.maskDepth = e.maskDepth || 0), - (this.maskAlpha = e.maskAlpha || 0), - (this.local.textSublayers = []), - (this.local.imageSublayers = []), - (this.local.videoSublayers = []), - (this.local.modelSublayers = []), - (this.local.textInstances = {}), - (this.local.canvasTextures = {}), - (this.local.sourceTextures = {}), - (this.local.modelInstances = {}), - (this.local.modelTextures = {}), - this.sublayers.forEach((e, i) => { - if ("text" === e.layerType) { - this.local.textSublayers.push(e); - const a = { ...e }, - s = Number.isInteger(e.sublayerIndex) ? e.sublayerIndex : i; - this.local.textInstances[s] = new mt(a, t, r).unpackage(); - } else if ("image" === e.layerType) this.local.imageSublayers.push(e); - else if ("video" === e.type) this.local.videoSublayers.push(e); - else if ("model" === e.layerType) { - this.local.modelSublayers.push(e); - const a = Number.isInteger(e.sublayerIndex) ? e.sublayerIndex : i; - this.local.modelInstances[a] = new pt(e, t, r); - } - }), - this.states.hover.some((e) => e.triggerOnElement) && - Object.values(this.local.modelInstances).forEach((e) => { - e.states.hover = [{ triggerOnElement: 1 }]; - }), - (this.local.remainingEffectItems = []), - (this.effects = []), - e.remainingEffects && - e.remainingEffects.length > 0 && - ((this.local.remainingEffectItems = e.remainingEffects.map((e) => - new ct(e, t, r).unpackage(), - )), - (this.effects = e.remainingEffects - .map((e) => e.parentLayer) - .filter(Boolean)))); - ([ - ...((null == (a = e.states) ? void 0 : a.appear) || []), - ...((null == (s = e.states) ? void 0 : s.scroll) || []), - ...((null == (n = e.states) ? void 0 : n.hover) || []), - ...((null == (l = e.states) ? void 0 : l.mousemove) || []), - ].forEach((t) => { - var i, r, a, s; - if (!t.prop || void 0 !== this[t.prop]) return; - let n; - const l = t.originalProp || t.prop; - if (l && Number.isInteger(t.sublayerIndex)) { - const e = this.sublayers.find( - (e) => e.sublayerIndex === t.sublayerIndex, - ); - e && void 0 !== e[l] && (n = e[l]); - } - const o = - null == - (a = - null == (r = null == (i = e.data) ? void 0 : i.uniforms) - ? void 0 - : r[t.prop]) - ? void 0 - : a.value, - u = null == (s = t.uniformData) ? void 0 : s.value; - this[t.prop] = n ?? o ?? u ?? t.value; - }), - this.breakpoints.length && this.setBreakpointValues()); - } - setBreakpointValues(e = null) { - (super.setBreakpointValues(e), this.syncTextBreakpoints()); - } - syncTextBreakpoints() { - const e = this.local.bpProps || {}; - Object.entries(this.local.textInstances || {}).forEach(([t, i]) => { - var r, a, s; - const n = this.sublayers.find( - (e) => (null == e ? void 0 : e.sublayerIndex) === Number(t), - ); - let l = !1; - (Object.entries(e).forEach(([e, r]) => { - const a = e.startsWith(`L${t}_`) ? e.slice(t.length + 2) : null; - a && - a in i && - (He(i, a, je(r)), n && a in n && He(n, a, je(r)), (l = !0)); - }), - l && - (null == (r = i.render) || r.call(i), - null == - (s = - null == (a = this.local.canvasTextures[t]) - ? void 0 - : a.needUpdate) || s.call(a))); - }); - } - getChildEffectItems() { - return this.local.remainingEffectItems || []; - } - hasRemainingEffects() { - return ( - this.local.remainingEffectItems && - this.local.remainingEffectItems.length > 0 - ); - } - unpackage() { - var e, t, i; - for (let r in this) - this[r] && "Vec2" === this[r].type - ? (this[r] = new s.Vec2(this[r]._x, this[r]._y)) - : this[r] && - "Vec3" === this[r].type && - (this[r] = new s.Vec3(this[r]._x, this[r]._y, this[r]._z)); - if (null == (e = this.data) ? void 0 : e.uniforms) - for (let r in this.data.uniforms) { - const e = this.data.uniforms[r]; - "Vec2" === - (null == (t = null == e ? void 0 : e.value) ? void 0 : t.type) - ? (e.value = new s.Vec2(e.value._x, e.value._y)) - : "Vec3" === - (null == (i = null == e ? void 0 : e.value) - ? void 0 - : i.type) && - (e.value = new s.Vec3(e.value._x, e.value._y, e.value._z)); - } - return this; - } - areTextAssetsReady() { - return Object.values(this.local.textInstances).every( - (e) => e.local.loaded, - ); - } - areImageAssetsReady() { - var e; - return ( - !(null == (e = this.data) ? void 0 : e.textures) || - this.data.textures - .filter((e) => "image" === e.type) - .every((e) => { - var t; - return !!(null == (t = this.local.sourceTextures) - ? void 0 - : t[e.sublayerIndex]); - }) - ); - } - areModelAssetsReady() { - var e; - if (!(null == (e = this.data) ? void 0 : e.textures)) return !0; - const t = this.data.textures.filter((e) => "modelRT" === e.type); - return ( - !t.length || - t.every((e) => { - var t, i, r, a; - const s = - null == (t = this.local.modelInstances) - ? void 0 - : t[e.sublayerIndex]; - return !!( - (null == (i = null == s ? void 0 : s.local) - ? void 0 - : i.rendererLoaded) && - (null == (r = null == s ? void 0 : s.local) - ? void 0 - : r.modelLoaded) && - (null == (a = this.local.modelTextures) - ? void 0 - : a[e.sublayerIndex]) - ); - }) - ); - } - resize() { - Object.entries(this.local.textInstances).forEach(([e, t]) => { - var i, r; - (t.resize(), - null == - (r = - null == (i = this.local.canvasTextures[e]) - ? void 0 - : i.needUpdate) || r.call(i)); - }); - } - isHovered(e) { - var t; - if (e) { - const i = e.match(/^L(\d+)_/); - if (i) { - const e = parseInt(i[1], 10), - r = null == (t = this.local.modelInstances) ? void 0 : t[e]; - return (null == r ? void 0 : r.isHovered) - ? r.isHovered() - : this._isSublayerHovered(e); - } - } - const i = this.local.modelInstances; - if ( - i && - Object.values(i).some((e) => { - var t; - return null == (t = null == e ? void 0 : e.isHovered) - ? void 0 - : t.call(e); - }) - ) - return !0; - for (const r of this.sublayers) - if ( - "model" !== r.layerType && - "effect" !== r.layerType && - this._isSublayerHovered(r.sublayerIndex) - ) - return !0; - return !1; - } - _isSublayerHovered(e) { - var t, i; - const r = - null == (t = this.sublayers) - ? void 0 - : t.find((t) => t.sublayerIndex === e); - if (!r || "effect" === r.layerType) return !1; - const a = this.state(); - return ( - !!(null == (i = null == a ? void 0 : a.mouse) ? void 0 : i.movePos) && - lt(r, a.canvasWidth, a.canvasHeight, a.mouse.movePos) - ); - } - } - class ft extends ut { - constructor(e, t, r) { - (super(e, t), - i(this, "layerType", "image"), - i(this, "isElement", !0), - i(this, "isGpuElement", !0), - (this.initOptions = r)); - for (let i in e) i in this || (this[i] = e[i]); - (ot(this, e), this.breakpoints.length && this.setBreakpointValues()); - } - } - class pt extends st { - constructor(e, t, r) { - var a; - (super(e, t, r), - i(this, "layerType", "model"), - i(this, "isModel", !0), - i(this, "contextType", "webgl"), - e.moduleRef && - (null == (a = null == r ? void 0 : r.modules) - ? void 0 - : a[e.moduleRef]) && - (this.moduleUrl = r.modules[e.moduleRef].url), - (this.trackMouse = void 0 !== e.trackMouse ? e.trackMouse : 0), - (this.mouseMomentum = void 0 !== e.mouseMomentum ? e.mouseMomentum : 0), - (this.mouseSpring = void 0 !== e.mouseSpring ? e.mouseSpring : 0), - (this.trackAxes = e.trackAxes || "xy"), - (this.lightTracking = void 0 !== e.lightTracking ? e.lightTracking : 0), - (this.rotationTracking = - void 0 !== e.rotationTracking ? e.rotationTracking : 0), - (this.speed = void 0 !== e.speed ? e.speed : 0.5), - (this.pos = new s.Vec3(e.pos._x, e.pos._y, e.pos._z)), - (this.modelUrl = e.modelUrl), - (this.scale = e.scale), - (this.modelRotation = new s.Vec3( - e.modelRotation._x, - e.modelRotation._y, - e.modelRotation._z, - )), - (this.lightIntensity = e.lightIntensity), - (this.lightColor = e.lightColor), - (this.ambientLightColor = e.ambientLightColor), - (this.fillLightColor = e.fillLightColor), - (this.ambientLightIntensity = e.ambientLightIntensity ?? 1.5), - (this.fillLightIntensity = e.fillLightIntensity ?? 1), - (this.lightPosition = new s.Vec3( - e.lightPosition._x, - e.lightPosition._y, - e.lightPosition._z, - )), - (this.materialMetalness = e.materialMetalness), - (this.materialRoughness = e.materialRoughness), - (this.refractScale = e.refractScale), - (this.animationAxis = new s.Vec3( - e.animationAxis._x, - e.animationAxis._y, - e.animationAxis._z, - )), - (this.renderNormals = e.renderNormals), - (this.animating = e.animating), - (this.opacity = e.opacity), - (this.colorMapUrl = e.colorMapUrl), - (this.colorMapScale = e.colorMapScale ?? 1), - (this.colorMapPosition = e.colorMapPosition - ? new s.Vec2(e.colorMapPosition.x ?? 0.5, e.colorMapPosition.y ?? 0.5) - : new s.Vec2(0.5, 0.5)), - (this.colorMapIntensity = e.colorMapIntensity ?? 1), - (this.quality = e.quality || "fast"), - (this.environmentMapIntensity = e.environmentMapIntensity ?? 0), - (this.environmentMapUrl = e.environmentMapUrl || ""), - (this.normalMapUrl = e.normalMapUrl || ""), - (this.normalMapScale = e.normalMapScale ?? 1), - (this.normalMapPosition = e.normalMapPosition - ? new s.Vec2( - e.normalMapPosition.x ?? 0.5, - e.normalMapPosition.y ?? 0.5, - ) - : new s.Vec2(0.5, 0.5)), - (this.normalMapIntensity = e.normalMapIntensity ?? 1), - (this.extrudeDepth = e.extrudeDepth ?? 10), - (this.bevelEnabled = e.bevelEnabled ?? !1), - (this.bevelThickness = e.bevelThickness ?? 1), - (this.bevelSize = e.bevelSize ?? 1), - (this.bevelSegments = e.bevelSegments ?? 2), - (this.glassIOR = e.glassIOR ?? 1.5), - (this.glassThickness = e.glassThickness ?? 0.5), - (this.glassRoughness = e.glassRoughness ?? 0), - (this.glassTint = e.glassTint || "#ffffff"), - (this.glassDispersion = e.glassDispersion ?? 0), - (this.materialMode = - e.materialMode || (e.renderNormals ? "glass" : "standard")), - (this.matcapUrl = - e.matcapUrl || - "https://assets.unicorn.studio/media/matcaps/unicorn_matcap_default.webp"), - (this.matcapIntensity = e.matcapIntensity ?? 0.5), - (this.matcapRotation = e.matcapRotation ?? 0), - (this.renderNormals = - "glass" === this.materialMode || this.renderNormals ? 1 : 0), - (this.loadCallback = null), - this.breakpoints.length && this.setBreakpointValues()); - } - unpackage() { - return ( - (this.pos = new s.Vec3(this.pos._x, this.pos._y, this.pos._z)), - (this.modelRotation = new s.Vec3( - this.modelRotation._x, - this.modelRotation._y, - this.modelRotation._z, - )), - (this.lightPosition = new s.Vec3( - this.lightPosition._x, - this.lightPosition._y, - this.lightPosition._z, - )), - (this.animationAxis = new s.Vec3( - this.animationAxis._x, - this.animationAxis._y, - this.animationAxis._z, - )), - this - ); - } - async loadRenderer() { - const e = this.state(); - if (!e.curtain || !e.curtain.renderer || !e.curtain.renderer.gl) return; - let t = - this.moduleUrl || - `https://cdn.jsdelivr.net/gh/hiunicornstudio/unicornstudio.js@v${ve}/extensions/model-renderer.js`; - try { - const i = await import(t); - ((this.local.initialize = i.initialize), - (this.local.loadModel = i.loadModel), - (this.local.draw = i.draw), - (this.local.dispose = i.dispose), - (this.local.rendererLoaded = !0), - requestAnimationFrame(() => { - var t; - const i = e.curtain.renderer.gl; - (this.local.renderTarget && - !this.local.renderTarget._frameBuffer && - this.local.renderTarget._initRenderTarget(), - i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, !1), - i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), - this.local.initialize(i, this), - (this.local.initialized = !0), - this.local.loadModel(this)); - const r = null == (t = e.curtain) ? void 0 : t.renderer; - r && ((r.state.flipY = null), (r.state.premultiplyAlpha = null)); - })); - } catch (i) {} - } - handleModelLoaded(e = null) { - var t, i, r, a; - if ( - ((this.local.modelLoaded = !0), - (this.local.modelObject = e), - this.local.renderTarget) - ) { - let e = this.local.renderTarget.getTexture(); - const a = - this.getPlane() || - (null == - (i = null == (t = this.local.hostLayer) ? void 0 : t.getPlane) - ? void 0 - : i.call(t)), - s = this.local.targetSamplerName || "uTexture"; - let n = - null == (r = null == a ? void 0 : a.textures) - ? void 0 - : r.find((e) => e._samplerName === s); - n && e && n.copy(e); - } - this.animating || (this.renderModel(), (this.local.renderedOnce = !0)); - const s = { - layer: this, - object: this.local.modelObject, - modelUrl: this.modelUrl, - }; - null == (a = this.loadCallback) || a.call(this, s); - } - onLoad(e) { - return "function" != typeof e - ? () => {} - : ((this.loadCallback = e), - this.local.modelLoaded && - e({ - layer: this, - object: this.local.modelObject || null, - modelUrl: this.modelUrl, - }), - () => { - this.loadCallback === e && (this.loadCallback = null); - }); - } - renderModel() { - var e, t, i, r, a, s; - if (!this.local.rendererLoaded || !this.local.modelLoaded) return; - const n = this.state(); - if ( - !n || - n.destroyed || - !n.curtain || - !n.curtain.renderer || - !n.curtain.renderer.gl - ) - return; - const l = n.curtain.renderer.gl; - if (0 === l.drawingBufferWidth || 0 === l.drawingBufferHeight) return; - if (this.animating) { - void 0 === this.local.time && (this.local.time = 0); - let t = - (null == (e = this.local.stateEffectProps) ? void 0 : e.speed) ?? - this.speed ?? - 0.5; - const i = n.fps ? 60 / n.fps : 1; - this.local.time += t * i * 60; - } - const o = - this.materialMode || (this.renderNormals ? "glass" : "standard"), - u = this.environmentMapUrl || ""; - if (this.environmentMapIntensity > 0) { - const e = - this.getPlane() || - (null == - (i = null == (t = this.local.hostLayer) ? void 0 : t.getPlane) - ? void 0 - : i.call(t)); - if (e && !u.trim()) { - const t = e.textures.find((e) => "uBgTexture" === e._samplerName); - (null == t ? void 0 : t._copiedFrom) && t._sampler - ? (this.local.envTexture = { - gl: l, - webglTexture: t._sampler.texture, - width: t._size.width, - height: t._size.height, - }) - : (this.local.envTexture = null); - } else u.trim() || (this.local.envTexture = null); - } else this.local.envTexture = null; - if ("glass" === o) { - const e = - this.getPlane() || - (null == - (a = null == (r = this.local.hostLayer) ? void 0 : r.getPlane) - ? void 0 - : a.call(r)); - if (e) { - const t = e.textures.find((e) => "uBgTexture" === e._samplerName); - (null == t ? void 0 : t._copiedFrom) && - t._sampler && - t._sampler.texture - ? (this.local.backgroundTexture = { - gl: l, - webglTexture: t._sampler.texture, - width: t._size.width, - height: t._size.height, - }) - : (this.local.backgroundTexture = null); - } else this.local.backgroundTexture = null; - } else this.local.backgroundTexture = null; - const d = - void 0 !== this.local.time ? this.local.time : performance.now(); - if (this.local.renderTarget) - if (this.local.renderTarget._frameBuffer) { - const e = this.local.renderTarget._frameBuffer, - t = this.local.renderTarget._size.width, - i = this.local.renderTarget._size.height; - (l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL, !1), - l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), - l.bindFramebuffer(l.FRAMEBUFFER, e), - l.viewport(0, 0, t, i)); - try { - this.local.draw(l, d, this); - } finally { - (l.bindFramebuffer(l.FRAMEBUFFER, null), - l.viewport(0, 0, l.drawingBufferWidth, l.drawingBufferHeight), - l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL, !0), - l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0)); - const e = null == (s = n.curtain) ? void 0 : s.renderer; - e && - (e.setBlendFunc(), - (e.state.currentProgramID = null), - (e.state.currentGeometryID = null), - (e.state.forceBufferUpdate = !0), - (e.state.frameBufferID = null), - (e.state.activeTexture = null), - (e.state.depthTest = null), - (e.state.cullFace = null), - (e.state.flipY = null), - (e.state.premultiplyAlpha = null)); - } - } else - (this.local.draw(l, d, this), - l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL, !0)); - } - resize() { - var e; - const t = this.state(); - if ( - !(null == t ? void 0 : t.resizeRenderTarget) || - !this.local.renderTarget || - !(null == (e = t.curtain) ? void 0 : e.canvas) - ) - return; - const i = this.getPlane(); - let r = this.userDownsample || 1; - (null == i ? void 0 : i.userData) && - void 0 !== i.userData.downSample && - (r = - "number" == typeof i.userData.downSample ? i.userData.downSample : 1); - const a = t.curtain.canvas.width * r, - s = t.curtain.canvas.height * r; - t.resizeRenderTarget(this.local.renderTarget, a, s); - } - cleanup() { - var e; - if ( - (this.local.dispose && this.local.dispose(this), - (this.local.initialize = null), - (this.local.loadModel = null), - (this.local.draw = null), - (this.local.dispose = null), - (this.local.rendererLoaded = !1), - (this.local.initialized = !1), - (this.local.modelLoaded = !1), - (this.local.modelObject = null), - this.local.renderTarget) - ) { - this.local.renderTarget.remove(); - let t = this.getPlane(); - (t && (null == (e = t.removeRenderTarget) || e.call(t)), - (this.local.renderTarget = null)); - } - } - isAnimating() { - return ( - this.visible && - (this.animating || - this.trackMouse > 0 || - this.rotationTracking > 0 || - this.lightTracking > 0) - ); - } - getProp(e) { - var t; - return ( - (null == (t = this.local.stateEffectProps) ? void 0 : t[e]) ?? this[e] - ); - } - isAnimatableLightColorProp(e) { - return me.includes(e); - } - getEventValue(e, t = this[e]) { - if (!this.isAnimatableLightColorProp(e) || null == t) return t; - if ("Vec3" === (null == t ? void 0 : t.type)) - return t instanceof s.Vec3 - ? t.clone() - : new s.Vec3(t.x ?? t._x, t.y ?? t._y, t.z ?? t._z); - const i = be(t); - return i ? new s.Vec3(...i.map((e) => e / 255)) : t; - } - fromEventValue(e, t) { - if ( - !this.isAnimatableLightColorProp(e) || - null == t || - "string" == typeof t - ) - return t; - if ("Vec3" === (null == t ? void 0 : t.type)) { - return (function (e, t, i) { - return ( - "#" + ((1 << 24) + (e << 16) + (t << 8) + i).toString(16).slice(1) - ); - })( - ...[t.x ?? t._x ?? 0, t.y ?? t._y ?? 0, t.z ?? t._z ?? 0].map((e) => - Math.max(0, Math.min(255, Math.round(255 * e))), - ), - ); - } - return t; - } - isHovered() { - if (!this.local.boundingBox) return !1; - const e = this.state(), - t = e.canvasWidth, - i = e.canvasHeight, - r = this.local.boundingBox.min, - a = this.local.boundingBox.max, - s = r.x * t, - n = r.y * i, - l = a.x * t, - o = a.y * i, - u = e.mouse.movePos; - return 2 * u.x >= s && 2 * u.x <= l && 2 * u.y >= n && 2 * u.y <= o; - } - dispose() { - (this.cleanup(), super.dispose()); - } - } - class mt extends ut { - constructor(e, t, r) { - (super(e, t), - i(this, "layerType", "text"), - i(this, "isText", !0), - (this.initOptions = r), - (this.opacity = e.opacity ?? 1), - (this.displace = e.displace || 0), - (this.bgDisplace = e.bgDisplace || 0), - (this.dispersion = e.dispersion || 0), - (this.rotation = e.rotation || 0), - (this.blendMode = e.blendMode || "NORMAL")); - let a = this.default(e || {}); - for (let i in a) this[i] = a[i]; - (this.breakpoints.length && this.setBreakpointValues(), - (this.isSafari = /^((?!chrome|android).)*safari/i.test( - navigator.userAgent, - )), - Object.keys(e).length && this.createLocalCanvas(), - this.loadFont()); - } - createLocalCanvas() { - const e = this.state(), - t = document.createElement("canvas"), - i = this.getPixelRatio(); - ((t.width = e.canvasWidth * i), (t.height = e.canvasHeight * i)); - const r = t.getContext("2d"); - (r.scale(i, i), (this.local.canvas = t), (this.local.ctx = r)); - } - resize() { - var e, t, i; - const r = this.state(); - if (this.local.canvas) { - const e = this.getPixelRatio(); - ((this.local.canvas.width = r.canvasWidth * e), - (this.local.canvas.height = r.canvasHeight * e), - this.local.ctx.scale(e, e)); - } - const a = null == (e = r.currentBreakpoint) ? void 0 : e.name; - ((null == (i = null == (t = this.states) ? void 0 : t.appear) - ? void 0 - : i.some( - (e) => - !e.complete && - (!e.breakpoints || - 0 === e.breakpoints.length || - e.breakpoints.includes(a)), - )) || this.render(), - Le(this, this.state().element)); - } - default(e) { - return { - fill: e.fill || ["#ffffff"], - fontSize: e.fontSize ?? 24, - fontSizeMode: e.fontSizeMode || "fixed", - fontCSS: e.fontCSS || null, - lineHeight: e.lineHeight ?? 25, - letterSpacing: e.letterSpacing || 0, - fontFamily: e.fontFamily || "arial", - fontStyle: e.fontStyle || "normal", - fontWeight: e.fontWeight || "normal", - textAlign: e.textAlign || "left", - textContent: e.textContent || "", - href: e.href || "", - gradientAngle: e.gradientAngle || e.gradAngle || 0, - gradientType: e.gradientType || e.gradType || "linear", - noTextAsHtml: e.noTextAsHtml || !1, - htmlOnly: e.htmlOnly || !1, - htmlRenderOrder: e.htmlRenderOrder ?? 0, - }; - } - unpackage() { - return ((this.fill = Re(this.fill)), this); - } - loadFont() { - var e; - const t = this.fontStyle.includes("italic") ? "italic" : "normal", - i = (e) => - "normal" === e || "400" === e || 400 === e ? "normal" : e.toString(), - r = isNaN(parseInt(this.fontWeight)) ? "normal" : i(this.fontWeight); - if ( - Array.from(document.fonts).some( - (e) => - e.family === this.fontFamily && - e.style === t && - i(e.weight) === r && - "loaded" === e.status, - ) || - !(null == (e = this.fontCSS) ? void 0 : e.src) - ) - return void this.handleFontLoaded(); - let a = this.fontCSS.src.split(" ").join("%20"); - const s = new FontFace(this.fontFamily, `url(${a})`, { - style: t, - weight: r, - }); - (document.fonts.add(s), - s - .load() - .then(() => { - this.handleFontLoaded(); - }) - .catch((e) => { - this.handleFontLoaded(); - })); - } - handleFontLoaded() { - ((this.local.loaded = !0), this.render(), this.render()); - const e = this.state(); - (e.renderFrame && e.renderFrame(), Le(this, this.state().element)); - } - getAbsoluteFontValues(e) { - var t, i, r, a, s, n; - const l = - (null == (i = null == (t = this.local) ? void 0 : t.stateEffectProps) - ? void 0 - : i.fontSize) || this.fontSize, - o = - (null == (a = null == (r = this.local) ? void 0 : r.stateEffectProps) - ? void 0 - : a.lineHeight) || this.lineHeight, - u = - (null == (n = null == (s = this.local) ? void 0 : s.stateEffectProps) - ? void 0 - : n.letterSpacing) || this.letterSpacing, - d = "fixed" === this.fontSizeMode ? l : l * e.canvasWidth; - return { - fontSize: d, - lineHeight: "fixed" === this.fontSizeMode ? o : o * d, - letterSpacing: "fixed" === this.fontSizeMode ? u : u * d, - }; - } - render() { - var e, t, i; - if (!(null == (e = this.local) ? void 0 : e.ctx)) return; - let r = this.local.ctx, - { left: a, top: s, width: n } = this.box(); - const l = nt(this.anchorPoint), - o = - ((null == (i = null == (t = this.local) ? void 0 : t.stateEffectProps) - ? void 0 - : i.rotation) ?? - this.rotation) || - 0; - let u = this.state(), - d = this.height, - c = a - l.x * n, - h = s - l.y * d, - f = 0, - { - fontSize: p, - lineHeight: m, - letterSpacing: v, - } = this.getAbsoluteFontValues(u), - g = this.fontStyle.includes("italic") ? "italic" : "normal", - y = /^\d+$/.test(this.fontStyle) ? this.fontStyle : "400"; - (r.clearRect(0, 0, u.canvasWidth, u.canvasHeight), - (r.font = `${g} ${y} ${p}px/${m}px ${this.fontFamily}, -apple-system, BlinkMacSystemFont, Helvetica, Arial`), - this.isSafari || - ((r.textAlign = this.textAlign), (r.letterSpacing = v + "px"))); - const x = r.measureText("m").width; - ((n = Math.max(n, x)), r.save()); - let b = c + n / 2, - _ = h + d / 2; - (r.translate(b, _), - r.rotate((360 * o * Math.PI) / 180), - r.translate(-b, -_), - "center" === this.textAlign && (c += n / 2), - "right" === this.textAlign && (c += n), - (r.fillStyle = this.fill[0])); - const P = (e, t) => { - let i = h + m * t + m / 2 + p / 3; - this.isSafari - ? ((e, t, i, r, a, s, n) => { - let l, - o = t - .split("") - .reduce( - (i, r, s) => - i + e.measureText(r).width + (s < t.length - 1 ? a : 0), - 0, - ); - if ( - ((l = "center" === s ? i + (n - o) / 2 - n / 2 : i), - "right" === s) - ) - for (let u = t.length - 1; u >= 0; u--) { - const i = t[u]; - ((l -= e.measureText(i).width), - e.fillText(i, l, r), - u > 0 && (l -= a)); - } - else - for (let u = 0; u < t.length; u++) - (e.fillText(t[u], l, r), - (l += e.measureText(t[u]).width + a)); - })(r, e, c, i, v, this.textAlign, n) - : r.fillText(e, c, i); - }, - T = this.textContent ? this.textContent.split("\n") : [""]; - let E = T.length; - const w = (e, t, i) => - t - .split("") - .reduce( - (r, a, s) => ( - (r += e.measureText(a).width), - s < t.length - 1 && (r += i), - r - ), - 0, - ); - for (let k = 0; k < E; k++) { - let e = "", - t = T[k].split(/(\s|\n)/); - for (let i = 0; i < t.length; i++) { - const a = t[i], - s = e + a; - if ( - (this.isSafari && v ? w(r, s, v) : r.measureText(s).width) > n || - "\n" === a - ) { - if ("" !== e) - ((T[k] = e.trim()), - i !== t.length - 1 - ? (T.splice(k + 1, 0, t.slice(i).join("")), E++) - : "\n" !== a && T.push(a)); - else { - let e = a, - s = k; - for (; e.length > 0; ) { - let t = ""; - for ( - let i = 0; - i < e.length && - (r.measureText(t + e[i]).width <= n || 0 == i); - i++ - ) - t += e[i]; - ((e = e.slice(t.length)), - (T[s] = t.trim()), - e.length > 0 && (T.splice(s + 1, 0, e), s++, E++)); - } - t.slice(i + 1).length > 0 && (T[s] += t.slice(i + 1).join("")); - } - break; - } - ((e = s), i === t.length - 1 && (T[k] = e.trim())); - } - } - (T.forEach((e, t) => { - (P(e, f), t < T.length - 1 && f++); - }), - r.translate(-(c + n / 2), -(h + d / 2)), - r.restore(), - (this.height = m * f + m)); - } - } - function vt() { - let e = performance.now(); - document[K] - ? (cancelAnimationFrame(Z), - Rt.forEach((t) => { - t.pauseTime = e; - })) - : (Ce(), - Rt.forEach((t) => { - ((t.pauseTime = t.pauseTime - e), - t.curtain.planes.forEach((e) => { - e.videos.forEach((e) => { - e.play(); - }); - })); - })); - } - function gt() { - ((ie = window.innerHeight || document.documentElement.clientHeight), - (re = window.innerWidth || document.documentElement.clientWidth), - Rt.filter((e) => e.initialized).forEach((e) => { - e.refresh(); - }), - xt()); - } - function yt(e, t, i = 50) { - const r = t || e.getBoundingClientRect(), - a = - (r.top >= -i && r.top <= ie + i) || - (r.bottom >= -i && r.bottom <= ie + i) || - (r.top <= 0 && r.bottom >= ie), - s = - (r.left >= -i && r.left <= re + i) || - (r.right >= -i && r.right <= re + i) || - (r.left <= 0 && r.right >= re); - return a && s; - } - function xt() { - Rt.filter((e) => e.getDynamicLayers().length).forEach((e) => { - let t = e.element.getBoundingClientRect(); - if (((e.scrollY = se), e.lastBbox)) { - 0 === Math.abs(t.top - e.lastBbox.top) && le > 0 - ? ((e.fixedCounter = (e.fixedCounter || 0) + 1), - e.fixedCounter > 3 && (e.isFixed = !0)) - : (e.fixedCounter = 0); - } - ((e.lastBbox = e.bbox), (e.bbox = t)); - }); - } - function bt() { - const e = performance.now(); - Rt.filter((e) => e.getDynamicLayers().length).forEach((t) => { - if (yt(t.element, t.bbox, 100)) { - if (!t.isInView) { - ((t.isInView = !0), (t.pauseTime = t.pauseTime - e)); - const i = t.element.offsetWidth > 0 && t.element.offsetHeight > 0; - (i && t.curtain - ? t.resize() - : i || - requestAnimationFrame(() => { - t.element.offsetWidth > 0 && - t.element.offsetHeight > 0 && - t.curtain && - t.resize(); - }), - !t.lazyLoad || - t.initialized || - t.initializing || - t.initializePlanes()); - } - } else t.isInView && ((t.isInView = !1), (t.pauseTime = e)); - }); - } - function _t() { - (xe(), xt(), bt()); - const e = Rt.filter((e) => e.getDynamicLayers().length), - t = Rt.filter((e) => e.rendering); - e.length && !t.length && Ce(); - } - function Pt() { - const e = Rt.filter((e) => e.getDynamicLayers().length), - t = Rt.filter((e) => e.rendering); - e.length && !t.length && Ce(); - const i = performance.now(); - ((!ue || i - ue > 80) && (xt(), (ue = i)), - clearTimeout(de), - (de = setTimeout(_t, 80)), - bt()); - } - function Tt() { - (xe(), Pt()); - } - function Et(e) { - var t; - if (e._hasMousePos) return !0; - if (!(null == (t = e.curtain) ? void 0 : t.planes)) return !1; - const i = e.curtain.planes.find((e) => e.uniforms.mousePos); - return (i && (e._hasMousePos = !0), !!i); - } - function wt(e) { - for (let t = 0; t < Rt.length; t++) { - const e = Rt[t]; - e.isInView && - ((e.mouse.page.x = 99999999999), - (e.mouse.page.y = 99999999999), - (e.mouse.enterTime = null)); - } - } - function kt(e) { - let t = performance.now(); - for (let i = 0; i < Rt.length; i++) { - const r = Rt[i]; - if (!r.isInView || !r.initialized) continue; - let a, - s, - n = r.bbox; - (Math.abs(le) > 1 && - t - r.lastBboxTime > 64 && - ((n = r.element.getBoundingClientRect()), - (r.lastBbox = r.bbox), - (r.bbox = n), - (r.scrollY = se), - (r.lastBboxTime = t)), - e.targetTouches - ? ((a = e.targetTouches[0].pageX), (s = e.targetTouches[0].pageY)) - : ((a = e.pageX), (s = e.pageY)), - r.isFixed && - ((r.scrollY = 0), - (s = e.targetTouches ? e.targetTouches[0].clientY : e.clientY))); - const l = a - n.left, - o = s - (n.top + (r.isFixed ? 0 : r.scrollY)); - ((r.mouse.page.x = a), - (r.mouse.page.y = s), - (r.mouse.movePos.x = 0.5 * l), - (r.mouse.movePos.y = 0.5 * o), - (r.mouse.movedInView = !0)); - } - } - let Rt = []; - class Mt { - constructor(e) { - (i(this, "local", {}), - i(this, "scrollY", 0), - i(this, "paused", !1), - i(this, "destroyed", !1), - i(this, "lastBboxTime", 0), - (this.id = e.id)); - const t = [ - { name: "Desktop", max: 1 / 0, min: 992 }, - { name: "Tablet", max: 991, min: 576 }, - { name: "Mobile", max: 575, min: 0 }, - ]; - if (e.breakpoints) - for (const i of e.breakpoints) { - const e = t.find((e) => e.name === i.name); - e && - (void 0 !== i.min && (e.min = i.min), - void 0 !== i.max && (e.max = i.max)); - } - ((this.breakpoints = t), - (this.projectId = e.projectId), - (this.canvasWidth = e.width || e.element.offsetWidth || re), - (this.canvasHeight = e.height || e.element.offsetHeight || ie), - (this.curtain = void 0), - (this.curtainRafId = void 0), - (this.dpi = +e.dpi || Math.min(1.5, window.devicePixelRatio)), - (this.element = e.element), - (this.fps = e.fps || 60), - (this.name = e.name), - (this.frameDuration = 1e3 / (e.fps || 60)), - (this.layers = e.layers), - (this.lazyLoad = e.lazyLoad), - (this.initialized = !1), - (this.lasTick = null), - (this.lastTime = 0), - (this.rendering = !1), - (this.bbox = {}), - (this.isFixed = - e.fixed || - "fixed" === window.getComputedStyle(this.element).position), - (this.interactivity = { mouse: { disableMobile: !1, disabled: !1 } }), - (this.mouse = { - downPos: { x: 0.5, y: 0.5 }, - movePos: { x: 0.5, y: 0.5 }, - lastPos: { x: 0.5, y: 0.5 }, - delta: { x: 0, y: 0 }, - page: { x: 99999999999, y: 99999999999 }, - dragging: !1, - movedInView: !1, - enterTime: null, - ticks: 0, - pos: { x: 0, y: 0 }, - }), - (this.renderingScale = e.renderingScale || 1), - (this.scale = e.scale || 1), - (this.split = !1), - (this.versionId = ""), - (this.variableCallbacks = []), - (this.initialVariables = e.initialVariables || {}), - (this.initialPreset = e.initialPreset || ""), - (this.editMetadata = e.editMetadata || {}), - (this.breakpointWidth = Number.isFinite(Number(e.breakpointWidth)) - ? Number(e.breakpointWidth) - : null), - e.width && - e.height && - ((this.element.style.width = e.width + "px"), - (this.element.style.height = e.height + "px")), - (this.bbox = this.element.getBoundingClientRect()), - (this.lastBbox = this.bbox), - (this.currentBreakpoint = this.getCurrentBreakpoint()), - this.createCurtains(), - this.setCanvasScale(), - Be(this.curtain) && - this.curtain.gl && - (this.textureLoader = new s.TextureLoader(this.curtain))); - } - hasValidTextureLoader() { - var e; - return !( - !this.textureLoader || - (!(null == (e = this.textureLoader.renderer) ? void 0 : e.cache) && - !this.textureLoader.cache) - ); - } - getLayer(e, t = null) { - var i, r; - const a = - this.layers.find((t) => n(t, e, { includeRuntimeLocalId: !0 })) || null; - if (a || !(null == t ? void 0 : t.target)) return a; - const s = this.layers.find( - (t) => - !( - !(null == t ? void 0 : t.isFlattened) || !Array.isArray(t.sublayers) - ) && t.sublayers.some((t) => n(t, e)), - ); - if (s) { - const a = s.sublayers.find((t) => n(t, e)), - l = null == a ? void 0 : a.sublayerIndex; - if (Number.isInteger(l)) - if ("prop" === (t.kind || "prop")) { - const e = `L${l}_${t.target}`, - r = `L${l}_elemOpacity`, - a = (null == (i = s.data) ? void 0 : i.uniforms) || {}; - "opacity" === t.target && a[r] - ? (t.target = r) - : a[e] && (t.target = e); - } else if ("texture" === t.kind || "source" === t.kind) { - const e = (null == (r = s.data) ? void 0 : r.textures) || [], - i = `uL${l}_${String(t.target || "").replace(/^u/, "")}`, - n = - e.find( - (e) => - (null == e ? void 0 : e.sublayerIndex) === l && - e.sampler === t.target, - ) || - e.find( - (e) => - (null == e ? void 0 : e.sublayerIndex) === l && - e.sampler === i, - ) || - ("source" === t.kind && - "video" !== (null == a ? void 0 : a.type) - ? e.find( - (e) => - (null == e ? void 0 : e.sublayerIndex) === l && - ["image", "media", "canvas", "modelRT"].includes( - e.type, - ), - ) - : null); - (null == n ? void 0 : n.sampler) && - ((t.kind = "texture"), (t.target = n.sampler)); - } - return s; - } - const l = this.layers.filter((e) => - Object.prototype.hasOwnProperty.call(e, t.target), - ); - return 1 === l.length ? l[0] : null; - } - setupVariables(e = {}, t = {}, i = "") { - ((this.variables = new U({ - variables: e, - getLayer: (e, t) => this.getLayer(e, t), - })), - this.variables.applyAll(), - i && this.variables.applyPreset(i), - this.variables.applyInitialValues(t)); - } - setVariable(e, t) { - var i; - if (null == (i = this.variables) ? void 0 : i.setValue(e, t)) { - const t = this.getVariable(e), - i = this.getVariables(); - this.variableCallbacks.forEach((r) => r(e, t, i)); - } else if (this.variables && !this.variables.getDefinition(e)) { - this.getCreateVariableUrl({ name: e, defaultValue: t }); - } - return this; - } - setVariables(e = {}) { - return ( - Object.entries(e || {}).forEach(([e, t]) => this.setVariable(e, t)), - this - ); - } - setPreset(e) { - var t; - const i = - (null == (t = this.variables) ? void 0 : t.applyPreset(e)) || []; - if (i.length) { - const e = this.getVariables(); - i.forEach((t) => { - this.variableCallbacks.forEach((i) => i(t, this.getVariable(t), e)); - }); - } - return this; - } - getPreset(e) { - var t; - return (null == (t = this.variables) ? void 0 : t.getPreset(e)) || null; - } - getPresets() { - var e; - return (null == (e = this.variables) ? void 0 : e.getPresets()) || []; - } - getVariable(e) { - var t; - return null == (t = this.variables) ? void 0 : t.getValue(e); - } - getVariables() { - var e; - return (null == (e = this.variables) ? void 0 : e.getValues()) || {}; - } - getVariableDefinition(e) { - var t; - const i = null == (t = this.variables) ? void 0 : t.getDefinition(e); - return i ? { ...i, defaultValue: je(i.defaultValue) } : null; - } - getVariableDefinitions() { - var e; - return (null == (e = this.variables) ? void 0 : e.getDefinitions()) || []; - } - getVariableManifest() { - var e; - return (null == (e = this.variables) ? void 0 : e.getManifest()) || []; - } - getMouse() { - var e, t, i, r, a, s, n, l, o, u; - const d = !!(null == (e = this.mouse) ? void 0 : e.movedInView), - c = - (null == (t = this.bbox) ? void 0 : t.width) || - (null == (i = this.element) ? void 0 : i.offsetWidth) || - this.canvasWidth || - 0, - h = - (null == (r = this.bbox) ? void 0 : r.height) || - (null == (a = this.element) ? void 0 : a.offsetHeight) || - this.canvasHeight || - 0; - if (!d || !c || !h) return { x: 0.5, y: 0.5, inBounds: !1, moved: d }; - const f = this.mouse.page || {}, - p = (null == (s = this.bbox) ? void 0 : s.left) || 0, - m = this.isFixed - ? (null == (n = this.bbox) ? void 0 : n.top) || 0 - : ((null == (l = this.bbox) ? void 0 : l.top) || 0) + this.scrollY, - v = (null == (o = this.lastBbox) ? void 0 : o.width) || c, - g = (null == (u = this.lastBbox) ? void 0 : u.height) || h, - y = f.x > p && f.y > m && f.x < v + p && f.y < g + m; - return { - x: (2 * this.mouse.movePos.x) / c, - y: 1 - (2 * this.mouse.movePos.y) / h, - inBounds: y, - moved: d, - }; - } - onVariableChange(e) { - return "function" != typeof e - ? () => {} - : (this.variableCallbacks.push(e), - () => { - this.variableCallbacks = this.variableCallbacks.filter( - (t) => t !== e, - ); - }); - } - getCreateVariableUrl({ - layer: e = null, - target: t = "", - defaultValue: i = 0, - kind: r = "prop", - name: a = "", - } = {}) { - const s = (null == e ? void 0 : e.hasPublishedPublicId) - ? null == e - ? void 0 - : e.id - : (null == e ? void 0 : e.editorLayerId) || (null == e ? void 0 : e.id); - if (e && t && !s) return ""; - const n = k({ - name: a, - layerId: s, - layerName: - (null == e ? void 0 : e.layerName) || (null == e ? void 0 : e.name), - target: t, - kind: r, - defaultValue: i, - canvasId: this.editMetadata.canvasId, - }); - return (function ({ - baseUrl: e = "https://unicorn.studio", - designId: t, - intent: i, - } = {}) { - const r = w(t); - if (!r || !i) return ""; - const a = new URL(`/edit/${r}`, e), - s = k(i); - return ( - a.searchParams.set("createVariable", R(s)), - s.canvasId && a.searchParams.set("canvasId", s.canvasId), - a.toString() - ); - })({ designId: this.editMetadata.designId, intent: n }); - } - setProp(e, t, i) { - const r = this.getLayer(e); - return r - ? (r.setRuntimeOverride(t, i, { source: "scene.setProp" }), this) - : this; - } - setTexture(e, t, i) { - const r = this.getLayer(e); - return r ? (r.setTexture(t, i), this) : this; - } - getLayers() { - return this.layers.map((e) => ({ - id: e.id, - publicId: e.publicId, - name: e.layerName || e.name || e.id, - type: e.layerType || e.type, - })); - } - preloadImage(e, t, i, r = !0) { - if (!e) return; - if (!this.hasValidTextureLoader()) return void (i && i(null)); - this.local.preloadedImages = this.local.preloadedImages || {}; - let a = this.local.preloadedImages[e]; - if ( - (a || - ((a = this.local.preloadedImages[e] = - { texture: null, loading: !0, claimed: !1, queue: [] }), - this.textureLoader.loadImage( - e, - { sampler: t, premultipliedAlpha: r }, - (t) => { - ((a.texture = t), (a.loading = !1)); - for (const i of a.queue) this._resolvePreloadedImage(e, i); - a.queue = []; - }, - () => { - ((a.loading = !1), - a.queue.forEach((e) => e.callback(null)), - (a.queue = [])); - }, - )), - !i) - ) - return; - const s = { callback: i, sampler: t, premultiplyAlpha: r }; - a.loading ? a.queue.push(s) : this._resolvePreloadedImage(e, s); - } - _resolvePreloadedImage(e, t) { - if (!this.hasValidTextureLoader()) return void t.callback(null); - const i = this.local.preloadedImages[e]; - i.claimed - ? this.textureLoader.loadImage( - e, - { sampler: t.sampler, premultipliedAlpha: t.premultiplyAlpha }, - t.callback, - () => t.callback(null), - ) - : ((i.claimed = !0), t.callback(i.texture)); - } - preloadVideo(e) { - if (!e) return null; - const t = e.includes(", ") ? Oe(e) : e; - if ( - ((this.local.preloadedVideos = this.local.preloadedVideos || {}), - !this.local.preloadedVideos[t]) - ) { - const e = document.createElement("video"); - ((e.crossOrigin = "anonymous"), - (e.muted = !0), - (e.preload = "auto"), - e.setAttribute("playsinline", ""), - (e.src = t), - e.load(), - (this.local.preloadedVideos[t] = e)); - } - return this.local.preloadedVideos[t]; - } - shouldPreloadLayerAssets(e) { - return !1 !== (null == e ? void 0 : e.visible); - } - ensureImageLayerTexture(e, t = null) { - "image" !== e.layerType || - !e.src || - e.local.sourceTexture || - e.local.sourceTextureLoading || - ((e.local.sourceTextureLoading = !0), - this.preloadImage(e.src, "uSourceImage", (i) => { - var r, a; - if (((e.local.sourceTextureLoading = !1), !i)) return; - ((e.local.sourceTexture = i), (e.local.imageReady = !0)); - const s = - t || - (null == (r = e.getPlanes) - ? void 0 - : r.call(e).find((e) => { - var t; - return !(null == (t = e.userData) ? void 0 : t.isComposite); - })) || - (null == (a = e.getPlane) ? void 0 : a.call(e)); - (s && - !s.textures.some((e) => "uSourceImage" === e._samplerName) && - s.addTexture(i), - this.requestSceneRender()); - })); - } - isFlattenedSublayerHidden(e, t, i = null) { - var r, a, s, n; - const l = null == t ? void 0 : t.sublayerIndex; - if (!(null == e ? void 0 : e.isFlattened) || !Number.isInteger(l)) - return !1; - const o = `L${l}_elemOpacity`, - u = `L${l}_opacity`, - d = - (null == (r = null == i ? void 0 : i.uniforms) ? void 0 : r[o]) || - (null == (a = null == i ? void 0 : i.uniforms) ? void 0 : a[u]); - if (d && 0 === d.value) return !0; - return ( - 0 === - ((null == (s = e.local.bpProps) ? void 0 : s[o]) ?? - (null == (n = e.local.bpProps) ? void 0 : n[u])) - ); - } - ensureFlattenedTexture(e, t, i = null) { - var r; - if ( - (null == e ? void 0 : e.isFlattened) && - t && - !this.isFlattenedSublayerHidden(e, t, i) - ) { - if ("image" === t.type && t.src) { - e.local.sourceTextures = e.local.sourceTextures || {}; - const r = e.local.sourceTextures[t.sublayerIndex]; - return r - ? void ( - i && - !i.textures.some((e) => e._samplerName === t.sampler) && - i.addTexture(r) - ) - : void this.preloadImage(t.src, t.sampler, (r) => { - var a; - if (!r) return; - e.local.sourceTextures[t.sublayerIndex] = r; - const s = i || (null == (a = e.getPlane) ? void 0 : a.call(e)); - let n = !1; - (s && - !s.textures.some((e) => e._samplerName === t.sampler) && - (s.addTexture(r), (n = !0)), - n && this.requestSceneRender()); - }); - } - if ("video" === t.type) { - const r = e.sublayers.find( - (e) => e.sublayerIndex === t.sublayerIndex, - ); - if (!(null == r ? void 0 : r.src)) return; - (e.local.videoElements || (e.local.videoElements = {}), - e.local.videoTextures || (e.local.videoTextures = {}), - e.local.videoTextureLoading || (e.local.videoTextureLoading = {})); - const a = - e.local.videoElements[t.sublayerIndex] || this.preloadVideo(r.src); - if ( - ((e.local.videoElements[t.sublayerIndex] = a), - !i || i.textures.some((e) => e._samplerName === t.sampler)) - ) - return; - if (e.local.videoTextures[t.sampler]) - return void i.addTexture(e.local.videoTextures[t.sampler]); - if (e.local.videoTextureLoading[t.sampler]) return; - return ( - (e.local.videoTextureLoading[t.sampler] = !0), - void i.loadVideo( - a, - { premultipliedAlpha: !0, sampler: t.sampler }, - (i) => { - ((e.local.videoTextureLoading[t.sampler] = !1), - (e.local.videoTextures[t.sampler] = i)); - const s = - (null == i ? void 0 : i.source) || - (null == i ? void 0 : i._source) || - a; - s && - ((s.loop = - !(null == r ? void 0 : r.hasOwnProperty("loop")) || r.loop), - (s.playbackRate = (null == r ? void 0 : r.playbackRate) || 1), - s.play(), - this.requestSceneRender()); - }, - () => { - e.local.videoTextureLoading[t.sampler] = !1; - }, - ) - ); - } - if ("media" === t.type && t.src) { - if ( - null == i - ? void 0 - : i.textures.some((e) => e._samplerName === t.sampler) - ) - return; - this.preloadImage( - t.src, - t.sampler, - (r) => { - var a; - if (!r) return; - const s = i || (null == (a = e.getPlane) ? void 0 : a.call(e)); - s && - !s.textures.some((e) => e._samplerName === t.sampler) && - (s.addTexture(r), this.requestSceneRender()); - }, - !1, - ); - } else if ("modelRT" === t.type) { - const a = - null == (r = e.local.modelInstances) ? void 0 : r[t.sublayerIndex]; - if (!a || !this.curtain) return; - ((a.local.hostLayer = e), - (a.local.targetSamplerName = t.sampler), - a.local.renderTarget || - (a.local.renderTarget = new s.RenderTarget(this.curtain, { - depth: !0, - maxWidth: this.curtain.canvas.width * (a.userDownsample || 1), - maxHeight: this.curtain.canvas.height * (a.userDownsample || 1), - texturesOptions: { sampler: t.sampler, premultiplyAlpha: !0 }, - }))); - const n = a.local.renderTarget.getTexture(); - (n && - ((e.local.modelTextures[t.sublayerIndex] = n), - i && - !i.textures.some((e) => e._samplerName === t.sampler) && - (i.addTexture(n), this.requestSceneRender())), - a.local.rendererLoaded || - a.local.rendererLoading || - ((a.local.rendererLoading = !0), - Promise.resolve(a.loadRenderer()).finally(() => { - a.local.rendererLoading = !1; - }))); - } - } - } - preloadTextures() { - this.hasValidTextureLoader() && - this.layers.forEach((e) => { - var t, i, r, a, s, n, l; - const o = this.shouldPreloadLayerAssets(e); - if (e.isFlattened) - return ( - (e.local.canvasTextures = {}), - (e.local.sourceTextures = {}), - void ( - (null == (t = e.data) ? void 0 : t.textures) && - e.data.textures.forEach((t) => { - var i, r; - if ("canvas" === t.type) { - const a = - null == (i = e.local.textInstances) - ? void 0 - : i[t.sublayerIndex]; - (null == (r = null == a ? void 0 : a.local) - ? void 0 - : r.canvas) && - this.textureLoader.loadCanvas( - a.local.canvas, - { sampler: t.sampler, premultiplyAlpha: !0 }, - (i) => { - var r; - ((i.shouldUpdate = !0), - (e.local.canvasTextures[t.sublayerIndex] = i)); - const a = - null == (r = e.getPlane) ? void 0 : r.call(e); - a && - !a.textures.some( - (e) => e._samplerName === t.sampler, - ) && - a.addTexture(i); - }, - ); - } else o && this.ensureFlattenedTexture(e, t); - }) - ) - ); - if (e.isElement) - e.local.canvas && !e.htmlOnly - ? this.textureLoader.loadCanvas( - e.local.canvas, - { sampler: "uTexture", premultiplyAlpha: !0 }, - (t) => { - ((t.userData.hasStateEffects = - e.states.appear.length > 0 || - e.states.scroll.length > 0 || - e.states.hover.length > 0 || - e.states.mousemove.length > 0), - (e.preloadedCanvasTexture = t)); - }, - (e) => {}, - ) - : "image" === e.layerType && - e.src && - o && - this.ensureImageLayerTexture(e); - else { - const t = - (null == (i = null == e ? void 0 : e.texture) - ? void 0 - : i.src) || - (null == - (a = - null == (r = null == e ? void 0 : e.data) - ? void 0 - : r.texture) - ? void 0 - : a.src), - u = - (null == (s = null == e ? void 0 : e.texture) - ? void 0 - : s.sampler) || - (null == - (l = - null == (n = null == e ? void 0 : e.data) - ? void 0 - : n.texture) - ? void 0 - : l.sampler) || - "uTexture"; - o && t && this.preloadImage(t, u, null, !1); - } - }); - } - setCanvasScale() { - ((this.canvasWidth = this.element.offsetWidth), - (this.canvasHeight = this.element.offsetHeight)); - } - destroy() { - var e, t; - ((this.destroyed = !0), (this.rendering = !1), (this.isInView = !1)); - const i = Rt.findIndex((e) => e.id === this.id); - (-1 !== i && Rt.splice(i, 1), - this.layers.filter((e) => e.dispose).forEach((e) => e.dispose()), - (this.layers = []), - (null == (e = this.curtain) ? void 0 : e.gl) && - (this.curtain.dispose(), (this.curtain = null)), - this.element && - (this.element.removeAttribute("data-us-initialized"), - this.element.removeAttribute("data-scene-id"), - null == (t = this.element.querySelector("canvas")) || t.remove(), - this.element.querySelectorAll("[data-us-text]").forEach((e) => { - e.remove(); - })), - Ce(), - Rt.length || At()); - } - syncPlaneVisibility() { - this.layers - .filter((e) => !e.parentLayer) - .forEach((e) => { - const t = e.visible; - (e.getChildEffectItems().forEach((e) => { - const i = t && e.visible; - e.getPlanes().forEach((e) => { - e.visible = i; - }); - }), - e.getPlanes().forEach((e) => { - e.visible = t; - })); - }); - } - applyLayerVisibility() { - let e = !1; - (this.layers - .filter((e) => !e.parentLayer) - .forEach((t) => { - const i = t.visible; - (t.getChildEffectItems().forEach((t) => { - const r = i && t.visible; - t.getPlanes().forEach((t) => { - (t.visible !== r && (e = !0), (t.visible = r)); - }); - }), - t.getPlanes().forEach((t) => { - (t.visible !== i && (e = !0), (t.visible = i)); - }), - i && - t.isModel && - !t.local.rendererLoaded && - !t.local.rendererLoading && - ((t.local.rendererLoading = !0), - Promise.resolve(t.loadRenderer()).finally(() => { - t.local.rendererLoading = !1; - }))); - }), - e && - (this.calculateRenderOrders(), - this.createTextures(), - this.renderFrame())); - } - getBreakpointWidth() { - return this.breakpointWidth || re; - } - getCurrentBreakpoint() { - const e = this.getBreakpointWidth(); - return this.breakpoints.find((t) => e >= t.min && e <= t.max); - } - applyBreakpointValues(e = !1) { - var t; - const i = this.currentBreakpoint; - this.currentBreakpoint = this.getCurrentBreakpoint(); - const r = - e || - (null == i ? void 0 : i.name) !== - (null == (t = this.currentBreakpoint) ? void 0 : t.name); - for (let a = 0; a < this.layers.length; a++) { - const e = this.layers[a]; - r && - e.breakpoints.length && - (e.setBreakpointValues(this.getBreakpointWidth()), - this.applyBreakpointUniforms(e)); - } - return r; - } - resize() { - ((this.lastBbox = this.bbox), - (this.bbox = this.element.getBoundingClientRect()), - this.setCanvasScale()); - const e = this.applyBreakpointValues(); - if (Be(this.curtain)) { - (this.curtain.resize(), - (this.curtain.canvas.style.width = this.canvasWidth + "px"), - (this.curtain.canvas.style.height = this.canvasHeight + "px")); - for (let e = 0; e < this.curtain.planes.length; e++) { - const t = this.curtain.planes[e]; - (t.uniforms.resolution && - ((t.uniforms.resolution.value.x = this.curtain.canvas.width), - (t.uniforms.resolution.value.y = this.curtain.canvas.height)), - t.uniforms.artboardResolution && - ((t.uniforms.artboardResolution.value.x = this.canvasWidth), - (t.uniforms.artboardResolution.value.y = this.canvasHeight))); - } - } - for (let t = 0; t < this.layers.length; t++) { - const e = this.layers[t]; - e.visible && e.resize && e.resize(); - } - e && - (this.applyLayerVisibility(), - this.createTextures(), - this.renderFrame()); - } - refresh() { - ((this.initialized = !1), - this.layers.forEach((e) => { - var t, i; - (null == (t = e.states) || t.scroll.forEach((e) => e.resetState()), - null == (i = e.states) || - i.appear.forEach((t) => { - e[t.prop] = - t.endValue ?? e.local.stateEffectProps[t.prop] ?? e[t.prop]; - }), - e.breakpoints.length && - (e.setBreakpointValues(this.getBreakpointWidth()), - this.applyBreakpointUniforms(e)), - e.preloadedCanvasTexture && - (e.preloadedCanvasTexture.shouldUpdate = !0)); - }), - requestAnimationFrame(() => { - this.curtain && - (this.curtain.planes.forEach((e) => { - e._canDraw = !0; - }), - (this.scrollY = se), - this.applyLayerVisibility(), - this.resize(), - this.handlePlaneCreation()); - })); - } - getDynamicLayers() { - return this.layers.filter((e) => Ve(e)); - } - createCurtains() { - ((this.curtain = new s.Curtains({ - container: this.element, - premultipliedAlpha: !0, - antialias: !1, - autoRender: !1, - autoResize: !1, - watchScroll: !1, - renderingScale: Math.min(Math.max(0.25, this.renderingScale), 1), - production: !1, - pixelRatio: this.dpi, - })), - this.curtain.gl && - (this.curtain.onError((e) => {}), - this.curtain.onContextLost(() => { - this.curtain.restoreContext(); - }), - this.curtain.onContextRestored(() => { - this.initialized && - (this.layers.forEach((e) => { - e.preloadedCanvasTexture && - (e.preloadedCanvasTexture.shouldUpdate = !0); - }), - requestAnimationFrame(() => { - this.curtain && - (this.curtain.planes.forEach((e) => { - e._canDraw = !0; - }), - this.renderFrame()); - })); - }), - (this.scrollY = se))); - } - applyBreakpointUniforms(e) { - e.local.bpProps && - e.getPlanes().forEach((t) => { - var i, r, a; - for (let s in t.uniforms) { - const n = X(e, s, { - breakpointProps: e.local.bpProps, - baseValue: - null == - (a = - null == (r = null == (i = e.data) ? void 0 : i.uniforms) - ? void 0 - : r[s]) - ? void 0 - : a.value, - sources: ["base", "breakpoint", "runtime"], - }); - void 0 !== n.value && ze(n.value, t.uniforms[s], s); - } - }); - } - getAppearStateUniformValue(e, t) { - var i, r; - const a = - null == (r = null == (i = e.states) ? void 0 : i.appear) - ? void 0 - : r - .filter((e) => e.prop === t) - .filter((e) => { - var t, i; - return ( - !(null == (t = e.breakpoints) ? void 0 : t.length) || - e.breakpoints.includes( - null == (i = this.currentBreakpoint) ? void 0 : i.name, - ) - ); - }) - .sort( - (e, t) => (e.transition.delay || 0) - (t.transition.delay || 0), - ); - if (!(null == a ? void 0 : a.length)) return { hasValue: !1 }; - const s = [...a] - .reverse() - .find((e) => e.complete && void 0 !== e.endValue); - if (s) return { hasValue: !0, value: s.endValue }; - const n = a.find((e) => !e.complete && void 0 !== e.value); - return n ? { hasValue: !0, value: n.value } : { hasValue: !1 }; - } - renderFrame() { - var e, t; - if ( - !this.destroyed && - Be(this.curtain) && - (this.layers.forEach((e) => { - e.local.currentFrameMouseValues = null; - }), - (this.local.renderFrameId = (this.local.renderFrameId || 0) + 1), - this.handleStateEffects(), - null == (t = (e = this.curtain).needRender) || t.call(e), - this.curtain.render(), - this.local.pendingStaticRedrawFinish) - ) { - const e = this.local.pendingStaticRedrawFinish; - ((this.local.pendingStaticRedrawFinish = null), e()); - } - } - requestSceneRender() { - Be(this.curtain) && - (this.rendering || - ("function" == typeof this.curtain.requestRender - ? this.curtain.requestRender() - : this.renderFrame())); - } - requestLayerRender(e) { - if (!Be(this.curtain)) return; - const t = this.getSplitOrderedItems(); - let i = t.static.indexOf(e); - if (-1 === i) return void this.requestSceneRender(); - const r = (e) => { - var r; - const a = t.static.indexOf(e); - (-1 !== a && (i = Math.min(i, a)), - null == (r = null == e ? void 0 : e.getChildEffectItems) || - r.call(e).forEach((e) => { - const r = t.static.indexOf(e); - -1 !== r && (i = Math.min(i, r)); - })); - }; - r(e); - if ( - (e.getPlanes().some((e) => { - var t; - return null == (t = e.textures) - ? void 0 - : t.some( - (e) => "uBgTexture" === (null == e ? void 0 : e._samplerName), - ); - }) && - i > 0 && - r(t.static[i - 1]), - t.static.slice(i).forEach((e) => { - e.getPlanes().forEach((e) => { - e._canDraw = !0; - }); - }), - this.local.staticRedrawQueued) - ) - return; - this.local.staticRedrawQueued = !0; - const a = () => { - ((this.local.staticRedrawQueued = !1), this.disablePlanes()); - }; - this.rendering && !this.paused - ? (this.local.pendingStaticRedrawFinish = a) - : this.rendering - ? (this.renderFrame(), a()) - : this.renderNFrames(1, a); - } - renderNFrames(e, t) { - let i = 0; - const r = () => { - (this.renderFrame(), - i < e ? (i++, requestAnimationFrame(r)) : t && t()); - }; - this.rendering || r(); - } - setInteractiveParams(e, t) { - let i = { mouse: { disableMobile: !1, disabled: !1 } }; - (t && - t.mouse && - ("disableMobile" in t.mouse && - (i.mouse.disableMobile = t.mouse.disableMobile), - "disabled" in t.mouse && (i.mouse.disabled = t.mouse.disabled)), - e && - e.interactivity && - e.interactivity.mouse && - ("disableMobile" in e.interactivity.mouse && - (i.mouse.disableMobile = e.interactivity.mouse.disableMobile), - "disabled" in e.interactivity.mouse && - (i.mouse.disabled = e.interactivity.mouse.disabled)), - (this.interactivity = i)); - } - getSplitOrderedItems() { - let e = this.getOrderedItems(), - t = 0, - i = e[t]; - if (i) { - let r = i.parentLayer ? i.getParent() : null, - a = r && Ve(r), - s = - r && - r.effects && - r.effects.length && - r.getChildEffectItems().filter((e) => Ve(e)).length; - for (; i && !Ve(i) && !a && !s; ) - (t++, - (i = e[t]), - i && - ((r = i.parentLayer ? i.getParent() : null), - (a = r && Ve(r)), - (s = - r && - r.effects && - r.effects.length && - r.getChildEffectItems().filter((e) => Ve(e)).length))); - return { - static: this.getOrderedItems().splice(0, t), - dynamic: this.getOrderedItems().splice(t), - }; - } - return { static: [], dynamic: [] }; - } - initializePlanes(e) { - ((this.initializing = !0), - Be(this.curtain) - ? this.handleItemPlanes(() => { - (this.handlePlaneCreation(), e && e(this)); - }) - : (this.initializing = !1)); - } - getPassPlane(e, t) { - var i; - return null == (i = this.curtain) - ? void 0 - : i.planes.find( - (i) => i.userData.id === e.local.id && i.userData.passIndex === t, - ); - } - getRenderTargets() { - var e; - return null == (e = this.curtain) - ? void 0 - : e.renderTargets.filter((e) => e.userData.id); - } - getPlanes() { - var e; - return null == (e = this.curtain) - ? void 0 - : e.planes.filter((e) => "PingPongPlane" !== e.type); - } - getPlaneParams(e, t) { - var i, r, a, n, l; - let o = - (null == (i = e.data) ? void 0 : i.heightSegments) || - (null == (r = e.data) ? void 0 : r.widthSegments) - ? 500 - : 1; - const u = { - resolution: { - name: "uResolution", - type: "2f", - value: new s.Vec2(this.canvasWidth, this.canvasHeight), - }, - mousePos: { name: "uMousePos", type: "2f", value: new s.Vec2(0.5) }, - time: { name: "uTime", type: "1f", value: 0 }, - }; - e.usesPingPong && - (u.previousMousePos = { - name: "uPreviousMousePos", - type: "2f", - value: new s.Vec2(0.5), - }); - let d = e.compiledFragmentShaders[t] || e.compiledFragmentShaders[0], - c = e.compiledVertexShaders[t] ?? e.compiledVertexShaders[0]; - if ( - (e.states && - [ - ...e.states.appear, - ...e.states.scroll, - ...e.states.hover, - ...e.states.mousemove, - ].forEach((t) => { - u[t.prop] || - (t.uniformData && - ((u[t.prop] = t.uniformData), (u[t.prop].value = e[t.prop]))); - }), - null == (a = e.data) ? void 0 : a.uniforms) - ) - for (let h in e.data.uniforms) { - let t = e.data.uniforms[h]; - ((u[h] = e.data.uniforms[h]), - "Vec3" === (null == (n = t.value) ? void 0 : n.type) - ? (u[h].value = new s.Vec3(t.value._x, t.value._y, t.value._z)) - : "Vec2" === (null == (l = t.value) ? void 0 : l.type) - ? (u[h].value = new s.Vec2(t.value._x, t.value._y)) - : "object" == typeof t.value && (u[h].value = Re(t.value))); - } - return { - fragmentShader: d, - vertexShader: c, - widthSegments: o, - heightSegments: o, - texturesOptions: { floatingPoint: "half-float", premultiplyAlpha: !0 }, - uniforms: u, - }; - } - getCompositePlaneRenderOrder(e, t, i) { - const r = e.getChildEffectItems(); - if (0 === r.length) return i; - const a = r[r.length - 1], - s = t.indexOf(a); - return -1 !== s ? s + 1 : i + r.length; - } - createPlane(e, t) { - var i; - let r, a; - ((r = - e.isElement || e.isModel || e.isFlattened - ? this.getPlaneParams(e) - : this.getPlaneParams(e, t ? t.index : null)), - (r.watchScroll = !1)); - try { - if (!this.curtain.container) - throw new Error("Can't find scene container"); - let n = - (null == t ? void 0 : t.downSample) || - (0 === (null == t ? void 0 : t.index) && - (null == (i = e.data) ? void 0 : i.downSample)), - l = this.renderingScale; - if ( - (n && - ((l = "number" == typeof n ? n : 0.5), (l *= this.renderingScale)), - e.userDownsample && - "number" == typeof e.userDownsample && - (l *= e.userDownsample), - (a = new s.Plane(this.curtain, this.curtain.container, r)), - !a || !a.userData || !a.textures) - ) - throw new Error("Plane not properly initialized"); - return ( - (a.textures.length = 0), - (a.userData.id = e.local.id), - (a.userData.layerType = e.layerType), - (a.userData.type = e.type), - (a.userData.downSample = l), - a - ); - } catch (n) { - return null; - } - } - createPingPongPlane(e, t) { - var i; - const r = - "number" == typeof (null == t ? void 0 : t.index) - ? t.index - : 1 + ((null == t ? void 0 : t.length) || 0); - let a = this.getPlaneParams(e, r), - n = - null == (i = this.curtain) - ? void 0 - : i.planes.find( - (t) => - "PingPongPlane" === t.type && t.userData.id === e.local.id, - ); - if (!n) { - if ( - ((n = new s.PingPongPlane(this.curtain, this.curtain.container, a)), - !n) - ) - return; - ((n.userData.id = e.local.id), - (n.userData.pingpong = !0), - n - .onReady(() => { - (this.setInitialEffectPlaneUniforms( - n, - e, - null == e ? void 0 : e.getParent(), - t, - ), - (n.userData.isReady = !0)); - }) - .onRender(() => { - this.setEffectPlaneUniforms(n, e); - })); - } - if (n) return n; - } - createEffectPlane(e, t) { - const i = this.createPlane(e, t); - if (!i) return; - const r = e.getParent(); - if (!i || !i.userData || !i.textures) - throw new Error("Plane not properly initialized", i); - (t && - ((i.userData.passIndex = t.index), - (i.userData.length = e.data.passes.length), - (i.userData.needsPreviousFrame = t.needsPreviousFrame), - Object.entries(t).forEach(([e, t]) => { - i.uniforms[e] && (i.uniforms[e].value = t); - })), - this.setInitialEffectPlaneUniforms(i, e, r, t), - i - .onReady(() => { - i.userData.isReady = !0; - }) - .onRender(() => this.setEffectPlaneUniforms(i, e)) - .onAfterRender(() => { - const t = i.userData.needsPreviousFrame; - if (t) { - const r = i.userData.passIndex ?? 0, - a = e.local.previousFrameTargets || {}, - s = e.local.previousFrameInputTargets || {}, - n = "target" === t ? s[r] : i.target, - l = a[r]; - n && l && this.blitRenderTarget(n, l); - } - })); - } - createFlattenedPlane(e) { - var t; - const i = this.createPlane(e); - i && - (i - .onReady(() => { - (this.setInitialFlattenedPlaneUniforms(i, e), - (i.userData.isReady = !0)); - }) - .onRender(() => this.setFlattenedPlaneUniforms(i, e)), - (e.hasRemainingEffects() || (e.mask && 0 !== e.mask)) && - (e.hasRemainingEffects() && - e.getChildEffectItems().forEach((e) => { - e.getPlanes().length || this.createEffectPlanes(e); - }), - (null == (t = e.data) ? void 0 : t.compositeShader) && - this.createCompositePlane(e))); - } - createElementPlane(e) { - const t = this.createPlane(e); - t && - (e.getChildEffectItems().filter((e) => e.visible).length > 0 && - this.createCompositePlane(e), - t - .onReady(() => { - (this.setInitialElementPlaneUniforms(t, e), - (t.userData.isReady = !0)); - }) - .onRender(() => this.setElementPlaneUniforms(t, e))); - } - createCompositePlane(e) { - var t, i, r; - if (!(null == (t = e.data) ? void 0 : t.compositeShader)) return null; - const a = { - vertexShader: e.data.compositeShader.vertexShader, - fragmentShader: e.data.compositeShader.fragmentShader, - texturesOptions: { premultiplyAlpha: !0 }, - uniforms: {}, - }; - if (e.data.compositeUniforms) - for (let l in e.data.compositeUniforms) { - let t = e.data.compositeUniforms[l]; - ((a.uniforms[l] = { ...t }), - "Vec3" === (null == (i = t.value) ? void 0 : i.type) - ? (a.uniforms[l].value = new s.Vec3( - t.value._x, - t.value._y, - t.value._z, - )) - : "Vec2" === (null == (r = t.value) ? void 0 : r.type) && - (a.uniforms[l].value = new s.Vec2(t.value._x, t.value._y))); - } - const n = new s.Plane(this.curtain, this.curtain.container, a); - return n && n.userData - ? ((n.textures.length = 0), - (n.userData.id = e.local.id), - (n.userData.isComposite = !0), - n - .onReady(() => { - n.userData.isReady = !0; - }) - .onRender(() => { - this.setCompositePlaneUniforms(n, e); - }), - n) - : null; - } - setCompositePlaneUniforms(e, t) { - var i, r; - if ( - (null == e ? void 0 : e.uniforms) && - e.visible && - (e.uniforms.resolution && - ((e.uniforms.resolution.value.x = this.curtain.canvas.width), - (e.uniforms.resolution.value.y = this.curtain.canvas.height)), - e.uniforms.opacity && - (e.uniforms.opacity.value = - (null == (r = null == (i = t.local) ? void 0 : i.stateEffectProps) - ? void 0 - : r.opacity) ?? - t.opacity ?? - 1), - e.uniforms.mousePos) - ) { - t.local.currentFrameMouseValues || - (t.local.currentFrameMouseValues = this.calculateItemMouseValues(t)); - const i = t.local.currentFrameMouseValues; - i && - this.mouse.movedInView && - ((e.uniforms.mousePos.value.x = i.x), - (e.uniforms.mousePos.value.y = i.y)); - } - } - handleMediaTextures(e, t, i) { - var r, a, s; - if ( - ((( - null == (a = null == (r = t.data) ? void 0 : r.textures) - ? void 0 - : a.length - ) - ? t.data.textures - : [t.texture, null == (s = t.data) ? void 0 : s.texture].filter( - (e) => (null == e ? void 0 : e.src), - ) - ) - .filter((e) => (null == e ? void 0 : e.src)) - .forEach((r) => { - var a; - if ( - null == (a = t.compiledFragmentShaders[i.passIndex ?? 0]) - ? void 0 - : a.includes(r.sampler) - ) { - if ("video" === r.type) { - const i = - "uVideoTexture" === r.sampler && t.src ? t.src : r.src; - if (!i || e.textures.some((e) => e._samplerName === r.sampler)) - return; - const a = this.preloadVideo(i); - if (!a) return; - return void e.loadVideo( - a, - { premultipliedAlpha: !0, sampler: r.sampler }, - (i) => { - const a = null == i ? void 0 : i.source; - a && - ((a.loop = r.loop ?? t.loop ?? !0), - (a.playbackRate = r.playbackRate || t.playbackRate || 1), - a.play(), - (e.userData.textureLoaded = !0)); - }, - ); - } - this.preloadImage( - r.src, - r.sampler, - (t) => { - if (t) { - (e.textures.some((e) => e._samplerName === r.sampler) || - e.addTexture(t), - (e.userData.textureLoaded = !0)); - } - }, - !1, - ); - } - }), - "video" === t.type && t.src) - ) { - if (e.textures.some((e) => "uVideoTexture" === e._samplerName)) return; - const i = this.preloadVideo(t.src); - e.loadVideo( - i, - { premultipliedAlpha: !0, sampler: "uVideoTexture" }, - (i) => { - const r = null == i ? void 0 : i.source; - r && - ((r.loop = !t.hasOwnProperty("loop") || t.loop), - (r.playbackRate = t.playbackRate || 1), - r.play(), - (e.userData.textureLoaded = !0)); - }, - ); - } - } - handleEffectPlane(e, t, i, r) { - var a; - const s = - "passIndex" in i ? this.getPassPlane(e, i.passIndex) : e.getPlane(); - if (!s) return !1; - let n = r[t - 1], - l = - null == (a = this.curtain) - ? void 0 - : a.planes.find( - (t) => - "PingPongPlane" === t.type && t.userData.id === e.local.id, - ), - o = e.compiledFragmentShaders[i.passIndex ?? 0]; - if ( - (l && - (null == o ? void 0 : o.includes("uPingPongTexture")) && - Ze(s, "uPingPongTexture", l.getTexture()), - n ? Ze(s, "uTexture", n.getTexture()) : Ze(s, "uTexture"), - null == o ? void 0 : o.includes("uBgTexture")) - ) { - let e = r[t - (1 + i.passIndex)]; - e && Ze(s, "uBgTexture", e.getTexture()); - } - (i.needsPreviousFrame && - Ze( - s, - "uPreviousFrameTexture", - this.createPreviousFrameTarget(e, i, t, r), - ), - this.handleMediaTextures(s, e, i)); - } - handleModelPlane(e, t, i) { - var r; - const a = e.getPlane(); - let s = i[t - 1], - n = this.findPreviousLayerForMask(e, 0); - (a.textures.forEach((e) => {}), - (a.textures = []), - e.local.renderTarget - ? a.addTexture(e.local.renderTarget.getTexture()) - : s - ? Ze(a, "uTexture", s.getTexture()) - : Ze(a, "uTexture"), - (null == (r = null == n ? void 0 : n.local) ? void 0 : r.lastTarget) - ? Ze(a, "uBgTexture", n.local.lastTarget.getTexture()) - : Ze(a, "uBgTexture")); - } - createPreviousFrameTarget(e, t, i, r) { - const a = t.passIndex ?? t.index ?? 0, - n = t.downSample || 1, - l = this.curtain.canvas.width * n, - o = this.curtain.canvas.height * n; - return ( - e.local.previousFrameTargets || (e.local.previousFrameTargets = {}), - e.local.previousFrameInputTargets || - (e.local.previousFrameInputTargets = {}), - e.local.previousFrameTargets[a] || - ((e.local.previousFrameTargets[a] = new s.RenderTarget(this.curtain, { - depth: !1, - clear: !1, - maxWidth: l, - maxHeight: o, - })), - (e.local.previousFrameTargets[a].userData.isPingPong = !0), - (e.local.previousFrameTargets[a].userData.isPreviousFrame = !0)), - "target" === t.needsPreviousFrame && - void 0 !== i && - (e.local.previousFrameInputTargets[a] = r[i - (1 + t.passIndex)]), - e.local.previousFrameTargets[a].getTexture() - ); - } - findPreviousLayerForMask(e, t) { - var i; - const r = this.layers.filter((e) => !e.parentLayer), - a = r.indexOf(e); - if (a < 0) return null; - const s = a - t - 1; - if (s < 0) return null; - for (let n = Math.max(0, s); n >= 0; n--) { - const t = r[n]; - if ( - (null == t ? void 0 : t.visible) && - (null == (i = null == t ? void 0 : t.local) - ? void 0 - : i.lastTarget) && - t !== e - ) - return t; - } - return null; - } - handleFlattenedPlane(e, t, i) { - var r; - const a = e.getPlane(); - if (!a) return; - let s = i[t - 1]; - (s && Ze(a, "uBgTexture", s.getTexture()), - (null == (r = e.data) ? void 0 : r.textures) && - e.data.textures.forEach((t) => { - "canvas" === t.type - ? e.local.canvasTextures && - e.local.canvasTextures[t.sublayerIndex] && - a.addTexture(e.local.canvasTextures[t.sublayerIndex]) - : this.ensureFlattenedTexture(e, t, a); - })); - } - ensureFlattenedPlaneTextures(e, t) { - var i; - e && - (null == (i = t.data) ? void 0 : i.textures) && - t.data.textures.forEach((i) => { - var r; - if (!e.textures.some((e) => e._samplerName === i.sampler)) - if ("canvas" === i.type) { - const a = - null == (r = t.local.canvasTextures) - ? void 0 - : r[i.sublayerIndex]; - a && e.addTexture(a); - } else this.ensureFlattenedTexture(t, i, e); - }); - } - handleElementPlane(e, t, i) { - const r = e.getPlanes().find((e) => !e.userData.isComposite); - if (!r) return !1; - const a = e.getChildEffectItems().filter((e) => e.visible); - let s, - n = i[t - 1]; - if (e.mask && e.maskDepthLayer > 0) { - const t = this.findPreviousLayerForMask(e, e.maskDepthLayer ?? 0); - t && (s = t.local.lastTarget); - } - if (e.isGpuElement) - return ( - "image" === e.layerType && - (r.textures.some((e) => "uSourceImage" === e._samplerName) || - (e.local.sourceTexture - ? (r.addTexture(e.local.sourceTexture), - (e.local.imageReady = !0)) - : this.ensureImageLayerTexture(e, r))), - void ( - 0 === a.length && - n && - (Ze(r, "uBgTexture", n.getTexture()), - s && e.mask && Ze(r, "uPreviousLayerTexture", s.getTexture())) - ) - ); - if ( - (a.length || (r.textures.length = 0), - n && a.length - ? Ze(r, "uTexture", n.getTexture()) - : r && - e.preloadedCanvasTexture && - r.addTexture(e.preloadedCanvasTexture), - n) - ) { - if (a.length) { - n = i[t - (1 + a.reduce((e, t) => e + t.getPlanes().length, 0))]; - } - n && - (Ze(r, "uBgTexture", n.getTexture()), - s && e.mask && Ze(r, "uPreviousLayerTexture", s.getTexture())); - } - } - handleCompositePlane(e, t, i, r) { - const a = e.getPlanes().find((e) => e.userData.isComposite); - if (!a) return; - let s; - if (e.mask && e.maskDepthLayer > 0) { - const t = this.findPreviousLayerForMask(e, e.maskDepthLayer ?? 0); - t && (s = t.local.lastTarget); - } - const n = r[t - 1]; - n && Ze(a, "uTexture", n.getTexture()); - const l = i.findIndex( - (t) => t.userData.id === e.local.id && !t.userData.isComposite, - ), - o = l > 0 ? l - 1 : -1, - u = o >= 0 ? r[o] : null; - u && - (Ze(a, "uBgTexture", u.getTexture()), - s && e.mask && Ze(a, "uPreviousLayerTexture", s.getTexture())); - } - handleChildEffectPlane(e, t, i, r) { - var a, s, n, l, o, u, d, c, h; - const f = - "passIndex" in i ? this.getPassPlane(e, i.passIndex) : e.getPlane(), - p = e.getParent(); - if (!f || !p) return; - let m = r[t - 1], - v = - null == (a = this.curtain) - ? void 0 - : a.planes.find( - (t) => - "PingPongPlane" === t.type && t.userData.id === e.local.id, - ), - g = e.compiledFragmentShaders[i.passIndex ?? 0], - y = p.effects.filter((e) => { - if (this.layers.find((t) => t.parentLayer === e)) - return this.layers.find((t) => t.parentLayer === e); - }), - x = y.indexOf(e.parentLayer), - b = y.at(-1) === y[x], - _ = i.passIndex === i.length; - const P = p.isGpuElement || p.isFlattened; - if ( - (v && - (null == g ? void 0 : g.includes("uPingPongTexture")) && - Ze(f, "uPingPongTexture", v.getTexture()), - null == g ? void 0 : g.includes("uBgTexture")) - ) - if (x && i.length > 1) { - let e = r[t - (1 + i.length)]; - e && Ze(f, "uBgTexture", e.getTexture()); - } else if (P) { - const e = p.getPlanes().find((e) => !e.userData.isComposite); - Ze( - f, - "uBgTexture", - null == (l = null == e ? void 0 : e.target) - ? void 0 - : l.getTexture(), - ); - } else - ( - null == - (n = null == (s = p.preloadedCanvasTexture) ? void 0 : s.userData) - ? void 0 - : n.used - ) - ? f.loadCanvas( - p.local.canvas, - { sampler: "uBgTexture", premultiplyAlpha: !0 }, - (e) => { - e.shouldUpdate = p.preloadedCanvasTexture.shouldUpdate; - }, - ) - : p.preloadedCanvasTexture && - ((p.preloadedCanvasTexture._samplerName = "uBgTexture"), - f.addTexture(p.preloadedCanvasTexture)); - if (m && (x || i.passIndex)) { - if (e.isMask && (!i.length || (b && _))) - if (!P && p.preloadedCanvasTexture) - f.addTexture(p.preloadedCanvasTexture); - else { - const e = p.getPlanes().find((e) => !e.userData.isComposite); - Ze( - f, - "uMaskTexture", - null == (o = null == e ? void 0 : e.target) - ? void 0 - : o.getTexture(), - ); - } - Ze(f, "uTexture", m.getTexture()); - } else if (e.isMask) { - if (!i.length || (b && _)) - if (!P && p.preloadedCanvasTexture) - f.addTexture(p.preloadedCanvasTexture); - else { - const e = p.getPlanes().find((e) => !e.userData.isComposite); - Ze( - f, - "uMaskTexture", - null == (u = null == e ? void 0 : e.target) - ? void 0 - : u.getTexture(), - ); - } - (b && _ && !P - ? f.addTexture(p.preloadedCanvasTexture) - : m - ? Ze(f, "uTexture", m.getTexture()) - : Ze(f, "uTexture"), - (m = r[t - 2]), - m && Ze(f, "uTexture", m.getTexture())); - } else if (null == g ? void 0 : g.includes("uTexture")) - if (P) { - const e = p.getPlanes().find((e) => !e.userData.isComposite); - Ze( - f, - "uTexture", - null == (d = null == e ? void 0 : e.target) - ? void 0 - : d.getTexture(), - ); - } else - p.preloadedCanvasTexture - ? (f.addTexture(p.preloadedCanvasTexture), - p.preloadedCanvasTexture && - (p.preloadedCanvasTexture.userData.used = !0)) - : Ze(f, "uTexture", m.getTexture()); - (i.needsPreviousFrame && - Ze( - f, - "uPreviousFrameTexture", - this.createPreviousFrameTarget(e, i, t, r), - ), - "custom" === e.type && - Ze( - f, - "uCustomTexture", - null == (h = null == (c = r[t]) ? void 0 : c.getTexture) - ? void 0 - : h.call(c), - ), - this.handleMediaTextures(f, e, i)); - } - createPlanes() { - (this.getOrderedItems().forEach((e) => { - ("text" === e.layerType && e.htmlOnly) || - e.getPlanes().length || - (e.isFlattened - ? this.createFlattenedPlane(e) - : e.isElement - ? this.createElementPlane(e) - : e.isModel - ? this.createModelPlane(e) - : this.createEffectPlanes(e)); - }), - this.calculateRenderOrders()); - } - calculateRenderOrders() { - var e; - let t = -9999; - this.layers - .filter((e) => !e.parentLayer) - .forEach((e) => { - var i, r, a; - if (e.isBackground) - return void (null == (i = e.getPlane()) || i.setRenderOrder(t)); - const s = e.getPlanes().filter((e) => !e.userData.isComposite), - n = - e.isGpuElement || - (e.isFlattened && - ((null == (r = e.hasRemainingEffects) ? void 0 : r.call(e)) || - (e.mask && 0 !== e.mask))); - (n && s.forEach((e) => e.setRenderOrder(t++)), - (null == (a = e.effects) ? void 0 : a.length) && - e.getChildEffectItems().forEach((e) => { - e.visible && - e.getPlanes().forEach((e) => e.setRenderOrder(t++)); - }), - n || s.forEach((e) => e.setRenderOrder(t++))); - const l = e.getPlanes().find((e) => e.userData.isComposite); - l && l.setRenderOrder(t++); - }); - const i = this.getPlanes() - .filter((e) => e.visible) - .sort((e, t) => e.renderOrder - t.renderOrder) - .at(-1); - if (null == i ? void 0 : i.target) { - const t = i.target; - (null == (e = i.removeRenderTarget) || e.call(i), t.remove()); - } - } - createModelPlane(e) { - const t = this.createPlane(e); - t && - t - .onReady(() => { - ((t.userData.isReady = !0), - (t.userData.createdAt = performance.now())); - let i = e.userDownsample || 1, - r = this.curtain.canvas.width * i, - a = this.curtain.canvas.height * i; - e.local.renderTarget || - ((e.local.renderTarget = new s.RenderTarget(this.curtain, { - depth: !0, - maxWidth: r, - maxHeight: a, - texturesOptions: { sampler: "uTexture", premultiplyAlpha: !0 }, - })), - e.local.rendererLoaded || - !1 === e.visible || - e.local.rendererLoading || - ((e.local.rendererLoading = !0), - Promise.resolve(e.loadRenderer()).finally(() => { - e.local.rendererLoading = !1; - }))); - }) - .onRender(() => { - t.visible && - (this.setModelPlaneUniforms(t, e), - this.curtain.gl && e.renderModel()); - }); - } - createEffectPlanes(e) { - var t, i, r, a, s; - const n = e.data, - l = - "custom" === e.type - ? null == (t = e.customPasses) - ? void 0 - : t[0] - : null, - o = - "custom" === e.type - ? (null == (i = e.customPasses) ? void 0 : i.length) || - ((null == (r = n.passes) ? void 0 : r.length) || 0) + 1 - : ((null == (a = n.passes) ? void 0 : a.length) || 0) + 1, - u = !!(null == (s = e.customPasses) - ? void 0 - : s.some((e) => (null == e ? void 0 : e.pingPong))); - if (n.passes && n.passes.length) { - const t = { - index: 0, - downSample: (null == l ? void 0 : l.downSample) ?? n.downSample, - length: o, - includeBg: null == l ? void 0 : l.includeBg, - needsPreviousFrame: - (null == l ? void 0 : l.needsPreviousFrame) ?? n.needsPreviousFrame, - }; - ((null == l ? void 0 : l.pingPong) - ? this.createPingPongPlane(e, t) - : this.createEffectPlane(e, t), - n.passes.forEach((t, i) => { - const r = { - index: i + 1, - length: o, - downSample: t.downSample, - includeBg: t.includeBg, - needsPreviousFrame: t.needsPreviousFrame, - [t.prop]: t.value, - }; - t.pingPong - ? this.createPingPongPlane(e, r) - : this.createEffectPlane(e, r); - }), - e.usesPingPong && !u && this.createPingPongPlane(e, n.passes)); - } else { - const t = l - ? { - index: 0, - downSample: l.downSample ?? n.downSample, - length: o, - includeBg: l.includeBg, - needsPreviousFrame: l.needsPreviousFrame ?? n.needsPreviousFrame, - } - : null; - ((null == l ? void 0 : l.pingPong) - ? this.createPingPongPlane(e, t) - : t - ? this.createEffectPlane(e, t) - : this.createEffectPlane(e), - e.usesPingPong && !u && this.createPingPongPlane(e)); - } - } - createTextures() { - const e = this.getPlanes() - .filter((e) => e.visible) - .sort((e, t) => e.renderOrder - t.renderOrder), - t = this.getRenderTargets(), - i = e.length; - for (let r = 0; r < i; r++) { - const a = e[r]; - let s = this.layers.find((e) => e.local.id === a.userData.id); - (r < i - 1 && this.assignRenderTargetToPlane(e, t, r, s, a), - this.handleTextures(s, r, a.userData, e, t), - (s.local.lastTarget = a.target)); - } - } - resizeRenderTarget(e, t, i) { - var r, a, s; - const n = (null == (r = e._size) ? void 0 : r.width) || 0, - l = (null == (a = e._size) ? void 0 : a.height) || 0; - if (Math.abs(n - t) <= 1 && Math.abs(l - i) <= 1) return; - const o = null == (s = e.textures) ? void 0 : s[0]; - if ( - (!e._frameBuffer || !(null == o ? void 0 : o._copiedFrom)) && - ((e._size = { width: t, height: i }), - (e._maxSize = { width: t, height: i }), - (e._minSize = { width: t, height: i }), - e._frameBuffer && o) - ) { - o._size = { width: t, height: i }; - const r = this.curtain.gl; - (r.bindTexture(r.TEXTURE_2D, o._sampler.texture), - r.texImage2D( - r.TEXTURE_2D, - 0, - o._globalParameters.internalFormat, - t, - i, - 0, - o._globalParameters.format, - o._globalParameters.type, - null, - ), - this.curtain.renderer.bindFrameBuffer(e, !0), - e._depth && - e._depthBuffer && - (r.bindRenderbuffer(r.RENDERBUFFER, e._depthBuffer), - r.renderbufferStorage(r.RENDERBUFFER, r.DEPTH_COMPONENT16, t, i), - r.framebufferRenderbuffer( - r.FRAMEBUFFER, - r.DEPTH_ATTACHMENT, - r.RENDERBUFFER, - e._depthBuffer, - )), - this.curtain.renderer.bindFrameBuffer(null)); - } - } - ensureRenderTargetInitialized(e, t, i) { - e && - (t && i && this.resizeRenderTarget(e, t, i), - e._frameBuffer || - (this.curtain.renderer.bindFrameBuffer(e, !0), - this.curtain.renderer.bindFrameBuffer(null))); - } - blitRenderTarget(e, t) { - var i, r, a; - const s = null == (i = this.curtain) ? void 0 : i.gl; - if (!s || "function" != typeof s.blitFramebuffer) return; - const n = - (null == (r = e._size) ? void 0 : r.width) || - this.curtain.canvas.width, - l = - (null == (a = e._size) ? void 0 : a.height) || - this.curtain.canvas.height; - (this.ensureRenderTargetInitialized(e, n, l), - this.ensureRenderTargetInitialized(t, n, l), - (null == e ? void 0 : e._frameBuffer) && - (null == t ? void 0 : t._frameBuffer) && - (s.bindFramebuffer(s.READ_FRAMEBUFFER, e._frameBuffer), - s.bindFramebuffer(s.DRAW_FRAMEBUFFER, t._frameBuffer), - s.blitFramebuffer( - 0, - 0, - n, - l, - 0, - 0, - n, - l, - s.COLOR_BUFFER_BIT, - s.NEAREST, - ), - s.bindFramebuffer(s.READ_FRAMEBUFFER, null), - s.bindFramebuffer(s.DRAW_FRAMEBUFFER, null))); - } - assignRenderTargetToPlane(e, t, i, r, a) { - let n = this.getTextureParams(e, i, r), - l = t[i]; - (l - ? this.resizeRenderTarget(l, n.maxWidth, n.maxHeight) - : ((l = new s.RenderTarget(this.curtain, n)), (t[i] = l)), - (l.userData.id = a.userData.id), - a && a.setRenderTarget(l)); - } - handleTextures(e, t, i, r, a) { - i.isComposite - ? this.handleCompositePlane(e, t, r, a) - : e.isFlattened - ? this.handleFlattenedPlane(e, t, a) - : e.isElement - ? this.handleElementPlane(e, t, a) - : e.isModel - ? this.handleModelPlane(e, t, a) - : e.parentLayer - ? this.handleChildEffectPlane(e, t, i, a) - : this.handleEffectPlane(e, t, i, a); - } - handleItemPlanes(e) { - (this.createPlanes(), - this.syncPlaneVisibility(), - this.createTextures(), - this.checkIfReady(e)); - } - checkIfReady(e) { - const t = () => { - var i; - let r = !1; - const a = null == (i = this.curtain) ? void 0 : i.planes; - if (a) { - for (let e = 0; e < a.length; e++) - if (!a[e].userData.isReady) { - r = !0; - break; - } - r ? (this.renderFrame(), requestAnimationFrame(t)) : e(); - } - }; - t(); - } - setModelPlaneUniforms(e, t) { - var i, r; - ((e.uniforms.resolution.value.x = this.curtain.canvas.width), - (e.uniforms.resolution.value.y = this.curtain.canvas.height), - t.local.currentFrameMouseValues || - (t.local.currentFrameMouseValues = this.calculateItemMouseValues(t))); - const a = t.local.currentFrameMouseValues; - (a && !t.local.mouse && (t.local.mouse = { x: 0.5, y: 0.5 }), - a && ((t.local.mouse.x = a.x), (t.local.mouse.y = a.y)), - e.uniforms.opacity && - (e.uniforms.opacity.value = t.local.modelLoaded - ? ((null == - (r = null == (i = t.local) ? void 0 : i.stateEffectProps) - ? void 0 - : r.opacity) ?? t.opacity) - : 0)); - } - setInitialEffectPlaneUniforms(e, t, i, r) { - var a; - if (!e.userData.initialUniformsSet || !e.userData.isReady) { - for (let i in e.uniforms) - (null == (a = t.states) - ? void 0 - : a.scroll.some((e) => e.prop === i)) || - (t.local.bpProps && i in t.local.bpProps - ? ze(t.local.bpProps[i], e.uniforms[i], i) - : i in t && ze(t[i], e.uniforms[i], i)); - (i && - r && - r.index < r.length - 1 && - e.uniforms.isMask && - (e.uniforms.isMask.value = 0), - i && - t.isMask && - !t.mouseMomentum && - (t.mouseMomentum = i.mouseMomentum), - (e.uniforms.resolution.value.x = this.curtain.canvas.width), - (e.uniforms.resolution.value.y = this.curtain.canvas.height), - (e.userData.initialUniformsSet = !0)); - } - } - handleStateEffects() { - this.layers.forEach((e) => { - const t = e.parentLayer ? e.getParent() : null; - (t ? t.visible : e.visible) && e.updateStateEffects(); - }); - } - setInitialFlattenedPlaneUniforms(e, t) { - var i, r; - (e.uniforms.resolution && - this.curtain.canvas && - ((e.uniforms.resolution.value.x = this.curtain.canvas.width), - (e.uniforms.resolution.value.y = this.curtain.canvas.height)), - e.uniforms.artboardResolution && - ((e.uniforms.artboardResolution.value.x = this.canvasWidth), - (e.uniforms.artboardResolution.value.y = this.canvasHeight))); - for (let a in e.uniforms) - (null == (i = t.states) - ? void 0 - : i.scroll.some((e) => e.prop === a)) || - (null == (r = t.states) - ? void 0 - : r.appear.some((e) => e.prop === a && !e.complete)) || - (t.local.bpProps && a in t.local.bpProps - ? ze(t.local.bpProps[a], e.uniforms[a], a) - : a in t && ze(t[a], e.uniforms[a], a)); - } - setFlattenedPlaneUniforms(e, t) { - var i, r, a, s, n; - if (!e.visible) return; - if ( - (this.ensureFlattenedPlaneTextures(e, t), - t.local.modelInstances && - Object.entries(t.local.modelInstances).forEach(([i, r]) => { - if (!r || !r.local) return; - const a = - e.uniforms[`L${i}_elemOpacity`] || e.uniforms[`L${i}_opacity`]; - if (a && 0 === a.value) return; - const s = `L${i}_`, - n = {}; - if (t.local.bpProps) - for (const e in t.local.bpProps) - e.startsWith(s) && (n[e.slice(s.length)] = t.local.bpProps[e]); - if (t.local.stateEffectProps) - for (const e in t.local.stateEffectProps) - e.startsWith(s) && - (n[e.slice(s.length)] = t.local.stateEffectProps[e]); - r.local.stateEffectProps = n; - const l = this.calculateItemMouseValues(r); - (l && !r.local.mouse && (r.local.mouse = { x: 0.5, y: 0.5 }), - l && ((r.local.mouse.x = l.x), (r.local.mouse.y = l.y)), - r.renderModel()); - }), - (null == (i = t.local.stateEffectProps) ? void 0 : i.playbackRate) && - e.videos.at(-1) && - (e.videos.at(-1).playbackRate = - t.local.stateEffectProps.playbackRate), - e.uniforms.mousePos && this.mouse.movedInView) - ) { - t.local.currentFrameMouseValues || - (t.local.currentFrameMouseValues = this.calculateItemMouseValues(t)); - const i = t.local.currentFrameMouseValues; - i && - ((e.uniforms.mousePos.value.x = i.x), - (e.uniforms.mousePos.value.y = i.y)); - } - const l = (t) => { - const i = t.match(/^L(\d+)_/); - if (!i) return !1; - const r = i[1], - a = e.uniforms[`L${r}_elemOpacity`] || e.uniforms[`L${r}_opacity`]; - return a && 0 === a.value; - }; - if ( - ((null == (a = null == (r = t.data) ? void 0 : r.timeUniforms) - ? void 0 - : a.length) && - t.data.timeUniforms.forEach(({ key: i, speed: r, animating: a }) => { - var s; - if (!l(i) && e.uniforms[i] && !1 !== a) { - const a = i.replace(/_time$/, "_speed"), - n = - (null == (s = t.local.stateEffectProps) ? void 0 : s[a]) ?? - t[a] ?? - r ?? - 1; - e.uniforms[i].value += (60 * n) / this.fps; - } - }), - null == (n = null == (s = t.data) ? void 0 : s.mouseUniforms) - ? void 0 - : n.length) - ) { - const i = this.bbox.width / 2, - r = this.bbox.height / 2, - a = this.mouse.pos.x, - s = this.mouse.pos.y; - (t.local.mouseStates || (t.local.mouseStates = {}), - t.data.mouseUniforms.forEach( - ({ key: n, momentum: o, spring: u, trackAxes: d }) => { - if (!e.uniforms[n]) return; - if (l(n)) return; - const c = d || "xy", - h = "x" === c || "xy" === c, - f = "y" === c || "xy" === c, - p = u || 0; - if (!t.local.mouseStates[n]) - return ( - (t.local.mouseStates[n] = { - x: h ? a / i : 0.5, - y: f ? 1 - s / r : 0.5, - vx: 0, - vy: 0, - }), - (e.uniforms[n].value.x = t.local.mouseStates[n].x), - void (e.uniforms[n].value.y = t.local.mouseStates[n].y) - ); - const m = t.local.mouseStates[n], - v = m.x * i, - g = (1 - m.y) * r; - if (p > 0) { - if (h) { - const e = Ie(v, a, m.vx, o, p); - ((m.x = e.value / i), (m.vx = e.velocity)); - } else m.x = 0.5; - if (f) { - const e = Ie(g, s, m.vy, o, p); - ((m.y = 1 - e.value / r), (m.vy = e.velocity)); - } else m.y = 0.5; - } else - ((m.x = h ? Me(a, v, 2 * o) / i : 0.5), - (m.y = f ? 1 - Me(s, g, 2 * o) / r : 0.5)); - ((e.uniforms[n].value.x = m.x), (e.uniforms[n].value.y = m.y)); - }, - )); - } - } - setInitialElementPlaneUniforms(e, t) { - var i; - ((e.uniforms.resolution.value.x = this.curtain.canvas.width), - (e.uniforms.resolution.value.y = this.curtain.canvas.height), - e.uniforms.artboardResolution && - ((e.uniforms.artboardResolution.value.x = this.canvasWidth), - (e.uniforms.artboardResolution.value.y = this.canvasHeight))); - for (let r in e.uniforms) { - const a = this.getAppearStateUniformValue(t, r); - a.hasValue - ? ze(a.value, e.uniforms[r], r) - : t.local.bpProps && r in t.local.bpProps - ? ze(t.local.bpProps[r], e.uniforms[r], r) - : r in t && - ze( - (null == (i = t.local.stateEffectProps) ? void 0 : i[r]) ?? - t[r], - e.uniforms[r], - r, - ); - } - (We(t, e, "fill"), We(t, e, "stroke")); - } - setElementPlaneUniforms(e, t) { - if ( - e.visible && - (We(t, e, "fill"), - We(t, e, "stroke"), - e.uniforms.resolution && - ((e.uniforms.resolution.value.x = this.curtain.canvas.width), - (e.uniforms.resolution.value.y = this.curtain.canvas.height)), - e.uniforms.artboardResolution && - ((e.uniforms.artboardResolution.value.x = this.canvasWidth), - (e.uniforms.artboardResolution.value.y = this.canvasHeight)), - e.uniforms.mousePos) - ) { - t.local.currentFrameMouseValues || - (t.local.currentFrameMouseValues = this.calculateItemMouseValues(t)); - const i = t.local.currentFrameMouseValues; - !this.mouse.movedInView || - (e.uniforms.mousePos.value.x === i.x && - e.uniforms.mousePos.value.y === i.y) || - ((e.uniforms.mousePos.value.x = i.x), - (e.uniforms.mousePos.value.y = i.y)); - } - } - calculateItemMouseValues(e) { - if (!this.mouse.movedInView) return null; - const t = this.bbox.width / 2, - i = this.bbox.height / 2, - r = this.getMousePosWithMomentum(e, t, i); - return ( - e.local.mouseValuePool || (e.local.mouseValuePool = new s.Vec2(0.5)), - (e.local.mouseValuePool.x = r.x), - (e.local.mouseValuePool.y = r.y), - e.local.mouseValuePool - ); - } - getMousePosWithMomentum(e, t, i) { - let r = this.mouse.pos.x, - a = this.mouse.pos.y, - s = e.trackAxes || "xy", - n = "x" === s || "xy" === s, - l = "y" === s || "xy" === s; - const o = e.mouseMomentum || 0, - u = e.mouseSpring || 0; - let d = r / t, - c = 1 - a / i; - if (!o && !u) return { x: n ? d : 0.5, y: l ? c : 0.5 }; - if (!e.local.lastMousePos) - return ( - (e.local.lastMousePos = { x: n ? d : 0.5, y: l ? c : 0.5 }), - e.local.lastMousePos - ); - const h = e.local.lastMousePos.x * t, - f = (1 - e.local.lastMousePos.y) * i; - if (u > 0) { - if ( - (e.local.mouseVelocity || (e.local.mouseVelocity = { x: 0, y: 0 }), n) - ) { - const i = Ie(h, r, e.local.mouseVelocity.x, o, u); - ((r = i.value), - (e.local.mouseVelocity.x = i.velocity), - (e.local.lastMousePos.x = r / t)); - } else e.local.lastMousePos.x = 0.5; - if (l) { - const t = Ie(f, a, e.local.mouseVelocity.y, o, u); - ((a = t.value), - (e.local.mouseVelocity.y = t.velocity), - (e.local.lastMousePos.y = 1 - a / i)); - } else e.local.lastMousePos.y = 0.5; - return e.local.lastMousePos; - } - const p = Math.abs(r - h), - m = Math.abs(a - f); - return ( - (p < ce && m < ce) || - (n - ? ((r = Me(r, h, 2 * o)), (e.local.lastMousePos.x = r / t)) - : (e.local.lastMousePos.x = 0.5), - l - ? ((a = Me(a, f, 2 * o)), (e.local.lastMousePos.y = 1 - a / i)) - : (e.local.lastMousePos.y = 0.5)), - e.local.lastMousePos - ); - } - setEffectPlaneUniforms(e, t) { - var i, r, a, s; - if (!e.visible) return; - let n = - (null == (i = t.local.stateEffectProps) ? void 0 : i.speed) ?? - t.speed ?? - 1; - if (t.animating && e.uniforms.time) { - const t = this.local.renderFrameId || 0; - e.userData.lastTimeUpdateFrameId !== t && - ((e.uniforms.time.value += (60 * n) / this.fps), - (e.userData.lastTimeUpdateFrameId = t)); - } - if ( - ((null == (r = t.local.stateEffectProps) ? void 0 : r.playbackRate) && - e.videos.at(-1) && - (e.videos.at(-1).playbackRate = - t.local.stateEffectProps.playbackRate), - Se() && - (null == (s = null == (a = this.interactivity) ? void 0 : a.mouse) - ? void 0 - : s.disableMobile)) - ) - return !1; - if (!this.mouse.movedInView) return; - t.local.currentFrameMouseValues || - (t.local.currentFrameMouseValues = this.calculateItemMouseValues(t)); - const l = t.local.currentFrameMouseValues; - l && - (e.uniforms.previousMousePos && - (this.mouse.ticks > 16 - ? ((e.uniforms.previousMousePos.value.x = - e.uniforms.mousePos.value.x), - (e.uniforms.previousMousePos.value.y = - e.uniforms.mousePos.value.y)) - : ((e.uniforms.previousMousePos.value.x = l.x), - (e.uniforms.previousMousePos.value.y = l.y))), - e.uniforms.mousePos && - !l.equals(e.uniforms.mousePos.value) && - ((e.uniforms.mousePos.value.x = l.x), - (e.uniforms.mousePos.value.y = l.y)), - this.mouse.ticks++); - } - getOrderedItems() { - let e = []; - return ( - this.layers - .filter((e) => !e.parentLayer) - .forEach((t) => { - (t.effects && - t.effects.length && - e.push(...t.getChildEffectItems()), - e.push(t)); - }), - e - ); - } - getTextureParams(e, t, i) { - var r; - const a = e[t]; - let s = 1; - a.userData.downSample && - (s = - "number" == typeof a.userData.downSample - ? a.userData.downSample - : 0.5); - return { - maxWidth: this.curtain.canvas.width * s, - maxHeight: this.curtain.canvas.height * s, - depth: null == (r = null == i ? void 0 : i.data) ? void 0 : r.depth, - }; - } - handlePlaneCreation() { - ((this.initialized = !0), - (this.initializing = !1), - this.rendering || this.renderNFrames(2), - this.waitForAssetsAndDisablePlanes(), - Ce()); - } - waitForAssetsAndDisablePlanes() { - var e, t; - (this.local.preloadedImages && - Object.values(this.local.preloadedImages).some((e) => e.loading)) || - this.layers.some( - (e) => - !1 !== e.visible && - ((e.isModel && !e.local.modelLoaded) || - ("image" === e.layerType && !e.local.imageReady) || - ("text" === e.layerType && !e.local.loaded) || - (e.isFlattened && - (!e.areTextAssetsReady() || - !e.areImageAssetsReady() || - !e.areModelAssetsReady()))), - ) - ? setTimeout(() => this.waitForAssetsAndDisablePlanes(), 32) - : (this.layers - .filter((e) => e.preloadedCanvasTexture) - .forEach((e) => { - e.preloadedCanvasTexture.shouldUpdate = !0; - }), - this.layers - .filter((e) => e.isFlattened) - .forEach((e) => { - Object.values(e.local.canvasTextures || {}).forEach((e) => { - e && (e.shouldUpdate = !0); - }); - }), - this.curtain && - this.curtain.planes.forEach((e) => { - (e.videos.forEach((e) => { - e.currentTime = 0; - }), - (e._canDraw = !0)); - }), - null == (t = null == (e = this.variables) ? void 0 : e.applyAll) || - t.call(e), - this.renderFrame(), - this.layers - .filter((e) => e.preloadedCanvasTexture) - .forEach((e) => { - e.preloadedCanvasTexture.shouldUpdate = - e.preloadedCanvasTexture.userData.hasStateEffects || !1; - }), - this.layers - .filter((e) => e.isFlattened) - .forEach((e) => { - Object.values(e.local.canvasTextures || {}).forEach((e) => { - e && (e.shouldUpdate = !1); - }); - }), - setTimeout(() => this.disablePlanes(), 16)); - } - disablePlanes() { - const e = this.getSplitOrderedItems(); - e.dynamic.length || e.static.pop(); - for (const t of e.static) - t.getPlanes().forEach((e) => { - e._canDraw = !1; - }); - } - } - function It(e, t, i) { - e.addEventListener(t, i, { passive: !0 }); - } - function Ft(e, t, i) { - e.removeEventListener(t, i); - } - function St() { - (It(window, "scroll", Tt), - Se() ? It(window, "touchmove", kt) : It(window, "mousemove", kt), - It(window, "routeChange", De), - It(document, "mouseleave", wt), - (ee = (function (e, t) { - let i; - return function (...r) { - (clearTimeout(i), - (i = setTimeout(() => { - e.apply(this, r); - }, t))); - }; - })(gt, 16)), - Se() ? It(window, "orientationchange", ee) : It(window, "resize", ee), - It(document, Q, vt), - (te = !0)); - } - function At() { - (Ft(window, "mousemove", kt), - Ft(window, "touchmove", kt), - Ft(window, "scroll", Tt), - Ft(window, "routeChange", De), - Ft(document, "mouseleave", wt), - ee && (Ft(window, "resize", ee), Ft(window, "orientationchange", ee)), - Ft(document, Q, vt), - (te = !1)); - } - function Vt() { - try { - return !!document.createElement("canvas").getContext("webgl2"); - } catch (e) { - return !1; - } - } - function Lt(e) { - let t = e.projectId ? e.projectId.split("?")[0] : null, - i = e.projectId ? e.projectId.split("?")[1] : null; - return new Promise((r, a) => { - (function (e, t, i, r, a) { - let s; - if (i) { - s = i; - const e = document.getElementById(i); - if (e) - try { - let t = JSON.parse(e.innerText); - return (null == t ? void 0 : t.options) && - ((null == t ? void 0 : t.layers) || - (null == t ? void 0 : t.history)) - ? Promise.resolve(t) - : (r(new Error(`Did not find valid JSON inside ${i}`)), - Promise.reject()); - } catch (n) { - return ( - r(new Error(`Error parsing JSON from ${i}: ${n.message}`)), - Promise.reject() - ); - } - } else { - let i = "https://storage.googleapis.com/unicornstudio-production"; - (a || (null == t ? void 0 : t.includes("production=true")) - ? ((i = "https://assets.unicorn.studio"), (t = `v=${Date.now()}`)) - : (null == t ? void 0 : t.includes("update=")) || - (t = `v=${Date.now()}`), - (s = `${i}/embeds/${e}${t ? "?" + t : ""}`)); - } - return fetch(s) - .then((e) => e.json()) - .then((e) => e) - .catch((e) => {}); - })(t, i, e.filePath, a, e.production) - .then((i) => { - var s; - (i && (i.layers || i.history) && i.options) || - a(new Error(`Error fetching data for project id '${e.projectId}'`)); - const n = i.options || {}, - l = - ((o = e.element), - ( - "object" == typeof HTMLElement - ? o instanceof HTMLElement - : o && - "object" == typeof o && - null !== o && - 1 === o.nodeType && - "string" == typeof o.nodeName - ) - ? e.element - : document.getElementById(e.elementId)); - var o; - if (!l) - return void a( - new Error( - `Couldn't find an element with id '${e.elementId}' on the page.`, - ), - ); - const u = we(); - l.setAttribute("data-scene-id", u); - let d = e.scale || n.scale || 1, - c = e.dpi || n.dpi || Math.min(1.5, window.devicePixelRatio); - const h = Number.isFinite(Number(e.breakpointWidth)) - ? Number(e.breakpointWidth) - : null, - f = (function (e, t, i, r) { - const a = r ? { ...i, modules: r } : i, - s = []; - return ( - e.forEach((e) => { - switch (e.layerType) { - case "text": - s.push(new mt(e, t, a).unpackage()); - break; - case "image": - s.push(new ft(e, t, a).unpackage()); - break; - case "model": - s.push(new pt(e, t, a).unpackage()); - break; - case "shape": - s.push(new dt(e, t, a).unpackage()); - break; - case "effect": - s.push(new ct(e, t, a).unpackage()); - break; - case "flattened": { - const i = new ht(e, t, a).unpackage(); - (s.push(i), - i.getChildEffectItems().forEach((e) => { - s.push(e); - })); - break; - } - } - }), - s - ); - })( - i.layers || i.history, - u, - (function (e, t, i, r = null) { - return { - canvasWidth: e.offsetWidth, - canvasHeight: e.offsetHeight, - scale: t, - dpi: i, - element: e, - breakpointWidth: r, - }; - })(l, d, c, h), - i.modules, - ); - if (!Vt()) { - const e = (function ({ id: e, element: t, layers: i }) { - return { - id: e, - element: t, - layers: i, - destroyed: !1, - fallbackOnly: !0, - getMouse: () => ({ x: 0.5, y: 0.5, inBounds: !1, moved: !1 }), - getDynamicLayers: () => [], - destroy() { - ((this.destroyed = !0), - this.element && - (this.element.removeAttribute("data-us-initialized"), - this.element.removeAttribute("data-scene-id"), - this.element - .querySelectorAll("[data-us-text]") - .forEach((e) => { - e.remove(); - }))); - }, - }; - })({ id: u, element: l, layers: f }); - return ( - (function (e, t) { - e.forEach((e) => { - var i; - ("text" === e.layerType && Le(e, t), - Object.values( - (null == (i = e.local) ? void 0 : i.textInstances) || {}, - ).forEach((e) => { - Le(e, t); - })); - }); - })(f, l), - Rt.push(e), - void r(e) - ); - } - const p = e.initialPreset || Ge(), - m = new Mt({ - id: u, - fps: e.fps || n.fps || 60, - dpi: c, - name: n.name, - projectId: t || e.filePath.split(".")[0], - renderingScale: d, - element: l, - lazyLoad: e.lazyLoad, - fixed: e.fixed, - width: e.width, - height: e.height, - breakpoints: e.breakpoints || n.breakpoints, - breakpointWidth: h, - initialVariables: e.initialVariables, - initialPreset: p, - editMetadata: { - designId: i.designId, - canvasId: i.canvasId, - designName: i.designName || i.projectName, - sceneName: i.sceneName, - }, - }); - (null == (s = m.curtain) ? void 0 : s.canvas) && - ((m.curtain.canvas.innerText = e.altText || ""), - m.curtain.canvas.setAttribute( - "aria-label", - e.ariaLabel || "Unicorn Studio Scene", - ), - m.curtain.canvas.setAttribute("role", "img")); - let v = n[Te("ZnJlZVBsYW4=")]; - (!v && - n[Te("aW5jbHVkZUxvZ28=")] && - (function (e, t) { - const i = document.createElement("a"); - ((i.href = "https://unicorn.studio?utm_source=public-url"), - (i.style = - "position: absolute; display: flex; bottom: 30px; left: 0; width: 190px; margin: 0 auto; right: 0rem; padding: 10px; border-radius: 6px; background-color: rgba(255, 255, 255, 1); box-shadow: 0 3px 9px 0 rgba(0, 0, 0, .2); z-index: 99999999; box-sizing: border-box;"), - (i.target = "_blank")); - const r = document.createElement("img"); - ((r.src = Te( - "aHR0cHM6Ly9hc3NldHMudW5pY29ybi5zdHVkaW8vbWVkaWEvbWFkZV9pbl91c19zbWFsbF93ZWIuc3Zn", - )), - (r.alt = Te("TWFkZSB3aXRoIHVuaWNvcm4uc3R1ZGlv")), - (r.style = "width: 170px; height: auto;"), - i.appendChild(r), - t.appendChild(i)); - })(0, l), - Rt.push(m), - (m.layers = f), - m.applyBreakpointValues(!0), - m.setupVariables(i.variables, e.initialVariables, p), - m.preloadTextures(), - m.setInteractiveParams(e, n), - (m.isInView = m.isFixed || yt(m.element, m.bbox, 50)), - (m.lazyLoad && !m.isInView) || m.initializePlanes(), - te || St(), - Qe(l, m, e), - r(m)); - }) - .catch((e) => { - a(e); - }); - }); - } - ((e.addScene = Lt), - (e.destroy = function () { - (Rt.forEach((e) => { - e.destroy(); - }), - (Rt.length = 0), - At()); - }), - (e.init = function () { - return ( - Vt(), - new Promise((e, t) => { - const i = [ - ...document.querySelectorAll( - "[data-us-project], [data-us-project-src]", - ), - ].filter((e) => !e.getAttribute("data-us-initialized")), - r = - "undefined" != typeof window && window.requestIdleCallback - ? window.requestIdleCallback - : (e) => setTimeout(e, 0); - i.length - ? Promise.all( - i.map( - (e) => ( - e.setAttribute("data-us-initialized", !0), - new Promise((t, i) => { - r(() => { - const r = Ae(e, "data-us-project"), - a = Ae(e, "data-us-project-src"), - s = Ae(e, "data-us-disablemobile"), - n = Ae(e, "data-us-disablemouse"); - Lt({ - projectId: a ? null : r, - filePath: a, - element: e, - dpi: +Ae(e, "data-us-dpi"), - scale: +Ae(e, "data-us-scale"), - production: Ae(e, "data-us-production"), - fps: +Ae(e, "data-us-fps"), - lazyLoad: Ae(e, "data-us-lazyload"), - altText: Ae(e, "data-us-alttext"), - ariaLabel: Ae(e, "data-us-arialabel"), - fixed: Ae(e, "data-us-fixed"), - initialVariables: $e(Ae(e, "data-us-vars")), - initialPreset: Ae(e, "data-us-preset") || Ge(), - interactivity: - s || n - ? { mouse: { disableMobile: s, disabled: n } } - : null, - }) - .then((e) => { - t(e); - }) - .catch((t) => { - (e.removeAttribute("data-us-initialized"), i(t)); - }); - }); - }) - ), - ), - ) - .then(() => e(Rt)) - .catch(t) - : e(Rt); - }) - ); - }), - (e.scenes = Rt), - (e.setScroll = function (e) { - const t = ge(e); - null !== t && ((ae = t), xe(t), Pt()); - }), - (e.unbindEvents = At), - (e.useNativeScroll = function () { - ((ae = null), xe(), Pt()); - }), - (e.version = ve), - Object.defineProperty(e, Symbol.toStringTag, { value: "Module" })); -}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).UnicornStudio={})}(this,function(e){"use strict";var t=Object.defineProperty,i=(e,i,r)=>((e,i,r)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[i]=r)(e,"symbol"!=typeof i?i+"":i,r),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},a={exports:{}};!function(e,t){function i(e,t,r){return i="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=n(e)););return e}(e,t);if(r){var a=Object.getOwnPropertyDescriptor(r,t);return a.get?a.get.call(i):a.value}},i(e,t,r||e)}function a(e,t){return(a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function s(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var i,r=n(e);if(t){var a=n(this).constructor;i=Reflect.construct(r,arguments,a)}else i=r.apply(this,arguments);return function(e,t){if(t&&("object"===m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,i)}}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||o(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){if(e){if("string"==typeof e)return u(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?u(e,t):void 0}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,r=new Array(t);i1&&void 0!==arguments[1]?arguments[1]:{};f(this,e),this.curtains=t,this.gl=null==t?void 0:t.gl,this.type="Texture",this.userData={},this.shouldUpdate=!1,this._samplerName=s.sampler||"uTexture",this._source=s.source||null,this.source=this._source,this.sourceType=this._source?"source":s.fromTexture?"copy":"empty",this._copiedFrom=null,this._videoFrameCallbackID=null,this._videoFrameCallback=null,this._videoFallbackRAF=null,this._sourceLoaded=!1,this._uploaded=!1,this._canDraw=!1,this._size={width:1,height:1},this._globalParameters=this.gl?(r=this.gl,a=s.floatingPoint,r instanceof WebGL2RenderingContext?"half-float"===a?{internalFormat:r.RGBA16F,format:r.RGBA,type:r.HALF_FLOAT}:"float"===a?{internalFormat:r.RGBA32F,format:r.RGBA,type:r.FLOAT}:{internalFormat:r.RGBA8,format:r.RGBA,type:r.UNSIGNED_BYTE}:{internalFormat:r.RGBA,format:r.RGBA,type:r.UNSIGNED_BYTE}):{internalFormat:0,format:0,type:0},this._sampler={texture:this.gl?this.gl.createTexture():null},this._premultiplyAlpha=null!==(i=s.premultiplyAlpha)&&void 0!==i&&i,this.gl&&this._sampler.texture&&this._initState(),s.fromTexture?this.copy(s.fromTexture):this._source?this.setSource(this._source):this._uploadFallback()}return p(e,[{key:"_bind",value:function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this._sampler.texture)}},{key:"_initState",value:function(){var e=this.gl;this._bind(),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha?1:0),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),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.bindTexture(e.TEXTURE_2D,null)}},{key:"_uploadFallback",value:function(){if(this.gl&&this._sampler.texture&&!this._copiedFrom){var e=this.gl;this._bind(),this._globalParameters.type===e.UNSIGNED_BYTE?e.texImage2D(e.TEXTURE_2D,0,this._globalParameters.internalFormat,1,1,0,this._globalParameters.format,this._globalParameters.type,t):e.texImage2D(e.TEXTURE_2D,0,this._globalParameters.internalFormat,1,1,0,this._globalParameters.format,this._globalParameters.type,null),this._uploaded=!0,this._canDraw=!0,e.bindTexture(e.TEXTURE_2D,null)}}},{key:"_scheduleVideoRender",value:function(){this.curtains&&!this._copiedFrom&&(this.shouldUpdate=!0,"function"==typeof this.curtains.requestRender?this.curtains.requestRender():"function"==typeof this.curtains.render&&this.curtains.render())}},{key:"_stopVideoFrameUpdates",value:function(){var e=this._source;e&&e instanceof HTMLVideoElement&&(null!==this._videoFrameCallbackID&&"function"==typeof e.cancelVideoFrameCallback&&e.cancelVideoFrameCallback(this._videoFrameCallbackID),this._videoFrameCallbackID=null,this._videoFrameCallback=null,null!==this._videoFallbackRAF&&(cancelAnimationFrame(this._videoFallbackRAF),this._videoFallbackRAF=null))}},{key:"_startVideoFrameUpdates",value:function(){var e=this,t=this._source;t&&t instanceof HTMLVideoElement&&!this._copiedFrom&&(this._stopVideoFrameUpdates(),"function"==typeof t.requestVideoFrameCallback?(this._videoFrameCallback=function(){e._scheduleVideoRender(),e._videoFrameCallbackID=t.requestVideoFrameCallback(e._videoFrameCallback)},this._videoFrameCallbackID=t.requestVideoFrameCallback(this._videoFrameCallback)):this._videoFallbackRAF=requestAnimationFrame(function i(){e._source===t?(!t.paused&&!t.ended&&t.readyState>=t.HAVE_CURRENT_DATA&&e._scheduleVideoRender(),e._videoFallbackRAF=requestAnimationFrame(i)):e._videoFallbackRAF=null}))}},{key:"_uploadSource",value:function(e){if(this.gl&&this._sampler.texture&&!this._copiedFrom){var t=this.gl,i=e.videoWidth||e.naturalWidth||e.width||1,r=e.videoHeight||e.naturalHeight||e.height||1;this._size={width:i,height:r},this._bind(),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha?1:0),t instanceof WebGL2RenderingContext?t.texImage2D(t.TEXTURE_2D,0,this._globalParameters.internalFormat,this._globalParameters.format,this._globalParameters.type,e):t.texImage2D(t.TEXTURE_2D,0,this._globalParameters.format,this._globalParameters.format,this._globalParameters.type,e),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,0),this._sourceLoaded=!0,this._uploaded=!0,this._canDraw=!0,this.sourceType=e instanceof HTMLVideoElement?"video":e instanceof HTMLCanvasElement?"canvas":"image",t.bindTexture(t.TEXTURE_2D,null)}}},{key:"setSource",value:function(e){return this._stopVideoFrameUpdates(),this._source=e,this.source=e,this._copiedFrom=null,this._uploadSource(e),e instanceof HTMLVideoElement&&this._startVideoFrameUpdates(),this}},{key:"copy",value:function(e){return e?(this._stopVideoFrameUpdates(),this._source=e._source||null,this.source=this._source,this._copiedFrom=e,this.sourceType=e.sourceType||"copy",this._sourceLoaded=!!e._sourceLoaded,this._uploaded=!!e._uploaded,this._canDraw=!1!==e._canDraw,this._sampler.texture=e._sampler.texture,this._size=c({},e._size),this._globalParameters=c({},e._globalParameters),this.shouldUpdate=!!e.shouldUpdate,this):this}},{key:"update",value:function(){this._source&&!this._copiedFrom&&this._uploadSource(this._source)}},{key:"needUpdate",value:function(){this._copiedFrom||(this.update(),this.curtains&&"function"==typeof this.curtains.requestRender?this.curtains.requestRender():this.curtains&&"function"==typeof this.curtains.render&&this.curtains.render())}},{key:"remove",value:function(){this._stopVideoFrameUpdates(),this.gl&&this._sampler.texture&&!this._copiedFrom&&this.gl.deleteTexture(this._sampler.texture)}}]),e}(),d=function(){function e(t){var i,r,a,s,n,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};f(this,e),this.curtains=t,this.gl=null==t?void 0:t.gl,this.type="RenderTarget",this.userData={},this._depth=!!l.depth,this._clear=void 0===l.clear||!!l.clear;var o=(null==t||null===(i=t.canvas)||void 0===i?void 0:i.width)||1,d=(null==t||null===(r=t.canvas)||void 0===r?void 0:r.height)||1;this._scaleWithCanvas=void 0===l.scaleWithCanvas||!!l.scaleWithCanvas,this._widthScale=void 0!==l.maxWidth&&o>0?l.maxWidth/o:null,this._heightScale=void 0!==l.maxHeight&&d>0?l.maxHeight/d:null,this._baseMaxSize={width:Math.max(1,Math.round(l.maxWidth||o)),height:Math.max(1,Math.round(l.maxHeight||d))},this._minSize={width:Math.max(1,Math.round(l.minWidth||1)),height:Math.max(1,Math.round(l.minHeight||1))},this._maxSize={width:this._baseMaxSize.width,height:this._baseMaxSize.height},this._size={width:this._baseMaxSize.width,height:this._baseMaxSize.height},this._setSize(),this.index=-1,this._frameBuffer=null,this._depthBuffer=null;var c=(null===(a=l.texturesOptions)||void 0===a?void 0:a.sampler)||"uTexture",h=l.texturesOptions&&l.texturesOptions.floatingPoint;this.textures=[new u(t,{sampler:c,premultiplyAlpha:null!==(s=null===(n=l.texturesOptions)||void 0===n?void 0:n.premultiplyAlpha)&&void 0!==s&&s,floatingPoint:h})],null!=t&&t.renderTargets&&!t.renderTargets.includes(this)&&(t.renderTargets.push(this),t.renderTargets.forEach(function(e,t){e.index=t})),this._initRenderTarget()}return p(e,[{key:"_setSize",value:function(){var e,t,i=1*((null===this.curtains||void 0===this.curtains||null===(e=this.curtains.canvas)||void 0===e?void 0:e.width)||1),r=1*((null===this.curtains||void 0===this.curtains||null===(t=this.curtains.canvas)||void 0===t?void 0:t.height)||1),a=this._baseMaxSize.width,s=this._baseMaxSize.height;this._scaleWithCanvas&&(null!==this._widthScale&&(a=Math.max(1,Math.round(i*this._widthScale))),null!==this._heightScale&&(s=Math.max(1,Math.round(r*this._heightScale)))),this._maxSize={width:a,height:s},this._size={width:Math.min(this._maxSize.width,Math.max(this._minSize.width,i)),height:Math.min(this._maxSize.height,Math.max(this._minSize.height,r))}}},{key:"_initRenderTarget",value:function(){if(this.gl){var e=this.gl;this._setSize(),this._frameBuffer||(this._frameBuffer=e.createFramebuffer());var t=this.getTexture();t&&(e.bindFramebuffer(e.FRAMEBUFFER,this._frameBuffer),e.bindTexture(e.TEXTURE_2D,t._sampler.texture),e.texImage2D(e.TEXTURE_2D,0,t._globalParameters.internalFormat,this._size.width,this._size.height,0,t._globalParameters.format,t._globalParameters.type,null),t._size=c({},this._size),t._sourceLoaded=!0,t._uploaded=!0,t._canDraw=!0,t.sourceType="fbo",e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t._sampler.texture,0),this._depth&&(this._depthBuffer||(this._depthBuffer=e.createRenderbuffer()),e.bindRenderbuffer(e.RENDERBUFFER,this._depthBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,this._size.width,this._size.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,this._depthBuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,null))}}},{key:"resize",value:function(){if(this.gl){var e=this._size.width,t=this._size.height;if(this._setSize(),e!==this._size.width||t!==this._size.height||!this._frameBuffer)if(this._frameBuffer){var i=this.getTexture();if(i){var r=this.gl;r.bindFramebuffer(r.FRAMEBUFFER,this._frameBuffer),r.bindTexture(r.TEXTURE_2D,i._sampler.texture),r.texImage2D(r.TEXTURE_2D,0,i._globalParameters.internalFormat,this._size.width,this._size.height,0,i._globalParameters.format,i._globalParameters.type,null),i._size=c({},this._size),i._sourceLoaded=!0,i._uploaded=!0,i._canDraw=!0,i.sourceType="fbo",r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,i._sampler.texture,0),this._depth&&(this._depthBuffer||(this._depthBuffer=r.createRenderbuffer()),r.bindRenderbuffer(r.RENDERBUFFER,this._depthBuffer),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT16,this._size.width,this._size.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,this._depthBuffer),r.bindRenderbuffer(r.RENDERBUFFER,null)),r.bindTexture(r.TEXTURE_2D,null),this.curtains&&this.curtains.renderer?this.curtains.renderer.bindFrameBuffer(null):r.bindFramebuffer(r.FRAMEBUFFER,null)}}else this._initRenderTarget()}}},{key:"getTexture",value:function(){return this.textures[0]||null}},{key:"remove",value:function(){var e,t=this;this.gl&&(this._depthBuffer&&(this.gl.deleteRenderbuffer(this._depthBuffer),this._depthBuffer=null),this._frameBuffer&&(this.gl.deleteFramebuffer(this._frameBuffer),this._frameBuffer=null),this.textures.forEach(function(e){return e.remove()}),null!==(e=this.curtains)&&void 0!==e&&e.renderTargets&&(this.curtains.renderTargets=this.curtains.renderTargets.filter(function(e){return e!==t}),this.curtains.renderTargets.forEach(function(e,t){e.index=t})))}}]),e}(),h=function(){function e(){var t,i,r,a=this,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};f(this,e),this.type="Curtains",this.options=c({},s),this.container=(r=s.container)?"string"==typeof r?document.querySelector(r):r:null,this.canvas=document.createElement("canvas"),this.canvas.style.display="block",this.canvas.style.width="100%",this.canvas.style.height="100%",this.container&&!this.container.contains(this.canvas)&&this.container.appendChild(this.canvas);var n={alpha:!0,antialias:null!==(t=s.antialias)&&void 0!==t&&t,premultipliedAlpha:null===(i=s.premultipliedAlpha)||void 0===i||i,preserveDrawingBuffer:!1};this.gl=this.canvas.getContext("webgl2",n)||this.canvas.getContext("webgl",n),this.gl instanceof WebGL2RenderingContext?(this.gl.getExtension("EXT_color_buffer_float"),this.gl.getExtension("OES_texture_float_linear")):(this.gl.getExtension("OES_texture_half_float"),this.gl.getExtension("OES_texture_half_float_linear"),this.gl.getExtension("OES_texture_float"),this.gl.getExtension("OES_texture_float_linear")),this.planes=[],this.renderTargets=[],this.pixelRatio=s.pixelRatio||1,this.renderingScale=s.renderingScale||1,this._renderRequestID=null,this._errorCallbacks=[],this._contextLostCallbacks=[],this._contextRestoredCallbacks=[];var l={currentProgramID:null,currentGeometryID:null,forceBufferUpdate:!1,depthTest:null,blending:null,cullFace:null,frameBufferID:null,activeTexture:null,flipY:null,premultiplyAlpha:null};this.renderer={gl:this.gl,premultipliedAlpha:n.premultipliedAlpha,state:l,nextRender:{execute:function(){}},setDepthTest:function(e){a.gl&&(e&&!l.depthTest?(l.depthTest=e,a.gl.enable(a.gl.DEPTH_TEST)):!e&&l.depthTest&&(l.depthTest=e,a.gl.disable(a.gl.DEPTH_TEST)))},setDepthFunc:function(){a.gl&&a.gl.depthFunc(a.gl.LEQUAL)},setBlending:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];a.gl&&(e&&!l.blending?(l.blending=e,a.gl.enable(a.gl.BLEND)):!e&&l.blending&&(l.blending=e,a.gl.disable(a.gl.BLEND)))},setBlendFunc:function(){a.gl&&(a.gl.enable(a.gl.BLEND),this.premultipliedAlpha?a.gl.blendFuncSeparate(a.gl.ONE,a.gl.ONE_MINUS_SRC_ALPHA,a.gl.ONE,a.gl.ONE_MINUS_SRC_ALPHA):a.gl.blendFuncSeparate(a.gl.SRC_ALPHA,a.gl.ONE_MINUS_SRC_ALPHA,a.gl.ONE,a.gl.ONE_MINUS_SRC_ALPHA))},setFaceCulling:function(e){if(a.gl&&l.cullFace!==e)if(l.cullFace=e,"none"===e)a.gl.disable(a.gl.CULL_FACE);else{var t="front"===e?a.gl.FRONT:a.gl.BACK;a.gl.enable(a.gl.CULL_FACE),a.gl.cullFace(t)}},useProgram:function(e){if(a.gl&&e){var t=void 0!==e.id?e.id:e,i=e.program||e;null!==l.currentProgramID&&l.currentProgramID===t||(a.gl.useProgram(i),l.currentProgramID=t)}},bindFrameBuffer:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(a.gl){e&&t&&!e._frameBuffer&&e._initRenderTarget();var i=e?void 0!==e.index?e.index:e._frameBuffer:null;i!==l.frameBufferID&&(a.gl.bindFramebuffer(a.gl.FRAMEBUFFER,e?e._frameBuffer:null),l.frameBufferID=i)}}},this.renderer.setBlendFunc(),this.renderer.setDepthFunc(),this.renderer.setDepthTest(!1),this._onContextLost=function(e){e.preventDefault(),a._contextLostCallbacks.forEach(function(t){return t(e)})},this._onContextRestored=function(){a._contextRestoredCallbacks.forEach(function(e){return e()})},this.canvas.addEventListener("webglcontextlost",this._onContextLost,!1),this.canvas.addEventListener("webglcontextrestored",this._onContextRestored,!1),this.resize()}return p(e,[{key:"_emitError",value:function(e){this._errorCallbacks.forEach(function(t){return t(e)})}},{key:"onError",value:function(e){return"function"==typeof e&&this._errorCallbacks.push(e),this}},{key:"onContextLost",value:function(e){return"function"==typeof e&&this._contextLostCallbacks.push(e),this}},{key:"onContextRestored",value:function(e){return"function"==typeof e&&this._contextRestoredCallbacks.push(e),this}},{key:"restoreContext",value:function(){return this}},{key:"createRenderTarget",value:function(){return new d(this,arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"requestRender",value:function(){var e=this;this.gl&&null===this._renderRequestID&&(this._renderRequestID=requestAnimationFrame(function(){e._renderRequestID=null,e.render()}))}},{key:"resize",value:function(){if(this.container){var e=Math.max(1,Math.round(this.container.clientWidth*this.pixelRatio*this.renderingScale)),t=Math.max(1,Math.round(this.container.clientHeight*this.pixelRatio*this.renderingScale));this.canvas.width=e,this.canvas.height=t,this.gl&&this.gl.viewport(0,0,e,t),this.renderTargets.slice().forEach(function(e){e&&"function"==typeof e.resize&&e.resize()})}}},{key:"render",value:function(){if(this.gl){this.renderer.nextRender.execute();var e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);var t=l(this.planes).filter(function(e){return!1!==e.visible}).sort(function(e,t){return(e.renderOrder||0)-(t.renderOrder||0)}),i=t.filter(function(e){return"PingPongPlane"===e.type}),r=t.filter(function(e){return"PingPongPlane"!==e.type}),a=r.filter(function(e){return!!e.target}).sort(function(e,t){var i=e.target&&void 0!==e.target.index?e.target.index:Number.MAX_SAFE_INTEGER,r=t.target&&void 0!==t.target.index?t.target.index:Number.MAX_SAFE_INTEGER;return i!==r?i-r:(e.renderOrder||0)-(t.renderOrder||0)}),s=r.filter(function(e){return!e.target});e.disable(e.DEPTH_TEST),e.enable(e.BLEND),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),i.forEach(function(e){!1!==e._canDraw&&e._render()}),a.forEach(function(e){!1!==e._canDraw&&e._render()}),s.forEach(function(e){!1!==e._canDraw&&e._render()})}}},{key:"dispose",value:function(){null!==this._renderRequestID&&(cancelAnimationFrame(this._renderRequestID),this._renderRequestID=null),this.planes.slice().forEach(function(e){return e.remove()}),this.renderTargets.slice().forEach(function(e){return e.remove()}),this.canvas&&(this.canvas.removeEventListener("webglcontextlost",this._onContextLost),this.canvas.removeEventListener("webglcontextrestored",this._onContextRestored)),this.planes=[],this.renderTargets=[]}}]),e}();function v(e,t,i){var r=e.createShader(t);if(e.shaderSource(r,i),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){var a=e.getShaderInfoLog(r)||"Unknown shader compile error";throw e.deleteShader(r),new Error(a)}return r}var g=function(){function e(t,i){var r=this,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};f(this,e),this.type="Plane",this.curtains=t,this.gl=null==t?void 0:t.gl,this.htmlElement=i||(null==t?void 0:t.container)||null,this.userData={},this.visible=!0,this.renderOrder=0,this.target=null,this._canDraw=!0,this.textures=[],this.videos=[],this.uniforms=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={};return Object.keys(e).forEach(function(i){t[i]=c({},e[i])}),t}(a.uniforms),this._readyCallbacks=[],this._renderCallbacks=[],this._afterRenderCallbacks=[],this._uniformLocations=new Map,this._vertexShader=a.vertexShader||"\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\n\nvarying vec2 vTextureCoord;\n\nvoid main() {\n gl_Position = vec4(aVertexPosition, 1.0);\n vTextureCoord = aTextureCoord;\n}\n",this._fragmentShader=a.fragmentShader||"\nprecision mediump float;\n\nuniform sampler2D uTexture;\nvarying vec2 vTextureCoord;\n\nvoid main() {\n gl_FragColor = texture2D(uTexture, vTextureCoord);\n}\n",this._geometry=null,this._program=null,this._positionLocation=-1,this._uvLocation=-1,this._mvMatrixLocation=null,this._pMatrixLocation=null,this._init(a),null==t||t.planes.push(this),requestAnimationFrame(function(){r._readyCallbacks.forEach(function(e){return e(r)})})}return p(e,[{key:"_init",value:function(e){if(this.gl)try{this._program=function(e,t,i){var r=v(e,e.VERTEX_SHADER,t),a=v(e,e.FRAGMENT_SHADER,i),s=e.createProgram();if(e.attachShader(s,r),e.attachShader(s,a),e.linkProgram(s),e.deleteShader(r),e.deleteShader(a),!e.getProgramParameter(s,e.LINK_STATUS)){var n=e.getProgramInfoLog(s)||"Unknown program link error";throw e.deleteProgram(s),new Error(n)}return s}(this.gl,this._vertexShader,this._fragmentShader),this._positionLocation=this.gl.getAttribLocation(this._program,"aVertexPosition"),this._uvLocation=this.gl.getAttribLocation(this._program,"aTextureCoord"),this._geometry=function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,r=Math.max(1,Math.floor(t)),a=Math.max(1,Math.floor(i)),s=(r+1)*(a+1),n=new Float32Array(3*s),l=new Float32Array(2*s),o=0,u=0,d=0;d<=a;d++)for(var c=d/a,h=1-2*c,f=0;f<=r;f++){var p=f/r,m=2*p-1;n[o++]=m,n[o++]=h,n[o++]=0,l[u++]=p,l[u++]=1-c}for(var v=r*a*6,g=s>65535,y=g?new Uint32Array(v):new Uint16Array(v),x=0,b=0;b=0&&(e.bindBuffer(e.ARRAY_BUFFER,t.positionBuffer),e.enableVertexAttribArray(this._positionLocation),e.vertexAttribPointer(this._positionLocation,3,e.FLOAT,!1,0,0)),this._uvLocation>=0&&(e.bindBuffer(e.ARRAY_BUFFER,t.uvBuffer),e.enableVertexAttribArray(this._uvLocation),e.vertexAttribPointer(this._uvLocation,2,e.FLOAT,!1,0,0)),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.indexBuffer))}},{key:"_bindUniforms",value:function(){var e=this;if(this._program){var t=this.gl;t.useProgram(this._program),Object.keys(this.uniforms).forEach(function(i){var r=e.uniforms[i];if(r){var a=e._uniformLocations.get(i);void 0===a&&(a=t.getUniformLocation(e._program,r.name||i),e._uniformLocations.set(i,a)),function(e,t,i,r){if(null!=t&&null!=r){var a=r&&"object"===m(r)&&"x"in r&&"y"in r,s=a&&"z"in r;switch(i){case"1f":e.uniform1f(t,Number(r));break;case"2f":e.uniform2f(t,a?r.x:r[0],a?r.y:r[1]);break;case"3f":e.uniform3f(t,s?r.x:r[0],s?r.y:r[1],s?r.z:r[2]);break;case"4f":e.uniform4f(t,r[0],r[1],r[2],r[3]);break;case"1i":e.uniform1i(t,Number(r));break;case"2i":e.uniform2i(t,r[0],r[1]);break;case"3i":e.uniform3i(t,r[0],r[1],r[2]);break;case"4i":e.uniform4i(t,r[0],r[1],r[2],r[3]);break;case"1fv":e.uniform1fv(t,r);break;case"2fv":e.uniform2fv(t,r);break;case"3fv":e.uniform3fv(t,r);break;case"4fv":e.uniform4fv(t,r);break;case"mat3":e.uniformMatrix3fv(t,!1,r);break;case"mat4":e.uniformMatrix4fv(t,!1,r);break;default:s?e.uniform3f(t,r.x,r.y,r.z):a?e.uniform2f(t,r.x,r.y):Array.isArray(r)||ArrayBuffer.isView(r)?16===r.length?e.uniformMatrix4fv(t,!1,r):9===r.length?e.uniformMatrix3fv(t,!1,r):4===r.length?e.uniform4fv(t,r):3===r.length?e.uniform3fv(t,r):2===r.length?e.uniform2fv(t,r):1===r.length&&e.uniform1f(t,r[0]):e.uniform1f(t,Number(r))}}}(t,a,r.type,r.value)}})}}},{key:"_bindTextures",value:function(){var e,t=this.gl,i=0,r=function(e,t){var i="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!i){if(Array.isArray(e)||(i=o(e))||t){i&&(e=i);var r=0,a=function(){};return{s:a,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,n=!0,l=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return n=e.done,e},e:function(e){l=!0,s=e},f:function(){try{n||null==i.return||i.return()}finally{if(l)throw s}}}}(this.textures);try{for(r.s();!(e=r.n()).done;){var a,s=e.value;if(null!=s&&null!==(a=s._sampler)&&void 0!==a&&a.texture){t.activeTexture(t.TEXTURE0+i),s._copiedFrom&&s.copy(s._copiedFrom),s.shouldUpdate&&s.update();var n=t.getUniformLocation(this._program,s._samplerName);null!=n&&(t.bindTexture(t.TEXTURE_2D,s._sampler.texture),t.uniform1i(n,i),i++)}}}catch(l){r.e(l)}finally{r.f()}}},{key:"_prepareRenderTarget",value:function(e){var t,i;if(!e||!this.gl)return this.curtains.renderer.bindFrameBuffer(null),void this.gl.viewport(0,0,this.curtains.canvas.width,this.curtains.canvas.height);this.curtains.renderer.bindFrameBuffer(e,!0);var r=(null===(t=e._size)||void 0===t?void 0:t.width)||this.curtains.canvas.width,a=(null===(i=e._size)||void 0===i?void 0:i.height)||this.curtains.canvas.height;this.gl.viewport(0,0,r,a),!1!==e._clear&&(this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT|(e._depth?this.gl.DEPTH_BUFFER_BIT:0)))}},{key:"_render",value:function(){var e=this;this.gl&&this._program&&this._geometry&&(this._renderCallbacks.forEach(function(t){return t(e)}),this._prepareRenderTarget(this.target),this.gl.useProgram(this._program),this._mvMatrixLocation&&this.gl.uniformMatrix4fv(this._mvMatrixLocation,!1,r),this._pMatrixLocation&&this.gl.uniformMatrix4fv(this._pMatrixLocation,!1,r),this._texMatrixLocation&&this.gl.uniformMatrix4fv(this._texMatrixLocation,!1,r),this._bindAttributes(),this._bindUniforms(),this._bindTextures(),this.gl.drawElements(this.gl.TRIANGLES,this._geometry.indexCount,this._geometry.indexType,0),this.curtains.renderer.bindFrameBuffer(null),this.gl.viewport(0,0,this.curtains.canvas.width,this.curtains.canvas.height),this._afterRenderCallbacks.forEach(function(t){return t(e)}))}},{key:"onReady",value:function(e){return"function"==typeof e&&this._readyCallbacks.push(e),this}},{key:"onRender",value:function(e){return"function"==typeof e&&this._renderCallbacks.push(e),this}},{key:"onAfterRender",value:function(e){return"function"==typeof e&&this._afterRenderCallbacks.push(e),this}},{key:"setRenderOrder",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.renderOrder=e,this}},{key:"setRenderTarget",value:function(e){var t;return this.target=e,e&&null!==(t=this.curtains)&&void 0!==t&&t.renderTargets&&!this.curtains.renderTargets.includes(e)&&(this.curtains.renderTargets.push(e),this.curtains.renderTargets.forEach(function(e,t){e.index=t})),this}},{key:"createTexture",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.sampler||"uTexture",r=this.textures.find(function(e){return e._samplerName===i});if(r&&t.fromTexture)return r.copy(t.fromTexture),r;var a=new u(this.curtains,{sampler:i,premultiplyAlpha:null!==(e=t.premultiplyAlpha)&&void 0!==e&&e,fromTexture:t.fromTexture});if(r){var s=this.textures.indexOf(r);return this.textures[s]=a,a}return this.textures.push(a),a}},{key:"addTexture",value:function(e){if(!e)return null;var t=e._samplerName||"uTexture",i=this.textures.findIndex(function(e){return e._samplerName===t});return i>=0?this.textures[i]=e:this.textures.push(e),e}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0;try{var a,s=new u(this.curtains,{sampler:t.sampler||"uTexture",source:e,premultiplyAlpha:null!==(a=t.premultiplyAlpha)&&void 0!==a&&a});return s.shouldUpdate=!0,this.addTexture(s),"function"==typeof i&&i(s),s}catch(n){return"function"==typeof r&&r(n),null}}},{key:"loadVideo",value:function(e){var t,i,r=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0;e instanceof HTMLVideoElement?t=e:((t=document.createElement("video")).crossOrigin="anonymous",t.src=e),t.preload="auto",t.muted=!0,t.loop=!0,t.setAttribute("playsinline",""),t.crossOrigin||(t.crossOrigin="anonymous");var l=new u(r.curtains,{sampler:a.sampler||"uVideoTexture",premultiplyAlpha:null!==(i=a.premultiplyAlpha)&&void 0!==i&&i});l.shouldUpdate=!0,r.addTexture(l);var o=function(){try{l.setSource(t),l.shouldUpdate=!0,r.videos.push(t),"function"==typeof s&&s(l)}catch(e){"function"==typeof n&&n(e)}};return t.readyState>=t.HAVE_CURRENT_DATA?o():(t.addEventListener("loadeddata",o,{once:!0}),t.addEventListener("error",function(e){"function"==typeof n&&n(e)},{once:!0}),e instanceof HTMLVideoElement||t.load()),t}},{key:"remove",value:function(){var e,t=this;this.gl&&(this.textures.forEach(function(e){return e.remove()}),this._geometry&&(this.gl.deleteBuffer(this._geometry.positionBuffer),this.gl.deleteBuffer(this._geometry.uvBuffer),this.gl.deleteBuffer(this._geometry.indexBuffer)),this._program&&this.gl.deleteProgram(this._program),null!==(e=this.curtains)&&void 0!==e&&e.planes&&(this.curtains.planes=this.curtains.planes.filter(function(e){return e!==t})))}}]),e}(),y=function(){function e(t){f(this,e),this.curtains=t,this.cache=new Map}return p(e,[{key:"loadImage",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,a=arguments.length>3?arguments[3]:void 0;if(!e)return"function"==typeof a&&a(new Error("Missing image src")),null;var s=this.cache.get(e),n=function(e){var a,s=new u(t.curtains,{sampler:i.sampler||"uTexture",source:e,premultiplyAlpha:null!==(a=i.premultiplyAlpha)&&void 0!==a&&a});"function"==typeof r&&r(s)};if(null!=s&&s.loaded&&s.image)return n(s.image),s.image;var l=(null==s?void 0:s.image)||new Image;l.crossOrigin="anonymous";var o=s||{image:l,loaded:!1};this.cache.set(e,o);var d=function(){o.loaded=!0,n(l)};return l.complete&&l.naturalWidth>0?(d(),l):(l.addEventListener("load",d,{once:!0}),l.addEventListener("error",function(e){"function"==typeof a&&a(e)},{once:!0}),l.src||(l.src=e),l)}},{key:"loadCanvas",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0;try{var a,s=new u(this.curtains,{sampler:t.sampler||"uTexture",source:e,premultiplyAlpha:null!==(a=t.premultiplyAlpha)&&void 0!==a&&a});return s.shouldUpdate=!0,"function"==typeof i&&i(s),s}catch(n){return"function"==typeof r&&r(n),null}}}]),e}(),x=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t;f(this,e),this.type="Vec2",this._x=Number.isFinite(t)?t:0,this._y=Number.isFinite(i)?i:0}return p(e,[{key:"x",get:function(){return this._x},set:function(e){this._x=Number.isFinite(e)?e:this._x}},{key:"y",get:function(){return this._y},set:function(e){this._y=Number.isFinite(e)?e:this._y}},{key:"equals",value:function(e){return!!e&&this._x===e.x&&this._y===e.y}}]),e}(),b=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t;f(this,e),this.type="Vec3",this._x=Number.isFinite(t)?t:0,this._y=Number.isFinite(i)?i:0,this._z=Number.isFinite(r)?r:0}return p(e,[{key:"x",get:function(){return this._x},set:function(e){this._x=Number.isFinite(e)?e:this._x}},{key:"y",get:function(){return this._y},set:function(e){this._y=Number.isFinite(e)?e:this._y}},{key:"z",get:function(){return this._z},set:function(e){this._z=Number.isFinite(e)?e:this._z}}]),e}(),_=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&a(e,t)}(r,e);var t=s(r);function r(e,i){var a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};f(this,r),(a=t.call(this,e,i,s)).type="PingPongPlane";var n=Object.assign({},s.texturesOptions,{sampler:s.sampler||"uPingPongTexture"});return void 0===n.premultiplyAlpha&&(n.premultiplyAlpha=!1),a._targets=[new d(e,{clear:!1,maxWidth:e.canvas.width,maxHeight:e.canvas.height,texturesOptions:n}),new d(e,{clear:!1,maxWidth:e.canvas.width,maxHeight:e.canvas.height,texturesOptions:n})],a._readIndex=0,a._sampler=s.sampler||"uPingPongTexture",a.createTexture({sampler:a._sampler,fromTexture:a._targets[a._readIndex].getTexture()}),a.setRenderTarget(a._targets[a._readIndex]),a}return p(r,[{key:"getTexture",value:function(){return this.textures.find(function(e){return e._samplerName===this._sampler},this)||this._targets[this._readIndex].getTexture()}},{key:"_render",value:function(){var e=0===this._readIndex?1:0;this.setRenderTarget(this._targets[e]),i(n(r.prototype),"_render",this).call(this),this._readIndex=e;var t=this._targets[this._readIndex].getTexture(),a=this.textures.find(function(e){return e._samplerName===this._sampler},this);a&&t&&a.copy(t)}},{key:"remove",value:function(){this._targets.forEach(function(e){return e.remove()}),i(n(r.prototype),"remove",this).call(this)}}]),r}(g);e.Curtains=h,e.PingPongPlane=_,e.Plane=g,e.RenderTarget=d,e.TextureLoader=y,e.Vec2=x,e.Vec3=b,Object.defineProperty(e,"__esModule",{value:!0})},"object"===m(t)?g(t):g((v="undefined"!=typeof globalThis?globalThis:v||self).window=v.window||{})}(0,a.exports);var s=a.exports;function n(e,t,i={}){return function(e,{includeRuntimeLocalId:t=!1,includeNames:i=!0}={}){var r;const a=[null==e?void 0:e.id,null==e?void 0:e.publicId];return i&&a.push(null==e?void 0:e.layerName,null==e?void 0:e.name),t&&a.push(null==(r=null==e?void 0:e.local)?void 0:r.id),a.filter(e=>null!=e&&""!==e)}(e,i).includes(t)}function l(e){return e&&"function"==typeof e.clone?e.clone():e&&"object"==typeof e?JSON.parse(JSON.stringify(e)):e}function o(e){return String(e||"").trim()}function u(e="var"){return`${e}_${Math.random().toString(36).slice(2,10)}`}function d(){return(new Date).toISOString()}function c(e,t,i,r){null==r||r(`Invalid value for Unicorn Studio variable "${e.name}". Expected ${t}; received ${function(e){if(null===e)return"null";if(void 0===e)return"undefined";if("object"==typeof e)try{return JSON.stringify(e)}catch(t){return Object.prototype.toString.call(e)}return`${typeof e} ${JSON.stringify(e)}`}(i)}.`)}function h(e){return e&&"object"==typeof e?e.src:e}function f(e){const t=Number(e);return Number.isFinite(t)?t:null}function p(e,t={}){const i=Number.isFinite(Number(t.min))?Number(t.min):-1/0,r=Number.isFinite(Number(t.max))?Number(t.max):1/0;return Math.min(r,Math.max(i,e))}function m(e,t){if(!e||"object"!=typeof e)return null;const i=2===t?"Vec2":"Vec3";if(e.type&&e.type!==i)return null;const r=f(e.x??e._x),a=f(e.y??e._y),s=3===t?f(e.z??e._z):0;return null===r||null===a||3===t&&null===s?null:{type:i,x:r,y:a,...3===t?{z:s}:{}}}function v(e){return"string"==typeof e&&/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)}function g(e){return Array.isArray(e)&&e.length>0&&e.every(e=>v(e))}function y(e,t,i){const r=e.validation||{},a=Array.isArray(r.options)?r.options:null;if(a&&!a.includes(t))return c(e,`one of: ${a.join(", ")}`,t,i),{valid:!1,value:t};if("number"===e.type){const a=f(t);if(null===a)return c(e,"a finite number",t,i),{valid:!1,value:t};return{valid:!0,value:p("integer"===r.output?Math.round(a):a,r)}}if("boolean"===e.type)return"boolean"==typeof t?{valid:!0,value:t}:"true"===t||"false"===t?{valid:!0,value:"true"===t}:(c(e,"a boolean",t,i),{valid:!1,value:t});if("string"===e.type)return"string"==typeof t?{valid:!0,value:t}:"number"==typeof t&&Number.isFinite(t)||"boolean"==typeof t?{valid:!0,value:String(t)}:(c(e,"a string",t,i),{valid:!1,value:t});if("color"===e.type){if(v(t))return{valid:!0,value:t};const r=m(t,3);return r?{valid:!0,value:r}:(c(e,"a hex color or Vec3 color object",t,i),{valid:!1,value:t})}if("vec2"===e.type||"vec3"===e.type){const r="vec2"===e.type?2:3,a=m(t,r);return a?{valid:!0,value:a}:(c(e,`{ type: 'Vec${r}', x, y${3===r?", z":""} }`,t,i),{valid:!1,value:t})}return"texture"===e.type?"string"==typeof t&&t.trim()?{valid:!0,value:t}:t&&"object"==typeof t&&"string"==typeof t.src&&t.src.trim()?{valid:!0,value:l(t)}:(c(e,"a texture URL string or object with a src",t,i),{valid:!1,value:t}):{valid:!0,value:t}}function x(e={}){return Object.entries(e||{}).reduce((e,[t,i])=>{const r=o(t);return r?(e[r]=l(i),e):e},{})}function b(e){const t=o(null==e?void 0:e.name);return t?{id:e.id||u("preset"),name:t,description:e.description||"",values:x(e.values),createdAt:e.createdAt||"",updatedAt:e.updatedAt||e.createdAt||""}:null}function _(e){return e?{...e,values:x(e.values)}:null}function P(e=[],t=new Set,{keepEmpty:i=!1}={}){return(e||[]).map(e=>{const r=function(e={},t=new Set){return Object.entries(e||{}).reduce((e,[i,r])=>(t.has(i)&&(e[i]=l(r)),e),{})}(e.values,t);return i||Object.keys(r).length?{...e,values:r}:null}).filter(Boolean)}function T(e){return"Vec2"===(null==e?void 0:e.type)?"vec2":"Vec3"===(null==e?void 0:e.type)?"vec3":"number"==typeof e?"number":"boolean"==typeof e?"boolean":"string"==typeof e&&/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)||g(e)?"color":"string"==typeof e?"string":e&&"object"==typeof e&&(e.src||e.sampler)?"texture":"value"}const E=new Set(["number","boolean","string","color","vec2","vec3","texture"]);function w(e,t=140){const i=o(e);return i?i.slice(0,t):""}function M(e={}){const t=w(e.layerId),i=w(e.target||e.property||e.prop),r=w(e.layerName),a=void 0!==e.defaultValue?l(e.defaultValue):0,s=function(e,t){if(E.has(e))return e;const i=T(t);return E.has(i)?i:"number"}(e.type,a),n=w(e.name)||function(e,t){const i=`${e||"Layer"} ${t||"Value"}`.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[^a-zA-Z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);return i.length?i.map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):"Layer Value"}(r||t,i),o=w(e.description,500);return{version:1,action:"createVariable",name:n,type:s,defaultValue:a,...o?{description:o}:{},...t?{layerId:t}:{},...r?{layerName:r}:{},...i?{target:i}:{},...e.kind?{kind:w(e.kind,24)}:{},...e.canvasId?{canvasId:w(e.canvasId)}:{}}}function k(e){return function(e){if("undefined"!=typeof Buffer)return Buffer.from(e,"utf8").toString("base64url");const t=(new TextEncoder).encode(e),i=Array.from(t,e=>String.fromCharCode(e)).join("");return btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}(JSON.stringify(M(e)))}function R(e){var t,i,r;return(null==e?void 0:e.isModel)?null==(t=null==e?void 0:e.default)?void 0:t.call(e,e):null==(r=null==(i=null==e?void 0:e.getParams)?void 0:i.call(e))?void 0:r.properties}function I(e,t){var i;return!function(e=null){return!(!e||!0!==e.variableDisabled&&(!e.options||e.radio||e.classic))}(null==(i=R(e))?void 0:i[t])}const F=["relative","fixed","auto"];function S(e,t){const i=null==t?void 0:t.mode;if(!i)return null==t?void 0:t.output;const r=(a=null==e?void 0:e[i],F.includes(a)?a:F[a]||a);var a;return"fixed"===r?"px":"relative"===r?"percent":null==t?void 0:t.output}function A(e){return"pixels"===e?"px":e}function V(e,t){var i;const r=null==(i=R(e))?void 0:i[t];if(!r)return;const a=A(S(e,r));return a?{output:a}:void 0}function L(e,t){var i;const r=null==(i=R(e))?void 0:i[t];return"color"===(null==r?void 0:r.type)||"color"===(null==r?void 0:r.output)||v(null==e?void 0:e[t])||g(null==e?void 0:e[t])?"color":void 0}function C(e,t,i,r){var a,s,n;if("texture"===(null==e?void 0:e.type)&&"string"==typeof(null==t?void 0:t[i]))return h(r);if("color"!==(null==e?void 0:e.type))return r;const l=null==t?void 0:t[i];if(Array.isArray(l)){const e=Array.isArray(r)?r[0]:function(e){const t=m(e,3);return t?`#${[t.x,t.y,t.z].map(e=>Math.max(0,Math.min(255,Math.round(255*e))).toString(16).padStart(2,"0")).join("")}`:null}(r)||r;return void 0===e?r:[e]}if("Vec3"===(null==l?void 0:l.type)||"3f"===(null==(n=null==(s=null==(a=null==t?void 0:t.data)?void 0:a.uniforms)?void 0:s[i])?void 0:n.type)){if("Vec3"===(null==r?void 0:r.type))return r;return function(e){if("string"!=typeof e)return null;const t=/^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e);if(!t)return null;let i=t[1];return 3===i.length?i=i.split("").map(e=>e+e).join(""):8===i.length&&(i=i.slice(0,6)),{type:"Vec3",x:parseInt(i.slice(0,2),16)/255,y:parseInt(i.slice(2,4),16)/255,z:parseInt(i.slice(4,6),16)/255}}(Array.isArray(r)?r[0]:r)||r}return Array.isArray(r)?r[0]:r}function O(e,t,i=""){if(e)return"Vec2"===(null==t?void 0:t.type)||"Vec3"===(null==t?void 0:t.type)?(e.value=e.value||{},e.value.x=t.x??t._x??0,e.value.y="pos"===i||i.endsWith("_pos")?1-(t.y??t._y??0):t.y??t._y??0,void("Vec3"===t.type&&(e.value.z=t.z??t._z??0))):void(e.value=t)}function D(e,t,i){var r,a,s,n,l,o,u,d,c,f,p,m,v,g,y,x,b;const _=null==(r=null==e?void 0:e.state)?void 0:r.call(e),P=null==i?void 0:i.texture,T=(null==i?void 0:i.target)||t.target,E=(null==i?void 0:i.src)||h(null==i?void 0:i.value),w=function(e){var t,i;const r=(null==e?void 0:e.source)||(null==e?void 0:e._source),a=(null==(t=null==e?void 0:e._size)?void 0:t.width)||(null==r?void 0:r.naturalWidth)||(null==r?void 0:r.width)||(null==r?void 0:r.videoWidth)||0,s=(null==(i=null==e?void 0:e._size)?void 0:i.height)||(null==r?void 0:r.naturalHeight)||(null==r?void 0:r.height)||(null==r?void 0:r.videoHeight)||0;return a&&s?{width:a,height:s}:null}(P);if(w&&"image"===(null==e?void 0:e.layerType)){const t={type:"Vec2",x:w.width,y:w.height,_x:w.width,_y:w.height},r=w.width/w.height;e.naturalWidth=w.width,e.naturalHeight=w.height,e.imageNaturalSize=t,e.aspectRatio=r,O(null==(s=null==(a=null==i?void 0:i.plane)?void 0:a.uniforms)?void 0:s.imageNaturalSize,t,"imageNaturalSize"),O(null==(l=null==(n=null==i?void 0:i.plane)?void 0:n.uniforms)?void 0:l.aspectRatio,r,"aspectRatio")}if(null==e?void 0:e.isFlattened){const t=null==(u=null==(o=e.data)?void 0:o.textures)?void 0:u.find(e=>(null==e?void 0:e.sampler)===T);t&&(t.src=E,Number.isInteger(t.sublayerIndex)&&(e.local.sourceTextures=e.local.sourceTextures||{},e.local.sourceTextures[t.sublayerIndex]=P));const r="image"===(null==t?void 0:t.type)&&Number.isInteger(t.sublayerIndex)?null==(d=e.sublayers)?void 0:d.find(e=>e.sublayerIndex===t.sublayerIndex):null;if(w&&"image"===(null==r?void 0:r.layerType)){const a={type:"Vec2",x:w.width,y:w.height,_x:w.width,_y:w.height},s=w.width/w.height,n=`L${t.sublayerIndex}_imageNaturalSize`,l=`L${t.sublayerIndex}_aspectRatio`;r.src=E,r.imageNaturalSize=a,r.aspectRatio=s,(null==(f=null==(c=e.data)?void 0:c.uniforms)?void 0:f[n])&&(e.data.uniforms[n].value=a),(null==(m=null==(p=e.data)?void 0:p.uniforms)?void 0:m[l])&&(e.data.uniforms[l].value=s),O(null==(g=null==(v=null==i?void 0:i.plane)?void 0:v.uniforms)?void 0:g[n],a,n),O(null==(x=null==(y=null==i?void 0:i.plane)?void 0:y.uniforms)?void 0:x[l],s,l)}}"function"==typeof(null==_?void 0:_.requestLayerRender)?_.requestLayerRender(e):null==(b=null==_?void 0:_.requestSceneRender)||b.call(_)}function B(e={}){e=e||{};const t=Array.isArray(e.definitions)?e.definitions.map(e=>{const t=o(e.name);return t?{id:e.id||u("var"),name:t,type:e.type||T(e.defaultValue),defaultValue:l(e.defaultValue),description:e.description||"",validation:e.validation||{}}:null}).filter(Boolean):[],i=Array.isArray(e.bindings)?e.bindings.map(e=>{var i;const r=o(e.layerId),a=o(e.target||e.prop||e.property),s=e.variableId||(null==(i=t.find(t=>t.name===e.variableName))?void 0:i.id);return r&&a&&s?{id:e.id||u("bind"),layerId:r,kind:["source","texture"].includes(e.kind)?e.kind:"prop",target:a,variableId:s,enabled:!1!==e.enabled}:null}).filter(Boolean):[],r=new Set(t.map(e=>e.id)),a=Array.isArray(e.presets)?P(e.presets.map(b).filter(Boolean),r,{keepEmpty:!0}):[];return{definitions:t,bindings:i,presets:a}}class U{constructor({variables:e={},getLayer:t,onChange:i,warn:r=console.warn}={}){this.getLayer=t||(()=>null),this.onChange=i||(()=>{}),this.warn=r,this.state=B(e),this.values={},this.state.definitions.forEach(e=>{this.values[e.name]=l(e.defaultValue)})}serialize(){return B({definitions:this.getDefinitions(),bindings:this.state.bindings,presets:this.state.presets})}getDefinitions(){return this.state.definitions.map(e=>({...e,defaultValue:l(e.defaultValue),validation:{...this.getInferredValidation(e),...e.validation}}))}getBindings(){return this.state.bindings.map(e=>({...e}))}getPresets(){return this.state.presets.map(_)}has(e){return!!this.getDefinition(e)}getDefinition(e){return this.state.definitions.find(t=>t.id===e||t.name===e)||null}getPreset(e){return _(this.state.presets.find(t=>t.id===e||t.name===e)||null)}getInferredValidation(e){return e&&this.state.bindings.filter(t=>!1!==t.enabled&&t.variableId===e.id).map(e=>V(this.getLayer(e.layerId,e),e.target)).find(e=>null==e?void 0:e.output)||{}}getValue(e){const t=this.getDefinition(e);if(t)return l(this.values[t.name])}getValues(){return this.state.definitions.reduce((e,t)=>(e[t.name]=l(this.values[t.name]),e),{})}add(e,t,i,r="prop",a=void 0,s={}){const n={kind:r,target:i},l=t&&i?this.getLayer(t,n):null,o=n.target,u=this.createVariable(e,{defaultValue:a,type:s.type||L(l,o),description:s.description,validation:s.validation||V(l,o),notify:!1});return this.bind(u.id,t,i,r,{notify:!1}),this.notify(),u}createVariable(e,t={}){const i=o(e);if(!i)throw new Error("Variable name is required.");if(this.state.definitions.some(e=>e.name===i))throw new Error(`Variable "${i}" already exists.`);const r={id:t.id||u("var"),name:i,type:t.type||T(t.defaultValue),defaultValue:l(t.defaultValue),description:t.description||"",validation:t.validation||{}};return this.state.definitions.push(r),this.values[r.name]=l(r.defaultValue),!1!==t.notify&&this.notify(),r}getCurrentPresetValues(){return this.state.definitions.reduce((e,t)=>(e[t.id]=l(this.values[t.name]),e),{})}createPreset(e,t={}){const i=o(e);if(!i)throw new Error("Preset name is required.");if(this.state.presets.some(e=>e.name===i))throw new Error(`Preset "${i}" already exists.`);const r=d(),a={id:t.id||u("preset"),name:i,description:t.description||"",values:x(t.values||this.getCurrentPresetValues()),createdAt:t.createdAt||r,updatedAt:t.updatedAt||r};return this.state.presets.push(a),!1!==t.notify&&this.notify(),_(a)}updatePreset(e,t={}){const i=this.state.presets.find(t=>t.id===e||t.name===e);if(!i)return!1;if(void 0!==t.name){const e=o(t.name);if(!e)throw new Error("Preset name is required.");if(this.state.presets.some(t=>t.id!==i.id&&t.name===e))throw new Error(`Preset "${e}" already exists.`);i.name=e}return void 0!==t.description&&(i.description=t.description||""),Object.prototype.hasOwnProperty.call(t,"values")&&(i.values=x(t.values)),i.updatedAt=t.updatedAt||d(),!1!==t.notify&&this.notify(),_(i)}deletePreset(e,t={}){const i=this.state.presets.findIndex(t=>t.id===e||t.name===e);return-1!==i&&(this.state.presets.splice(i,1),!1!==t.notify&&this.notify(),!0)}applyPreset(e,t={}){var i;const r=this.state.presets.find(t=>t.id===e||t.name===e);if(!r)return null==(i=this.warn)||i.call(this,`Unknown Unicorn Studio preset "${e}".`),[];const a=[];return Object.entries(r.values||{}).forEach(([e,i])=>{var s;const n=this.getDefinition(e);n?this.setValue(n.name,i,{persistDefault:!!t.persistDefault,notify:!1})&&a.push(n.name):null==(s=this.warn)||s.call(this,`Preset "${r.name}" references missing variable "${e}".`)}),t.persistDefault&&a.length&&this.notify(),a}bind(e,t,i,r="prop",a={}){var s,n,l;const o=this.getDefinition(e);if(!o)throw new Error(`Variable "${e}" does not exist.`);const d=["source","texture"].includes(r)?r:"prop",c={kind:d,target:i},h=t&&i?this.getLayer(t,c):null,f=c.target;if("prop"===d&&!I(h,f))return null==(s=this.warn)||s.call(this,`Variable binding is disabled for "${i}".`),null;const p={...o,validation:{...this.getInferredValidation(o),...o.validation}};if("prop"===d&&!function(e,t,i){var r,a;const s=A(null==(r=null==e?void 0:e.validation)?void 0:r.output);if(!s)return!0;const n=A(null==(a=V(t,i))?void 0:a.output);return!n||s===n||"integer"===s&&"number"===n}(p,h,f)){const e=null==(n=V(h,f))?void 0:n.output;return null==(l=this.warn)||l.call(this,`Unable to bind variable "${o.name}" to "${i}". Expected ${p.validation.output}, target uses ${e}.`),null}const m=this.state.bindings.find(e=>e.variableId===o.id&&e.layerId===t&&e.kind===d&&e.target===i);if(m)return m;const v={id:a.id||u("bind"),variableId:o.id,layerId:t,kind:d,target:i,enabled:!1!==a.enabled};return this.state.bindings.push(v),this.applyBinding(v,this.values[o.name]),!1!==a.notify&&this.notify(),v}unbind(e,t={}){const i=this.state.bindings.findIndex(t=>t.id===e);if(-1===i)return!1;const[r]=this.state.bindings.splice(i,1);return this.clearBinding(r),!1!==t.notify&&this.notify(),!0}deleteVariable(e){const t=this.getDefinition(e);return!!t&&(this.state.bindings.filter(e=>e.variableId===t.id).forEach(e=>this.clearBinding(e)),this.state.definitions=this.state.definitions.filter(e=>e.id!==t.id),this.state.bindings=this.state.bindings.filter(e=>e.variableId!==t.id),this.state.presets=P(this.state.presets,new Set(this.state.definitions.map(e=>e.id)),{keepEmpty:!0}),delete this.values[t.name],this.notify(),!0)}renameVariable(e,t){const i=this.getDefinition(e),r=o(t);if(!i||!r||i.name===r)return!1;if(this.state.definitions.some(e=>e.id!==i.id&&e.name===r))throw new Error(`Variable "${r}" already exists.`);const a=this.values[i.name];return delete this.values[i.name],i.name=r,this.values[i.name]=a,this.notify(),!0}updateVariable(e,t={}){const i=this.getDefinition(e);if(!i)return!1;const r=void 0!==t.name?o(t.name):i.name;if(!r)throw new Error("Variable name is required.");if(this.state.definitions.some(e=>e.id!==i.id&&e.name===r))throw new Error(`Variable "${r}" already exists.`);const a={...i,name:r,type:void 0!==t.type?t.type:i.type,description:void 0!==t.description?t.description||"":i.description,validation:void 0!==t.validation?t.validation||{}:i.validation},s=Object.prototype.hasOwnProperty.call(t,"defaultValue"),n=y(a,s?t.defaultValue:this.values[i.name],this.warn);return!!n.valid&&(i.name!==r&&delete this.values[i.name],i.name=r,i.type=a.type,i.description=a.description,i.validation=a.validation,s&&(i.defaultValue=l(n.value)),this.values[i.name]=l(n.value),this.applyVariable(i),!1!==t.notify&&this.notify(),!0)}setValue(e,t,i={}){var r;const a=this.getDefinition(e);if(!a){const t=this.state.definitions.map(e=>e.name).join(", ")||"none";return null==(r=this.warn)||r.call(this,`Unknown Unicorn Studio variable "${e}". Available variables: ${t}.`),!1}const s=y(a,t,this.warn);return!!s.valid&&(this.values[a.name]=l(s.value),this.applyVariable(a),i.persistDefault&&(a.defaultValue=l(s.value),!1!==i.notify&&this.notify()),!0)}setValues(e={},t={}){const i=[];return Object.entries(e||{}).forEach(([e,r])=>{this.setValue(e,r,{...t,notify:!1})&&i.push(e)}),t.persistDefault&&this.notify(),i}applyInitialValues(e={}){Object.entries(e||{}).forEach(([e,t])=>this.setValue(e,t))}applyAll(){this.state.definitions.forEach(e=>this.applyVariable(e))}applyVariable(e){this.state.bindings.filter(t=>!1!==t.enabled&&t.variableId===e.id).forEach(t=>this.applyBinding(t,this.values[e.name]))}applyBinding(e,t){var i,r,a,s,n,l,o;const u=this.getLayer(e.layerId,e);if(!u){const t=this.getDefinition(e.variableId);return void(null==(i=this.warn)||i.call(this,`Unable to apply Unicorn Studio variable binding for "${(null==t?void 0:t.name)||e.variableId}". Layer "${e.layerId}" was not found. Target: ${e.kind||"prop"}:${e.target}.`))}const d=this.getDefinition(e.variableId);if(!d)return void(null==(r=this.warn)||r.call(this,`Unable to apply Unicorn Studio variable binding. Variable "${e.variableId}" was not found for layer "${e.layerId}" target "${e.target}".`));if("prop"===(e.kind||"prop")&&!I(u,e.target))return void(null==(a=this.warn)||a.call(this,`Skipping variable binding for "${e.target}" because variables are disabled for that property.`));const c=C(d,u,e.target,t);if("source"===e.kind){const t=h(c);if("function"==typeof u.setSource)u.setSource(t,{onLoad:t=>D(u,e,t)});else if("function"==typeof u.replaceSource){const i=c&&"object"==typeof c?c.thumb||c.src:t;null==(s=u.setRuntimeOverride)||s.call(u,e.target||"src",t),u.replaceSource(t,i||u.thumb,u.naturalWidth,u.naturalHeight)}else"function"==typeof u.setProp?u.setProp(e.target||"src",t,{runtimeOverride:!0}):null==(n=this.warn)||n.call(this,`Unable to apply source variable "${d.name}". Layer "${e.layerId}" does not support source updates.`);return}"texture"!==e.kind?"function"==typeof u.setPropertySource?u.setPropertySource(e.target,"runtime",c,{owner:"variable"}):"function"==typeof u.setRuntimeOverride?u.setRuntimeOverride(e.target,c,{source:"variable"}):"function"==typeof u.setProp?u.setProp(e.target,c,{runtimeOverride:!0}):Object.prototype.hasOwnProperty.call(u,e.target)?u[e.target]=c:null==(o=this.warn)||o.call(this,`Unable to apply prop variable "${d.name}". Layer "${e.layerId}" does not expose target "${e.target}".`):"function"==typeof u.setTexture?u.setTexture(e.target,c,{onLoad:t=>D(u,e,t)}):"function"==typeof u.setProp?u.setProp(e.target,c,{runtimeOverride:!0}):null==(l=this.warn)||l.call(this,`Unable to apply texture variable "${d.name}". Layer "${e.layerId}" does not support texture target "${e.target}".`)}clearBinding(e){const t=this.getLayer(e.layerId,e);if(t&&"function"==typeof t.clearRuntimeOverride){if("source"===e.kind)return t.clearRuntimeOverride(e.target||"src"),void("function"==typeof t.replaceSource&&t.replaceSource(t.src,t.thumb,t.naturalWidth,t.naturalHeight));if("texture"===e.kind){const i=Object.keys(t).find(i=>{var r;return(null==(r=t[i])?void 0:r.sampler)===e.target})||"texture";return void t.clearRuntimeOverride(i)}t.clearRuntimeOverride(e.target)}}getManifest(){return this.getDefinitions().map(e=>{const t=this.state.bindings.filter(t=>t.variableId===e.id);return{...e,currentValue:l(this.values[e.name]),bindingCount:t.length,bindings:t.map(e=>({layerId:e.layerId,kind:e.kind,target:e.target,enabled:e.enabled}))}})}notify(){this.onChange(this.serialize())}}const N=["base","breakpoint","runtime","event","preview"],z={runtime:"runtimeOverrides",event:"stateEffectProps",preview:"previewProps"},j=["Desktop","Tablet","Mobile"];function H(e,t){return!!e&&Object.prototype.hasOwnProperty.call(e,t)}function W(e){return e&&"function"==typeof e.clone?e.clone():Array.isArray(e)?e.map(W):e&&"object"==typeof e?JSON.parse(JSON.stringify(e)):e}function $(e){return Array.isArray(e)?e:Array.isArray(null==e?void 0:e.breakpoints)?e.breakpoints:[]}function q(e,t={}){const i=$(e);if(!i.length)return{};if(!t.breakpointName&&!H(t,"width"))return{};const r=t.breakpointName?function(e,t,i={}){const r=$(e),a=function(e,t){return Array.isArray(t)&&t.length?t.map(e=>"string"==typeof e?e:null==e?void 0:e.name).filter(Boolean):e.map(e=>null==e?void 0:e.name).filter(Boolean)}(r,i.breakpointOrder),s=a.indexOf(t);if(-1===s)return{};const n={};for(let l=s;l>=0;l--){const e=r.find(e=>(null==e?void 0:e.name)===a[l]);(null==e?void 0:e.props)&&Object.keys(e.props).forEach(t=>{H(n,t)||(n[t]=e.props[t])})}return n}(i,t.breakpointName,t):function(e,t,i={}){const r=$(e);if(!r.length)return{};const a=Number.isFinite(Number(t))?Number(t):0,s=[...r].sort((e,t)=>((null==t?void 0:t.min)??0)-((null==e?void 0:e.min)??0)),n={};for(let u=s.length-1;u>=0;u--){const e=s[u];(null==e?void 0:e.props)&&((null===e.max||a<=e.max)&&Object.keys(e.props).forEach(t=>{H(n,t)||(n[t]=e.props[t])}))}const l=i.baseBreakpointName||"Desktop",o=r.find(e=>(null==e?void 0:e.name)===l);(null==o?void 0:o.props)&&Object.keys(o.props).forEach(e=>{H(n,e)||(n[e]=o.props[e])});return n}(i,t.width,t);return function(e,t){return Array.isArray(t)?t.reduce((t,i)=>(H(e,i)&&(t[i]=e[i]),t),{}):e}(r,t.props)}function G(e,t,i,r,a={}){if(!e||!t)return!1;const s=a.cloneValue||W;if("base"===i)return function(e,t,i){const r=null==e?void 0:e[t];if(r&&(null==i?void 0:i.type)){const e=i.x??i._x,t=i.y??i._y,a=i.z??i._z;return void 0!==e&&(r.x=e),void 0!==t&&(r.y=t),void 0!==a&&(r.z=a),void 0!==e&&(r._x=e),void 0!==t&&(r._y=t),void 0!==a&&(r._z=a),r}e[t]=i}(e,t,s(r)),!0;if("breakpoint"===i){const i=a.breakpointName,n=$(e).find(e=>(null==e?void 0:e.name)===i);return!!n&&(n.props=n.props||{},n.props[t]=s(r),!0)}const n=z[i];if(!n)return!1;if(e.local=e.local||{},e.local[n]=e.local[n]||{},"runtime"===i&&(e.local.runtimeOverrideBaseValues=e.local.runtimeOverrideBaseValues||{},!H(e.local[n],t))){const i=H(a,"baseValue")?a.baseValue:e[t];e.local.runtimeOverrideBaseValues[t]=s(i)}return e.local[n][t]=s(r),!0}function Y(e,t,i,r={}){if(!e||!t)return;if("breakpoint"===i){const i=$(e).find(e=>(null==e?void 0:e.name)===r.breakpointName);if(!(null==i?void 0:i.props)||!H(i.props,t))return;const a=i.props[t];return delete i.props[t],a}if(!e.local)return;const a=z[i];if(!a||!e.local[a]||!H(e.local[a],t))return;const s=e.local[a][t];if(delete e.local[a][t],"runtime"===i&&e.local.runtimeOverrideBaseValues){const i=e.local.runtimeOverrideBaseValues[t];return delete e.local.runtimeOverrideBaseValues[t],i}return s}function X(e,t,i={}){var r,a,s,n,l,o;const u=i.breakpointProps||q(e,i),d={base:H(i,"baseValue")?i.baseValue:null==e?void 0:e[t],breakpoint:H(u,t)?u[t]:void 0,runtime:null==(a=null==(r=null==e?void 0:e.local)?void 0:r.runtimeOverrides)?void 0:a[t],event:null==(n=null==(s=null==e?void 0:e.local)?void 0:s.stateEffectProps)?void 0:n[t],preview:null==(o=null==(l=null==e?void 0:e.local)?void 0:l.previewProps)?void 0:o[t]},c=i.sources||N;for(let h=c.length-1;h>=0;h--){const e=c[h];if(void 0!==d[e])return{prop:t,source:e,value:d[e],sources:d}}return{prop:t,source:"base",value:d.base,sources:d}}function Q(e,t,i,r=(null==e?void 0:e[t])){if(!e||!i)return r;const a=e.responsiveProps,s=j.indexOf(i);if(-1===s){const e=null==a?void 0:a[i];return e&&H(e,t)?e[t]:r}for(let n=s;n>=0;n--){const e=null==a?void 0:a[j[n]];if(e&&H(e,t))return e[t]}return r}let J,K,Z,ee,te=!1,ie=window.innerHeight||document.documentElement.clientHeight,re=window.innerWidth||document.documentElement.clientWidth,ae=null,se=Pe(),ne=0,le=0,oe=0,ue=0,de=null,ce=!1,he=!1,fe=[],pe=null;const me=.001,ve=["relative","fixed","auto"],ge=["relative","fixed"],ye={enterTime:null,movePos:{x:.5,y:.5}},xe=["lightColor","ambientLightColor","fillLightColor"];let be="2.2.7";function _e(e){if(null==e||""===e)return null;if("string"==typeof e&&""===e.trim())return null;const t=Number(e);return Number.isFinite(t)?t:null}function Pe(){return null!==ae?ae:window.scrollY||window.pageYOffset||0}function Te(e=Pe()){const t=_e(e);return null!==t&&(se=t,le=se-ne,ne=se,!0)}function Ee(e){if(!e||"string"!=typeof e)return null;9===e.length?e=e.substring(0,7):8===e.length&&"#"!==e[0]&&(e="#"+e.substring(0,6));e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,t,i,r){return t+t+i+i+r+r});const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]:null}function we(e){const t=Ee(e);return t?new s.Vec3(...t.map(e=>e/255)):null}void 0!==document.hidden?(J="hidden",K="visibilitychange"):void 0!==document.msHidden?(J="msHidden",K="msvisibilitychange"):void 0!==document.webkitHidden&&(J="webkitHidden",K="webkitvisibilitychange");const Me=new Set(["gradient","gradientMap","gradientFill"]);function ke(e){return window.atob(e)}function Re(e){return ge.includes(e)?e:ge[e??0]??ge[0]}function Ie(){return"id-"+Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}function Fe(e){const t={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>1-(1-e)*(1-e),easeInOutQuad:e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,easeInCubic:e=>e*e*e,easeOutCubic:e=>1-Math.pow(1-e,3),easeInOutCubic:e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,easeInQuart:e=>e**4,easeOutQuart:e=>1-Math.pow(1-e,4),easeInOutQuart:e=>e<.5?8*e**4:1-Math.pow(-2*e+2,4)/2,easeInQuint:e=>e**5,easeOutQuint:e=>1-Math.pow(1-e,5),easeInOutQuint:e=>e<.5?16*e**5:1-Math.pow(-2*e+2,5)/2,easeOutElastic:e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:Math.pow(2,-10*e)*Math.sin((10*e-.75)*t)+1},easeInElastic:e=>{const t=2*Math.PI/3;return 0===e?0:1===e?1:-Math.pow(2,10*e-10)*Math.sin((10*e-10.75)*t)},easeInOutElastic:e=>{const t=2*Math.PI/4.5;return 0===e?0:1===e?1:e<.5?-Math.pow(2,20*e-10)*Math.sin((20*e-11.125)*t)/2:Math.pow(2,-20*e+10)*Math.sin((20*e-11.125)*t)/2+1},easeOutSpringSoft:e=>0===e||1===e?e:1-Math.exp(-5*e)*Math.cos(3*e*Math.PI),easeOutSpring:e=>0===e||1===e?e:1-Math.exp(-6*e)*Math.cos(4.5*e*Math.PI),easeInSpring:e=>{if(0===e||1===e)return e;const t=1-e;return Math.exp(-6*t)*Math.cos(4.5*t*Math.PI)},easeInOutSpring:e=>{if(0===e||1===e)return e;if(e<.5){const t=1-2*e;return Math.exp(-6*t)*Math.cos(4.5*t*Math.PI)/2}const t=2*e-1;return 1-Math.exp(-6*t)*Math.cos(4.5*t*Math.PI)/2},easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInCirc:e=>1-Math.sqrt(1-e**2),easeOutCirc:e=>Math.sqrt(1-Math.pow(e-1,2)),easeInOutCirc:e=>e<.5?(1-Math.sqrt(1-(2*e)**2))/2:(Math.sqrt(1-Math.pow(-2*e+2,2))+1)/2,easeInExpo:e=>0===e?0:Math.pow(2,10*e-10),easeOutExpo:e=>1===e?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>0===e?0:1===e?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2,easeInBack:e=>{const t=1.70158;return(t+1)*e*e*e-t*e*e},easeOutBack:e=>{const t=1.70158;return 1+(t+1)*Math.pow(e-1,3)+t*Math.pow(e-1,2)},easeInOutBack:e=>{const t=2.5949095;return e<.5?Math.pow(2*e,2)*(7.189819*e-t)/2:(Math.pow(2*e-2,2)*((t+1)*(2*e-2)+t)+2)/2}};if("string"==typeof e&&(e.includes("=>")||e.includes("function")));else if(t[e])return t[e];return t.easeInOutQuad}function Se(e){return e&&"string"==typeof e&&(e=JSON.parse(e)),Object.values(e)}function Ae(e,t,i){for(let r=0;r0,s=Array.isArray(null==(t=e.data)?void 0:t.timeUniforms)&&e.data.timeUniforms.some(e=>!1!==(null==e?void 0:e.animating)&&Math.abs(Number((null==e?void 0:e.speed)??0))>1e-5),n=!!(null==(i=e.data)?void 0:i.hasMouseTracking),l=!!(null==(r=e.data)?void 0:r.hasVideoSublayers),o=Array.isArray(e.sublayers)&&e.sublayers.some(e=>!!e&&("video"===e.type||("effect"===e.layerType||"model"===e.layerType)&&!!e.animating)),u=a||s||n||l||o;return e.local.isDynamicCache=u,u}const s=["trackMouse","axisTilt","trackMouseMove","rotationTracking","lightTracking"].some(t=>e.hasOwnProperty(t)&&0!==e[t]),n=e.states&&[...e.states.appear,...e.states.scroll,...e.states.hover,...e.states.mousemove].length>0,l=("effect"===e.layerType||e.isModel)&&(e.animating||e.usesPingPong),o="video"===e.type,u=Array.isArray(null==(a=e.data)?void 0:a.textures)&&e.data.textures.some(e=>"video"===(null==e?void 0:e.type)&&(null==e?void 0:e.src)),d=s||n||l||o||u;return e.local.isDynamicCache=d,d}function Be(e,t){var i,r,a,s;if(e.noTextAsHtml)return;if(!t)return;const n=function(e){if(!e||"string"!=typeof e)return"";const t=e.trim();if(!t||/[\u0000-\u001F\u007F]/.test(t))return"";const i=t.match(/^([a-z][a-z0-9+.-]*):/i);if(i){const e=i[1].toLowerCase();return["http","https","mailto","tel"].includes(e)?t:""}if(t.startsWith("/")||t.startsWith("#")||t.startsWith("?")||t.startsWith("./")||t.startsWith("../"))return t;if(t.startsWith("//"))return t;return""}(e.href),l=Re(e.leftMode),o=Re(e.topMode);let u="fixed"===e.widthMode?e.width:e.width*t.offsetWidth,d=e.height,c="fixed"===e.fontSizeMode?e.fontSize:e.fontSize*t.offsetWidth,h="fixed"===e.fontSizeMode?e.lineHeight:e.lineHeight*c,f="fixed"===e.fontSizeMode?e.letterSpacing:e.letterSpacing*c,p="fixed"===o?e.top:e.top*t.offsetHeight,m="fixed"===l?e.left:e.left*t.offsetWidth,v=dt(e.anchorPoint);m-=v.x*u,p-=v.y*d,p+=t.offsetTop,m+=t.offsetLeft;let g=t.querySelector(`[data-us-text="${e.local.id}"]`);const y=n?"a":"div";let x=!g;g&&g.tagName.toLowerCase()!==y&&(g.remove(),g=null,x=!0),g=g||document.createElement(y);const b=Array.isArray(e.fill)?e.fill:[],_={MULTIPLY:"multiply",SCREEN:"screen",OVERLAY:"overlay",DARKEN:"darken",LIGHTEN:"lighten",COLOR_DODGE:"color-dodge",COLOR_BURN:"color-burn",HARD_LIGHT:"hard-light",SOFT_LIGHT:"soft-light",DIFFERENCE:"difference",EXCLUSION:"exclusion"}[e.blendMode&&0!==e.blendMode?String(e.blendMode).toUpperCase():"NORMAL"],P=(null==(r=null==(i=e.local)?void 0:i.stateEffectProps)?void 0:r.opacity)??e.opacity??(null==(a=e.data)?void 0:a.elementOpacity)??1;let T="color:transparent;";e.htmlOnly&&(T=`color:${b[0]||"#000000"};`),g.setAttribute("data-us-text",e.local.id),n?(g.setAttribute("href",n),g.setAttribute("target","_blank"),g.setAttribute("rel","noopener noreferrer")):(g.removeAttribute("href"),g.removeAttribute("target"),g.removeAttribute("rel")),g.style.cssText=`width:${u}px;top:${p}px;left:${m}px;font-size:${c}px;line-height:${h}px;letter-spacing:${f}px;font-family:${e.fontFamily};font-style:${(null==(s=e.fontStyle)?void 0:s.includes("italic"))?"italic":"normal"};font-weight:${e.fontWeight};text-align:${e.textAlign};position:absolute;word-break:break-word;white-space:pre-wrap;transform:rotateZ(${Math.round(360*e.rotation)}deg);opacity:${P};z-index:${e.htmlOnly?100+(e.htmlRenderOrder??0):2};display:block;text-decoration:none;pointer-events:${n?"auto":"none"};cursor:${n?"pointer":"inherit"};${_?`mix-blend-mode:${_};`:""}${T}`,g.innerText=e.textContent,x&&t.appendChild(g)}function Ue(e){const t=e.split(",").map(e=>e.trim()),i=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),r=/iPad|iPhone|iPod/.test(navigator.userAgent);if(i||r){const e=t.find(e=>e.endsWith(".mov")||e.endsWith(".mp4"));if(e)return e}const a=t.find(e=>e.endsWith(".webm"));return a||t[0]}function Ne(){Ot.filter(e=>!document.body.contains(e.element)).forEach(e=>{e.curtain&&e.curtain.dispose();const t=Ot.indexOf(e);-1!==t&&Ot.splice(t,1)})}function ze(e){return e&&e.renderer&&e.renderer.nextRender&&"function"==typeof e.renderer.nextRender.execute}function je(){cancelAnimationFrame(Z);let e=Ot.filter(e=>!e.destroyed&&e.getDynamicLayers().length>0);const t=i=>{let r=!1;e.forEach(e=>{if(!e.destroyed)if(e.isInView&&e.initialized){e.rendering=!0;const t=i-(e.lastTime||0);e.lastTime&&!(t>=e.frameDuration)||e.paused||(e.renderFrame(),e.lastTime=e.lastTime?i-t%e.frameDuration:i),r=!0}else e.rendering=!1}),(!oe||i-oe>64)&&(Te(),oe=i,(le>1e3||le<0&&!ne&&!se)&&Rt()),r?(!function(){var e,t,i,r;let a=performance.now();const s=Ce();for(let n=0;nt&&l.mouse.page.y>e&&l.mouse.page.xfunction(e){if("transparent"===e)return 0;if("string"!=typeof e)return 1;const t=/^#(?:[0-9a-f]{6})([0-9a-f]{2})$/i.exec(e);return t?parseInt(t[1],16)/255:1}(e));t.uniforms.fillAlpha.value=e.length?Math.max(...e):1}for(let d=0;d<16;d++){const e=null==(l=t.uniforms)?void 0:l[`color${d}`];if(!e)continue;const i=d{const i=document.createElement("script");i.src=a||"https://assets.unicorn.studio/controls/controls.umd.js",i.async=!0,i.onload=()=>{var i;(null==(i=window.UnicornStudioControls)?void 0:i.initControls)?e(window.UnicornStudioControls):t(new Error("UnicornStudioControls loaded without initControls()."))},i.onerror=()=>t(new Error(`Unable to load Unicorn Studio controls from ${i.src}.`)),(document.head||document.body).appendChild(i)}),Qe)).then(a=>a.initControls({...r,scene:t,element:e,title:et(t,i),draggable:r.draggable??i.controlsDraggable??!0})).catch(e=>{})}function rt(e,t,i){var r,a;i&&(null==(r=null==e?void 0:e.target)?void 0:r.getTexture)&&i===e.target.getTexture()&&(i=null);const s=null==(a=e.textures)?void 0:a.find(e=>e._samplerName===t);if(s){if(i&&s._copiedFrom!==i)return s.copy(i),s;if(!i&&s._copiedFrom){s._dispose(),e.textures=e.textures.filter(e=>e!==s);const i=e.createTexture({sampler:t,premultiplyAlpha:!0});return function(e){var t;null==(t=e.textures)||t.forEach((t,i)=>{var r;t.index=i,(null==(r=e._program)?void 0:r.compiled)&&t._setTextureUniforms()})}(e),i}return s}return e.createTexture({sampler:t,premultiplyAlpha:!0,fromTexture:i})}function at(e){return e&&"object"==typeof e?JSON.parse(JSON.stringify(e)):{}}class st{constructor({prop:e,value:t,endValue:r,transition:a,breakpoints:s,uniformData:n,loop:l="none",loopDelay:o=0,responsiveProps:u}){i(this,"id",Ie()),this.prop=e,this.transition=a,this.complete=!1,this.progress=0,this.uniformData=n,this.value=We(t),this.endValue=void 0!==r?We(r||0):null,this.responsiveProps=at(u),this.lastTick=void 0,this.initialized=!1,this.startTime=null,this.breakpoints=s||[],this.loop=l,this.loopDelay=o,this.easeFunction=Fe(this.transition.ease)}updateEffect(e,t){const i=Q(this,"value",this.activeBreakpointName,this.value);if(void 0===(e=Q(this,"endValue",this.activeBreakpointName,this.endValue??e)))return!1;const r=performance.now(),a=r-((this.startTime||t)+this.transition.delay);if(a<0)return!1;if("none"!==this.loop){const t=this.transition.duration+this.loopDelay,s=a%t;if(s>this.transition.duration)return!1;const n=s/this.transition.duration,l=Math.floor(a/t);let o=n;return"reverse"===this.loop&&l%2==1&&(o=1-n),this.progress=this.easeFunction(o),this.lastTick=r,He(i,e,this.progress)}const s=Math.max(0,Math.min(1,a/this.transition.duration));return this.progress=this.easeFunction(s),0!==this.progress&&(s>=1?(this.complete=!0,this.progress=0,e):(this.lastTick=r,!this.complete&&He(i,e,this.progress)))}resetState(){this.progress=0,this.complete=!1,this.lastTick=void 0,this.initialized=!1}}class nt{constructor({prop:e,value:t,range:r,offset:a,momentum:s,spring:n,uniformData:l,mode:o="scrollIntoView",delta:u=.01,absScrollValue:d=!0,breakpoints:c=[],responsiveProps:h}){i(this,"id",Ie()),this.prop=e,this.progress=0,this.momentum=s,this.spring=n??0,this._velocity=0,this.range=r,this.offset=a,this.mode=o,this.delta=u,this.absScrollValue=d,this.uniformData=l,this.value=We(t),this.responsiveProps=at(h),this.lastTick=void 0,this.breakpoints=c||[]}updateEffect(e,{top:t,height:i,isFixed:r}){if(void 0===e)return!1;if(r&&(t-=se),"scrollIntoView"===this.mode){const r=t+se-ie*this.offset,a=r+(ie+i)*this.range;let s=(se-r)/(a-r),n=Math.max(0,Math.min(1,s));if(void 0!==this.lastTick){if(this.spring>0){const e=Ve(this.lastTick,n,this._velocity,this.momentum,this.spring);n=e.value,this._velocity=e.velocity}else n=Ae(n,this.lastTick,2*this.momentum);if(Math.abs(this.lastTick-n)0){const e=Ve(this.lastTick,t,this._velocity,this.momentum,this.spring);t=e.value,this._velocity=e.velocity}else t=Ae(t,this.lastTick,2*this.momentum);if(Math.abs(t)me;return this.progress=u,!(!t&&!d)&&(!t&&this.transition.forwardsOnly&&(this.progress=0,this.rawProgress=0),this.lastTick=s,this.lastEnterTime=t,!!d&&He(e,Q(this,"value",this.activeBreakpointName,this.value),this.progress))}resetState(){this.progress=0}}class ot{constructor({prop:e,value:t,sensitivity:r,momentum:a,spring:s,delay:n,mode:l,axisMode:o,point:u,breakpoints:d,uniformData:c,responsiveProps:h}){i(this,"id",Ie()),this.prop=e,this.progress=0,this.sensitivity=r??.5,this.momentum=a??.25,this.spring=s??0,this._velocity=0,this.delay=n??0,this.mode=l??"velocity",this.axisMode=o??"both",this.point=u??{x:.5,y:.5},this.value=We(t),this.responsiveProps=at(h),this.uniformData=c,this.lastMousePos=null,this.lastMoveTime=null,this.breakpoints=d||[]}updateEffect(e,t,i){if(void 0===e)return!1;const r=performance.now();let a=0;if(null!==this.lastMousePos&&t){const e=t.x-this.lastMousePos.x,i=t.y-this.lastMousePos.y;a="x"===this.axisMode?Math.abs(e):"y"===this.axisMode?Math.abs(i):Math.sqrt(e*e+i*i),a>1e-4&&(this.lastMoveTime=r)}t&&(this.lastMousePos={x:t.x,y:t.y});let s,n=this.progress;if("proximity"===this.mode){if(!t)return!1;const e=.5*((null==i?void 0:i.canvasWidth)||0),r=.5*((null==i?void 0:i.canvasHeight)||0);if(!e||!r)return!1;const a=this.point.x*e,s=this.point.y*r;let l=t.x-a,o=t.y-s,u=Math.sqrt(e*e+r*r);"x"===this.axisMode?(o=0,u=e):"y"===this.axisMode&&(l=0,u=r);const d=Math.sqrt(l*l+o*o),c=1-Math.min(1,d/u),h=1+4*this.sensitivity;n=Math.pow(c,h)}else{(this.lastMoveTime?r-this.lastMoveTime:1/0)>this.delay?n=0:a>0&&(n=Math.min(1,this.progress+a*(this.sensitivity/500)))}if(this.spring>0){const e=Ve(this.progress,n,this._velocity,this.momentum,this.spring);s=e.value,this._velocity=e.velocity}else s=Ae(n,this.progress,this.momentum);return Math.abs(s-this.progress){var t,i;for(let r in e.props)"Vec2"===(null==(t=e.props[r])?void 0:t.type)?e.props[r]=new s.Vec2(e.props[r]._x,e.props[r]._y):"Vec3"===(null==(i=e.props[r])?void 0:i.type)?e.props[r]=new s.Vec3(e.props[r]._x,e.props[r]._y,e.props[r]._z):"object"==typeof e.props[r]&&(e.props[r]=Se(e.props[r]))}),a),this.local.sceneId=t,this.id=e.id||Ie(),this.publicId=e.publicId||this.id,this.hasPublishedPublicId=Object.prototype.hasOwnProperty.call(e,"publicId"),this.local.id=this.id,this.editorLayerId=e.editorLayerId,this.compiledFragmentShaders=e.compiledFragmentShaders||[],this.compiledVertexShaders=e.compiledVertexShaders||[],this.states={appear:e.states&&e.states.appear?e.states.appear.map(e=>new st(e)):[],scroll:e.states&&e.states.scroll?e.states.scroll.map(e=>new nt(e)):[],hover:e.states&&e.states.hover?e.states.hover.map(e=>new lt(e)):[],mousemove:e.states&&e.states.mousemove?e.states.mousemove.map(e=>new ot(e)):[]},function(e){const t={};(e.breakpoints||[]).forEach(e=>{Object.assign(t,e.props||{})}),Object.keys(t).forEach(i=>{Object.prototype.hasOwnProperty.call(e,i)||(e[i]=qe(t[i]))})}(this)}state(){return Ot.find(e=>e.id===this.local.sceneId)||this.initOptions}getIndex(){return this.state().layers.map(e=>e.local.id).indexOf(this.local.id)}getPixelRatio(){const e=this.state();return e.dpi*e.scale*this.userDownsample}getPlane(){var e,t,i;return null==(i=null==(t=null==(e=this.state())?void 0:e.curtain)?void 0:t.planes)?void 0:i.find(e=>"PingPongPlane"!==e.type&&e.userData.id===this.local.id)}getPlanes(){var e,t,i;return(null==(i=null==(t=null==(e=this.state())?void 0:e.curtain)?void 0:t.planes)?void 0:i.filter(e=>"PingPongPlane"!==e.type&&e.userData.id===this.local.id))||[]}getMaskedItem(){return!!this.mask&&this.state().layers.filter(e=>!e.parentLayer&&!e.groupLayer)[this.getIndex()-1]}getChildEffectItems(){if(this.effects&&this.effects.length){const e=this.state();if(!e||!e.layers)return[];const t=e.layers.filter(e=>this.effects.includes(e.parentLayer));return this.effects.map(e=>t.find(t=>t.parentLayer===e)).filter(e=>void 0!==e)}return[]}getGroup(){var e,t;return this.groupLayer&&(null==(t=null==(e=this.state())?void 0:e.layers)?void 0:t.find(e=>{var t;return e.isGroup&&(null==(t=e.members)?void 0:t.includes(this.groupLayer))}))||null}setVisible(e=!this.visible){var t,i;const r=!1!==e;return this.visible===r||(this.visible=r,this.invalidatePerformanceCaches(),null==(i=null==(t=this.state())?void 0:t.applyLayerVisibility)||i.call(t)),this}show(){return this.setVisible(!0)}hide(){return this.setVisible(!1)}setProp(e,t,i={}){return i.runtimeOverride?this.setRuntimeOverride(e,t,i):this.applyRuntimeProp(e,t)}hasRuntimePropTarget(e){var t,i;return!(!this.local.stateEffectProps||!Object.prototype.hasOwnProperty.call(this.local.stateEffectProps,e))||(!!(null==(i=null==(t=this.data)?void 0:t.uniforms)?void 0:i[e])||(!!this.getPlanes().some(t=>{var i;return null==(i=t.uniforms)?void 0:i[e]})||!(!this.isText||!Object.prototype.hasOwnProperty.call(this,e))))}warnMissingRuntimeProp(e,t){var i,r;const a=null==(i=this.state)?void 0:i.call(this);null==(r=null==a?void 0:a.getCreateVariableUrl)||r.call(a,{layer:this,target:e,defaultValue:t,kind:"prop"})}setRuntimeOverride(e,t,i={}){return"scene.setProp"!==i.source||this.hasRuntimePropTarget(e)||this.warnMissingRuntimeProp(e,t),G(this,e,"runtime",t,{cloneValue:qe}),this.applyRuntimeProp(e,t)}clearRuntimeOverride(e){if(!this.local.runtimeOverrides||!Object.prototype.hasOwnProperty.call(this.local.runtimeOverrides,e))return this;const t=Y(this,e,"runtime");return void 0!==t&&this.applyRuntimeProp(e,t),this}setPropertySource(e,t,i){return"runtime"===t?this.setRuntimeOverride(e,i):"event"===t?(this.updateStateEffectProperty(e,i),this):(G(this,e,t,i,{cloneValue:qe}),this)}clearPropertySource(e,t,i={}){return"runtime"===t?this.clearRuntimeOverride(e):"event"===t?(Y(this,e,"event"),this):(Y(this,e,t,i),this)}applyRuntimeOverrides(){Object.entries(this.local.runtimeOverrides||{}).forEach(([e,t])=>{this.applyRuntimeProp(e,t)})}applyRuntimeProp(e,t){return Ge(this,e,qe(t)),this.syncRuntimeProp(e),this}syncRuntimeProp(e){var t,i,r,a;const s=this.state();this.local.stateEffectProps&&Object.prototype.hasOwnProperty.call(this.local.stateEffectProps,e)?null==(t=null==s?void 0:s.requestLayerRender)||t.call(s,this):(this.getPlanes().forEach(t=>{var i;Ye(this,t,e),function(e,t,i){var r,a,s,n;if("fill"!==i||!Me.has(e.type))return!1;const l=Array.isArray(e.fill)?e.fill:[e.fill||"#777777"],o=Math.min(l.length,16),u=Math.max(o-1,1);(null==(r=t.uniforms)?void 0:r.count)&&(t.uniforms.count.value=o);for(let d=0;d<16;d++){const i=null==(a=t.uniforms)?void 0:a[`color${d}`];if(i&&d{var r,a,l;if(!i)return;this.local.sourceTexture=i,this.local.imageReady=!0;const o=null==(r=null==e?void 0:e.textures)?void 0:r.find(e=>"uSourceImage"===e._samplerName);(null==o?void 0:o.copy)?(o.copy(i),null==(a=o.needUpdate)||a.call(o)):e&&e.addTexture(i),null==(l=t.onLoad)||l.call(t,{layer:this,target:"uSourceImage",value:s,texture:i,plane:e,src:s}),n.requestSceneRender()})}else if("video"===this.type){const e=null==(r=this.getPlane)?void 0:r.call(this);if(e){e.videos=[],e.textures=e.textures.filter(e=>"video"!==e.sourceType);const t=(null==(a=s.includes)?void 0:a.call(s,", "))?Ue(s):s;e.loadVideo(t,{sampler:"uVideoTexture",premultipliedAlpha:!1},()=>n.requestSceneRender())}}return this}setTexture(e,t,i={}){var r,a,s,n,l;if(!new Set([null==(r=this.texture)?void 0:r.sampler,null==(s=null==(a=this.data)?void 0:a.texture)?void 0:s.sampler,...((null==(n=this.data)?void 0:n.textures)||[]).map(e=>null==e?void 0:e.sampler),...this.getPlanes().flatMap(e=>(e.textures||[]).map(e=>e._samplerName))].filter(Boolean)).has(e))return this;const o="string"==typeof t?{src:t,sampler:e}:{...t||{},sampler:e},u=Object.keys(this).find(t=>{var i;return(null==(i=this[t])?void 0:i.sampler)===e})||"texture";this.setRuntimeOverride(u,o);const d=o.src,c=null==(l=this.getPlane)?void 0:l.call(this),h=this.state();return d&&c&&(null==h?void 0:h.preloadImage)?(h.preloadImage(d,e,t=>{var r,a;if(!t)return;const s=c.textures.find(t=>t._samplerName===e);(null==s?void 0:s.copy)?(s.copy(t),null==(r=s.needUpdate)||r.call(s)):c.addTexture(t),null==(a=i.onLoad)||a.call(i,{layer:this,target:e,value:o,texture:t,plane:c,src:d}),h.requestSceneRender()},!1),this):this}setBreakpointValues(e=null){var t,i;const r=null==(t=this.state)?void 0:t.call(this),a=(null==(i=null==r?void 0:r.getBreakpointWidth)?void 0:i.call(r))||(null==r?void 0:r.breakpointWidth),s=e||a||re,n=[...this.breakpoints].sort((e,t)=>t.min-e.min);if(1===n.length&&"Desktop"===n[0].name)return;if(n.length>=1&&!n.find(e=>"Desktop"===e.name))throw new Error("Malfored breakpoint data, missing Desktop");const l=e=>{for(let t in e)if(Object.prototype.hasOwnProperty.call(this,t)){let i=e[t];(null==i?void 0:i.type)?(this[t].x=i._x,this[t].y=i._y,void 0!==i._z&&(this[t].z=i._z)):this[t]=i}};l(q(this,{breakpointName:"Desktop"}));const o=q(this,{width:s});l(o),this.local.bpProps=o,Object.keys(this.local.runtimeOverrides||{}).forEach(e=>{this.local.runtimeOverrideBaseValues=this.local.runtimeOverrideBaseValues||{},this.local.runtimeOverrideBaseValues[e]=qe(this[e])}),this.applyRuntimeOverrides()}updateStateEffects(){var e,t,i,r,a;if(!this.states.appear.some(e=>!e.complete)&&!(null==(e=this.states)?void 0:e.scroll.length)&&!(null==(t=this.states)?void 0:t.hover.length)&&!(null==(i=this.states)?void 0:i.mousemove.length)||this.isModel&&!this.local.modelLoaded)return;this.local.uniformUpdatesPool||(this.local.uniformUpdatesPool={}),this.local.updatedProps?this.local.updatedProps.clear():this.local.updatedProps=new Set,this.local.hasUpdates=!1;const s=this.state()||{},n=s.mouse||ye;let l=performance.now();this.local.cachedBreakpoint&&this.local.cachedBreakpoint===(null==(r=s.currentBreakpoint)?void 0:r.name)||(this.local.cachedBreakpoint=null==(a=s.currentBreakpoint)?void 0:a.name);const o=e=>!e.breakpoints||0===e.breakpoints.length||e.breakpoints.find(e=>e===this.local.cachedBreakpoint);s.isInView&&(null===this.local.createdAt&&(this.local.createdAt=l),this.states.appear.filter(e=>!e.complete).forEach(e=>{if(e.activeBreakpointName=this.local.cachedBreakpoint,!o(e))return void(this.local.stateEffectProps&&this.local.stateEffectProps[e.prop]&&delete this.local.stateEffectProps[e.prop]);let t=e.startTime||this.local.createdAt;if(!e.initialized){const i=[...this.states.appear.filter(t=>t.prop===e.prop)].sort((e,t)=>(e.transition.delay||0)-(t.transition.delay||0))[0];(null==i?void 0:i.id)===e.id&&(this.local.uniformUpdatesPool[e.prop]=Q(e,"value",this.local.cachedBreakpoint),this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop)),e.initialized=!0,t||(e.startTime=l)}(null==s?void 0:s.pauseTime)&&(t+=Math.abs(null==s?void 0:s.pauseTime));const i=this.getEventValue?this.getEventValue(e.prop,this[e.prop]):this[e.prop];e.activeBreakpointName=this.local.cachedBreakpoint;const r=e.updateEffect(i,t);!1!==r&&(this.local.uniformUpdatesPool[e.prop]=r,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop)),this.isText&&e.complete&&this.local.stateEffectProps&&this.local.stateEffectProps[e.prop]&&delete this.local.stateEffectProps[e.prop]})),this.states.hover.forEach(e=>{if(!o(e))return void(this.local.stateEffectProps&&this.local.stateEffectProps[e.prop]&&delete this.local.stateEffectProps[e.prop]);const t=this.getEventValue?this.getEventValue(e.prop,this[e.prop]):this[e.prop];e.activeBreakpointName=this.local.cachedBreakpoint;const i=e.updateEffect(t,n.enterTime,this);!1!==i&&(this.local.uniformUpdatesPool[e.prop]=i,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop))}),this.states.scroll.forEach(e=>{var t;if(!o(e))return void(this.local.stateEffectProps&&this.local.stateEffectProps[e.prop]&&delete this.local.stateEffectProps[e.prop]);const i=s.bbox;if(!i)return;const r=this.getEventValue?this.getEventValue(e.prop,this[e.prop]):this[e.prop];e.activeBreakpointName=this.local.cachedBreakpoint;const a=e.updateEffect(r,{top:s.isFixed?0:null==(t=s.bbox)?void 0:t.top,height:i.height/2,isFixed:s.isFixed});!1!==a&&(this.local.uniformUpdatesPool[e.prop]=a,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop))}),this.states.mousemove.forEach(e=>{if(!o(e))return void(this.local.stateEffectProps&&this.local.stateEffectProps[e.prop]&&delete this.local.stateEffectProps[e.prop]);const t=this.getEventValue?this.getEventValue(e.prop,this[e.prop]):this[e.prop];e.activeBreakpointName=this.local.cachedBreakpoint;const i=e.updateEffect(t,n.movePos,s);!1!==i&&(this.local.uniformUpdatesPool[e.prop]=i,this.local.hasUpdates=!0,this.local.updatedProps.add(e.prop))}),this.local.hasUpdates&&(this.getPlanes().forEach(e=>{var t;for(let i of this.local.updatedProps){const r=this.local.uniformUpdatesPool[i];void 0!==r&&((null==(t=e.uniforms[i])?void 0:t.lastValue)!==r&&(e.uniforms[i]&&$e(r,e.uniforms[i],i),this.updateStateEffectProperty(i,this.fromEventValue?this.fromEventValue(i,r):r)))}}),this.isText&&this.local.stateEffectProps&&Object.keys(this.local.stateEffectProps).length&&this.render())}updateStateEffectProperty(e,t){G(this,e,"event",t,{cloneValue:qe})}invalidatePerformanceCaches(){this.local.isDynamicCache=void 0,this.local.cachedBreakpoint=void 0,this.local.lastCalculatedMousePos=void 0,this.local.lastCalculatedMouseValues=void 0}dispose(){this.invalidatePerformanceCaches()}}function dt(e){const t={topLeft:{x:0,y:0},topCenter:{x:.5,y:0},topRight:{x:1,y:0},rightCenter:{x:1,y:.5},bottomRight:{x:1,y:1},bottomCenter:{x:.5,y:1},bottomLeft:{x:0,y:1},leftCenter:{x:0,y:.5},center:{x:.5,y:.5}};return t[e]?t[e]:Object.values(t)[e]}function ct(e,t,i,r){const a=e.left??.5,s=e.top??.5,n="fixed"===Re(e.leftMode)?a:a*t,l="fixed"===Re(e.topMode)?s:s*i,o=ve.includes(e.widthMode)?e.widthMode:ve[e.widthMode??1],u=ve.includes(e.heightMode)?e.heightMode:ve[e.heightMode??1],d=e.aspectRatio||(e.imageNaturalSize?e.imageNaturalSize._x/e.imageNaturalSize._y:1);let c,h;return"auto"===o&&"auto"===u?(c=e.width??0,h=e.height??0):("auto"!==o&&(c="fixed"===o?e.width??0:(e.width??0)*t),h="auto"===u?c/(d||1):"fixed"===u?e.height??0:(e.height??0)*i,"auto"===o&&(c=h*(d||1))),function(e,t,i,r,a,s){const n=dt(a??"center");i<0&&(i=Math.abs(i)),r<0&&(t+=r,r=Math.abs(r));const l=e-n.x*i,o=t-n.y*r;return 2*s.x>=l&&2*s.x<=l+i&&2*s.y>=o&&2*s.y<=o+r}(n,l,c,h,e.anchorPoint,r)}function ht(e,t={}){const i=Number(t.maskDepth??e.maskDepth??0),r=Number.isFinite(i)?i:0,a=Number(t.maskDepthLayer??e.maskDepthLayer??1),s=Number.isFinite(a)?Math.max(0,Math.floor(a)):1;e.maskInvert=Object.prototype.hasOwnProperty.call(t,"maskInvert")?t.maskInvert:e.maskInvert??0,e.maskDepth=1===r?1:0,e.maskDepthLayer=1===r?s:0}class ft extends ut{constructor(e,t){super(e,t),i(this,"isElement",!0),i(this,"isGpuElement",!1),this.width=e.width||0,this.height=e.height||0,this.widthMode=e.widthMode??"fixed",this.heightMode=e.heightMode??"fixed",this.anchorPoint=e.anchorPoint??"center",this.left=e.left||0,this.top=e.top||0,this.leftMode=e.leftMode??"relative",this.topMode=e.topMode??"relative",this.effects=e.effects||[],this.trackMouse=e.trackMouse||0,this.trackAxes=e.trackAxes||"xy",this.axisTilt=e.axisTilt||0,this.mouseMomentum=e.mouseMomentum||0,this.groupLayer=e.groupLayer||!1,this.mask=e.mask||0,this.maskAlpha=e.maskAlpha||0,this.maskBackground=e.maskBackground||new s.Vec3(0),ht(this,e)}unpackage(){this.effects=Se(this.effects);for(let e in this)this[e]&&this[e].type&&("Vec2"===this[e].type?this[e]=new s.Vec2(this[e]._x,this[e]._y):"Vec3"===this[e].type&&(this[e]=new s.Vec3(this[e]._x,this[e]._y,this[e]._z)));return this}dispose(){this.local.canvas&&(this.local.canvas.width=1,this.local.canvas.height=1,this.local.canvas=null),this.local.ctx&&(this.local.ctx=null),super.dispose()}box(){const e=dt(this.anchorPoint),{width:t,height:i}=this.getAbsoluteDimensions(),{left:r,top:a}=this.getAbsolutePosition();return{anchor:{x:r+t*(.5-e.x),y:a+i*(.5-e.y)},center:{x:r+t/2,y:a+i/2},left:r,top:a,width:t,height:i}}getAbsolutePosition(){var e,t,i,r;const a=this.state(),s=a.canvasWidth,n=a.canvasHeight;let l=(null==(t=null==(e=this.local)?void 0:e.stateEffectProps)?void 0:t.left)??this.left,o=(null==(r=null==(i=this.local)?void 0:i.stateEffectProps)?void 0:r.top)??this.top;let u="fixed"===Re(this.leftMode)?l:l*s,d="fixed"===Re(this.topMode)?o:o*n;return u=+u.toFixed(1),d=+d.toFixed(1),{left:u,top:d}}getAbsoluteDimensions(){var e,t,i,r;const a=this.state();let s,n;const l=a.canvasWidth,o=a.canvasHeight;let u=(null==(t=null==(e=this.local)?void 0:e.stateEffectProps)?void 0:t.width)??this.width,d=(null==(r=null==(i=this.local)?void 0:i.stateEffectProps)?void 0:r.height)??this.height,c=ve.includes(this.widthMode)?this.widthMode:ve[this.widthMode],h=ve.includes(this.heightMode)?this.heightMode:ve[this.heightMode];return"auto"!==c&&(s="fixed"===c?u:u*l,"auto"===h&&(n=s/(this.aspectRatio||1),this.height="fixed"===c?n:n/o)),"auto"!==h&&(n="fixed"===this.heightMode?d:d*o,"auto"===c&&(s=n*(this.aspectRatio||1),this.width="fixed"===c?s:s/l)),"text"===this.layerType&&(n=this.height),{width:s,height:n}}isHovered(){const e=this.state();return ct(this,e.canvasWidth,e.canvasHeight,e.mouse.movePos)}}class pt extends ft{constructor(e,t,r){super(e,t),i(this,"layerType","shape"),i(this,"isElement",!0),i(this,"isGpuElement",!0),this.initOptions=r;for(let i in e)i in this||(this[i]=e[i]);ht(this,e),this.breakpoints.length&&this.setBreakpointValues()}}class mt extends ut{constructor(e,t,r){super(e,t),i(this,"layerType","effect"),this.initOptions=r,this.type=e.type||"sine",this.usesPingPong=e.usesPingPong||!1,this.speed=e.speed??.5,this.parentLayer=e.parentLayer||!1,this.animating=e.animating||!1,this.isMask=e.isMask||0,this.texture=e.texture||null,this.mouseMomentum=e.mouseMomentum||0;for(let i in e)this[i]||(this[i]=e[i]);this.breakpoints.length&&this.setBreakpointValues()}unpackage(){for(let e in this)this[e]&&this[e].type&&("Vec2"===this[e].type?this[e]=new s.Vec2(this[e]._x,this[e]._y):"Vec3"===this[e].type&&(this[e]=new s.Vec3(this[e]._x,this[e]._y,this[e]._z)));return this}getParent(){return this.state().layers.filter(e=>e.effects&&e.effects.length).find(e=>e.effects.includes(this.parentLayer))}}class vt extends ut{constructor(e,t,r){super(e,t,r),i(this,"layerType","group"),i(this,"isGroup",!0),this.members=e.members||[],this.effects=e.effects||[],this.opacity=e.opacity??1,this.blendMode=e.blendMode||"NORMAL",this.trackMouse=e.trackMouse||0,this.axisTilt=e.axisTilt||0,this.mouseMomentum=e.mouseMomentum||0,this.mouseSpring=e.mouseSpring||0,this.displace=e.displace||0,this.bgDisplace=e.bgDisplace||0,this.dispersion=e.dispersion||0,this.mask=0}getMemberItems(){var e,t;if(!(null==(e=this.members)?void 0:e.length))return[];const i=this.state(),r=(null==(t=null==i?void 0:i.layers)?void 0:t.filter(e=>this.members.includes(e.groupLayer)))||[];return this.members.map(e=>r.find(t=>t.groupLayer===e)).filter(Boolean)}getChildEffectItems(){var e,t;if(!(null==(e=this.effects)?void 0:e.length))return[];const i=this.state(),r=(null==(t=null==i?void 0:i.layers)?void 0:t.filter(e=>this.effects.includes(e.parentLayer)))||[];return this.effects.map(e=>r.find(t=>t.parentLayer===e)).filter(Boolean)}unpackage(){return this.members=Se(this.members),this.effects=Se(this.effects),this}}class gt extends ut{constructor(e,t,r){var a,s,n,l;super(e,t),i(this,"layerType","flattened"),i(this,"isFlattened",!0),this.initOptions=r,this.sublayers=e.sublayers||[],this.visible=!1!==e.visible,this.consumedMaskId=e.consumedMaskId||null,this.mask=e.mask||0,this.maskDepthLayer=e.maskDepthLayer??0,this.maskInvert=e.maskInvert||0,this.maskDepth=e.maskDepth||0,this.maskAlpha=e.maskAlpha||0,this.local.textSublayers=[],this.local.imageSublayers=[],this.local.videoSublayers=[],this.local.modelSublayers=[],this.local.textInstances={},this.local.canvasTextures={},this.local.sourceTextures={},this.local.modelInstances={},this.local.modelTextures={},this.sublayers.forEach((e,i)=>{if("text"===e.layerType){this.local.textSublayers.push(e);const a={...e},s=Number.isInteger(e.sublayerIndex)?e.sublayerIndex:i;this.local.textInstances[s]=new bt(a,t,r).unpackage()}else if("image"===e.layerType)this.local.imageSublayers.push(e);else if("video"===e.type)this.local.videoSublayers.push(e);else if("model"===e.layerType){this.local.modelSublayers.push(e);const a=Number.isInteger(e.sublayerIndex)?e.sublayerIndex:i;this.local.modelInstances[a]=new xt(e,t,r)}}),this.states.hover.some(e=>e.triggerOnElement)&&Object.values(this.local.modelInstances).forEach(e=>{e.states.hover=[{triggerOnElement:1}]}),this.local.remainingEffectItems=[],this.effects=[],e.remainingEffects&&e.remainingEffects.length>0&&(this.local.remainingEffectItems=e.remainingEffects.map(e=>new mt(e,t,r).unpackage()),this.effects=e.remainingEffects.map(e=>e.parentLayer).filter(Boolean));[...(null==(a=e.states)?void 0:a.appear)||[],...(null==(s=e.states)?void 0:s.scroll)||[],...(null==(n=e.states)?void 0:n.hover)||[],...(null==(l=e.states)?void 0:l.mousemove)||[]].forEach(t=>{var i,r,a,s;if(!t.prop||void 0!==this[t.prop])return;let n;const l=t.originalProp||t.prop;if(l&&Number.isInteger(t.sublayerIndex)){const e=this.sublayers.find(e=>e.sublayerIndex===t.sublayerIndex);e&&void 0!==e[l]&&(n=e[l])}const o=null==(a=null==(r=null==(i=e.data)?void 0:i.uniforms)?void 0:r[t.prop])?void 0:a.value,u=null==(s=t.uniformData)?void 0:s.value;this[t.prop]=n??o??u??t.value}),this.breakpoints.length&&this.setBreakpointValues()}setBreakpointValues(e=null){super.setBreakpointValues(e),this.syncTextBreakpoints()}syncTextBreakpoints(){const e=this.local.bpProps||{};Object.entries(this.local.textInstances||{}).forEach(([t,i])=>{var r,a,s;const n=this.sublayers.find(e=>(null==e?void 0:e.sublayerIndex)===Number(t));let l=!1;Object.entries(e).forEach(([e,r])=>{const a=e.startsWith(`L${t}_`)?e.slice(t.length+2):null;a&&a in i&&(Ge(i,a,qe(r)),n&&a in n&&Ge(n,a,qe(r)),l=!0)}),l&&(null==(r=i.render)||r.call(i),null==(s=null==(a=this.local.canvasTextures[t])?void 0:a.needUpdate)||s.call(a))})}getChildEffectItems(){return this.local.remainingEffectItems||[]}hasRemainingEffects(){return this.local.remainingEffectItems&&this.local.remainingEffectItems.length>0}unpackage(){var e,t,i;for(let r in this)this[r]&&"Vec2"===this[r].type?this[r]=new s.Vec2(this[r]._x,this[r]._y):this[r]&&"Vec3"===this[r].type&&(this[r]=new s.Vec3(this[r]._x,this[r]._y,this[r]._z));if(null==(e=this.data)?void 0:e.uniforms)for(let r in this.data.uniforms){const e=this.data.uniforms[r];"Vec2"===(null==(t=null==e?void 0:e.value)?void 0:t.type)?e.value=new s.Vec2(e.value._x,e.value._y):"Vec3"===(null==(i=null==e?void 0:e.value)?void 0:i.type)&&(e.value=new s.Vec3(e.value._x,e.value._y,e.value._z))}return this}areTextAssetsReady(){return Object.values(this.local.textInstances).every(e=>e.local.loaded)}areImageAssetsReady(){var e;return!(null==(e=this.data)?void 0:e.textures)||this.data.textures.filter(e=>"image"===e.type).every(e=>{var t;return!!(null==(t=this.local.sourceTextures)?void 0:t[e.sublayerIndex])})}areModelAssetsReady(){var e;if(!(null==(e=this.data)?void 0:e.textures))return!0;const t=this.data.textures.filter(e=>"modelRT"===e.type);return!t.length||t.every(e=>{var t,i,r,a;const s=null==(t=this.local.modelInstances)?void 0:t[e.sublayerIndex];return!!((null==(i=null==s?void 0:s.local)?void 0:i.rendererLoaded)&&(null==(r=null==s?void 0:s.local)?void 0:r.modelLoaded)&&(null==(a=this.local.modelTextures)?void 0:a[e.sublayerIndex]))})}resize(){Object.entries(this.local.textInstances).forEach(([e,t])=>{var i,r;t.resize(),null==(r=null==(i=this.local.canvasTextures[e])?void 0:i.needUpdate)||r.call(i)})}isHovered(e){var t;if(e){const i=e.match(/^L(\d+)_/);if(i){const e=parseInt(i[1],10),r=null==(t=this.local.modelInstances)?void 0:t[e];return(null==r?void 0:r.isHovered)?r.isHovered():this._isSublayerHovered(e)}}const i=this.local.modelInstances;if(i&&Object.values(i).some(e=>{var t;return null==(t=null==e?void 0:e.isHovered)?void 0:t.call(e)}))return!0;for(const r of this.sublayers)if("model"!==r.layerType&&"effect"!==r.layerType&&this._isSublayerHovered(r.sublayerIndex))return!0;return!1}_isSublayerHovered(e){var t,i;const r=null==(t=this.sublayers)?void 0:t.find(t=>t.sublayerIndex===e);if(!r||"effect"===r.layerType)return!1;const a=this.state();return!!(null==(i=null==a?void 0:a.mouse)?void 0:i.movePos)&&ct(r,a.canvasWidth,a.canvasHeight,a.mouse.movePos)}}class yt extends ft{constructor(e,t,r){super(e,t),i(this,"layerType","image"),i(this,"isElement",!0),i(this,"isGpuElement",!0),this.initOptions=r;for(let i in e)i in this||(this[i]=e[i]);ht(this,e),this.breakpoints.length&&this.setBreakpointValues()}}class xt extends ut{constructor(e,t,r){var a;super(e,t,r),i(this,"layerType","model"),i(this,"isModel",!0),i(this,"contextType","webgl"),e.moduleRef&&(null==(a=null==r?void 0:r.modules)?void 0:a[e.moduleRef])&&(this.moduleUrl=r.modules[e.moduleRef].url),this.trackMouse=void 0!==e.trackMouse?e.trackMouse:0,this.mouseMomentum=void 0!==e.mouseMomentum?e.mouseMomentum:0,this.mouseSpring=void 0!==e.mouseSpring?e.mouseSpring:0,this.trackAxes=e.trackAxes||"xy",this.lightTracking=void 0!==e.lightTracking?e.lightTracking:0,this.rotationTracking=void 0!==e.rotationTracking?e.rotationTracking:0,this.groupLayer=e.groupLayer||!1,this.speed=void 0!==e.speed?e.speed:.5,this.pos=new s.Vec3(e.pos._x,e.pos._y,e.pos._z),this.modelUrl=e.modelUrl,this.scale=e.scale,this.modelRotation=new s.Vec3(e.modelRotation._x,e.modelRotation._y,e.modelRotation._z),this.lightIntensity=e.lightIntensity,this.lightColor=e.lightColor,this.ambientLightColor=e.ambientLightColor,this.fillLightColor=e.fillLightColor,this.ambientLightIntensity=e.ambientLightIntensity??1.5,this.fillLightIntensity=e.fillLightIntensity??1,this.lightPosition=new s.Vec3(e.lightPosition._x,e.lightPosition._y,e.lightPosition._z),this.materialMetalness=e.materialMetalness,this.materialRoughness=e.materialRoughness,this.refractScale=e.refractScale,this.animationAxis=new s.Vec3(e.animationAxis._x,e.animationAxis._y,e.animationAxis._z),this.renderNormals=e.renderNormals,this.animating=e.animating,this.opacity=e.opacity,this.colorMapUrl=e.colorMapUrl,this.colorMapScale=e.colorMapScale??1,this.colorMapPosition=e.colorMapPosition?new s.Vec2(e.colorMapPosition.x??.5,e.colorMapPosition.y??.5):new s.Vec2(.5,.5),this.colorMapIntensity=e.colorMapIntensity??1,this.quality=e.quality||"fast",this.environmentMapIntensity=e.environmentMapIntensity??0,this.environmentMapUrl=e.environmentMapUrl||"",this.normalMapUrl=e.normalMapUrl||"",this.normalMapScale=e.normalMapScale??1,this.normalMapPosition=e.normalMapPosition?new s.Vec2(e.normalMapPosition.x??.5,e.normalMapPosition.y??.5):new s.Vec2(.5,.5),this.normalMapIntensity=e.normalMapIntensity??1,this.extrudeDepth=e.extrudeDepth??10,this.bevelEnabled=e.bevelEnabled??!1,this.bevelThickness=e.bevelThickness??1,this.bevelSize=e.bevelSize??1,this.bevelSegments=e.bevelSegments??2,this.glassIOR=e.glassIOR??1.5,this.glassThickness=e.glassThickness??.5,this.glassRoughness=e.glassRoughness??0,this.glassTint=e.glassTint||"#ffffff",this.glassDispersion=e.glassDispersion??0,this.materialMode=e.materialMode||(e.renderNormals?"glass":"standard"),this.matcapUrl=e.matcapUrl||"https://assets.unicorn.studio/media/matcaps/unicorn_matcap_default.webp",this.matcapIntensity=e.matcapIntensity??.5,this.matcapRotation=e.matcapRotation??0,this.renderNormals="glass"===this.materialMode||this.renderNormals?1:0,this.loadCallback=null,this.breakpoints.length&&this.setBreakpointValues()}unpackage(){return this.pos=new s.Vec3(this.pos._x,this.pos._y,this.pos._z),this.modelRotation=new s.Vec3(this.modelRotation._x,this.modelRotation._y,this.modelRotation._z),this.lightPosition=new s.Vec3(this.lightPosition._x,this.lightPosition._y,this.lightPosition._z),this.animationAxis=new s.Vec3(this.animationAxis._x,this.animationAxis._y,this.animationAxis._z),this}async loadRenderer(){const e=this.state();if(!e.curtain||!e.curtain.renderer||!e.curtain.renderer.gl)return;let t=this.moduleUrl||`https://cdn.jsdelivr.net/gh/hiunicornstudio/unicornstudio.js@v${be}/extensions/model-renderer.js`;try{const i=await import(t);this.local.initialize=i.initialize,this.local.loadModel=i.loadModel,this.local.draw=i.draw,this.local.dispose=i.dispose,this.local.rendererLoaded=!0,requestAnimationFrame(()=>{var t;const i=e.curtain.renderer.gl;this.local.renderTarget&&!this.local.renderTarget._frameBuffer&&this.local.renderTarget._initRenderTarget(),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!1),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),this.local.initialize(i,this),this.local.initialized=!0,this.local.loadModel(this);const r=null==(t=e.curtain)?void 0:t.renderer;r&&(r.state.flipY=null,r.state.premultiplyAlpha=null)})}catch(i){}}handleModelLoaded(e=null){var t,i,r,a;if(this.local.modelLoaded=!0,this.local.modelObject=e,this.local.renderTarget){let e=this.local.renderTarget.getTexture();const a=this.getPlane()||(null==(i=null==(t=this.local.hostLayer)?void 0:t.getPlane)?void 0:i.call(t)),s=this.local.targetSamplerName||"uTexture";let n=null==(r=null==a?void 0:a.textures)?void 0:r.find(e=>e._samplerName===s);n&&e&&n.copy(e)}this.animating||(this.renderModel(),this.local.renderedOnce=!0);const s={layer:this,object:this.local.modelObject,modelUrl:this.modelUrl};null==(a=this.loadCallback)||a.call(this,s)}onLoad(e){return"function"!=typeof e?()=>{}:(this.loadCallback=e,this.local.modelLoaded&&e({layer:this,object:this.local.modelObject||null,modelUrl:this.modelUrl}),()=>{this.loadCallback===e&&(this.loadCallback=null)})}renderModel(){var e,t,i,r,a,s;if(!this.local.rendererLoaded||!this.local.modelLoaded)return;const n=this.state();if(!n||n.destroyed||!n.curtain||!n.curtain.renderer||!n.curtain.renderer.gl)return;const l=n.curtain.renderer.gl;if(0===l.drawingBufferWidth||0===l.drawingBufferHeight)return;if(this.animating){void 0===this.local.time&&(this.local.time=0);let t=(null==(e=this.local.stateEffectProps)?void 0:e.speed)??this.speed??.5;const i=n.fps?60/n.fps:1;this.local.time+=t*i*60}const o=this.materialMode||(this.renderNormals?"glass":"standard"),u=this.environmentMapUrl||"";if(this.environmentMapIntensity>0){const e=this.getPlane()||(null==(i=null==(t=this.local.hostLayer)?void 0:t.getPlane)?void 0:i.call(t));if(e&&!u.trim()){const t=e.textures.find(e=>"uBgTexture"===e._samplerName);(null==t?void 0:t._copiedFrom)&&t._sampler?this.local.envTexture={gl:l,webglTexture:t._sampler.texture,width:t._size.width,height:t._size.height}:this.local.envTexture=null}else u.trim()||(this.local.envTexture=null)}else this.local.envTexture=null;if("glass"===o){const e=this.getPlane()||(null==(a=null==(r=this.local.hostLayer)?void 0:r.getPlane)?void 0:a.call(r));if(e){const t=e.textures.find(e=>"uBgTexture"===e._samplerName);(null==t?void 0:t._copiedFrom)&&t._sampler&&t._sampler.texture?this.local.backgroundTexture={gl:l,webglTexture:t._sampler.texture,width:t._size.width,height:t._size.height}:this.local.backgroundTexture=null}else this.local.backgroundTexture=null}else this.local.backgroundTexture=null;const d=void 0!==this.local.time?this.local.time:performance.now();if(this.local.renderTarget)if(this.local.renderTarget._frameBuffer){const e=this.local.renderTarget._frameBuffer,t=this.local.renderTarget._size.width,i=this.local.renderTarget._size.height;l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL,!1),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),l.bindFramebuffer(l.FRAMEBUFFER,e),l.viewport(0,0,t,i);try{this.local.draw(l,d,this)}finally{l.bindFramebuffer(l.FRAMEBUFFER,null),l.viewport(0,0,l.drawingBufferWidth,l.drawingBufferHeight),l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL,!0),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);const e=null==(s=n.curtain)?void 0:s.renderer;e&&(e.setBlendFunc(),e.state.currentProgramID=null,e.state.currentGeometryID=null,e.state.forceBufferUpdate=!0,e.state.frameBufferID=null,e.state.activeTexture=null,e.state.depthTest=null,e.state.cullFace=null,e.state.flipY=null,e.state.premultiplyAlpha=null)}}else this.local.draw(l,d,this),l.pixelStorei(l.UNPACK_FLIP_Y_WEBGL,!0)}resize(){var e;const t=this.state();if(!(null==t?void 0:t.resizeRenderTarget)||!this.local.renderTarget||!(null==(e=t.curtain)?void 0:e.canvas))return;const i=this.getPlane();let r=this.userDownsample||1;(null==i?void 0:i.userData)&&void 0!==i.userData.downSample&&(r="number"==typeof i.userData.downSample?i.userData.downSample:1);const a=t.curtain.canvas.width*r,s=t.curtain.canvas.height*r;t.resizeRenderTarget(this.local.renderTarget,a,s)}cleanup(){var e;if(this.local.dispose&&this.local.dispose(this),this.local.initialize=null,this.local.loadModel=null,this.local.draw=null,this.local.dispose=null,this.local.rendererLoaded=!1,this.local.initialized=!1,this.local.modelLoaded=!1,this.local.modelObject=null,this.local.renderTarget){this.local.renderTarget.remove();let t=this.getPlane();t&&(null==(e=t.removeRenderTarget)||e.call(t)),this.local.renderTarget=null}}isAnimating(){return this.visible&&(this.animating||this.trackMouse>0||this.rotationTracking>0||this.lightTracking>0)}getProp(e){var t;return(null==(t=this.local.stateEffectProps)?void 0:t[e])??this[e]}isAnimatableLightColorProp(e){return xe.includes(e)}getEventValue(e,t=this[e]){if(!this.isAnimatableLightColorProp(e)||null==t)return t;if("Vec3"===(null==t?void 0:t.type))return t instanceof s.Vec3?t.clone():new s.Vec3(t.x??t._x,t.y??t._y,t.z??t._z);const i=Ee(t);return i?new s.Vec3(...i.map(e=>e/255)):t}fromEventValue(e,t){if(!this.isAnimatableLightColorProp(e)||null==t||"string"==typeof t)return t;if("Vec3"===(null==t?void 0:t.type)){return function(e,t,i){return"#"+((1<<24)+(e<<16)+(t<<8)+i).toString(16).slice(1)}(...[t.x??t._x??0,t.y??t._y??0,t.z??t._z??0].map(e=>Math.max(0,Math.min(255,Math.round(255*e)))))}return t}isHovered(){if(!this.local.boundingBox)return!1;const e=this.state(),t=e.canvasWidth,i=e.canvasHeight,r=this.local.boundingBox.min,a=this.local.boundingBox.max,s=r.x*t,n=r.y*i,l=a.x*t,o=a.y*i,u=e.mouse.movePos;return 2*u.x>=s&&2*u.x<=l&&2*u.y>=n&&2*u.y<=o}dispose(){this.cleanup(),super.dispose()}}class bt extends ft{constructor(e,t,r){super(e,t),i(this,"layerType","text"),i(this,"isText",!0),this.initOptions=r,this.opacity=e.opacity??1,this.displace=e.displace||0,this.bgDisplace=e.bgDisplace||0,this.dispersion=e.dispersion||0,this.rotation=e.rotation||0,this.blendMode=e.blendMode||"NORMAL";let a=this.default(e||{});for(let i in a)this[i]=a[i];this.breakpoints.length&&this.setBreakpointValues(),this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Object.keys(e).length&&this.createLocalCanvas(),this.loadFont()}createLocalCanvas(){const e=this.state(),t=document.createElement("canvas"),i=this.getPixelRatio();t.width=e.canvasWidth*i,t.height=e.canvasHeight*i;const r=t.getContext("2d");r.scale(i,i),this.local.canvas=t,this.local.ctx=r}resize(){var e,t,i;const r=this.state();if(this.local.canvas){const e=this.getPixelRatio();this.local.canvas.width=r.canvasWidth*e,this.local.canvas.height=r.canvasHeight*e,this.local.ctx.scale(e,e)}const a=null==(e=r.currentBreakpoint)?void 0:e.name;(null==(i=null==(t=this.states)?void 0:t.appear)?void 0:i.some(e=>!e.complete&&(!e.breakpoints||0===e.breakpoints.length||e.breakpoints.includes(a))))||this.render(),Be(this,this.state().element)}default(e){return{fill:e.fill||["#ffffff"],fontSize:e.fontSize??24,fontSizeMode:e.fontSizeMode||"fixed",fontCSS:e.fontCSS||null,lineHeight:e.lineHeight??25,letterSpacing:e.letterSpacing||0,fontFamily:e.fontFamily||"arial",fontStyle:e.fontStyle||"normal",fontWeight:e.fontWeight||"normal",textAlign:e.textAlign||"left",textContent:e.textContent||"",href:e.href||"",gradientAngle:e.gradientAngle||e.gradAngle||0,gradientType:e.gradientType||e.gradType||"linear",noTextAsHtml:e.noTextAsHtml||!1,htmlOnly:e.htmlOnly||!1,htmlRenderOrder:e.htmlRenderOrder??0}}unpackage(){return this.fill=Se(this.fill),this}loadFont(){var e;const t=this.fontStyle.includes("italic")?"italic":"normal",i=e=>"normal"===e||"400"===e||400===e?"normal":e.toString(),r=isNaN(parseInt(this.fontWeight))?"normal":i(this.fontWeight);if(Array.from(document.fonts).some(e=>e.family===this.fontFamily&&e.style===t&&i(e.weight)===r&&"loaded"===e.status)||!(null==(e=this.fontCSS)?void 0:e.src))return void this.handleFontLoaded();let a=this.fontCSS.src.split(" ").join("%20");const s=new FontFace(this.fontFamily,`url(${a})`,{style:t,weight:r});document.fonts.add(s),s.load().then(()=>{this.handleFontLoaded()}).catch(e=>{this.handleFontLoaded()})}handleFontLoaded(){this.local.loaded=!0,this.render(),this.render();const e=this.state();e.renderFrame&&e.renderFrame(),Be(this,this.state().element)}getAbsoluteFontValues(e){var t,i,r,a,s,n;const l=(null==(i=null==(t=this.local)?void 0:t.stateEffectProps)?void 0:i.fontSize)||this.fontSize,o=(null==(a=null==(r=this.local)?void 0:r.stateEffectProps)?void 0:a.lineHeight)||this.lineHeight,u=(null==(n=null==(s=this.local)?void 0:s.stateEffectProps)?void 0:n.letterSpacing)||this.letterSpacing,d="fixed"===this.fontSizeMode?l:l*e.canvasWidth;return{fontSize:d,lineHeight:"fixed"===this.fontSizeMode?o:o*d,letterSpacing:"fixed"===this.fontSizeMode?u:u*d}}render(){var e,t,i;if(!(null==(e=this.local)?void 0:e.ctx))return;let r=this.local.ctx,{left:a,top:s,width:n}=this.box();const l=dt(this.anchorPoint),o=((null==(i=null==(t=this.local)?void 0:t.stateEffectProps)?void 0:i.rotation)??this.rotation)||0;let u=this.state(),d=this.height,c=a-l.x*n,h=s-l.y*d,f=0,{fontSize:p,lineHeight:m,letterSpacing:v}=this.getAbsoluteFontValues(u),g=this.fontStyle.includes("italic")?"italic":"normal",y=/^\d+$/.test(this.fontStyle)?this.fontStyle:"400";r.clearRect(0,0,u.canvasWidth,u.canvasHeight),r.font=`${g} ${y} ${p}px/${m}px ${this.fontFamily}, -apple-system, BlinkMacSystemFont, Helvetica, Arial`,this.isSafari||(r.textAlign=this.textAlign,r.letterSpacing=v+"px");const x=r.measureText("m").width;n=Math.max(n,x),r.save();let b=c+n/2,_=h+d/2;r.translate(b,_),r.rotate(360*o*Math.PI/180),r.translate(-b,-_),"center"===this.textAlign&&(c+=n/2),"right"===this.textAlign&&(c+=n),r.fillStyle=this.fill[0];const P=(e,t)=>{let i=h+m*t+m/2+p/3;this.isSafari?((e,t,i,r,a,s,n)=>{let l,o=t.split("").reduce((i,r,s)=>i+e.measureText(r).width+(s=0;u--){const i=t[u];l-=e.measureText(i).width,e.fillText(i,l,r),u>0&&(l-=a)}else for(let u=0;ut.split("").reduce((r,a,s)=>(r+=e.measureText(a).width,sn||"\n"===a){if(""!==e)T[M]=e.trim(),i!==t.length-1?(T.splice(M+1,0,t.slice(i).join("")),E++):"\n"!==a&&T.push(a);else{let e=a,s=M;for(;e.length>0;){let t="";for(let i=0;i0&&(T.splice(s+1,0,e),s++,E++)}t.slice(i+1).length>0&&(T[s]+=t.slice(i+1).join(""))}break}e=s,i===t.length-1&&(T[M]=e.trim())}}T.forEach((e,t)=>{P(e,f),t{t.pauseTime=e})):(je(),Mt(),Ot.forEach(t=>{var i,r;t.pauseTime=t.pauseTime-e,null==(r=null==(i=t.curtain)?void 0:i.planes)||r.forEach(e=>{e.videos.forEach(e=>{e.play()})})}))}function Pt(){ie=window.innerHeight||document.documentElement.clientHeight,re=window.innerWidth||document.documentElement.clientWidth,Ot.filter(e=>e.initialized).forEach(e=>{e.refresh()}),Rt()}function Tt(e,t,i=50){const r=t||e.getBoundingClientRect(),a=r.top>=-i&&r.top<=ie+i||r.bottom>=-i&&r.bottom<=ie+i||r.top<=0&&r.bottom>=ie,s=r.left>=-i&&r.left<=re+i||r.right>=-i&&r.right<=re+i||r.left<=0&&r.right>=re;return a&&s}function Et(e){"function"==typeof window.requestIdleCallback?window.requestIdleCallback(e,{timeout:500}):setTimeout(()=>e({didTimeout:!1,timeRemaining:()=>8}),16)}function wt(e){const t=e.bbox||e.element.getBoundingClientRect();return t.bottom<0?-t.bottom:t.top>ie?t.top-ie:0}function Mt(){!he&&fe.length&&(he=!0,Et(()=>{if(he=!1,fe=fe.filter(e=>!e.destroyed&&Ot.includes(e)&&document.body.contains(e.element)&&!e.initialized&&!e.initializing),!fe.length)return;const e=Ot.some(e=>e.isInView&&e.initializing&&!e.destroyed);if(ce||document.hidden||e)return void setTimeout(Mt,80);fe.sort((e,t)=>{const i=2*ie,r=wt(e),a=wt(t);return(r<=i?0:1)-(a<=i?0:1)||r-a});const t=fe.shift();t.local.prewarmQueued=!1,t.initializePlanes(()=>Mt(),!0)}))}function kt(e){!(null==e?void 0:e.lazyLoad)||e.destroyed||e.initialized||e.initializing||e.local.prewarmQueued||(e.local.prewarmQueued=!0,fe.push(e),Mt())}function Rt(){Ot.filter(e=>e.getDynamicLayers().length||e.lazyLoad&&!e.initialized).forEach(e=>{let t=e.element.getBoundingClientRect();if(e.scrollY=se,e.lastBbox){0===Math.abs(t.top-e.lastBbox.top)&&le>0?(e.fixedCounter=(e.fixedCounter||0)+1,e.fixedCounter>3&&(e.isFixed=!0)):e.fixedCounter=0}e.lastBbox=e.bbox,e.bbox=t})}function It(){const e=performance.now();Ot.filter(e=>e.getDynamicLayers().length||e.lazyLoad&&!e.initialized).forEach(t=>{if(Tt(t.element,t.bbox,100)){if(!t.isInView){t.isInView=!0,t.pauseTime=t.pauseTime-e;const i=t.element.offsetWidth>0&&t.element.offsetHeight>0;i&&t.curtain?t.resize():i||requestAnimationFrame(()=>{t.element.offsetWidth>0&&t.element.offsetHeight>0&&t.curtain&&t.resize()}),kt(t)}}else t.isInView&&(t.isInView=!1,t.pauseTime=e)})}function Ft(){ce=!1,Te(),Rt(),It();const e=Ot.filter(e=>e.getDynamicLayers().length),t=Ot.filter(e=>e.rendering);e.length&&!t.length&&je(),Mt()}function St(){ce=!0;const e=Ot.filter(e=>e.getDynamicLayers().length),t=Ot.filter(e=>e.rendering);e.length&&!t.length&&je();const i=performance.now();(!ue||i-ue>80)&&(Rt(),ue=i),clearTimeout(de),de=setTimeout(Ft,80),It()}function At(){Te(),St()}function Vt(e){var t;if(e._hasMousePos)return!0;if(!(null==(t=e.curtain)?void 0:t.planes))return!1;const i=e.curtain.planes.find(e=>e.uniforms.mousePos);return i&&(e._hasMousePos=!0),!!i}function Lt(e){for(let t=0;t1&&t-r.lastBboxTime>64&&(n=r.element.getBoundingClientRect(),r.lastBbox=r.bbox,r.bbox=n,r.scrollY=se,r.lastBboxTime=t),e.targetTouches?(a=e.targetTouches[0].pageX,s=e.targetTouches[0].pageY):(a=e.pageX,s=e.pageY),r.isFixed&&(r.scrollY=0,s=e.targetTouches?e.targetTouches[0].clientY:e.clientY);const l=a-n.left,o=s-(n.top+(r.isFixed?0:r.scrollY));r.mouse.page.x=a,r.mouse.page.y=s,r.mouse.movePos.x=.5*l,r.mouse.movePos.y=.5*o,r.mouse.movedInView=!0}}let Ot=[];class Dt{constructor(e){i(this,"local",{}),i(this,"scrollY",0),i(this,"paused",!1),i(this,"destroyed",!1),i(this,"lastBboxTime",0),this.id=e.id;const t=[{name:"Desktop",max:1/0,min:992},{name:"Tablet",max:991,min:576},{name:"Mobile",max:575,min:0}];if(e.breakpoints)for(const i of e.breakpoints){const e=t.find(e=>e.name===i.name);e&&(void 0!==i.min&&(e.min=i.min),void 0!==i.max&&(e.max=i.max))}this.breakpoints=t,this.projectId=e.projectId,this.canvasWidth=e.width||e.element.offsetWidth||re,this.canvasHeight=e.height||e.element.offsetHeight||ie,this.curtain=void 0,this.curtainRafId=void 0,this.dpi=+e.dpi||Math.min(1.5,window.devicePixelRatio),this.element=e.element,this.altText=e.altText||"",this.ariaLabel=e.ariaLabel||"Unicorn Studio Scene",this.fps=e.fps||60,this.name=e.name,this.frameDuration=1e3/(e.fps||60),this.layers=e.layers,this.lazyLoad=e.lazyLoad,this.initialized=!1,this.lasTick=null,this.lastTime=0,this.rendering=!1,this.bbox={},this.isFixed=e.fixed||"fixed"===window.getComputedStyle(this.element).position,this.interactivity={mouse:{disableMobile:!1,disabled:!1}},this.mouse={downPos:{x:.5,y:.5},movePos:{x:.5,y:.5},lastPos:{x:.5,y:.5},delta:{x:0,y:0},page:{x:99999999999,y:99999999999},dragging:!1,movedInView:!1,enterTime:null,ticks:0,pos:{x:0,y:0}},this.renderingScale=e.renderingScale||1,this.scale=e.scale||1,this.split=!1,this.versionId="",this.variableCallbacks=[],this.initialVariables=e.initialVariables||{},this.initialPreset=e.initialPreset||"",this.editMetadata=e.editMetadata||{},this.breakpointWidth=Number.isFinite(Number(e.breakpointWidth))?Number(e.breakpointWidth):null,e.width&&e.height&&(this.element.style.width=e.width+"px",this.element.style.height=e.height+"px"),this.bbox=this.element.getBoundingClientRect(),this.lastBbox=this.bbox,this.currentBreakpoint=this.getCurrentBreakpoint(),e.deferCurtains||this.ensureCurtains()}ensureCurtains(){return this.curtain||(this.createCurtains(),this.setCanvasScale()),ze(this.curtain)&&this.curtain.gl&&(this.applyCanvasA11yAttrs(),this.textureLoader||(this.textureLoader=new s.TextureLoader(this.curtain))),ze(this.curtain)&&!!this.curtain.gl}applyCanvasA11yAttrs(){var e;(null==(e=this.curtain)?void 0:e.canvas)&&(this.curtain.canvas.innerText=this.altText,this.curtain.canvas.setAttribute("aria-label",this.ariaLabel),this.curtain.canvas.setAttribute("role","img"))}hasValidTextureLoader(){var e;return!(!this.textureLoader||!(null==(e=this.textureLoader.renderer)?void 0:e.cache)&&!this.textureLoader.cache)}getLayer(e,t=null){var i,r;const a=this.layers.find(t=>n(t,e,{includeRuntimeLocalId:!0}))||null;if(a||!(null==t?void 0:t.target))return a;const s=this.layers.find(t=>!(!(null==t?void 0:t.isFlattened)||!Array.isArray(t.sublayers))&&t.sublayers.some(t=>n(t,e)));if(s){const a=s.sublayers.find(t=>n(t,e)),l=null==a?void 0:a.sublayerIndex;if(Number.isInteger(l))if("prop"===(t.kind||"prop")){const e=`L${l}_${t.target}`,r=`L${l}_elemOpacity`,a=(null==(i=s.data)?void 0:i.uniforms)||{};"opacity"===t.target&&a[r]?t.target=r:a[e]&&(t.target=e)}else if("texture"===t.kind||"source"===t.kind){const e=(null==(r=s.data)?void 0:r.textures)||[],i=`uL${l}_${String(t.target||"").replace(/^u/,"")}`,n=e.find(e=>(null==e?void 0:e.sublayerIndex)===l&&e.sampler===t.target)||e.find(e=>(null==e?void 0:e.sublayerIndex)===l&&e.sampler===i)||("source"===t.kind&&"video"!==(null==a?void 0:a.type)?e.find(e=>(null==e?void 0:e.sublayerIndex)===l&&["image","media","canvas","modelRT"].includes(e.type)):null);(null==n?void 0:n.sampler)&&(t.kind="texture",t.target=n.sampler)}return s}const l=this.layers.filter(e=>Object.prototype.hasOwnProperty.call(e,t.target));return 1===l.length?l[0]:null}setupVariables(e={},t={},i=""){this.variables=new U({variables:e,getLayer:(e,t)=>this.getLayer(e,t)}),this.variables.applyAll(),i&&this.variables.applyPreset(i),this.variables.applyInitialValues(t)}setVariable(e,t){var i;if(null==(i=this.variables)?void 0:i.setValue(e,t)){const t=this.getVariable(e),i=this.getVariables();this.variableCallbacks.forEach(r=>r(e,t,i))}else if(this.variables&&!this.variables.getDefinition(e)){this.getCreateVariableUrl({name:e,defaultValue:t})}return this}setVariables(e={}){return Object.entries(e||{}).forEach(([e,t])=>this.setVariable(e,t)),this}setPreset(e){var t;const i=(null==(t=this.variables)?void 0:t.applyPreset(e))||[];if(i.length){const e=this.getVariables();i.forEach(t=>{this.variableCallbacks.forEach(i=>i(t,this.getVariable(t),e))})}return this}getPreset(e){var t;return(null==(t=this.variables)?void 0:t.getPreset(e))||null}getPresets(){var e;return(null==(e=this.variables)?void 0:e.getPresets())||[]}getVariable(e){var t;return null==(t=this.variables)?void 0:t.getValue(e)}getVariables(){var e;return(null==(e=this.variables)?void 0:e.getValues())||{}}getVariableDefinition(e){var t;const i=null==(t=this.variables)?void 0:t.getDefinition(e);return i?{...i,defaultValue:qe(i.defaultValue)}:null}getVariableDefinitions(){var e;return(null==(e=this.variables)?void 0:e.getDefinitions())||[]}getVariableManifest(){var e;return(null==(e=this.variables)?void 0:e.getManifest())||[]}getMouse(){var e,t,i,r,a,s,n,l,o,u;const d=!!(null==(e=this.mouse)?void 0:e.movedInView),c=(null==(t=this.bbox)?void 0:t.width)||(null==(i=this.element)?void 0:i.offsetWidth)||this.canvasWidth||0,h=(null==(r=this.bbox)?void 0:r.height)||(null==(a=this.element)?void 0:a.offsetHeight)||this.canvasHeight||0;if(!d||!c||!h)return{x:.5,y:.5,inBounds:!1,moved:d};const f=this.mouse.page||{},p=(null==(s=this.bbox)?void 0:s.left)||0,m=this.isFixed?(null==(n=this.bbox)?void 0:n.top)||0:((null==(l=this.bbox)?void 0:l.top)||0)+this.scrollY,v=(null==(o=this.lastBbox)?void 0:o.width)||c,g=(null==(u=this.lastBbox)?void 0:u.height)||h,y=f.x>p&&f.y>m&&f.x{}:(this.variableCallbacks.push(e),()=>{this.variableCallbacks=this.variableCallbacks.filter(t=>t!==e)})}getCreateVariableUrl({layer:e=null,target:t="",defaultValue:i=0,kind:r="prop",name:a=""}={}){const s=(null==e?void 0:e.hasPublishedPublicId)?null==e?void 0:e.id:(null==e?void 0:e.editorLayerId)||(null==e?void 0:e.id);if(e&&t&&!s)return"";const n=M({name:a,layerId:s,layerName:(null==e?void 0:e.layerName)||(null==e?void 0:e.name),target:t,kind:r,defaultValue:i,canvasId:this.editMetadata.canvasId});return function({baseUrl:e="https://unicorn.studio",designId:t,intent:i}={}){const r=w(t);if(!r||!i)return"";const a=new URL(`/edit/${r}`,e),s=M(i);return a.searchParams.set("createVariable",k(s)),s.canvasId&&a.searchParams.set("canvasId",s.canvasId),a.toString()}({designId:this.editMetadata.designId,intent:n})}setProp(e,t,i){const r=this.getLayer(e);return r?(r.setRuntimeOverride(t,i,{source:"scene.setProp"}),this):this}setTexture(e,t,i){const r=this.getLayer(e);return r?(r.setTexture(t,i),this):this}getLayers(){return this.layers.map(e=>({id:e.id,publicId:e.publicId,name:e.layerName||e.name||e.id,type:e.layerType||e.type}))}preloadImage(e,t,i,r=!0){if(!e)return;if(!this.hasValidTextureLoader())return void(i&&i(null));this.local.preloadedImages=this.local.preloadedImages||{};let a=this.local.preloadedImages[e];if(a||(a=this.local.preloadedImages[e]={texture:null,loading:!0,claimed:!1,queue:[]},this.textureLoader.loadImage(e,{sampler:t,premultipliedAlpha:r},t=>{a.texture=t,a.loading=!1;for(const i of a.queue)this._resolvePreloadedImage(e,i);a.queue=[]},()=>{a.loading=!1,a.queue.forEach(e=>e.callback(null)),a.queue=[]})),!i)return;const s={callback:i,sampler:t,premultiplyAlpha:r};a.loading?a.queue.push(s):this._resolvePreloadedImage(e,s)}_resolvePreloadedImage(e,t){if(!this.hasValidTextureLoader())return void t.callback(null);const i=this.local.preloadedImages[e];i.claimed?this.textureLoader.loadImage(e,{sampler:t.sampler,premultipliedAlpha:t.premultiplyAlpha},t.callback,()=>t.callback(null)):(i.claimed=!0,t.callback(i.texture))}preloadVideo(e){if(!e)return null;const t=e.includes(", ")?Ue(e):e;if(this.local.preloadedVideos=this.local.preloadedVideos||{},!this.local.preloadedVideos[t]){const e=document.createElement("video");e.crossOrigin="anonymous",e.muted=!0,e.preload="auto",e.setAttribute("playsinline",""),e.src=t,e.load(),this.local.preloadedVideos[t]=e}return this.local.preloadedVideos[t]}shouldPreloadLayerAssets(e){return!1!==(null==e?void 0:e.visible)}ensureImageLayerTexture(e,t=null){"image"!==e.layerType||!e.src||e.local.sourceTexture||e.local.sourceTextureLoading||(e.local.sourceTextureLoading=!0,this.preloadImage(e.src,"uSourceImage",i=>{var r,a;if(e.local.sourceTextureLoading=!1,!i)return;e.local.sourceTexture=i,e.local.imageReady=!0;const s=t||(null==(r=e.getPlanes)?void 0:r.call(e).find(e=>{var t;return!(null==(t=e.userData)?void 0:t.isComposite)}))||(null==(a=e.getPlane)?void 0:a.call(e));s&&!s.textures.some(e=>"uSourceImage"===e._samplerName)&&s.addTexture(i),this.requestSceneRender()}))}isFlattenedSublayerHidden(e,t,i=null){var r,a,s,n;const l=null==t?void 0:t.sublayerIndex;if(!(null==e?void 0:e.isFlattened)||!Number.isInteger(l))return!1;const o=`L${l}_elemOpacity`,u=`L${l}_opacity`,d=(null==(r=null==i?void 0:i.uniforms)?void 0:r[o])||(null==(a=null==i?void 0:i.uniforms)?void 0:a[u]);if(d&&0===d.value)return!0;return 0===((null==(s=e.local.bpProps)?void 0:s[o])??(null==(n=e.local.bpProps)?void 0:n[u]))}ensureFlattenedTexture(e,t,i=null){var r;if((null==e?void 0:e.isFlattened)&&t&&!this.isFlattenedSublayerHidden(e,t,i)){if("image"===t.type&&t.src){e.local.sourceTextures=e.local.sourceTextures||{};const r=e.local.sourceTextures[t.sublayerIndex];return r?void(i&&!i.textures.some(e=>e._samplerName===t.sampler)&&i.addTexture(r)):void this.preloadImage(t.src,t.sampler,r=>{var a;if(!r)return;e.local.sourceTextures[t.sublayerIndex]=r;const s=i||(null==(a=e.getPlane)?void 0:a.call(e));let n=!1;s&&!s.textures.some(e=>e._samplerName===t.sampler)&&(s.addTexture(r),n=!0),n&&this.requestSceneRender()})}if("video"===t.type){const r=e.sublayers.find(e=>e.sublayerIndex===t.sublayerIndex);if(!(null==r?void 0:r.src))return;e.local.videoElements||(e.local.videoElements={}),e.local.videoTextures||(e.local.videoTextures={}),e.local.videoTextureLoading||(e.local.videoTextureLoading={});const a=e.local.videoElements[t.sublayerIndex]||this.preloadVideo(r.src);if(e.local.videoElements[t.sublayerIndex]=a,!i||i.textures.some(e=>e._samplerName===t.sampler))return;if(e.local.videoTextures[t.sampler])return void i.addTexture(e.local.videoTextures[t.sampler]);if(e.local.videoTextureLoading[t.sampler])return;return e.local.videoTextureLoading[t.sampler]=!0,void i.loadVideo(a,{premultipliedAlpha:!0,sampler:t.sampler},i=>{e.local.videoTextureLoading[t.sampler]=!1,e.local.videoTextures[t.sampler]=i;const s=(null==i?void 0:i.source)||(null==i?void 0:i._source)||a;s&&(s.loop=!(null==r?void 0:r.hasOwnProperty("loop"))||r.loop,s.playbackRate=(null==r?void 0:r.playbackRate)||1,s.play(),this.requestSceneRender())},()=>{e.local.videoTextureLoading[t.sampler]=!1})}if("media"===t.type&&t.src){if(null==i?void 0:i.textures.some(e=>e._samplerName===t.sampler))return;this.preloadImage(t.src,t.sampler,r=>{var a;if(!r)return;const s=i||(null==(a=e.getPlane)?void 0:a.call(e));s&&!s.textures.some(e=>e._samplerName===t.sampler)&&(s.addTexture(r),this.requestSceneRender())},!1)}else if("modelRT"===t.type){const a=null==(r=e.local.modelInstances)?void 0:r[t.sublayerIndex];if(!a||!this.curtain)return;a.local.hostLayer=e,a.local.targetSamplerName=t.sampler,a.local.renderTarget||(a.local.renderTarget=new s.RenderTarget(this.curtain,{depth:!0,maxWidth:this.curtain.canvas.width*(a.userDownsample||1),maxHeight:this.curtain.canvas.height*(a.userDownsample||1),texturesOptions:{sampler:t.sampler,premultiplyAlpha:!0}}));const n=a.local.renderTarget.getTexture();n&&(e.local.modelTextures[t.sublayerIndex]=n,i&&!i.textures.some(e=>e._samplerName===t.sampler)&&(i.addTexture(n),this.requestSceneRender())),a.local.rendererLoaded||a.local.rendererLoading||(a.local.rendererLoading=!0,Promise.resolve(a.loadRenderer()).finally(()=>{a.local.rendererLoading=!1}))}}}preloadTextures(){!this.local.texturesPreloaded&&this.hasValidTextureLoader()&&(this.local.texturesPreloaded=!0,this.layers.forEach(e=>{var t,i,r,a,s,n,l;const o=this.shouldPreloadLayerAssets(e);if(e.isFlattened)return e.local.canvasTextures={},e.local.sourceTextures={},void((null==(t=e.data)?void 0:t.textures)&&e.data.textures.forEach(t=>{var i,r;if("canvas"===t.type){const a=null==(i=e.local.textInstances)?void 0:i[t.sublayerIndex];(null==(r=null==a?void 0:a.local)?void 0:r.canvas)&&this.textureLoader.loadCanvas(a.local.canvas,{sampler:t.sampler,premultiplyAlpha:!0},i=>{var r;i.shouldUpdate=!0,e.local.canvasTextures[t.sublayerIndex]=i;const a=null==(r=e.getPlane)?void 0:r.call(e);a&&!a.textures.some(e=>e._samplerName===t.sampler)&&a.addTexture(i)})}else o&&this.ensureFlattenedTexture(e,t)}));if(e.isElement)e.local.canvas&&!e.htmlOnly?this.textureLoader.loadCanvas(e.local.canvas,{sampler:"uTexture",premultiplyAlpha:!0},t=>{t.userData.hasStateEffects=e.states.appear.length>0||e.states.scroll.length>0||e.states.hover.length>0||e.states.mousemove.length>0,e.preloadedCanvasTexture=t},e=>{}):"image"===e.layerType&&e.src&&o&&this.ensureImageLayerTexture(e);else{const t=(null==(i=null==e?void 0:e.texture)?void 0:i.src)||(null==(a=null==(r=null==e?void 0:e.data)?void 0:r.texture)?void 0:a.src),u=(null==(s=null==e?void 0:e.texture)?void 0:s.sampler)||(null==(l=null==(n=null==e?void 0:e.data)?void 0:n.texture)?void 0:l.sampler)||"uTexture";o&&t&&this.preloadImage(t,u,null,!1)}}))}setCanvasScale(){this.canvasWidth=this.element.offsetWidth,this.canvasHeight=this.element.offsetHeight}destroy(){var e,t;this.destroyed=!0,this.rendering=!1,this.isInView=!1,this.local.prewarmQueued=!1,fe=fe.filter(e=>e!==this),Mt();const i=Ot.findIndex(e=>e.id===this.id);-1!==i&&Ot.splice(i,1),this.layers.filter(e=>e.dispose).forEach(e=>e.dispose()),this.layers=[],(null==(e=this.curtain)?void 0:e.gl)&&(this.curtain.dispose(),this.curtain=null),this.element&&(this.element.removeAttribute("data-us-initialized"),this.element.removeAttribute("data-scene-id"),null==(t=this.element.querySelector("canvas"))||t.remove(),this.element.querySelectorAll("[data-us-text]").forEach(e=>{e.remove()})),je(),Ot.length||zt()}syncPlaneVisibility(){this.layers.filter(e=>!e.parentLayer&&!e.groupLayer).forEach(e=>{const t=e.visible;e.isGroup&&e.getMemberItems().forEach(e=>{const i=t&&e.visible;e.getChildEffectItems().forEach(e=>{const t=i&&e.visible;e.getPlanes().forEach(e=>{e.visible=t})}),e.getPlanes().forEach(e=>{e.visible=i})}),e.getChildEffectItems().forEach(e=>{const i=t&&e.visible;e.getPlanes().forEach(e=>{e.visible=i})}),e.getPlanes().forEach(e=>{e.visible=t})})}applyLayerVisibility(){let e=!1;this.layers.filter(e=>!e.parentLayer&&!e.groupLayer).forEach(t=>{const i=t.visible;t.isGroup&&t.getMemberItems().forEach(t=>{const r=i&&t.visible;t.getChildEffectItems().forEach(t=>{const i=r&&t.visible;t.getPlanes().forEach(t=>{t.visible!==i&&(e=!0),t.visible=i})}),t.getPlanes().forEach(t=>{t.visible!==r&&(e=!0),t.visible=r})}),t.getChildEffectItems().forEach(t=>{const r=i&&t.visible;t.getPlanes().forEach(t=>{t.visible!==r&&(e=!0),t.visible=r})}),t.getPlanes().forEach(t=>{t.visible!==i&&(e=!0),t.visible=i}),i&&t.isModel&&!t.local.rendererLoaded&&!t.local.rendererLoading&&(t.local.rendererLoading=!0,Promise.resolve(t.loadRenderer()).finally(()=>{t.local.rendererLoading=!1}))}),e&&(this.calculateRenderOrders(),this.createTextures(),this.renderFrame())}getBreakpointWidth(){return this.breakpointWidth||re}getCurrentBreakpoint(){const e=this.getBreakpointWidth();return this.breakpoints.find(t=>e>=t.min&&e<=t.max)}applyBreakpointValues(e=!1){var t;const i=this.currentBreakpoint;this.currentBreakpoint=this.getCurrentBreakpoint();const r=e||(null==i?void 0:i.name)!==(null==(t=this.currentBreakpoint)?void 0:t.name);for(let a=0;a{var t,i;null==(t=e.states)||t.scroll.forEach(e=>e.resetState()),null==(i=e.states)||i.appear.forEach(t=>{e[t.prop]=t.endValue??e.local.stateEffectProps[t.prop]??e[t.prop]}),e.breakpoints.length&&(e.setBreakpointValues(this.getBreakpointWidth()),this.applyBreakpointUniforms(e)),e.preloadedCanvasTexture&&(e.preloadedCanvasTexture.shouldUpdate=!0)}),requestAnimationFrame(()=>{this.curtain&&(this.curtain.planes.forEach(e=>{e._canDraw=!0}),this.scrollY=se,this.applyLayerVisibility(),this.resize(),this.handlePlaneCreation())})}getDynamicLayers(){return this.layers.filter(e=>De(e))}createCurtains(){this.curtain=new s.Curtains({container:this.element,premultipliedAlpha:!0,antialias:!1,autoRender:!1,autoResize:!1,watchScroll:!1,renderingScale:Math.min(Math.max(.25,this.renderingScale),1),production:!1,pixelRatio:this.dpi}),this.curtain.gl&&(this.curtain.onError(e=>{}),this.curtain.onContextLost(()=>{this.curtain.restoreContext()}),this.curtain.onContextRestored(()=>{this.initialized&&(this.layers.forEach(e=>{e.preloadedCanvasTexture&&(e.preloadedCanvasTexture.shouldUpdate=!0)}),requestAnimationFrame(()=>{this.curtain&&(this.curtain.planes.forEach(e=>{e._canDraw=!0}),this.renderFrame())}))}),this.scrollY=se)}applyBreakpointUniforms(e){e.local.bpProps&&e.getPlanes().forEach(t=>{var i,r,a;for(let s in t.uniforms){const n=X(e,s,{breakpointProps:e.local.bpProps,baseValue:null==(a=null==(r=null==(i=e.data)?void 0:i.uniforms)?void 0:r[s])?void 0:a.value,sources:["base","breakpoint","runtime"]});void 0!==n.value&&$e(n.value,t.uniforms[s],s)}})}getAppearStateUniformValue(e,t){var i,r;const a=null==(r=null==(i=e.states)?void 0:i.appear)?void 0:r.filter(e=>e.prop===t).filter(e=>{var t,i;return!(null==(t=e.breakpoints)?void 0:t.length)||e.breakpoints.includes(null==(i=this.currentBreakpoint)?void 0:i.name)}).sort((e,t)=>(e.transition.delay||0)-(t.transition.delay||0));if(!(null==a?void 0:a.length))return{hasValue:!1};const s=[...a].reverse().find(e=>e.complete&&void 0!==e.endValue);if(s)return{hasValue:!0,value:s.endValue};const n=a.find(e=>!e.complete&&void 0!==e.value);return n?{hasValue:!0,value:n.value}:{hasValue:!1}}renderFrame(){var e,t;if(!this.destroyed&&ze(this.curtain)&&(this.layers.forEach(e=>{e.local.currentFrameMouseValues=null}),this.local.renderFrameId=(this.local.renderFrameId||0)+1,this.handleStateEffects(),null==(t=(e=this.curtain).needRender)||t.call(e),this.curtain.render(),this.local.pendingStaticRedrawFinish)){const e=this.local.pendingStaticRedrawFinish;this.local.pendingStaticRedrawFinish=null,e()}}requestSceneRender(){ze(this.curtain)&&(this.rendering||("function"==typeof this.curtain.requestRender?this.curtain.requestRender():this.renderFrame()))}requestLayerRender(e){if(!ze(this.curtain))return;const t=this.getSplitOrderedItems();let i=t.static.indexOf(e);if(-1===i)return void this.requestSceneRender();const r=e=>{var r;const a=t.static.indexOf(e);-1!==a&&(i=Math.min(i,a)),null==(r=null==e?void 0:e.getChildEffectItems)||r.call(e).forEach(e=>{const r=t.static.indexOf(e);-1!==r&&(i=Math.min(i,r))})};r(e);if(e.getPlanes().some(e=>{var t;return null==(t=e.textures)?void 0:t.some(e=>"uBgTexture"===(null==e?void 0:e._samplerName))})&&i>0&&r(t.static[i-1]),t.static.slice(i).forEach(e=>{e.getPlanes().forEach(e=>{e._canDraw=!0})}),this.local.staticRedrawQueued)return;this.local.staticRedrawQueued=!0;const a=()=>{this.local.staticRedrawQueued=!1,this.disablePlanes()};this.rendering&&!this.paused?this.local.pendingStaticRedrawFinish=a:this.rendering?(this.renderFrame(),a()):this.renderNFrames(1,a)}renderNFrames(e,t){let i=0;const r=()=>{this.renderFrame(),iDe(e)).length;for(;i&&!De(i)&&!a&&!s;)t++,i=e[t],i&&(r=i.parentLayer?i.getParent():null,a=r&&De(r),s=r&&r.effects&&r.effects.length&&r.getChildEffectItems().filter(e=>De(e)).length);return{static:this.getOrderedItems().splice(0,t),dynamic:this.getOrderedItems().splice(t)}}return{static:[],dynamic:[]}}initializePlanes(e,t=!1){if(this.initializing=!0,!this.ensureCurtains())return this.initializing=!1,void(e&&e(this));const i=()=>{this.handleItemPlanes(()=>{this.handlePlaneCreation(),e&&e(this)},t)};t&&!this.local.texturesPreloaded?this.runIdleTasks([()=>this.preloadTextures()],i):(this.preloadTextures(),i())}getPassPlane(e,t){var i;return null==(i=this.curtain)?void 0:i.planes.find(i=>i.userData.id===e.local.id&&i.userData.passIndex===t)}getRenderTargets(){var e;return null==(e=this.curtain)?void 0:e.renderTargets.filter(e=>e.userData.id)}getPlanes(){var e;return null==(e=this.curtain)?void 0:e.planes.filter(e=>"PingPongPlane"!==e.type)}getPlaneParams(e,t){var i,r,a,n,l;const o=(null==(i=e.data)?void 0:i.widthSegments)||1,u=(null==(r=e.data)?void 0:r.heightSegments)||1,d={resolution:{name:"uResolution",type:"2f",value:new s.Vec2(this.canvasWidth,this.canvasHeight)},mousePos:{name:"uMousePos",type:"2f",value:new s.Vec2(.5)},time:{name:"uTime",type:"1f",value:0}};e.usesPingPong&&(d.previousMousePos={name:"uPreviousMousePos",type:"2f",value:new s.Vec2(.5)});let c=e.compiledFragmentShaders[t]||e.compiledFragmentShaders[0],h=e.compiledVertexShaders[t]??e.compiledVertexShaders[0];if(e.states&&[...e.states.appear,...e.states.scroll,...e.states.hover,...e.states.mousemove].forEach(t=>{d[t.prop]||t.uniformData&&(d[t.prop]=t.uniformData,d[t.prop].value=e[t.prop])}),null==(a=e.data)?void 0:a.uniforms)for(let f in e.data.uniforms){let t=e.data.uniforms[f];d[f]=e.data.uniforms[f],"Vec3"===(null==(n=t.value)?void 0:n.type)?d[f].value=new s.Vec3(t.value._x,t.value._y,t.value._z):"Vec2"===(null==(l=t.value)?void 0:l.type)?d[f].value=new s.Vec2(t.value._x,t.value._y):"object"==typeof t.value&&(d[f].value=Se(t.value))}return{fragmentShader:c,vertexShader:h,widthSegments:o,heightSegments:u,texturesOptions:{floatingPoint:"half-float",premultiplyAlpha:!0},uniforms:d}}getCompositePlaneRenderOrder(e,t,i){const r=e.getChildEffectItems();if(0===r.length)return i;const a=r[r.length-1],s=t.indexOf(a);return-1!==s?s+1:i+r.length}createPlane(e,t){var i;let r,a;r=e.isElement||e.isModel||e.isFlattened?this.getPlaneParams(e):this.getPlaneParams(e,t?t.index:null),r.watchScroll=!1;try{if(!this.curtain.container)throw new Error("Can't find scene container");let n=(null==t?void 0:t.downSample)||0===(null==t?void 0:t.index)&&(null==(i=e.data)?void 0:i.downSample),l=this.renderingScale;if(n&&(l="number"==typeof n?n:.5,l*=this.renderingScale),e.userDownsample&&"number"==typeof e.userDownsample&&(l*=e.userDownsample),a=new s.Plane(this.curtain,this.curtain.container,r),!a||!a.userData||!a.textures)throw new Error("Plane not properly initialized");return a.textures.length=0,a.userData.id=e.local.id,a.userData.layerType=e.layerType,a.userData.type=e.type,a.userData.downSample=l,a}catch(n){return null}}createPingPongPlane(e,t){var i;const r="number"==typeof(null==t?void 0:t.index)?t.index:1+((null==t?void 0:t.length)||0);let a=this.getPlaneParams(e,r),n=null==(i=this.curtain)?void 0:i.planes.find(t=>"PingPongPlane"===t.type&&t.userData.id===e.local.id);if(!n){if(n=new s.PingPongPlane(this.curtain,this.curtain.container,a),!n)return;n.userData.id=e.local.id,n.userData.pingpong=!0,n.onReady(()=>{this.setInitialEffectPlaneUniforms(n,e,null==e?void 0:e.getParent(),t),n.userData.isReady=!0}).onRender(()=>{this.setEffectPlaneUniforms(n,e)})}if(n)return n}createEffectPlane(e,t){const i=this.createPlane(e,t);if(!i)return;const r=e.getParent();if(!i||!i.userData||!i.textures)throw new Error("Plane not properly initialized",i);t&&(i.userData.passIndex=t.index,i.userData.length=e.data.passes.length,i.userData.needsPreviousFrame=t.needsPreviousFrame,Object.entries(t).forEach(([e,t])=>{i.uniforms[e]&&(i.uniforms[e].value=t)})),this.setInitialEffectPlaneUniforms(i,e,r,t),i.onReady(()=>{i.userData.isReady=!0}).onRender(()=>this.setEffectPlaneUniforms(i,e)).onAfterRender(()=>{const t=i.userData.needsPreviousFrame;if(t){const r=i.userData.passIndex??0,a=e.local.previousFrameTargets||{},s=e.local.previousFrameInputTargets||{},n="target"===t?s[r]:i.target,l=a[r];n&&l&&this.blitRenderTarget(n,l)}})}createFlattenedPlane(e,t=e=>e(),i=!1){var r;const a=this.createPlane(e);a&&(a.onReady(()=>{this.setInitialFlattenedPlaneUniforms(a,e),a.userData.isReady=!0}).onRender(()=>this.setFlattenedPlaneUniforms(a,e)),(e.hasRemainingEffects()||e.mask&&0!==e.mask)&&(e.hasRemainingEffects()&&!i&&e.getChildEffectItems().forEach(e=>{e.getPlanes().length||this.createEffectPlanes(e,t)}),(null==(r=e.data)?void 0:r.compositeShader)&&t(()=>this.createCompositePlane(e))))}createGroupPlane(e,t=e=>e(),i=!1){const r={vertexShader:"#version 300 es\nprecision highp float;\nin vec3 aVertexPosition;\nin vec2 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nuniform mat4 uTextureMatrix;\nout vec2 vTextureCoord;\nvoid main() {\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n vTextureCoord = (uTextureMatrix * vec4(aTextureCoord, 0.0, 1.0)).xy;\n}",fragmentShader:"#version 300 es\nprecision highp float;\nin vec2 vTextureCoord;\nout vec4 fragColor;\nvoid main() {\n fragColor = vec4(0.0);\n}",texturesOptions:{premultiplyAlpha:!0},uniforms:{}},a=new s.Plane(this.curtain,this.curtain.container,r);a&&(a.textures.length=0,a.userData.id=e.local.id,a.userData.isGroupSource=!0,a.onReady(()=>{a.userData.isReady=!0}),i||e.getChildEffectItems().forEach(e=>{e.getPlanes().length||this.createEffectPlanes(e,t)}),t(()=>this.createCompositePlane(e)))}createElementPlane(e,t=e=>e()){const i=this.createPlane(e);i&&(e.getChildEffectItems().filter(e=>e.visible).length>0&&t(()=>this.createCompositePlane(e)),i.onReady(()=>{this.setInitialElementPlaneUniforms(i,e),i.userData.isReady=!0}).onRender(()=>this.setElementPlaneUniforms(i,e)))}createCompositePlane(e){var t,i,r;if(!(null==(t=e.data)?void 0:t.compositeShader))return null;const a={vertexShader:e.data.compositeShader.vertexShader,fragmentShader:e.data.compositeShader.fragmentShader,texturesOptions:{premultiplyAlpha:!0},uniforms:{}};if(e.data.compositeUniforms)for(let l in e.data.compositeUniforms){let t=e.data.compositeUniforms[l];a.uniforms[l]={...t},"Vec3"===(null==(i=t.value)?void 0:i.type)?a.uniforms[l].value=new s.Vec3(t.value._x,t.value._y,t.value._z):"Vec2"===(null==(r=t.value)?void 0:r.type)&&(a.uniforms[l].value=new s.Vec2(t.value._x,t.value._y))}const n=new s.Plane(this.curtain,this.curtain.container,a);return n&&n.userData?(n.textures.length=0,n.userData.id=e.local.id,n.userData.isComposite=!0,n.onReady(()=>{n.userData.isReady=!0}).onRender(()=>{this.setCompositePlaneUniforms(n,e)}),n):null}setCompositePlaneUniforms(e,t){var i,r;if((null==e?void 0:e.uniforms)&&e.visible&&(e.uniforms.resolution&&(e.uniforms.resolution.value.x=this.curtain.canvas.width,e.uniforms.resolution.value.y=this.curtain.canvas.height),e.uniforms.opacity&&(e.uniforms.opacity.value=(null==(r=null==(i=t.local)?void 0:i.stateEffectProps)?void 0:r.opacity)??t.opacity??1),e.uniforms.mousePos)){t.local.currentFrameMouseValues||(t.local.currentFrameMouseValues=this.calculateItemMouseValues(t));const i=t.local.currentFrameMouseValues;i&&this.mouse.movedInView&&(e.uniforms.mousePos.value.x=i.x,e.uniforms.mousePos.value.y=i.y)}}handleMediaTextures(e,t,i){var r,a,s;if(((null==(a=null==(r=t.data)?void 0:r.textures)?void 0:a.length)?t.data.textures:[t.texture,null==(s=t.data)?void 0:s.texture].filter(e=>null==e?void 0:e.src)).filter(e=>null==e?void 0:e.src).forEach(r=>{var a;if(null==(a=t.compiledFragmentShaders[i.passIndex??0])?void 0:a.includes(r.sampler)){if("video"===r.type){const i="uVideoTexture"===r.sampler&&t.src?t.src:r.src;if(!i||e.textures.some(e=>e._samplerName===r.sampler))return;const a=this.preloadVideo(i);if(!a)return;return void e.loadVideo(a,{premultipliedAlpha:!0,sampler:r.sampler},i=>{const a=null==i?void 0:i.source;a&&(a.loop=r.loop??t.loop??!0,a.playbackRate=r.playbackRate||t.playbackRate||1,a.play(),e.userData.textureLoaded=!0)})}this.preloadImage(r.src,r.sampler,t=>{if(t){e.textures.some(e=>e._samplerName===r.sampler)||e.addTexture(t),e.userData.textureLoaded=!0}},!1)}}),"video"===t.type&&t.src){if(e.textures.some(e=>"uVideoTexture"===e._samplerName))return;const i=this.preloadVideo(t.src);e.loadVideo(i,{premultipliedAlpha:!0,sampler:"uVideoTexture"},i=>{const r=null==i?void 0:i.source;r&&(r.loop=!t.hasOwnProperty("loop")||t.loop,r.playbackRate=t.playbackRate||1,r.play(),e.userData.textureLoaded=!0)})}}handleEffectPlane(e,t,i,r){var a;const s="passIndex"in i?this.getPassPlane(e,i.passIndex):e.getPlane();if(!s)return!1;let n=r[t-1],l=null==(a=this.curtain)?void 0:a.planes.find(t=>"PingPongPlane"===t.type&&t.userData.id===e.local.id),o=e.compiledFragmentShaders[i.passIndex??0];if(l&&(null==o?void 0:o.includes("uPingPongTexture"))&&rt(s,"uPingPongTexture",l.getTexture()),n?rt(s,"uTexture",n.getTexture()):rt(s,"uTexture"),null==o?void 0:o.includes("uBgTexture")){let e=r[t-(1+i.passIndex)];e&&rt(s,"uBgTexture",e.getTexture())}i.needsPreviousFrame&&rt(s,"uPreviousFrameTexture",this.createPreviousFrameTarget(e,i,t,r)),this.handleMediaTextures(s,e,i)}handleModelPlane(e,t,i){var r;const a=e.getPlane();let s=i[t-1],n=this.findPreviousLayerForMask(e,0);a.textures.forEach(e=>{}),a.textures=[],e.local.renderTarget?a.addTexture(e.local.renderTarget.getTexture()):s?rt(a,"uTexture",s.getTexture()):rt(a,"uTexture"),(null==(r=null==n?void 0:n.local)?void 0:r.lastTarget)?rt(a,"uBgTexture",n.local.lastTarget.getTexture()):rt(a,"uBgTexture")}createPreviousFrameTarget(e,t,i,r){const a=t.passIndex??t.index??0,n=t.downSample||1,l=this.curtain.canvas.width*n,o=this.curtain.canvas.height*n;return e.local.previousFrameTargets||(e.local.previousFrameTargets={}),e.local.previousFrameInputTargets||(e.local.previousFrameInputTargets={}),e.local.previousFrameTargets[a]||(e.local.previousFrameTargets[a]=new s.RenderTarget(this.curtain,{depth:!1,clear:!1,maxWidth:l,maxHeight:o}),e.local.previousFrameTargets[a].userData.isPingPong=!0,e.local.previousFrameTargets[a].userData.isPreviousFrame=!0),"target"===t.needsPreviousFrame&&void 0!==i&&(e.local.previousFrameInputTargets[a]=r[i-(1+t.passIndex)]),e.local.previousFrameTargets[a].getTexture()}findPreviousLayerForMask(e,t){var i;const r=this.layers.filter(e=>!e.parentLayer),a=r.indexOf(e);if(a<0)return null;const s=a-t-1;if(s<0)return null;for(let n=Math.max(0,s);n>=0;n--){const t=r[n];if((null==t?void 0:t.visible)&&(null==(i=null==t?void 0:t.local)?void 0:i.lastTarget)&&t!==e)return t}return null}handleFlattenedPlane(e,t,i){var r;const a=e.getPlane();if(!a)return;let s=i[t-1];s&&rt(a,"uBgTexture",s.getTexture()),(null==(r=e.data)?void 0:r.textures)&&e.data.textures.forEach(t=>{"canvas"===t.type?e.local.canvasTextures&&e.local.canvasTextures[t.sublayerIndex]&&a.addTexture(e.local.canvasTextures[t.sublayerIndex]):this.ensureFlattenedTexture(e,t,a)})}ensureFlattenedPlaneTextures(e,t){var i;e&&(null==(i=t.data)?void 0:i.textures)&&t.data.textures.forEach(i=>{var r;if(!e.textures.some(e=>e._samplerName===i.sampler))if("canvas"===i.type){const a=null==(r=t.local.canvasTextures)?void 0:r[i.sublayerIndex];a&&e.addTexture(a)}else this.ensureFlattenedTexture(t,i,e)})}handleElementPlane(e,t,i){const r=e.getPlanes().find(e=>!e.userData.isComposite);if(!r)return!1;const a=e.getChildEffectItems().filter(e=>e.visible);let s,n=i[t-1];if(e.mask&&e.maskDepthLayer>0){const t=this.findPreviousLayerForMask(e,e.maskDepthLayer??0);t&&(s=t.local.lastTarget)}if(e.isGpuElement)return"image"===e.layerType&&(r.textures.some(e=>"uSourceImage"===e._samplerName)||(e.local.sourceTexture?(r.addTexture(e.local.sourceTexture),e.local.imageReady=!0):this.ensureImageLayerTexture(e,r))),void(0===a.length&&n&&(rt(r,"uBgTexture",n.getTexture()),s&&e.mask&&rt(r,"uPreviousLayerTexture",s.getTexture())));if(a.length||(r.textures.length=0),n&&a.length?rt(r,"uTexture",n.getTexture()):r&&e.preloadedCanvasTexture&&r.addTexture(e.preloadedCanvasTexture),n){if(a.length){n=i[t-(1+a.reduce((e,t)=>e+t.getPlanes().length,0))]}n&&(rt(r,"uBgTexture",n.getTexture()),s&&e.mask&&rt(r,"uPreviousLayerTexture",s.getTexture()))}}handleCompositePlane(e,t,i,r){const a=e.getPlanes().find(e=>e.userData.isComposite);if(!a)return;let s;if(e.mask&&e.maskDepthLayer>0){const t=this.findPreviousLayerForMask(e,e.maskDepthLayer??0);t&&(s=t.local.lastTarget)}const n=r[t-1];n&&rt(a,"uTexture",n.getTexture());const l=i.findIndex(t=>t.userData.id===e.local.id&&!t.userData.isComposite),o=l>0?l-1:-1,u=o>=0?r[o]:null;u&&(rt(a,"uBgTexture",u.getTexture()),s&&e.mask&&rt(a,"uPreviousLayerTexture",s.getTexture()))}handleChildEffectPlane(e,t,i,r){var a,s,n,l,o,u,d,c,h;const f="passIndex"in i?this.getPassPlane(e,i.passIndex):e.getPlane(),p=e.getParent();if(!f||!p)return;let m=r[t-1],v=null==(a=this.curtain)?void 0:a.planes.find(t=>"PingPongPlane"===t.type&&t.userData.id===e.local.id),g=e.compiledFragmentShaders[i.passIndex??0],y=p.effects.filter(e=>{if(this.layers.find(t=>t.parentLayer===e))return this.layers.find(t=>t.parentLayer===e)}),x=y.indexOf(e.parentLayer),b=y.at(-1)===y[x],_=i.passIndex===i.length;const P=p.isGpuElement||p.isFlattened;if(v&&(null==g?void 0:g.includes("uPingPongTexture"))&&rt(f,"uPingPongTexture",v.getTexture()),null==g?void 0:g.includes("uBgTexture"))if(x&&i.length>1){let e=r[t-(1+i.length)];e&&rt(f,"uBgTexture",e.getTexture())}else if(p.isGroup)m&&rt(f,"uBgTexture",m.getTexture());else if(P){const e=p.getPlanes().find(e=>!e.userData.isComposite);rt(f,"uBgTexture",null==(l=null==e?void 0:e.target)?void 0:l.getTexture())}else(null==(n=null==(s=p.preloadedCanvasTexture)?void 0:s.userData)?void 0:n.used)?f.loadCanvas(p.local.canvas,{sampler:"uBgTexture",premultiplyAlpha:!0},e=>{e.shouldUpdate=p.preloadedCanvasTexture.shouldUpdate}):p.preloadedCanvasTexture&&(p.preloadedCanvasTexture._samplerName="uBgTexture",f.addTexture(p.preloadedCanvasTexture));if(m&&(x||i.passIndex)){if(e.isMask&&(!i.length||b&&_))if(!P&&p.preloadedCanvasTexture)f.addTexture(p.preloadedCanvasTexture);else{const e=p.getPlanes().find(e=>!e.userData.isComposite);rt(f,"uMaskTexture",null==(o=null==e?void 0:e.target)?void 0:o.getTexture())}rt(f,"uTexture",m.getTexture())}else if(e.isMask){if(!i.length||b&&_)if(!P&&p.preloadedCanvasTexture)f.addTexture(p.preloadedCanvasTexture);else{const e=p.getPlanes().find(e=>!e.userData.isComposite);rt(f,"uMaskTexture",null==(u=null==e?void 0:e.target)?void 0:u.getTexture())}b&&_&&!P?f.addTexture(p.preloadedCanvasTexture):m?rt(f,"uTexture",m.getTexture()):rt(f,"uTexture"),m=r[t-2],m&&rt(f,"uTexture",m.getTexture())}else if(null==g?void 0:g.includes("uTexture"))if(p.isGroup&&m)rt(f,"uTexture",m.getTexture());else if(P){const e=p.getPlanes().find(e=>!e.userData.isComposite);rt(f,"uTexture",null==(d=null==e?void 0:e.target)?void 0:d.getTexture())}else p.preloadedCanvasTexture?(f.addTexture(p.preloadedCanvasTexture),p.preloadedCanvasTexture&&(p.preloadedCanvasTexture.userData.used=!0)):rt(f,"uTexture",m.getTexture());i.needsPreviousFrame&&rt(f,"uPreviousFrameTexture",this.createPreviousFrameTarget(e,i,t,r)),"custom"===e.type&&rt(f,"uCustomTexture",null==(h=null==(c=r[t])?void 0:c.getTexture)?void 0:h.call(c)),this.handleMediaTextures(f,e,i)}runIdleTasks(e,t){let i=0;const r=()=>{this.destroyed?this.initializing=!1:ce&&!this.isInView||document.hidden?setTimeout(()=>Et(r),80):ii.push(e):e=>e();this.getOrderedItems().forEach(e=>{"text"===e.layerType&&e.htmlOnly||r(()=>{e.getPlanes().length||(e.isGroup?this.createGroupPlane(e,r,t):e.isFlattened?this.createFlattenedPlane(e,r,t):e.isElement?this.createElementPlane(e,r):e.isModel?this.createModelPlane(e):this.createEffectPlanes(e,r))})});const a=()=>{this.calculateRenderOrders(),e&&e()};t?this.runIdleTasks(i,a):a()}calculateRenderOrders(){var e;let t=-9999;const i=e=>{var i,r,a;if(e.isBackground)return void(null==(i=e.getPlane())||i.setRenderOrder(t));const s=e.getPlanes().filter(e=>!e.userData.isComposite),n=e.isGpuElement||e.isFlattened&&((null==(r=e.hasRemainingEffects)?void 0:r.call(e))||e.mask&&0!==e.mask);n&&s.forEach(e=>e.setRenderOrder(t++)),(null==(a=e.effects)?void 0:a.length)&&e.getChildEffectItems().forEach(e=>{e.visible&&e.getPlanes().forEach(e=>e.setRenderOrder(t++))}),n||s.forEach(e=>e.setRenderOrder(t++));const l=e.getPlanes().find(e=>e.userData.isComposite);l&&l.setRenderOrder(t++)};this.layers.filter(e=>!e.parentLayer&&!e.groupLayer).forEach(e=>{if(e.isGroup){e.getPlanes().filter(e=>!e.userData.isComposite).forEach(e=>e.setRenderOrder(t++)),e.getMemberItems().filter(e=>!1!==e.visible).forEach(e=>{i(e)}),e.getChildEffectItems().forEach(e=>{e.visible&&e.getPlanes().forEach(e=>e.setRenderOrder(t++))});const r=e.getPlanes().find(e=>e.userData.isComposite);return void(r&&r.setRenderOrder(t++))}i(e)});const r=this.getPlanes().filter(e=>e.visible).sort((e,t)=>e.renderOrder-t.renderOrder).at(-1);if(null==r?void 0:r.target){const t=r.target;null==(e=r.removeRenderTarget)||e.call(r),t.remove()}}createModelPlane(e){const t=this.createPlane(e);t&&t.onReady(()=>{t.userData.isReady=!0,t.userData.createdAt=performance.now();let i=e.userDownsample||1,r=this.curtain.canvas.width*i,a=this.curtain.canvas.height*i;e.local.renderTarget||(e.local.renderTarget=new s.RenderTarget(this.curtain,{depth:!0,maxWidth:r,maxHeight:a,texturesOptions:{sampler:"uTexture",premultiplyAlpha:!0}}),e.local.rendererLoaded||!1===e.visible||e.local.rendererLoading||(e.local.rendererLoading=!0,Promise.resolve(e.loadRenderer()).finally(()=>{e.local.rendererLoading=!1})))}).onRender(()=>{t.visible&&(this.setModelPlaneUniforms(t,e),this.curtain.gl&&e.renderModel())})}createEffectPlanes(e,t=e=>e()){var i,r,a,s,n;const l=e.data,o="custom"===e.type?null==(i=e.customPasses)?void 0:i[0]:null,u="custom"===e.type?(null==(r=e.customPasses)?void 0:r.length)||((null==(a=l.passes)?void 0:a.length)||0)+1:((null==(s=l.passes)?void 0:s.length)||0)+1,d=!!(null==(n=e.customPasses)?void 0:n.some(e=>null==e?void 0:e.pingPong));if(l.passes&&l.passes.length){const i={index:0,downSample:(null==o?void 0:o.downSample)??l.downSample,length:u,includeBg:null==o?void 0:o.includeBg,needsPreviousFrame:(null==o?void 0:o.needsPreviousFrame)??l.needsPreviousFrame};(null==o?void 0:o.pingPong)?t(()=>this.createPingPongPlane(e,i)):t(()=>this.createEffectPlane(e,i)),l.passes.forEach((i,r)=>{const a={index:r+1,length:u,downSample:i.downSample,includeBg:i.includeBg,needsPreviousFrame:i.needsPreviousFrame,[i.prop]:i.value};i.pingPong?t(()=>this.createPingPongPlane(e,a)):t(()=>this.createEffectPlane(e,a))}),e.usesPingPong&&!d&&t(()=>this.createPingPongPlane(e,l.passes))}else{const i=o?{index:0,downSample:o.downSample??l.downSample,length:u,includeBg:o.includeBg,needsPreviousFrame:o.needsPreviousFrame??l.needsPreviousFrame}:null;(null==o?void 0:o.pingPong)?t(()=>this.createPingPongPlane(e,i)):t(i?()=>this.createEffectPlane(e,i):()=>this.createEffectPlane(e)),e.usesPingPong&&!d&&t(()=>this.createPingPongPlane(e))}}createTextures(e,t=!1){const i=this.getPlanes().filter(e=>e.visible).sort((e,t)=>e.renderOrder-t.renderOrder),r=this.getRenderTargets(),a=i.length,s=[];for(let n=0;n{const e=i[n];let t=this.layers.find(t=>t.local.id===e.userData.id);ne()),e&&e())}resizeRenderTarget(e,t,i){var r,a,s;const n=(null==(r=e._size)?void 0:r.width)||0,l=(null==(a=e._size)?void 0:a.height)||0;if(Math.abs(n-t)<=1&&Math.abs(l-i)<=1)return;const o=null==(s=e.textures)?void 0:s[0];if((!e._frameBuffer||!(null==o?void 0:o._copiedFrom))&&(e._size={width:t,height:i},e._maxSize={width:t,height:i},e._minSize={width:t,height:i},e._frameBuffer&&o)){o._size={width:t,height:i};const r=this.curtain.gl;r.bindTexture(r.TEXTURE_2D,o._sampler.texture),r.texImage2D(r.TEXTURE_2D,0,o._globalParameters.internalFormat,t,i,0,o._globalParameters.format,o._globalParameters.type,null),this.curtain.renderer.bindFrameBuffer(e,!0),e._depth&&e._depthBuffer&&(r.bindRenderbuffer(r.RENDERBUFFER,e._depthBuffer),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT16,t,i),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,e._depthBuffer)),this.curtain.renderer.bindFrameBuffer(null)}}ensureRenderTargetInitialized(e,t,i){e&&(t&&i&&this.resizeRenderTarget(e,t,i),e._frameBuffer||(this.curtain.renderer.bindFrameBuffer(e,!0),this.curtain.renderer.bindFrameBuffer(null)))}blitRenderTarget(e,t){var i,r,a;const s=null==(i=this.curtain)?void 0:i.gl;if(!s||"function"!=typeof s.blitFramebuffer)return;const n=(null==(r=e._size)?void 0:r.width)||this.curtain.canvas.width,l=(null==(a=e._size)?void 0:a.height)||this.curtain.canvas.height;this.ensureRenderTargetInitialized(e,n,l),this.ensureRenderTargetInitialized(t,n,l),(null==e?void 0:e._frameBuffer)&&(null==t?void 0:t._frameBuffer)&&(s.bindFramebuffer(s.READ_FRAMEBUFFER,e._frameBuffer),s.bindFramebuffer(s.DRAW_FRAMEBUFFER,t._frameBuffer),s.blitFramebuffer(0,0,n,l,0,0,n,l,s.COLOR_BUFFER_BIT,s.NEAREST),s.bindFramebuffer(s.READ_FRAMEBUFFER,null),s.bindFramebuffer(s.DRAW_FRAMEBUFFER,null))}assignRenderTargetToPlane(e,t,i,r,a){let n=this.getTextureParams(e,i,r),l=t[i];l?this.resizeRenderTarget(l,n.maxWidth,n.maxHeight):(l=new s.RenderTarget(this.curtain,n),t[i]=l),l.userData.id=a.userData.id,a&&a.setRenderTarget(l)}handleTextures(e,t,i,r,a){i.isComposite?this.handleCompositePlane(e,t,r,a):e.isGroup||(e.isFlattened?this.handleFlattenedPlane(e,t,a):e.isElement?this.handleElementPlane(e,t,a):e.isModel?this.handleModelPlane(e,t,a):e.parentLayer?this.handleChildEffectPlane(e,t,i,a):this.handleEffectPlane(e,t,i,a))}handleItemPlanes(e,t=!1){this.createPlanes(()=>{this.syncPlaneVisibility(),this.createTextures(()=>this.checkIfReady(e,t),t)},t)}checkIfReady(e,t=!1){const i=()=>{var r;if(this.destroyed)return;if(t&&ce&&!this.isInView)return void requestAnimationFrame(i);let a=!1;const s=null==(r=this.curtain)?void 0:r.planes;if(s){for(let e=0;ee.prop===i))||(t.local.bpProps&&i in t.local.bpProps?$e(t.local.bpProps[i],e.uniforms[i],i):i in t&&$e(t[i],e.uniforms[i],i));i&&r&&r.index{const t=e.parentLayer?e.getParent():null;(t?t.visible:e.visible)&&e.updateStateEffects()})}setInitialFlattenedPlaneUniforms(e,t){var i,r;e.uniforms.resolution&&this.curtain.canvas&&(e.uniforms.resolution.value.x=this.curtain.canvas.width,e.uniforms.resolution.value.y=this.curtain.canvas.height),e.uniforms.artboardResolution&&(e.uniforms.artboardResolution.value.x=this.canvasWidth,e.uniforms.artboardResolution.value.y=this.canvasHeight);for(let a in e.uniforms)(null==(i=t.states)?void 0:i.scroll.some(e=>e.prop===a))||(null==(r=t.states)?void 0:r.appear.some(e=>e.prop===a&&!e.complete))||(t.local.bpProps&&a in t.local.bpProps?$e(t.local.bpProps[a],e.uniforms[a],a):a in t&&$e(t[a],e.uniforms[a],a))}setFlattenedPlaneUniforms(e,t){var i,r,a,s,n;if(!e.visible)return;if(this.ensureFlattenedPlaneTextures(e,t),t.local.modelInstances&&Object.entries(t.local.modelInstances).forEach(([i,r])=>{if(!r||!r.local)return;const a=e.uniforms[`L${i}_elemOpacity`]||e.uniforms[`L${i}_opacity`];if(a&&0===a.value)return;const s=`L${i}_`,n={};if(t.local.bpProps)for(const e in t.local.bpProps)e.startsWith(s)&&(n[e.slice(s.length)]=t.local.bpProps[e]);if(t.local.stateEffectProps)for(const e in t.local.stateEffectProps)e.startsWith(s)&&(n[e.slice(s.length)]=t.local.stateEffectProps[e]);r.local.stateEffectProps=n;const l=this.calculateItemMouseValues(r);l&&!r.local.mouse&&(r.local.mouse={x:.5,y:.5}),l&&(r.local.mouse.x=l.x,r.local.mouse.y=l.y),r.renderModel()}),(null==(i=t.local.stateEffectProps)?void 0:i.playbackRate)&&e.videos.at(-1)&&(e.videos.at(-1).playbackRate=t.local.stateEffectProps.playbackRate),e.uniforms.mousePos&&this.mouse.movedInView){t.local.currentFrameMouseValues||(t.local.currentFrameMouseValues=this.calculateItemMouseValues(t));const i=t.local.currentFrameMouseValues;i&&(e.uniforms.mousePos.value.x=i.x,e.uniforms.mousePos.value.y=i.y)}const l=t=>{const i=t.match(/^L(\d+)_/);if(!i)return!1;const r=i[1],a=e.uniforms[`L${r}_elemOpacity`]||e.uniforms[`L${r}_opacity`];return a&&0===a.value};if((null==(a=null==(r=t.data)?void 0:r.timeUniforms)?void 0:a.length)&&t.data.timeUniforms.forEach(({key:i,speed:r,animating:a})=>{var s;if(!l(i)&&e.uniforms[i]&&!1!==a){const a=i.replace(/_time$/,"_speed"),n=(null==(s=t.local.stateEffectProps)?void 0:s[a])??t[a]??r??1;e.uniforms[i].value+=60*n/this.fps}}),null==(n=null==(s=t.data)?void 0:s.mouseUniforms)?void 0:n.length){const i=this.bbox.width/2,r=this.bbox.height/2,a=this.mouse.pos.x,s=this.mouse.pos.y;t.local.mouseStates||(t.local.mouseStates={}),t.data.mouseUniforms.forEach(({key:n,momentum:o,spring:u,trackAxes:d})=>{if(!e.uniforms[n])return;if(l(n))return;const c=d||"xy",h="x"===c||"xy"===c,f="y"===c||"xy"===c,p=u||0;if(!t.local.mouseStates[n])return t.local.mouseStates[n]={x:h?a/i:.5,y:f?1-s/r:.5,vx:0,vy:0},e.uniforms[n].value.x=t.local.mouseStates[n].x,void(e.uniforms[n].value.y=t.local.mouseStates[n].y);const m=t.local.mouseStates[n],v=m.x*i,g=(1-m.y)*r;if(p>0){if(h){const e=Ve(v,a,m.vx,o,p);m.x=e.value/i,m.vx=e.velocity}else m.x=.5;if(f){const e=Ve(g,s,m.vy,o,p);m.y=1-e.value/r,m.vy=e.velocity}else m.y=.5}else m.x=h?Ae(a,v,2*o)/i:.5,m.y=f?1-Ae(s,g,2*o)/r:.5;e.uniforms[n].value.x=m.x,e.uniforms[n].value.y=m.y})}}setInitialElementPlaneUniforms(e,t){var i;e.uniforms.resolution.value.x=this.curtain.canvas.width,e.uniforms.resolution.value.y=this.curtain.canvas.height,e.uniforms.artboardResolution&&(e.uniforms.artboardResolution.value.x=this.canvasWidth,e.uniforms.artboardResolution.value.y=this.canvasHeight);for(let r in e.uniforms){const a=this.getAppearStateUniformValue(t,r);a.hasValue?$e(a.value,e.uniforms[r],r):t.local.bpProps&&r in t.local.bpProps?$e(t.local.bpProps[r],e.uniforms[r],r):r in t&&$e((null==(i=t.local.stateEffectProps)?void 0:i[r])??t[r],e.uniforms[r],r)}Ye(t,e,"fill"),Ye(t,e,"stroke")}setElementPlaneUniforms(e,t){if(e.visible&&(Ye(t,e,"fill"),Ye(t,e,"stroke"),e.uniforms.resolution&&(e.uniforms.resolution.value.x=this.curtain.canvas.width,e.uniforms.resolution.value.y=this.curtain.canvas.height),e.uniforms.artboardResolution&&(e.uniforms.artboardResolution.value.x=this.canvasWidth,e.uniforms.artboardResolution.value.y=this.canvasHeight),e.uniforms.mousePos)){t.local.currentFrameMouseValues||(t.local.currentFrameMouseValues=this.calculateItemMouseValues(t));const i=t.local.currentFrameMouseValues;!this.mouse.movedInView||e.uniforms.mousePos.value.x===i.x&&e.uniforms.mousePos.value.y===i.y||(e.uniforms.mousePos.value.x=i.x,e.uniforms.mousePos.value.y=i.y)}}calculateItemMouseValues(e){if(!this.mouse.movedInView)return null;const t=this.bbox.width/2,i=this.bbox.height/2,r=this.getMousePosWithMomentum(e,t,i);return e.local.mouseValuePool||(e.local.mouseValuePool=new s.Vec2(.5)),e.local.mouseValuePool.x=r.x,e.local.mouseValuePool.y=r.y,e.local.mouseValuePool}getMousePosWithMomentum(e,t,i){let r=this.mouse.pos.x,a=this.mouse.pos.y,s=e.trackAxes||"xy",n="x"===s||"xy"===s,l="y"===s||"xy"===s;const o=e.mouseMomentum||0,u=e.mouseSpring||0;let d=r/t,c=1-a/i;if(!o&&!u)return{x:n?d:.5,y:l?c:.5};if(!e.local.lastMousePos)return e.local.lastMousePos={x:n?d:.5,y:l?c:.5},e.local.lastMousePos;const h=e.local.lastMousePos.x*t,f=(1-e.local.lastMousePos.y)*i;if(u>0){if(e.local.mouseVelocity||(e.local.mouseVelocity={x:0,y:0}),n){const i=Ve(h,r,e.local.mouseVelocity.x,o,u);r=i.value,e.local.mouseVelocity.x=i.velocity,e.local.lastMousePos.x=r/t}else e.local.lastMousePos.x=.5;if(l){const t=Ve(f,a,e.local.mouseVelocity.y,o,u);a=t.value,e.local.mouseVelocity.y=t.velocity,e.local.lastMousePos.y=1-a/i}else e.local.lastMousePos.y=.5;return e.local.lastMousePos}const p=Math.abs(r-h),m=Math.abs(a-f);return p16?(e.uniforms.previousMousePos.value.x=e.uniforms.mousePos.value.x,e.uniforms.previousMousePos.value.y=e.uniforms.mousePos.value.y):(e.uniforms.previousMousePos.value.x=l.x,e.uniforms.previousMousePos.value.y=l.y)),e.uniforms.mousePos&&!l.equals(e.uniforms.mousePos.value)&&(e.uniforms.mousePos.value.x=l.x,e.uniforms.mousePos.value.y=l.y),this.mouse.ticks++)}getOrderedItems(){let e=[];return this.layers.filter(e=>!e.parentLayer&&!e.groupLayer).forEach(t=>{if(t.isGroup)return e.push(t),t.getMemberItems().filter(e=>!1!==e.visible).forEach(t=>{t.effects&&t.effects.length&&e.push(...t.getChildEffectItems()),e.push(t)}),void(t.effects&&t.effects.length&&e.push(...t.getChildEffectItems()));t.effects&&t.effects.length&&e.push(...t.getChildEffectItems()),e.push(t)}),e}getTextureParams(e,t,i){var r;const a=e[t];let s=1;a.userData.downSample&&(s="number"==typeof a.userData.downSample?a.userData.downSample:.5);return{maxWidth:this.curtain.canvas.width*s,maxHeight:this.curtain.canvas.height*s,depth:null==(r=null==i?void 0:i.data)?void 0:r.depth}}handlePlaneCreation(){this.initialized=!0,this.initializing=!1,this.rendering||this.renderNFrames(2),this.waitForAssetsAndDisablePlanes(),je()}waitForAssetsAndDisablePlanes(){var e,t;this.local.preloadedImages&&Object.values(this.local.preloadedImages).some(e=>e.loading)||this.layers.some(e=>!1!==e.visible&&(e.isModel&&!e.local.modelLoaded||"image"===e.layerType&&!e.local.imageReady||"text"===e.layerType&&!e.local.loaded||e.isFlattened&&(!e.areTextAssetsReady()||!e.areImageAssetsReady()||!e.areModelAssetsReady())))?setTimeout(()=>this.waitForAssetsAndDisablePlanes(),32):(this.layers.filter(e=>e.preloadedCanvasTexture).forEach(e=>{e.preloadedCanvasTexture.shouldUpdate=!0}),this.layers.filter(e=>e.isFlattened).forEach(e=>{Object.values(e.local.canvasTextures||{}).forEach(e=>{e&&(e.shouldUpdate=!0)})}),this.curtain&&this.curtain.planes.forEach(e=>{e.videos.forEach(e=>{e.currentTime=0}),e._canDraw=!0}),null==(t=null==(e=this.variables)?void 0:e.applyAll)||t.call(e),this.renderFrame(),this.layers.filter(e=>e.preloadedCanvasTexture).forEach(e=>{e.preloadedCanvasTexture.shouldUpdate=e.preloadedCanvasTexture.userData.hasStateEffects||!1}),this.layers.filter(e=>e.isFlattened).forEach(e=>{Object.values(e.local.canvasTextures||{}).forEach(e=>{e&&(e.shouldUpdate=!1)})}),setTimeout(()=>this.disablePlanes(),16))}disablePlanes(){const e=this.getSplitOrderedItems();e.dynamic.length||e.static.pop();for(const t of e.static)t.getPlanes().forEach(e=>{e._canDraw=!1})}}function Bt(e,t,i){e.addEventListener(t,i,{passive:!0})}function Ut(e,t,i){e.removeEventListener(t,i)}function Nt(){Bt(window,"scroll",At),Ce()?Bt(window,"touchmove",Ct):Bt(window,"mousemove",Ct),Bt(window,"routeChange",Ne),Bt(document,"mouseleave",Lt),ee=function(e,t){let i;return function(...r){clearTimeout(i),i=setTimeout(()=>{e.apply(this,r)},t)}}(Pt,16),Ce()?Bt(window,"orientationchange",ee):Bt(window,"resize",ee),Bt(document,K,_t),te=!0}function zt(){Ut(window,"mousemove",Ct),Ut(window,"touchmove",Ct),Ut(window,"scroll",At),Ut(window,"routeChange",Ne),Ut(document,"mouseleave",Lt),ee&&(Ut(window,"resize",ee),Ut(window,"orientationchange",ee)),Ut(document,K,_t),te=!1}function jt(){var e;if(null!==pe)return pe;try{const t=document.createElement("canvas").getContext("webgl2");pe=!!t,null==(e=null==t?void 0:t.getExtension("WEBGL_lose_context"))||e.loseContext()}catch{pe=!1}return pe}function Ht(e){let t=e.projectId?e.projectId.split("?")[0]:null,i=e.projectId?e.projectId.split("?")[1]:null;return new Promise((r,a)=>{(function(e,t,i,r,a){let s;if(i){s=i;const e=document.getElementById(i);if(e)try{let t=JSON.parse(e.innerText);return(null==t?void 0:t.options)&&((null==t?void 0:t.layers)||(null==t?void 0:t.history))?Promise.resolve(t):(r(new Error(`Did not find valid JSON inside ${i}`)),Promise.reject())}catch(n){return r(new Error(`Error parsing JSON from ${i}: ${n.message}`)),Promise.reject()}}else{let i="https://storage.googleapis.com/unicornstudio-production";a||(null==t?void 0:t.includes("production=true"))?(i="https://assets.unicorn.studio",(null==t?void 0:t.includes("update="))||(t=null)):(null==t?void 0:t.includes("update="))||(t=`v=${Date.now()}`),s=`${i}/embeds/${e}${t?"?"+t:""}`}return fetch(s).then(e=>e.json()).then(e=>e).catch(e=>{})})(t,i,e.filePath,a,e.production).then(i=>{i&&(i.layers||i.history)&&i.options||a(new Error(`Error fetching data for project id '${e.projectId}'`));const s=i.options||{},n=(l=e.element,("object"==typeof HTMLElement?l instanceof HTMLElement:l&&"object"==typeof l&&null!==l&&1===l.nodeType&&"string"==typeof l.nodeName)?e.element:document.getElementById(e.elementId));var l;if(!n)return void a(new Error(`Couldn't find an element with id '${e.elementId}' on the page.`));const o=Ie();n.setAttribute("data-scene-id",o);let u=e.scale||s.scale||1,d=e.dpi||s.dpi||Math.min(1.5,window.devicePixelRatio);const c=Number.isFinite(Number(e.breakpointWidth))?Number(e.breakpointWidth):null,h=function(e,t,i,r){const a=r?{...i,modules:r}:i,s=[];return e.forEach(e=>{switch(e.layerType){case"text":s.push(new bt(e,t,a).unpackage());break;case"image":s.push(new yt(e,t,a).unpackage());break;case"model":s.push(new xt(e,t,a).unpackage());break;case"shape":s.push(new pt(e,t,a).unpackage());break;case"effect":s.push(new mt(e,t,a).unpackage());break;case"group":s.push(new vt(e,t,a).unpackage());break;case"flattened":{const i=new gt(e,t,a).unpackage();s.push(i),i.getChildEffectItems().forEach(e=>{s.push(e)});break}}}),s}(i.layers||i.history,o,function(e,t,i,r=null){return{canvasWidth:e.offsetWidth,canvasHeight:e.offsetHeight,scale:t,dpi:i,element:e,breakpointWidth:r}}(n,u,d,c),i.modules);if(!jt()){const e=function({id:e,element:t,layers:i}){return{id:e,element:t,layers:i,destroyed:!1,fallbackOnly:!0,getMouse:()=>({x:.5,y:.5,inBounds:!1,moved:!1}),getDynamicLayers:()=>[],destroy(){this.destroyed=!0,this.element&&(this.element.removeAttribute("data-us-initialized"),this.element.removeAttribute("data-scene-id"),this.element.querySelectorAll("[data-us-text]").forEach(e=>{e.remove()}))}}}({id:o,element:n,layers:h});return function(e,t){e.forEach(e=>{var i;"text"===e.layerType&&Be(e,t),Object.values((null==(i=e.local)?void 0:i.textInstances)||{}).forEach(e=>{Be(e,t)})})}(h,n),Ot.push(e),void r(e)}const f=e.initialPreset||Je(),p=!!e.fixed||Tt(n,null,50),m=new Dt({id:o,fps:e.fps||s.fps||60,dpi:d,name:s.name,projectId:t||e.filePath.split(".")[0],renderingScale:u,element:n,lazyLoad:e.lazyLoad,fixed:e.fixed,width:e.width,height:e.height,breakpoints:e.breakpoints||s.breakpoints,breakpointWidth:c,initialVariables:e.initialVariables,initialPreset:f,altText:e.altText,ariaLabel:e.ariaLabel,deferCurtains:!!e.lazyLoad&&!p,editMetadata:{designId:i.designId,canvasId:i.canvasId,designName:i.designName||i.projectName,sceneName:i.sceneName}});m.applyCanvasA11yAttrs();let v=s[ke("ZnJlZVBsYW4=")];!v&&s[ke("aW5jbHVkZUxvZ28=")]&&function(e,t){const i=document.createElement("a");i.href="https://unicorn.studio?utm_source=public-url",i.style="position: absolute; display: flex; bottom: 30px; left: 0; width: 190px; margin: 0 auto; right: 0rem; padding: 10px; border-radius: 6px; background-color: rgba(255, 255, 255, 1); box-shadow: 0 3px 9px 0 rgba(0, 0, 0, .2); z-index: 99999999; box-sizing: border-box;",i.target="_blank";const r=document.createElement("img");r.src=ke("aHR0cHM6Ly9hc3NldHMudW5pY29ybi5zdHVkaW8vbWVkaWEvbWFkZV9pbl91c19zbWFsbF93ZWIuc3Zn"),r.alt=ke("TWFkZSB3aXRoIHVuaWNvcm4uc3R1ZGlv"),r.style="width: 170px; height: auto;",i.appendChild(r),t.appendChild(i)}(0,n),Ot.push(m),m.layers=h,m.applyBreakpointValues(!0),m.setupVariables(i.variables,e.initialVariables,f),m.preloadTextures(),m.setInteractiveParams(e,s),m.isInView=m.isFixed||p,!m.lazyLoad||m.isInView?m.initializePlanes():kt(m),te||Nt(),it(n,m,e),r(m)}).catch(e=>{a(e)})})}e.addScene=Ht,e.destroy=function(){Ot.forEach(e=>{e.destroy()}),Ot.length=0,zt()},e.init=function(){return jt(),new Promise((e,t)=>{const i=[...document.querySelectorAll("[data-us-project], [data-us-project-src]")].filter(e=>!e.getAttribute("data-us-initialized")),r="undefined"!=typeof window&&window.requestIdleCallback?window.requestIdleCallback:e=>setTimeout(e,0);i.length?Promise.all(i.map(e=>(e.setAttribute("data-us-initialized",!0),new Promise((t,i)=>{r(()=>{const r=Oe(e,"data-us-project"),a=Oe(e,"data-us-project-src"),s=Oe(e,"data-us-disablemobile"),n=Oe(e,"data-us-disablemouse");Ht({projectId:a?null:r,filePath:a,element:e,dpi:+Oe(e,"data-us-dpi"),scale:+Oe(e,"data-us-scale"),production:Oe(e,"data-us-production"),fps:+Oe(e,"data-us-fps"),lazyLoad:Oe(e,"data-us-lazyload"),altText:Oe(e,"data-us-alttext"),ariaLabel:Oe(e,"data-us-arialabel"),fixed:Oe(e,"data-us-fixed"),initialVariables:Xe(Oe(e,"data-us-vars")),initialPreset:Oe(e,"data-us-preset")||Je(),interactivity:s||n?{mouse:{disableMobile:s,disabled:n}}:null}).then(e=>{t(e)}).catch(t=>{e.removeAttribute("data-us-initialized"),i(t)})})})))).then(()=>e(Ot)).catch(t):e(Ot)})},e.scenes=Ot,e.setScroll=function(e){const t=_e(e);null!==t&&(ae=t,Te(t),St())},e.unbindEvents=zt,e.useNativeScroll=function(){ae=null,Te(),St()},e.version=be,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});