ng-cw-v12
Version:
Angular UI Component Library
766 lines (754 loc) • 43.3 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('three'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('ng-cw-v12/prismatic-burst-background', ['exports', '@angular/core', 'three', '@angular/common'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global["ng-cw-v12"] = global["ng-cw-v12"] || {}, global["ng-cw-v12"]["prismatic-burst-background"] = {}), global.ng.core, global.THREE, global.ng.common));
})(this, (function (exports, i0, THREE, common) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
function accept(f) { if (f !== void 0 && typeof f !== "function")
throw new TypeError("Function expected"); return f; }
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
var _, done = false;
for (var i = decorators.length - 1; i >= 0; i--) {
var context = {};
for (var p in contextIn)
context[p] = p === "access" ? {} : contextIn[p];
for (var p in contextIn.access)
context.access[p] = contextIn.access[p];
context.addInitializer = function (f) { if (done)
throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
if (kind === "accessor") {
if (result === void 0)
continue;
if (result === null || typeof result !== "object")
throw new TypeError("Object expected");
if (_ = accept(result.get))
descriptor.get = _;
if (_ = accept(result.set))
descriptor.set = _;
if (_ = accept(result.init))
initializers.push(_);
}
else if (_ = accept(result)) {
if (kind === "field")
initializers.push(_);
else
descriptor[key] = _;
}
}
if (target)
Object.defineProperty(target, contextIn.name, descriptor);
done = true;
}
;
function __runInitializers(thisArg, initializers, value) {
var useValue = arguments.length > 2;
for (var i = 0; i < initializers.length; i++) {
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
}
return useValue ? value : void 0;
}
;
function __propKey(x) {
return typeof x === "symbol" ? x : "".concat(x);
}
;
function __setFunctionName(f, name, prefix) {
if (typeof name === "symbol")
name = name.description ? "[".concat(name.description, "]") : "";
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
}
;
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function () { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
function __classPrivateFieldIn(state, receiver) {
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
throw new TypeError("Cannot use 'in' operator on non-object");
return typeof state === "function" ? receiver === state : state.has(receiver);
}
;
var vertexShader = "\nin vec3 position;\nin vec2 uv;\nout vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = vec4(position, 1.0);\n}\n";
var fragmentShader = "\nprecision highp float;\nprecision highp int;\n\nout vec4 fragColor;\n\nuniform vec2 uResolution;\nuniform float uTime;\n\nuniform float uIntensity;\nuniform float uSpeed;\nuniform int uAnimType;\nuniform vec2 uMouse;\nuniform int uColorCount;\nuniform float uDistort;\nuniform vec2 uOffset;\nuniform sampler2D uGradient;\nuniform float uNoiseAmount;\nuniform int uRayCount;\n\nfloat hash21(vec2 p){\n p = floor(p);\n float f = 52.9829189 * fract(dot(p, vec2(0.065, 0.005)));\n return fract(f);\n}\n\nmat2 rot30(){ return mat2(0.8, -0.5, 0.5, 0.8); }\n\nfloat layeredNoise(vec2 fragPx){\n vec2 p = mod(fragPx + vec2(uTime * 30.0, -uTime * 21.0), 1024.0);\n vec2 q = rot30() * p;\n float n = 0.0;\n n += 0.40 * hash21(q);\n n += 0.25 * hash21(q * 2.0 + 17.0);\n n += 0.20 * hash21(q * 4.0 + 47.0);\n n += 0.10 * hash21(q * 8.0 + 113.0);\n n += 0.05 * hash21(q * 16.0 + 191.0);\n return n;\n}\n\nvec3 rayDir(vec2 frag, vec2 res, vec2 offset, float dist){\n float focal = res.y * max(dist, 1e-3);\n return normalize(vec3(2.0 * (frag - offset) - res, focal));\n}\n\nfloat edgeFade(vec2 frag, vec2 res, vec2 offset){\n vec2 toC = frag - 0.5 * res - offset;\n float r = length(toC) / (0.5 * min(res.x, res.y));\n float x = clamp(r, 0.0, 1.0);\n float q = x * x * x * (x * (x * 6.0 - 15.0) + 10.0);\n float s = q * 0.5;\n s = pow(s, 1.5);\n float tail = 1.0 - pow(1.0 - s, 2.0);\n s = mix(s, tail, 0.2);\n float dn = (layeredNoise(frag * 0.15) - 0.5) * 0.0015 * s;\n return clamp(s + dn, 0.0, 1.0);\n}\n\nmat3 rotX(float a){ float c = cos(a), s = sin(a); return mat3(1.0,0.0,0.0, 0.0,c,-s, 0.0,s,c); }\nmat3 rotY(float a){ float c = cos(a), s = sin(a); return mat3(c,0.0,s, 0.0,1.0,0.0, -s,0.0,c); }\nmat3 rotZ(float a){ float c = cos(a), s = sin(a); return mat3(c,-s,0.0, s,c,0.0, 0.0,0.0,1.0); }\n\nvec3 sampleGradient(float t){\n t = clamp(t, 0.0, 1.0);\n return texture(uGradient, vec2(t, 0.5)).rgb;\n}\n\nvec2 rot2(vec2 v, float a){\n float s = sin(a), c = cos(a);\n return mat2(c, -s, s, c) * v;\n}\n\nfloat bendAngle(vec3 q, float t){\n float a = 0.8 * sin(q.x * 0.55 + t * 0.6)\n + 0.7 * sin(q.y * 0.50 - t * 0.5)\n + 0.6 * sin(q.z * 0.60 + t * 0.7);\n return a;\n}\n\nvoid main(){\n vec2 frag = gl_FragCoord.xy;\n float t = uTime * uSpeed;\n float jitterAmp = 0.1 * clamp(uNoiseAmount, 0.0, 1.0);\n vec3 dir = rayDir(frag, uResolution, uOffset, 1.0);\n float marchT = 0.0;\n vec3 col = vec3(0.0);\n float n = layeredNoise(frag);\n vec4 c = cos(t * 0.2 + vec4(0.0, 33.0, 11.0, 0.0));\n mat2 M2 = mat2(c.x, c.y, c.z, c.w);\n float amp = clamp(uDistort, 0.0, 50.0) * 0.15;\n\n mat3 rot3dMat = mat3(1.0);\n if(uAnimType == 1){\n vec3 ang = vec3(t * 0.31, t * 0.21, t * 0.17);\n rot3dMat = rotZ(ang.z) * rotY(ang.y) * rotX(ang.x);\n }\n mat3 hoverMat = mat3(1.0);\n if(uAnimType == 2){\n vec2 m = uMouse * 2.0 - 1.0;\n vec3 ang = vec3(m.y * 0.6, m.x * 0.6, 0.0);\n hoverMat = rotY(ang.y) * rotX(ang.x);\n }\n\n for (int i = 0; i < 44; ++i) {\n vec3 P = marchT * dir;\n P.z -= 2.0;\n float rad = length(P);\n vec3 Pl = P * (10.0 / max(rad, 1e-6));\n\n if(uAnimType == 0){\n Pl.xz *= M2;\n } else if(uAnimType == 1){\n Pl = rot3dMat * Pl;\n } else {\n Pl = hoverMat * Pl;\n }\n\n float stepLen = min(rad - 0.3, n * jitterAmp) + 0.1;\n\n float grow = smoothstep(0.35, 3.0, marchT);\n float a1 = amp * grow * bendAngle(Pl * 0.6, t);\n float a2 = 0.5 * amp * grow * bendAngle(Pl.zyx * 0.5 + 3.1, t * 0.9);\n vec3 Pb = Pl;\n Pb.xz = rot2(Pb.xz, a1);\n Pb.xy = rot2(Pb.xy, a2);\n\n float rayPattern = smoothstep(\n 0.5, 0.7,\n sin(Pb.x + cos(Pb.y) * cos(Pb.z)) *\n sin(Pb.z + sin(Pb.y) * cos(Pb.x + t))\n );\n\n if (uRayCount > 0) {\n float ang = atan(Pb.y, Pb.x);\n float comb = 0.5 + 0.5 * cos(float(uRayCount) * ang);\n comb = pow(comb, 3.0);\n rayPattern *= smoothstep(0.15, 0.95, comb);\n }\n\n vec3 spectralDefault = 1.0 + vec3(\n cos(marchT * 3.0 + 0.0),\n cos(marchT * 3.0 + 1.0),\n cos(marchT * 3.0 + 2.0)\n );\n\n float saw = fract(marchT * 0.25);\n float tRay = saw * saw * (3.0 - 2.0 * saw);\n vec3 userGradient = 2.0 * sampleGradient(tRay);\n vec3 spectral = (uColorCount > 0) ? userGradient : spectralDefault;\n vec3 base = (0.05 / (0.4 + stepLen))\n * smoothstep(5.0, 0.0, rad)\n * spectral;\n\n col += base * rayPattern;\n marchT += stepLen;\n }\n\n col *= edgeFade(frag, uResolution, uOffset);\n col *= uIntensity;\n\n fragColor = vec4(clamp(col, 0.0, 1.0), 1.0);\n}\n";
var hexToRgb01 = function (hex) {
var h = hex.trim();
if (h.startsWith('#'))
h = h.slice(1);
if (h.length === 3) {
var r_1 = h[0], g_1 = h[1], b_1 = h[2];
h = r_1 + r_1 + g_1 + g_1 + b_1 + b_1;
}
var intVal = parseInt(h, 16);
if (isNaN(intVal) || (h.length !== 6 && h.length !== 8))
return [1, 1, 1];
var r = ((intVal >> 16) & 255) / 255;
var g = ((intVal >> 8) & 255) / 255;
var b = (intVal & 255) / 255;
return [r, g, b];
};
var toPx = function (v) {
if (v == null)
return 0;
if (typeof v === 'number')
return v;
var s = String(v).trim();
var num = parseFloat(s.replace('px', ''));
return isNaN(num) ? 0 : num;
};
var PrismaticBurstBackgroundComponent = /** @class */ (function () {
function PrismaticBurstBackgroundComponent(ngZone) {
var _this = this;
this.ngZone = ngZone;
/** 累加后应用整体亮度倍增器(0.1-5) */
this.ncIntensity = 2;
/** 控制光线运动和扭曲的全局时间倍增器(0-2) */
this.ncSpeed = 0.5;
/** 动画类型:'rotate' | '3drotate' | 'hover' */
this.ncAnimationType = '3drotate';
/** 设置特定颜色(十六进制字符串数组) */
this.ncColors = [];
/** 对行进空间施加的弯曲/扭曲程度(增加自然的摇摆感,0-10) */
this.ncDistort = 0;
/** 是否暂停动画 */
this._paused = false;
/** 中心点的偏移量 (x, y) */
this.ncOffset = { x: 0, y: 0 };
/** 当ncAnimationType='hover'时,指针跟踪的平滑因子(0-1) */
this.ncHoverDampness = 0;
/** 如果大于0,则应用角度梳状滤波器生成离散光线辐条(0-64) */
this.ncRayCount = 0;
this.mouseTarget = [0.5, 0.5];
this.mouseSmooth = [0.5, 0.5];
this.isVisible = true;
this.rafId = null;
this.lastTime = performance.now();
this.accumTime = 0;
this.onResizeBound = function () { return _this.resizeCanvas(); };
this.updateLoop = function (now) {
var dt = Math.max(0, now - _this.lastTime) * 0.001;
_this.lastTime = now;
var visible = _this.isVisible && !document.hidden;
if (!_this.ncPaused) {
_this.accumTime += dt;
}
if (!visible) {
_this.rafId = requestAnimationFrame(_this.updateLoop);
return;
}
var tau = 0.02 + Math.max(0, Math.min(1, _this.ncHoverDampness)) * 0.5;
var alpha = 1 - Math.exp(-dt / tau);
var tgt = _this.mouseTarget;
var sm = _this.mouseSmooth;
sm[0] += (tgt[0] - sm[0]) * alpha;
sm[1] += (tgt[1] - sm[1]) * alpha;
if (_this.material) {
_this.material.uniforms['uMouse'].value.set(sm[0], sm[1]);
_this.material.uniforms['uTime'].value = _this.accumTime;
}
if (_this.renderer && _this.scene && _this.camera) {
_this.renderer.render(_this.scene, _this.camera);
}
_this.rafId = requestAnimationFrame(_this.updateLoop);
};
}
Object.defineProperty(PrismaticBurstBackgroundComponent.prototype, "ncPaused", {
get: function () {
return this._paused;
},
set: function (val) {
this._paused = val !== null && val !== undefined && val !== false && val !== 'false';
},
enumerable: false,
configurable: true
});
PrismaticBurstBackgroundComponent.prototype.ngOnInit = function () { };
PrismaticBurstBackgroundComponent.prototype.ngAfterViewInit = function () {
var _this = this;
this.ngZone.runOutsideAngular(function () {
_this.initScene();
_this.applyOptions();
_this.setupObservers();
_this.updateLoop(performance.now());
});
};
PrismaticBurstBackgroundComponent.prototype.ngOnDestroy = function () {
this.cleanup();
};
PrismaticBurstBackgroundComponent.prototype.ngOnChanges = function (changes) {
if (this.material) {
this.applyOptions();
}
};
PrismaticBurstBackgroundComponent.prototype.onPointerMove = function (event) {
var _a;
if (!((_a = this.containerRef) === null || _a === void 0 ? void 0 : _a.nativeElement))
return;
var rect = this.containerRef.nativeElement.getBoundingClientRect();
var x = (event.clientX - rect.left) / Math.max(rect.width, 1);
var y = (event.clientY - rect.top) / Math.max(rect.height, 1);
this.mouseTarget = [Math.min(Math.max(x, 0), 1), Math.min(Math.max(y, 0), 1)];
};
PrismaticBurstBackgroundComponent.prototype.onVisibilityChange = function () {
this.isVisible = !document.hidden;
};
PrismaticBurstBackgroundComponent.prototype.initScene = function () {
var container = this.containerRef.nativeElement;
var dpr = Math.min(window.devicePixelRatio || 1, 2);
this.renderer = new THREE__namespace.WebGLRenderer({ alpha: false, antialias: false });
this.renderer.setPixelRatio(dpr);
// 初始化画布样式
var canvas = this.renderer.domElement;
canvas.style.position = 'absolute';
canvas.style.inset = '0';
canvas.style.width = '100%';
canvas.style.height = '100%';
container.appendChild(canvas);
this.scene = new THREE__namespace.Scene();
this.camera = new THREE__namespace.OrthographicCamera(-1, 1, 1, -1, 0, 1);
var white = new Uint8Array([255, 255, 255, 255]);
this.gradientTex = new THREE__namespace.DataTexture(white, 1, 1, THREE__namespace.RGBAFormat);
this.gradientTex.minFilter = THREE__namespace.LinearFilter;
this.gradientTex.magFilter = THREE__namespace.LinearFilter;
this.gradientTex.wrapS = THREE__namespace.ClampToEdgeWrapping;
this.gradientTex.wrapT = THREE__namespace.ClampToEdgeWrapping;
this.gradientTex.generateMipmaps = false;
this.gradientTex.needsUpdate = true;
this.material = new THREE__namespace.RawShaderMaterial({
vertexShader: vertexShader,
fragmentShader: fragmentShader,
glslVersion: THREE__namespace.GLSL3,
uniforms: {
uResolution: { value: new THREE__namespace.Vector2(1, 1) },
uTime: { value: 0 },
uIntensity: { value: 1 },
uSpeed: { value: 1 },
uAnimType: { value: 0 },
uMouse: { value: new THREE__namespace.Vector2(0.5, 0.5) },
uColorCount: { value: 0 },
uDistort: { value: 0 },
uOffset: { value: new THREE__namespace.Vector2(0, 0) },
uGradient: { value: this.gradientTex },
uNoiseAmount: { value: 0.8 },
uRayCount: { value: 0 }
}
});
var geometry = new THREE__namespace.PlaneGeometry(2, 2);
this.mesh = new THREE__namespace.Mesh(geometry, this.material);
this.scene.add(this.mesh);
this.resizeCanvas();
};
PrismaticBurstBackgroundComponent.prototype.setupObservers = function () {
var _this = this;
var container = this.containerRef.nativeElement;
if (typeof ResizeObserver !== 'undefined') {
this.resizeObserver = new ResizeObserver(function () {
_this.resizeCanvas();
});
this.resizeObserver.observe(container);
}
else {
window.addEventListener('resize', this.onResizeBound);
}
if (typeof IntersectionObserver !== 'undefined') {
this.intersectionObserver = new IntersectionObserver(function (entries) {
if (entries[0]) {
_this.isVisible = entries[0].isIntersecting;
}
}, { root: null, threshold: 0.01 });
this.intersectionObserver.observe(container);
}
};
PrismaticBurstBackgroundComponent.prototype.resizeCanvas = function () {
if (!this.containerRef || !this.renderer)
return;
var container = this.containerRef.nativeElement;
var w = container.clientWidth || 1;
var h = container.clientHeight || 1;
// false 指代不修改 style 里面的 width 和 height
this.renderer.setSize(w, h, false);
var gl = this.renderer.getContext();
this.material.uniforms['uResolution'].value.set(gl.drawingBufferWidth, gl.drawingBufferHeight);
};
PrismaticBurstBackgroundComponent.prototype.applyOptions = function () {
var _a, _b, _c, _d, _e, _f, _g;
if (!this.material)
return;
var uniforms = this.material.uniforms;
uniforms['uIntensity'].value = (_a = this.ncIntensity) !== null && _a !== void 0 ? _a : 1;
uniforms['uSpeed'].value = (_b = this.ncSpeed) !== null && _b !== void 0 ? _b : 1;
var animTypeMap = {
rotate: 0,
'3drotate': 1,
hover: 2
};
uniforms['uAnimType'].value = (_d = animTypeMap[(_c = this.ncAnimationType) !== null && _c !== void 0 ? _c : 'rotate']) !== null && _d !== void 0 ? _d : 0;
uniforms['uDistort'].value = typeof this.ncDistort === 'number' ? this.ncDistort : 0;
var ox = toPx((_e = this.ncOffset) === null || _e === void 0 ? void 0 : _e.x);
var oy = toPx((_f = this.ncOffset) === null || _f === void 0 ? void 0 : _f.y);
uniforms['uOffset'].value.set(ox, oy);
uniforms['uRayCount'].value = Math.max(0, Math.floor((_g = this.ncRayCount) !== null && _g !== void 0 ? _g : 0));
var count = 0;
if (Array.isArray(this.ncColors) && this.ncColors.length > 0) {
var capped = this.ncColors.slice(0, 64);
count = capped.length;
var data = new Uint8Array(count * 4);
for (var i = 0; i < count; i++) {
var _h = __read(hexToRgb01(capped[i]), 3), r = _h[0], g = _h[1], b = _h[2];
data[i * 4 + 0] = Math.round(r * 255);
data[i * 4 + 1] = Math.round(g * 255);
data[i * 4 + 2] = Math.round(b * 255);
data[i * 4 + 3] = 255;
}
if (this.gradientTex) {
this.gradientTex.dispose();
}
this.gradientTex = new THREE__namespace.DataTexture(data, count, 1, THREE__namespace.RGBAFormat);
this.gradientTex.minFilter = THREE__namespace.LinearFilter;
this.gradientTex.magFilter = THREE__namespace.LinearFilter;
this.gradientTex.wrapS = THREE__namespace.ClampToEdgeWrapping;
this.gradientTex.wrapT = THREE__namespace.ClampToEdgeWrapping;
this.gradientTex.generateMipmaps = false;
this.gradientTex.needsUpdate = true;
uniforms['uGradient'].value = this.gradientTex;
}
uniforms['uColorCount'].value = count;
};
PrismaticBurstBackgroundComponent.prototype.cleanup = function () {
var _a;
if (this.rafId !== null) {
cancelAnimationFrame(this.rafId);
this.rafId = null;
}
if (this.resizeObserver) {
this.resizeObserver.disconnect();
}
window.removeEventListener('resize', this.onResizeBound);
if (this.intersectionObserver) {
this.intersectionObserver.disconnect();
}
if (this.mesh && this.scene) {
this.scene.remove(this.mesh);
this.mesh.geometry.dispose();
if (this.material) {
this.material.dispose();
}
}
if (this.gradientTex) {
this.gradientTex.dispose();
}
if (this.renderer) {
this.renderer.dispose();
var container = (_a = this.containerRef) === null || _a === void 0 ? void 0 : _a.nativeElement;
if (container && this.renderer.domElement.parentNode === container) {
container.removeChild(this.renderer.domElement);
}
}
};
return PrismaticBurstBackgroundComponent;
}());
PrismaticBurstBackgroundComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: PrismaticBurstBackgroundComponent, deps: [{ token: i0__namespace.NgZone }], target: i0__namespace.ɵɵFactoryTarget.Component });
PrismaticBurstBackgroundComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.5", type: PrismaticBurstBackgroundComponent, selector: "nc-prismatic-burst-background", inputs: { ncIntensity: "ncIntensity", ncSpeed: "ncSpeed", ncAnimationType: "ncAnimationType", ncColors: "ncColors", ncDistort: "ncDistort", ncPaused: "ncPaused", ncOffset: "ncOffset", ncHoverDampness: "ncHoverDampness", ncRayCount: "ncRayCount" }, host: { listeners: { "pointermove": "onPointerMove($event)", "document:visibilitychange": "onVisibilityChange()" } }, viewQueries: [{ propertyName: "containerRef", first: true, predicate: ["container"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0__namespace, template: "<div #container class=\"nc-prismatic-burst-canvas-container\"></div>\r\n<div class=\"nc-content-wrapper\">\r\n <ng-content></ng-content>\r\n</div>\r\n", styles: [":host{display:block;position:relative;width:100%;height:100%;overflow:hidden}.nc-prismatic-burst-canvas-container{position:absolute;inset:0;z-index:0}.nc-content-wrapper{position:relative;z-index:1;width:100%;height:100%}\n"] });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: PrismaticBurstBackgroundComponent, decorators: [{
type: i0.Component,
args: [{
selector: 'nc-prismatic-burst-background',
templateUrl: './prismatic-burst-background.component.html',
styleUrls: ['./prismatic-burst-background.component.less']
}]
}], ctorParameters: function () { return [{ type: i0__namespace.NgZone }]; }, propDecorators: { containerRef: [{
type: i0.ViewChild,
args: ['container', { static: true }]
}], ncIntensity: [{
type: i0.Input
}], ncSpeed: [{
type: i0.Input
}], ncAnimationType: [{
type: i0.Input
}], ncColors: [{
type: i0.Input
}], ncDistort: [{
type: i0.Input
}], ncPaused: [{
type: i0.Input
}], ncOffset: [{
type: i0.Input
}], ncHoverDampness: [{
type: i0.Input
}], ncRayCount: [{
type: i0.Input
}], onPointerMove: [{
type: i0.HostListener,
args: ['pointermove', ['$event']]
}], onVisibilityChange: [{
type: i0.HostListener,
args: ['document:visibilitychange']
}] } });
var NcPrismaticBurstBackgroundModule = /** @class */ (function () {
function NcPrismaticBurstBackgroundModule() {
}
return NcPrismaticBurstBackgroundModule;
}());
NcPrismaticBurstBackgroundModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcPrismaticBurstBackgroundModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
NcPrismaticBurstBackgroundModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcPrismaticBurstBackgroundModule, declarations: [PrismaticBurstBackgroundComponent], imports: [common.CommonModule], exports: [PrismaticBurstBackgroundComponent] });
NcPrismaticBurstBackgroundModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcPrismaticBurstBackgroundModule, imports: [[
common.CommonModule
]] });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcPrismaticBurstBackgroundModule, decorators: [{
type: i0.NgModule,
args: [{
declarations: [
PrismaticBurstBackgroundComponent
],
imports: [
common.CommonModule
],
exports: [
PrismaticBurstBackgroundComponent
]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
exports.NcPrismaticBurstBackgroundModule = NcPrismaticBurstBackgroundModule;
exports.PrismaticBurstBackgroundComponent = PrismaticBurstBackgroundComponent;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=ng-cw-v12-prismatic-burst-background.umd.js.map