targetj 1.0.260 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Export.js +3 -0
- package/build/AnimationManager.js +1 -1
- package/build/App.js +10 -2
- package/build/BaseModel.js +8 -4
- package/build/Bracket.js +7 -1
- package/build/EventListener.js +10 -1
- package/build/LocationManager.js +137 -46
- package/build/PageManager.js +35 -134
- package/build/ParticleChild.js +575 -0
- package/build/ParticleRenderer.js +249 -68
- package/build/ParticleRuntime.js +898 -283
- package/build/ParticleTModel.js +610 -227
- package/build/ParticleUtil.js +119 -171
- package/build/RunScheduler.js +10 -3
- package/build/StateManager.js +81 -24
- package/build/StateUtil.js +1 -1
- package/build/TModel.js +1 -1
- package/build/TModelManager.js +105 -90
- package/build/TModelUtil.js +11 -8
- package/build/TUtil.js +57 -52
- package/build/TargetData.js +6 -0
- package/build/TargetExecutor.js +11 -3
- package/build/TargetManager.js +34 -21
- package/build/TargetParser.js +21 -2
- package/build/TargetUtil.js +24 -3
- package/build/VisibilityUtil.js +4 -2
- package/build/index.js +1 -0
- package/dist/targetjs.js +1 -1
- package/dist/targetjs.js.gz +0 -0
- package/package.json +1 -1
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
3
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
7
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
8
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
2
9
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
10
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
4
11
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
@@ -8,6 +15,7 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r),
|
|
|
8
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
16
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
17
|
import { ColorUtil } from "./ColorUtil.js";
|
|
18
|
+
import { TUtil } from "./TUtil.js";
|
|
11
19
|
|
|
12
20
|
/**
|
|
13
21
|
* It renders GPU-backed children using WebGPU.
|
|
@@ -29,6 +37,8 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
29
37
|
this.transitionActive = false;
|
|
30
38
|
this.particleCount = 0;
|
|
31
39
|
this.canvasLayer = undefined;
|
|
40
|
+
this.canvasX = 0;
|
|
41
|
+
this.canvasY = 0;
|
|
32
42
|
this.initializationPromise = undefined;
|
|
33
43
|
}
|
|
34
44
|
return _createClass(ParticleRenderer, [{
|
|
@@ -137,7 +147,10 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
137
147
|
}, {
|
|
138
148
|
key: "createCanvas",
|
|
139
149
|
value: function createCanvas() {
|
|
140
|
-
var _this$tmodel$$dom
|
|
150
|
+
var _this$tmodel$$dom,
|
|
151
|
+
_this2 = this,
|
|
152
|
+
_this$tmodel$$dom2,
|
|
153
|
+
_this$tmodel$getParen;
|
|
141
154
|
if (this.canvas) {
|
|
142
155
|
return;
|
|
143
156
|
}
|
|
@@ -163,7 +176,7 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
163
176
|
this.canvas = document.createElement("canvas");
|
|
164
177
|
this.canvas.setAttribute("data-targetjs-gpu-children", "true");
|
|
165
178
|
Object.assign(this.canvas.style, {
|
|
166
|
-
position: "
|
|
179
|
+
position: "absolute",
|
|
167
180
|
left: "0px",
|
|
168
181
|
top: "0px",
|
|
169
182
|
width: "1px",
|
|
@@ -173,6 +186,24 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
173
186
|
});
|
|
174
187
|
this.canvasLayer.appendChild(this.canvas);
|
|
175
188
|
parent.prepend(this.canvasLayer);
|
|
189
|
+
this.onScroll = function () {
|
|
190
|
+
return _this2.tmodel.requestParticleRender();
|
|
191
|
+
};
|
|
192
|
+
this.scrollElements = _toConsumableArray(new Set([(_this$tmodel$$dom2 = this.tmodel.$dom) === null || _this$tmodel$$dom2 === void 0 ? void 0 : _this$tmodel$$dom2.element, (_this$tmodel$getParen = this.tmodel.getParent()) === null || _this$tmodel$getParen === void 0 || (_this$tmodel$getParen = _this$tmodel$getParen.$dom) === null || _this$tmodel$getParen === void 0 ? void 0 : _this$tmodel$getParen.element].filter(Boolean)));
|
|
193
|
+
var _iterator = _createForOfIteratorHelper(this.scrollElements),
|
|
194
|
+
_step;
|
|
195
|
+
try {
|
|
196
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
197
|
+
var element = _step.value;
|
|
198
|
+
element.addEventListener("scroll", this.onScroll, {
|
|
199
|
+
passive: true
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
} catch (err) {
|
|
203
|
+
_iterator.e(err);
|
|
204
|
+
} finally {
|
|
205
|
+
_iterator.f();
|
|
206
|
+
}
|
|
176
207
|
}
|
|
177
208
|
}, {
|
|
178
209
|
key: "createUniformBuffer",
|
|
@@ -186,7 +217,7 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
186
217
|
key: "createPipeline",
|
|
187
218
|
value: function createPipeline() {
|
|
188
219
|
var shaderModule = this.device.createShaderModule({
|
|
189
|
-
code: "\n struct Uniforms {\n viewport: vec2f,\n contentOffset: vec2f,\n step: f32,\n transitionActive: f32,\n padding: vec2f,\n }\n\n @group(0) @binding(0)\n var<uniform> uniforms: Uniforms;\n\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) localPosition: vec2f,\n @location(1) backgroundColor: vec4f,\n @location(2) size: vec2f,\n @location(3) borderRadius: f32,\n }\n\n fn getProgress(step: f32, steps: f32) -> f32 {\n if (uniforms.transitionActive < 0.5) {\n return 0.0;\n }\n\n if (steps < 0.0) {\n return 0.0;\n }\n\n if (steps == 0.0) {\n return 1.0;\n }\n\n return clamp(step / steps, 0.0, 1.0);\n }\n\n @vertex\n fn vertexMain(\n @location(0) childPosition: vec2f,\n @location(1) childSize: vec2f,\n @location(2) childBackgroundColor: vec4f,\n @location(3) childGeometry: vec2f,\n @location(4) targetPosition: vec2f,\n @location(5) targetSize: vec2f,\n @location(6) targetBackgroundColor: vec4f,\n @location(7) targetGeometry: vec2f,\n @location(8) targetPositionSteps: vec2f,\n @location(9) targetSizeSteps: vec2f,\n @location(10) targetBackgroundColorSteps: f32,\n @location(11) targetGeometrySteps: vec2f,\n @builtin(vertex_index) vertexIndex: u32\n ) -> VertexOutput {\n let corners = array<vec2f, 6>(\n vec2f(-1.0, -1.0),\n vec2f( 1.0, -1.0),\n vec2f(-1.0, 1.0),\n vec2f(-1.0, 1.0),\n vec2f( 1.0, -1.0),\n vec2f( 1.0, 1.0)\n );\n\n let xProgress = getProgress(uniforms.step, targetPositionSteps.x);\n let yProgress = getProgress(uniforms.step, targetPositionSteps.y);\n let widthProgress = getProgress(uniforms.step, targetSizeSteps.x);\n let heightProgress = getProgress(uniforms.step, targetSizeSteps.y);\n let backgroundColorProgress = getProgress(uniforms.step, targetBackgroundColorSteps);\n let borderRadiusProgress = getProgress(uniforms.step, targetGeometrySteps.x);\n let rotateProgress = getProgress(uniforms.step, targetGeometrySteps.y);\n\n let position = vec2f(\n mix(childPosition.x, targetPosition.x, xProgress),\n mix(childPosition.y, targetPosition.y, yProgress)\n );\n\n let size = vec2f(\n mix(childSize.x, targetSize.x, widthProgress),\n mix(childSize.y, targetSize.y, heightProgress)\n );\n\n let backgroundColor = mix(childBackgroundColor, targetBackgroundColor, backgroundColorProgress);\n let borderRadius = mix(childGeometry.x, targetGeometry.x, borderRadiusProgress);\n let rotate = mix(childGeometry.y, targetGeometry.y, rotateProgress);\n let localPosition = corners[vertexIndex];\n let localPixelPosition = localPosition * size * 0.5;\n let angle = rotate * 3.141592653589793 / 180.0;\n let cosine = cos(angle);\n let sine = sin(angle);\n\n let rotatedPosition = vec2f(\n localPixelPosition.x * cosine - localPixelPosition.y * sine,\n localPixelPosition.x * sine + localPixelPosition.y * cosine\n );\n\n let elementCenter = position - uniforms.contentOffset + size * 0.5;\n let pixelPosition = elementCenter + rotatedPosition;\n\n let clipPosition = vec2f(\n pixelPosition.x / uniforms.viewport.x * 2.0 - 1.0,\n 1.0 - pixelPosition.y / uniforms.viewport.y * 2.0\n );\n\n var output: VertexOutput;\n\n output.position = vec4f(clipPosition, 0.0, 1.0);\n output.localPosition = localPosition;\n output.backgroundColor = backgroundColor;\n output.size = size;\n output.borderRadius = borderRadius;\n\n return output;\n }\n
|
|
220
|
+
code: "\n struct Uniforms {\n viewport: vec2f,\n contentOffset: vec2f,\n step: f32,\n transitionActive: f32,\n padding: vec2f,\n }\n\n @group(0) @binding(0)\n var<uniform> uniforms: Uniforms;\n\n struct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) localPosition: vec2f,\n @location(1) backgroundColor: vec4f,\n @location(2) size: vec2f,\n @location(3) borderRadius: f32,\n }\n\n fn getProgress(step: f32, steps: f32) -> f32 {\n if (uniforms.transitionActive < 0.5) {\n return 0.0;\n }\n\n if (steps < 0.0) {\n return 0.0;\n }\n\n if (steps == 0.0) {\n return 1.0;\n }\n\n return clamp(step / steps, 0.0, 1.0);\n }\n\n @vertex\n fn vertexMain(\n @location(0) childPosition: vec2f,\n @location(1) childSize: vec2f,\n @location(2) childBackgroundColor: vec4f,\n @location(3) childGeometry: vec2f,\n @location(4) targetPosition: vec2f,\n @location(5) targetSize: vec2f,\n @location(6) targetBackgroundColor: vec4f,\n @location(7) targetGeometry: vec2f,\n @location(8) targetPositionSteps: vec2f,\n @location(9) targetSizeSteps: vec2f,\n @location(10) targetBackgroundColorSteps: f32,\n @location(11) targetGeometrySteps: vec2f,\n @location(12) childScale: f32,\n @location(13) targetScale: f32,\n @location(14) targetScaleSteps: f32,\n @builtin(vertex_index) vertexIndex: u32\n ) -> VertexOutput {\n let corners = array<vec2f, 6>(\n vec2f(-1.0, -1.0),\n vec2f( 1.0, -1.0),\n vec2f(-1.0, 1.0),\n vec2f(-1.0, 1.0),\n vec2f( 1.0, -1.0),\n vec2f( 1.0, 1.0)\n );\n\n let xProgress = getProgress(uniforms.step, targetPositionSteps.x);\n let yProgress = getProgress(uniforms.step, targetPositionSteps.y);\n let widthProgress = getProgress(uniforms.step, targetSizeSteps.x);\n let heightProgress = getProgress(uniforms.step, targetSizeSteps.y);\n let backgroundColorProgress = getProgress(uniforms.step, targetBackgroundColorSteps);\n let borderRadiusProgress = getProgress(uniforms.step, targetGeometrySteps.x);\n let rotateProgress = getProgress(uniforms.step, targetGeometrySteps.y);\n let scaleProgress = getProgress(uniforms.step, targetScaleSteps);\n \n let position = vec2f(\n mix(childPosition.x, targetPosition.x, xProgress),\n mix(childPosition.y, targetPosition.y, yProgress)\n );\n\n let size = vec2f(\n mix(childSize.x, targetSize.x, widthProgress),\n mix(childSize.y, targetSize.y, heightProgress)\n );\n\n let backgroundColor = mix(childBackgroundColor, targetBackgroundColor, backgroundColorProgress);\n let borderRadius = mix(childGeometry.x, targetGeometry.x, borderRadiusProgress);\n let rotate = mix(childGeometry.y, targetGeometry.y, rotateProgress);\n let scale = mix(childScale, targetScale, scaleProgress);\n\n let localPosition = corners[vertexIndex];\n let localPixelPosition = localPosition * size * 0.5 * scale;\n\n let angle = rotate * 3.141592653589793 / 180.0;\n let cosine = cos(angle);\n let sine = sin(angle);\n\n let rotatedPosition = vec2f(\n localPixelPosition.x * cosine - localPixelPosition.y * sine,\n localPixelPosition.x * sine + localPixelPosition.y * cosine\n );\n\n let elementCenter = position - uniforms.contentOffset + size * 0.5;\n let pixelPosition = elementCenter + rotatedPosition;\n\n let clipPosition = vec2f(\n pixelPosition.x / uniforms.viewport.x * 2.0 - 1.0,\n 1.0 - pixelPosition.y / uniforms.viewport.y * 2.0\n );\n\n var output: VertexOutput;\n\n output.position = vec4f(clipPosition, 0.0, 1.0);\n output.localPosition = localPosition;\n output.backgroundColor = backgroundColor;\n output.size = size;\n output.borderRadius = borderRadius;\n\n return output;\n }\n @fragment\n fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {\n let halfSize = max(input.size * 0.5, vec2f(0.0001));\n let radius = clamp(input.borderRadius, 0.0, min(halfSize.x, halfSize.y));\n let pixelPosition = input.localPosition * halfSize;\n let q = abs(pixelPosition) - (halfSize - vec2f(radius));\n let distance = length(max(q, vec2f(0.0))) + min(max(q.x, q.y), 0.0) - radius;\n let aa = max(fwidth(distance), 0.0001);\n\n if (radius <= 0.0) {\n return input.backgroundColor;\n }\n\n let coverage = 1.0 - smoothstep(-aa, aa, distance);\n\n if (coverage <= 0.0) {\n discard;\n }\n\n let alpha = input.backgroundColor.a * coverage;\n\n return vec4f(input.backgroundColor.rgb * alpha, alpha);\n }\n "
|
|
190
221
|
});
|
|
191
222
|
this.pipeline = this.device.createRenderPipeline({
|
|
192
223
|
layout: "auto",
|
|
@@ -212,6 +243,10 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
212
243
|
shaderLocation: 3,
|
|
213
244
|
offset: 32,
|
|
214
245
|
format: "float32x2"
|
|
246
|
+
}, {
|
|
247
|
+
shaderLocation: 12,
|
|
248
|
+
offset: 68,
|
|
249
|
+
format: "float32"
|
|
215
250
|
}]
|
|
216
251
|
}, {
|
|
217
252
|
arrayStride: 80,
|
|
@@ -248,6 +283,14 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
248
283
|
shaderLocation: 11,
|
|
249
284
|
offset: 60,
|
|
250
285
|
format: "float32x2"
|
|
286
|
+
}, {
|
|
287
|
+
shaderLocation: 13,
|
|
288
|
+
offset: 68,
|
|
289
|
+
format: "float32"
|
|
290
|
+
}, {
|
|
291
|
+
shaderLocation: 14,
|
|
292
|
+
offset: 72,
|
|
293
|
+
format: "float32"
|
|
251
294
|
}]
|
|
252
295
|
}]
|
|
253
296
|
},
|
|
@@ -255,7 +298,19 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
255
298
|
module: shaderModule,
|
|
256
299
|
entryPoint: "fragmentMain",
|
|
257
300
|
targets: [{
|
|
258
|
-
format: this.format
|
|
301
|
+
format: this.format,
|
|
302
|
+
blend: {
|
|
303
|
+
color: {
|
|
304
|
+
srcFactor: "one",
|
|
305
|
+
dstFactor: "one-minus-src-alpha",
|
|
306
|
+
operation: "add"
|
|
307
|
+
},
|
|
308
|
+
alpha: {
|
|
309
|
+
srcFactor: "one",
|
|
310
|
+
dstFactor: "one-minus-src-alpha",
|
|
311
|
+
operation: "add"
|
|
312
|
+
}
|
|
313
|
+
}
|
|
259
314
|
}]
|
|
260
315
|
},
|
|
261
316
|
primitive: {
|
|
@@ -282,18 +337,21 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
282
337
|
}, {
|
|
283
338
|
key: "getBackgroundColor",
|
|
284
339
|
value: function getBackgroundColor(value) {
|
|
340
|
+
if (!TUtil.isDefined(value)) {
|
|
341
|
+
return [0, 0, 0, 0];
|
|
342
|
+
}
|
|
285
343
|
if (Array.isArray(value)) {
|
|
286
|
-
return [this.toNumber(value[0],
|
|
344
|
+
return [this.toNumber(value[0], 0), this.toNumber(value[1], 0), this.toNumber(value[2], 0), this.toNumber(value[3], 0)];
|
|
287
345
|
}
|
|
288
|
-
var color = ColorUtil.color2Integers(value
|
|
346
|
+
var color = ColorUtil.color2Integers(value);
|
|
289
347
|
if (!color) {
|
|
290
|
-
return [
|
|
348
|
+
return [0, 0, 0, 0];
|
|
291
349
|
}
|
|
292
350
|
var alpha = this.toNumber(color[3], 1);
|
|
293
351
|
if (alpha > 1) {
|
|
294
352
|
alpha /= 255;
|
|
295
353
|
}
|
|
296
|
-
return [this.toNumber(color[0],
|
|
354
|
+
return [this.toNumber(color[0], 0) / 255, this.toNumber(color[1], 0) / 255, this.toNumber(color[2], 0) / 255, alpha];
|
|
297
355
|
}
|
|
298
356
|
}, {
|
|
299
357
|
key: "getTargetStep",
|
|
@@ -303,32 +361,61 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
303
361
|
}
|
|
304
362
|
return Math.max(0, this.toNumber(steps[key], 0));
|
|
305
363
|
}
|
|
364
|
+
}, {
|
|
365
|
+
key: "writeParticleData",
|
|
366
|
+
value: function writeParticleData(particleData, offset, values, steps) {
|
|
367
|
+
var _values, _values2;
|
|
368
|
+
var x = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : (_values = values) === null || _values === void 0 ? void 0 : _values.x;
|
|
369
|
+
var y = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : (_values2 = values) === null || _values2 === void 0 ? void 0 : _values2.y;
|
|
370
|
+
values || (values = {});
|
|
371
|
+
var backgroundColor = this.getBackgroundColor(values.backgroundColor);
|
|
372
|
+
var opacity = Math.max(0, Math.min(1, this.toNumber(values.opacity, 1)));
|
|
373
|
+
particleData[offset] = this.toNumber(x, 0);
|
|
374
|
+
particleData[offset + 1] = this.toNumber(y, 0);
|
|
375
|
+
particleData[offset + 2] = this.toNumber(values.width, 0);
|
|
376
|
+
particleData[offset + 3] = this.toNumber(values.height, 0);
|
|
377
|
+
particleData[offset + 4] = backgroundColor[0];
|
|
378
|
+
particleData[offset + 5] = backgroundColor[1];
|
|
379
|
+
particleData[offset + 6] = backgroundColor[2];
|
|
380
|
+
particleData[offset + 7] = backgroundColor[3] * opacity;
|
|
381
|
+
particleData[offset + 8] = Math.max(0, this.toNumber(values.borderRadius, 0));
|
|
382
|
+
particleData[offset + 9] = this.toNumber(values.rotate, 0);
|
|
383
|
+
particleData[offset + 10] = this.getTargetStep(steps, "x");
|
|
384
|
+
particleData[offset + 11] = this.getTargetStep(steps, "y");
|
|
385
|
+
particleData[offset + 12] = this.getTargetStep(steps, "width");
|
|
386
|
+
particleData[offset + 13] = this.getTargetStep(steps, "height");
|
|
387
|
+
var backgroundColorSteps = this.getTargetStep(steps, "backgroundColor");
|
|
388
|
+
var opacitySteps = this.getTargetStep(steps, "opacity");
|
|
389
|
+
particleData[offset + 14] = opacitySteps >= 0 ? opacitySteps : backgroundColorSteps;
|
|
390
|
+
particleData[offset + 15] = this.getTargetStep(steps, "borderRadius");
|
|
391
|
+
particleData[offset + 16] = this.getTargetStep(steps, "rotate");
|
|
392
|
+
particleData[offset + 17] = this.toNumber(values.scale, 1);
|
|
393
|
+
particleData[offset + 18] = this.getTargetStep(steps, "scale");
|
|
394
|
+
}
|
|
395
|
+
}, {
|
|
396
|
+
key: "createChildData",
|
|
397
|
+
value: function createChildData(children) {
|
|
398
|
+
var particleData = new Float32Array(children.length * 20);
|
|
399
|
+
for (var i = 0; i < children.length; i++) {
|
|
400
|
+
var child = children[i];
|
|
401
|
+
var values = child.actualValues;
|
|
402
|
+
var _this$getParticlePosi = this.getParticlePosition(child, values),
|
|
403
|
+
x = _this$getParticlePosi.x,
|
|
404
|
+
y = _this$getParticlePosi.y;
|
|
405
|
+
this.writeParticleData(particleData, i * 20, values, undefined, x, y);
|
|
406
|
+
}
|
|
407
|
+
return particleData;
|
|
408
|
+
}
|
|
306
409
|
}, {
|
|
307
410
|
key: "createParticleData",
|
|
308
411
|
value: function createParticleData(values, targetSteps) {
|
|
309
412
|
var particleData = new Float32Array(values.length * 20);
|
|
310
413
|
for (var i = 0; i < values.length; i++) {
|
|
311
|
-
var child =
|
|
312
|
-
var
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
particleData[
|
|
316
|
-
particleData[offset + 1] = this.toNumber(child.y, 0);
|
|
317
|
-
particleData[offset + 2] = this.toNumber(child.width, 0);
|
|
318
|
-
particleData[offset + 3] = this.toNumber(child.height, 0);
|
|
319
|
-
particleData[offset + 4] = backgroundColor[0];
|
|
320
|
-
particleData[offset + 5] = backgroundColor[1];
|
|
321
|
-
particleData[offset + 6] = backgroundColor[2];
|
|
322
|
-
particleData[offset + 7] = backgroundColor[3];
|
|
323
|
-
particleData[offset + 8] = Math.max(0, this.toNumber(child.borderRadius, 0));
|
|
324
|
-
particleData[offset + 9] = this.toNumber(child.rotate, 0);
|
|
325
|
-
particleData[offset + 10] = this.getTargetStep(steps, "x");
|
|
326
|
-
particleData[offset + 11] = this.getTargetStep(steps, "y");
|
|
327
|
-
particleData[offset + 12] = this.getTargetStep(steps, "width");
|
|
328
|
-
particleData[offset + 13] = this.getTargetStep(steps, "height");
|
|
329
|
-
particleData[offset + 14] = this.getTargetStep(steps, "backgroundColor");
|
|
330
|
-
particleData[offset + 15] = this.getTargetStep(steps, "borderRadius");
|
|
331
|
-
particleData[offset + 16] = this.getTargetStep(steps, "rotate");
|
|
414
|
+
var child = this.tmodel.childHandles[i];
|
|
415
|
+
var _this$getParticlePosi2 = this.getParticlePosition(child, values[i]),
|
|
416
|
+
x = _this$getParticlePosi2.x,
|
|
417
|
+
y = _this$getParticlePosi2.y;
|
|
418
|
+
this.writeParticleData(particleData, i * 20, values[i], targetSteps === null || targetSteps === void 0 ? void 0 : targetSteps[i], x, y);
|
|
332
419
|
}
|
|
333
420
|
return particleData;
|
|
334
421
|
}
|
|
@@ -354,12 +441,12 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
354
441
|
}, {
|
|
355
442
|
key: "setParticles",
|
|
356
443
|
value: function () {
|
|
357
|
-
var _setParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(
|
|
444
|
+
var _setParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(children) {
|
|
358
445
|
var initialized, particleData;
|
|
359
446
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
360
447
|
while (1) switch (_context3.prev = _context3.next) {
|
|
361
448
|
case 0:
|
|
362
|
-
|
|
449
|
+
children = Array.isArray(children) ? children : [children];
|
|
363
450
|
_context3.next = 3;
|
|
364
451
|
return this.init();
|
|
365
452
|
case 3:
|
|
@@ -368,16 +455,17 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
368
455
|
_context3.next = 6;
|
|
369
456
|
break;
|
|
370
457
|
}
|
|
371
|
-
return _context3.abrupt("return");
|
|
458
|
+
return _context3.abrupt("return", false);
|
|
372
459
|
case 6:
|
|
373
|
-
particleData = this.
|
|
374
|
-
this.particleCount =
|
|
460
|
+
particleData = this.createChildData(children);
|
|
461
|
+
this.particleCount = children.length;
|
|
375
462
|
this.particleBuffer = this.uploadParticleBuffer(this.particleBuffer, particleData);
|
|
376
463
|
this.targetParticleBuffer = this.uploadParticleBuffer(this.targetParticleBuffer, particleData);
|
|
377
464
|
this.transitionStep = 0;
|
|
378
465
|
this.transitionActive = false;
|
|
379
466
|
this.render();
|
|
380
|
-
|
|
467
|
+
return _context3.abrupt("return", true);
|
|
468
|
+
case 14:
|
|
381
469
|
case "end":
|
|
382
470
|
return _context3.stop();
|
|
383
471
|
}
|
|
@@ -391,12 +479,12 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
391
479
|
}, {
|
|
392
480
|
key: "updateParticles",
|
|
393
481
|
value: function () {
|
|
394
|
-
var _updateParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(
|
|
482
|
+
var _updateParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(children) {
|
|
395
483
|
var initialized, particleData;
|
|
396
484
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
397
485
|
while (1) switch (_context4.prev = _context4.next) {
|
|
398
486
|
case 0:
|
|
399
|
-
|
|
487
|
+
children = Array.isArray(children) ? children : [children];
|
|
400
488
|
_context4.next = 3;
|
|
401
489
|
return this.init();
|
|
402
490
|
case 3:
|
|
@@ -405,16 +493,21 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
405
493
|
_context4.next = 6;
|
|
406
494
|
break;
|
|
407
495
|
}
|
|
408
|
-
return _context4.abrupt("return");
|
|
496
|
+
return _context4.abrupt("return", false);
|
|
409
497
|
case 6:
|
|
410
|
-
particleData = this.
|
|
411
|
-
this.particleCount =
|
|
498
|
+
particleData = this.createChildData(children);
|
|
499
|
+
this.particleCount = children.length;
|
|
412
500
|
this.particleBuffer = this.uploadParticleBuffer(this.particleBuffer, particleData);
|
|
413
|
-
if (!this.transitionActive) {
|
|
501
|
+
if (!children.length || !this.transitionActive) {
|
|
414
502
|
this.targetParticleBuffer = this.uploadParticleBuffer(this.targetParticleBuffer, particleData);
|
|
415
503
|
}
|
|
504
|
+
if (!children.length) {
|
|
505
|
+
this.transitionStep = 0;
|
|
506
|
+
this.transitionActive = false;
|
|
507
|
+
}
|
|
416
508
|
this.render();
|
|
417
|
-
|
|
509
|
+
return _context4.abrupt("return", true);
|
|
510
|
+
case 13:
|
|
418
511
|
case "end":
|
|
419
512
|
return _context4.stop();
|
|
420
513
|
}
|
|
@@ -429,33 +522,46 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
429
522
|
key: "setTargetParticles",
|
|
430
523
|
value: function () {
|
|
431
524
|
var _setTargetParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(values, steps) {
|
|
432
|
-
var
|
|
525
|
+
var generation,
|
|
526
|
+
initialized,
|
|
527
|
+
currentChildren,
|
|
528
|
+
currentParticleData,
|
|
529
|
+
particleData,
|
|
530
|
+
_args5 = arguments;
|
|
433
531
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
434
532
|
while (1) switch (_context5.prev = _context5.next) {
|
|
435
533
|
case 0:
|
|
534
|
+
generation = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : this.tmodel.childGeneration;
|
|
436
535
|
values = Array.isArray(values) ? values : [values];
|
|
437
|
-
_context5.next =
|
|
536
|
+
_context5.next = 4;
|
|
438
537
|
return this.init();
|
|
439
|
-
case
|
|
538
|
+
case 4:
|
|
440
539
|
initialized = _context5.sent;
|
|
441
|
-
if (initialized) {
|
|
442
|
-
_context5.next =
|
|
540
|
+
if (!(!initialized || generation !== this.tmodel.childGeneration)) {
|
|
541
|
+
_context5.next = 7;
|
|
443
542
|
break;
|
|
444
543
|
}
|
|
445
|
-
return _context5.abrupt("return");
|
|
446
|
-
case
|
|
447
|
-
|
|
448
|
-
|
|
544
|
+
return _context5.abrupt("return", false);
|
|
545
|
+
case 7:
|
|
546
|
+
currentChildren = this.tmodel.childHandles;
|
|
547
|
+
if (!(values.length !== currentChildren.length)) {
|
|
548
|
+
_context5.next = 10;
|
|
449
549
|
break;
|
|
450
550
|
}
|
|
451
|
-
|
|
452
|
-
case
|
|
551
|
+
return _context5.abrupt("return", false);
|
|
552
|
+
case 10:
|
|
553
|
+
if (this.particleCount !== currentChildren.length || !this.particleBuffer) {
|
|
554
|
+
currentParticleData = this.createChildData(currentChildren);
|
|
555
|
+
this.particleCount = currentChildren.length;
|
|
556
|
+
this.particleBuffer = this.uploadParticleBuffer(this.particleBuffer, currentParticleData);
|
|
557
|
+
}
|
|
453
558
|
particleData = this.createParticleData(values, steps);
|
|
454
559
|
this.targetParticleBuffer = this.uploadParticleBuffer(this.targetParticleBuffer, particleData);
|
|
455
560
|
this.transitionStep = 0;
|
|
456
561
|
this.transitionActive = true;
|
|
457
562
|
this.render();
|
|
458
|
-
|
|
563
|
+
return _context5.abrupt("return", true);
|
|
564
|
+
case 17:
|
|
459
565
|
case "end":
|
|
460
566
|
return _context5.stop();
|
|
461
567
|
}
|
|
@@ -469,7 +575,11 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
469
575
|
}, {
|
|
470
576
|
key: "setTransitionStep",
|
|
471
577
|
value: function setTransitionStep(step) {
|
|
472
|
-
|
|
578
|
+
step = Math.max(0, this.toNumber(step, 0));
|
|
579
|
+
if (step === this.transitionStep) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
this.transitionStep = step;
|
|
473
583
|
this.render();
|
|
474
584
|
}
|
|
475
585
|
}, {
|
|
@@ -482,11 +592,28 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
482
592
|
}, {
|
|
483
593
|
key: "getRenderHeight",
|
|
484
594
|
value: function getRenderHeight() {
|
|
485
|
-
var _this$tmodel$
|
|
595
|
+
var _this$tmodel$getParen2;
|
|
486
596
|
var modelHeight = Number(this.tmodel.getHeight()) || 1;
|
|
487
|
-
var parentHeight = Number((_this$tmodel$
|
|
597
|
+
var parentHeight = Number((_this$tmodel$getParen2 = this.tmodel.getParent()) === null || _this$tmodel$getParen2 === void 0 ? void 0 : _this$tmodel$getParen2.getHeight()) || window.innerHeight || 1;
|
|
488
598
|
return Math.max(1, Math.min(modelHeight, parentHeight));
|
|
489
599
|
}
|
|
600
|
+
}, {
|
|
601
|
+
key: "updateCanvasLayerWidthHeight",
|
|
602
|
+
value: function updateCanvasLayerWidthHeight() {
|
|
603
|
+
if (!this.canvasLayer) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
var height = Math.max(this.getRenderHeight(), Number(this.tmodel.getContentHeight()) || 0);
|
|
607
|
+
var width = Math.max(this.getRenderWidth(), Number(this.tmodel.getContentWidth()) || 0);
|
|
608
|
+
var cssHeight = "".concat(height, "px");
|
|
609
|
+
var cssWidth = "".concat(width, "px");
|
|
610
|
+
if (this.canvasLayer.style.height !== cssHeight) {
|
|
611
|
+
this.canvasLayer.style.height = cssHeight;
|
|
612
|
+
}
|
|
613
|
+
if (this.canvasLayer.style.width !== cssWidth) {
|
|
614
|
+
this.canvasLayer.style.width = cssWidth;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
490
617
|
}, {
|
|
491
618
|
key: "resizeCanvas",
|
|
492
619
|
value: function resizeCanvas() {
|
|
@@ -515,15 +642,49 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
515
642
|
if (this.canvas.height !== pixelHeight) {
|
|
516
643
|
this.canvas.height = pixelHeight;
|
|
517
644
|
}
|
|
645
|
+
this.updateCanvasLayerWidthHeight();
|
|
646
|
+
}
|
|
647
|
+
}, {
|
|
648
|
+
key: "repositionCanvas",
|
|
649
|
+
value: function repositionCanvas() {
|
|
650
|
+
var _parent$$dom, _parent$$dom2;
|
|
651
|
+
if (!this.canvas || !this.canvasLayer || !this.tmodel.hasDom()) {
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
var tmodel = this.tmodel;
|
|
655
|
+
var parent = tmodel.getParent();
|
|
656
|
+
var domScrollLeft = (parent === null || parent === void 0 || (_parent$$dom = parent.$dom) === null || _parent$$dom === void 0 ? void 0 : _parent$$dom.getScrollLeft()) || tmodel.$dom.getScrollLeft() || 0;
|
|
657
|
+
var domScrollTop = (parent === null || parent === void 0 || (_parent$$dom2 = parent.$dom) === null || _parent$$dom2 === void 0 ? void 0 : _parent$$dom2.getScrollTop()) || tmodel.$dom.getScrollTop() || 0;
|
|
658
|
+
var scrollLeft = tmodel.getScrollLeft();
|
|
659
|
+
var scrollTop = tmodel.getScrollTop();
|
|
660
|
+
var x = domScrollLeft - tmodel.x;
|
|
661
|
+
var y = domScrollTop - tmodel.y;
|
|
662
|
+
this.canvasX = scrollLeft + x;
|
|
663
|
+
this.canvasY = scrollTop + y;
|
|
664
|
+
var transform = "translate3d(".concat(x, "px, ").concat(y, "px, 0px)");
|
|
665
|
+
if (this.canvas.style.transform !== transform) {
|
|
666
|
+
this.canvas.style.transform = transform;
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
}, {
|
|
672
|
+
key: "getParticlePosition",
|
|
673
|
+
value: function getParticlePosition(child) {
|
|
674
|
+
var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : child === null || child === void 0 ? void 0 : child.actualValues;
|
|
675
|
+
var layoutScrollLeft = Number(this.tmodel.getScrollLeft()) || 0;
|
|
676
|
+
var layoutScrollTop = Number(this.tmodel.getScrollTop()) || 0;
|
|
677
|
+
return {
|
|
678
|
+
x: child.allTargetMap.x ? values.x : child.x + layoutScrollLeft,
|
|
679
|
+
y: child.allTargetMap.y ? values.y : child.y + layoutScrollTop
|
|
680
|
+
};
|
|
518
681
|
}
|
|
519
682
|
}, {
|
|
520
683
|
key: "updateUniforms",
|
|
521
684
|
value: function updateUniforms() {
|
|
522
685
|
var width = this.getRenderWidth();
|
|
523
686
|
var height = this.getRenderHeight();
|
|
524
|
-
|
|
525
|
-
var scrollTop = this.tmodel.getRenderScrollTop();
|
|
526
|
-
this.device.queue.writeBuffer(this.uniformBuffer, 0, new Float32Array([width, height, scrollLeft, scrollTop, this.transitionStep, this.transitionActive ? 1 : 0, 0, 0]));
|
|
687
|
+
this.device.queue.writeBuffer(this.uniformBuffer, 0, new Float32Array([width, height, this.canvasX, this.canvasY, this.transitionStep, this.transitionActive ? 1 : 0, 0, 0]));
|
|
527
688
|
}
|
|
528
689
|
}, {
|
|
529
690
|
key: "waitForPresentedFrame",
|
|
@@ -559,11 +720,15 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
559
720
|
}, {
|
|
560
721
|
key: "render",
|
|
561
722
|
value: function render() {
|
|
562
|
-
if (!this.device || !this.context
|
|
723
|
+
if (!this.device || !this.context) {
|
|
563
724
|
return;
|
|
564
725
|
}
|
|
565
726
|
this.resizeCanvas();
|
|
566
|
-
this.
|
|
727
|
+
this.repositionCanvas();
|
|
728
|
+
var canDraw = this.pipeline && this.bindGroup && this.particleBuffer && this.targetParticleBuffer && this.particleCount > 0;
|
|
729
|
+
if (canDraw) {
|
|
730
|
+
this.updateUniforms();
|
|
731
|
+
}
|
|
567
732
|
var commandEncoder = this.device.createCommandEncoder();
|
|
568
733
|
var renderPass = commandEncoder.beginRenderPass({
|
|
569
734
|
colorAttachments: [{
|
|
@@ -578,11 +743,13 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
578
743
|
storeOp: "store"
|
|
579
744
|
}]
|
|
580
745
|
});
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
746
|
+
if (canDraw) {
|
|
747
|
+
renderPass.setPipeline(this.pipeline);
|
|
748
|
+
renderPass.setBindGroup(0, this.bindGroup);
|
|
749
|
+
renderPass.setVertexBuffer(0, this.particleBuffer);
|
|
750
|
+
renderPass.setVertexBuffer(1, this.targetParticleBuffer);
|
|
751
|
+
renderPass.draw(6, this.particleCount);
|
|
752
|
+
}
|
|
586
753
|
renderPass.end();
|
|
587
754
|
this.device.queue.submit([commandEncoder.finish()]);
|
|
588
755
|
}
|
|
@@ -611,7 +778,21 @@ var ParticleRenderer = /*#__PURE__*/function () {
|
|
|
611
778
|
}, {
|
|
612
779
|
key: "destroy",
|
|
613
780
|
value: function destroy() {
|
|
614
|
-
var _this$particleBuffer, _this$targetParticleB, _this$uniformBuffer, _this$context, _this$canvasLayer;
|
|
781
|
+
var _this$particleBuffer, _this$targetParticleB, _this$uniformBuffer, _this$context, _this$canvasLayer, _this$scrollElements;
|
|
782
|
+
var _iterator2 = _createForOfIteratorHelper((_this$scrollElements = this.scrollElements) !== null && _this$scrollElements !== void 0 ? _this$scrollElements : []),
|
|
783
|
+
_step2;
|
|
784
|
+
try {
|
|
785
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
786
|
+
var element = _step2.value;
|
|
787
|
+
element.removeEventListener("scroll", this.onScroll);
|
|
788
|
+
}
|
|
789
|
+
} catch (err) {
|
|
790
|
+
_iterator2.e(err);
|
|
791
|
+
} finally {
|
|
792
|
+
_iterator2.f();
|
|
793
|
+
}
|
|
794
|
+
this.scrollElements = undefined;
|
|
795
|
+
this.onScroll = undefined;
|
|
615
796
|
(_this$particleBuffer = this.particleBuffer) === null || _this$particleBuffer === void 0 || _this$particleBuffer.destroy();
|
|
616
797
|
(_this$targetParticleB = this.targetParticleBuffer) === null || _this$targetParticleB === void 0 || _this$targetParticleB.destroy();
|
|
617
798
|
(_this$uniformBuffer = this.uniformBuffer) === null || _this$uniformBuffer === void 0 || _this$uniformBuffer.destroy();
|