targetj 1.0.259 → 1.0.260
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 +13 -1
- package/README.md +18 -25
- package/build/AnimationUtil.js +1 -8
- package/build/App.js +3 -2
- package/build/BaseModel.js +31 -10
- package/build/Child.js +504 -0
- package/build/LocationManager.js +30 -0
- package/build/ParticleRenderer.js +637 -0
- package/build/ParticleRuntime.js +898 -0
- package/build/ParticleTModel.js +1040 -0
- package/build/ParticleUtil.js +317 -0
- package/build/ScheduleUtil.js +2 -2
- package/build/StateManager.js +173 -26
- package/build/StateUtil.js +13 -14
- package/build/TModel.js +61 -27
- package/build/TModelFactory.js +48 -0
- package/build/TModelManager.js +55 -22
- package/build/TUtil.js +8 -3
- package/build/TargetData.js +1 -1
- package/build/TargetExecutor.js +52 -6
- package/build/TargetManager.js +5 -2
- package/build/TargetParser.js +19 -2
- package/build/TargetUtil.js +2 -2
- package/build/Viewport.js +2 -2
- package/build/index.js +5 -1
- package/dist/targetjs.js +1 -1
- package/dist/targetjs.js.gz +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,637 @@
|
|
|
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 _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
|
+
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
|
+
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); }); }; }
|
|
5
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
6
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
7
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
|
+
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
|
+
import { ColorUtil } from "./ColorUtil.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* It renders GPU-backed children using WebGPU.
|
|
14
|
+
*/
|
|
15
|
+
var ParticleRenderer = /*#__PURE__*/function () {
|
|
16
|
+
function ParticleRenderer(tmodel) {
|
|
17
|
+
_classCallCheck(this, ParticleRenderer);
|
|
18
|
+
this.tmodel = tmodel;
|
|
19
|
+
this.canvas = undefined;
|
|
20
|
+
this.device = undefined;
|
|
21
|
+
this.context = undefined;
|
|
22
|
+
this.format = undefined;
|
|
23
|
+
this.pipeline = undefined;
|
|
24
|
+
this.bindGroup = undefined;
|
|
25
|
+
this.particleBuffer = undefined;
|
|
26
|
+
this.targetParticleBuffer = undefined;
|
|
27
|
+
this.uniformBuffer = undefined;
|
|
28
|
+
this.transitionStep = 0;
|
|
29
|
+
this.transitionActive = false;
|
|
30
|
+
this.particleCount = 0;
|
|
31
|
+
this.canvasLayer = undefined;
|
|
32
|
+
this.initializationPromise = undefined;
|
|
33
|
+
}
|
|
34
|
+
return _createClass(ParticleRenderer, [{
|
|
35
|
+
key: "init",
|
|
36
|
+
value: function () {
|
|
37
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
38
|
+
var _this = this;
|
|
39
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
40
|
+
while (1) switch (_context.prev = _context.next) {
|
|
41
|
+
case 0:
|
|
42
|
+
if (!this.device) {
|
|
43
|
+
_context.next = 2;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
return _context.abrupt("return", true);
|
|
47
|
+
case 2:
|
|
48
|
+
if (this.tmodel.hasDom()) {
|
|
49
|
+
_context.next = 4;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
return _context.abrupt("return", false);
|
|
53
|
+
case 4:
|
|
54
|
+
if (!this.initializationPromise) {
|
|
55
|
+
this.initializationPromise = this.initialize().catch(function (error) {
|
|
56
|
+
_this.initializationPromise = undefined;
|
|
57
|
+
throw error;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
_context.next = 7;
|
|
61
|
+
return this.initializationPromise;
|
|
62
|
+
case 7:
|
|
63
|
+
return _context.abrupt("return", !!this.device);
|
|
64
|
+
case 8:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee, this);
|
|
69
|
+
}));
|
|
70
|
+
function init() {
|
|
71
|
+
return _init.apply(this, arguments);
|
|
72
|
+
}
|
|
73
|
+
return init;
|
|
74
|
+
}()
|
|
75
|
+
}, {
|
|
76
|
+
key: "initialize",
|
|
77
|
+
value: function () {
|
|
78
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
79
|
+
var adapter;
|
|
80
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
81
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
if (navigator.gpu) {
|
|
84
|
+
_context2.next = 2;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
throw new Error("WebGPU is not supported by this browser.");
|
|
88
|
+
case 2:
|
|
89
|
+
if (globalThis.GPUBufferUsage) {
|
|
90
|
+
_context2.next = 4;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
throw new Error("GPUBufferUsage is not available in this WebGPU environment.");
|
|
94
|
+
case 4:
|
|
95
|
+
this.createCanvas();
|
|
96
|
+
_context2.next = 7;
|
|
97
|
+
return navigator.gpu.requestAdapter();
|
|
98
|
+
case 7:
|
|
99
|
+
adapter = _context2.sent;
|
|
100
|
+
if (adapter) {
|
|
101
|
+
_context2.next = 10;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
throw new Error("Unable to obtain a WebGPU adapter.");
|
|
105
|
+
case 10:
|
|
106
|
+
_context2.next = 12;
|
|
107
|
+
return adapter.requestDevice();
|
|
108
|
+
case 12:
|
|
109
|
+
this.device = _context2.sent;
|
|
110
|
+
this.context = this.canvas.getContext("webgpu");
|
|
111
|
+
if (this.context) {
|
|
112
|
+
_context2.next = 16;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
throw new Error("Unable to obtain a WebGPU canvas context.");
|
|
116
|
+
case 16:
|
|
117
|
+
this.format = navigator.gpu.getPreferredCanvasFormat();
|
|
118
|
+
this.resizeCanvas();
|
|
119
|
+
this.context.configure({
|
|
120
|
+
device: this.device,
|
|
121
|
+
format: this.format,
|
|
122
|
+
alphaMode: "premultiplied"
|
|
123
|
+
});
|
|
124
|
+
this.createUniformBuffer();
|
|
125
|
+
this.createPipeline();
|
|
126
|
+
case 21:
|
|
127
|
+
case "end":
|
|
128
|
+
return _context2.stop();
|
|
129
|
+
}
|
|
130
|
+
}, _callee2, this);
|
|
131
|
+
}));
|
|
132
|
+
function initialize() {
|
|
133
|
+
return _initialize.apply(this, arguments);
|
|
134
|
+
}
|
|
135
|
+
return initialize;
|
|
136
|
+
}()
|
|
137
|
+
}, {
|
|
138
|
+
key: "createCanvas",
|
|
139
|
+
value: function createCanvas() {
|
|
140
|
+
var _this$tmodel$$dom;
|
|
141
|
+
if (this.canvas) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
var parent = (_this$tmodel$$dom = this.tmodel.$dom) === null || _this$tmodel$$dom === void 0 ? void 0 : _this$tmodel$$dom.element;
|
|
145
|
+
if (!parent) {
|
|
146
|
+
throw new Error("Unable to create a GPU child layer without a parent DOM element.");
|
|
147
|
+
}
|
|
148
|
+
var oldLayer = parent.querySelector('[data-targetjs-gpu-layer="true"]');
|
|
149
|
+
if (oldLayer) {
|
|
150
|
+
oldLayer.remove();
|
|
151
|
+
}
|
|
152
|
+
this.canvasLayer = document.createElement("div");
|
|
153
|
+
this.canvasLayer.setAttribute("data-targetjs-gpu-layer", "true");
|
|
154
|
+
Object.assign(this.canvasLayer.style, {
|
|
155
|
+
position: "absolute",
|
|
156
|
+
left: "0px",
|
|
157
|
+
top: "0px",
|
|
158
|
+
width: "100%",
|
|
159
|
+
height: "100%",
|
|
160
|
+
pointerEvents: "none",
|
|
161
|
+
zIndex: "0"
|
|
162
|
+
});
|
|
163
|
+
this.canvas = document.createElement("canvas");
|
|
164
|
+
this.canvas.setAttribute("data-targetjs-gpu-children", "true");
|
|
165
|
+
Object.assign(this.canvas.style, {
|
|
166
|
+
position: "sticky",
|
|
167
|
+
left: "0px",
|
|
168
|
+
top: "0px",
|
|
169
|
+
width: "1px",
|
|
170
|
+
height: "1px",
|
|
171
|
+
display: "block",
|
|
172
|
+
pointerEvents: "none"
|
|
173
|
+
});
|
|
174
|
+
this.canvasLayer.appendChild(this.canvas);
|
|
175
|
+
parent.prepend(this.canvasLayer);
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "createUniformBuffer",
|
|
179
|
+
value: function createUniformBuffer() {
|
|
180
|
+
this.uniformBuffer = this.device.createBuffer({
|
|
181
|
+
size: 32,
|
|
182
|
+
usage: globalThis.GPUBufferUsage.UNIFORM | globalThis.GPUBufferUsage.COPY_DST
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
key: "createPipeline",
|
|
187
|
+
value: function createPipeline() {
|
|
188
|
+
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\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\n if (radius > 0.0) {\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\n if (distance > 0.0) {\n discard;\n }\n }\n\n return input.backgroundColor;\n }\n "
|
|
190
|
+
});
|
|
191
|
+
this.pipeline = this.device.createRenderPipeline({
|
|
192
|
+
layout: "auto",
|
|
193
|
+
vertex: {
|
|
194
|
+
module: shaderModule,
|
|
195
|
+
entryPoint: "vertexMain",
|
|
196
|
+
buffers: [{
|
|
197
|
+
arrayStride: 80,
|
|
198
|
+
stepMode: "instance",
|
|
199
|
+
attributes: [{
|
|
200
|
+
shaderLocation: 0,
|
|
201
|
+
offset: 0,
|
|
202
|
+
format: "float32x2"
|
|
203
|
+
}, {
|
|
204
|
+
shaderLocation: 1,
|
|
205
|
+
offset: 8,
|
|
206
|
+
format: "float32x2"
|
|
207
|
+
}, {
|
|
208
|
+
shaderLocation: 2,
|
|
209
|
+
offset: 16,
|
|
210
|
+
format: "float32x4"
|
|
211
|
+
}, {
|
|
212
|
+
shaderLocation: 3,
|
|
213
|
+
offset: 32,
|
|
214
|
+
format: "float32x2"
|
|
215
|
+
}]
|
|
216
|
+
}, {
|
|
217
|
+
arrayStride: 80,
|
|
218
|
+
stepMode: "instance",
|
|
219
|
+
attributes: [{
|
|
220
|
+
shaderLocation: 4,
|
|
221
|
+
offset: 0,
|
|
222
|
+
format: "float32x2"
|
|
223
|
+
}, {
|
|
224
|
+
shaderLocation: 5,
|
|
225
|
+
offset: 8,
|
|
226
|
+
format: "float32x2"
|
|
227
|
+
}, {
|
|
228
|
+
shaderLocation: 6,
|
|
229
|
+
offset: 16,
|
|
230
|
+
format: "float32x4"
|
|
231
|
+
}, {
|
|
232
|
+
shaderLocation: 7,
|
|
233
|
+
offset: 32,
|
|
234
|
+
format: "float32x2"
|
|
235
|
+
}, {
|
|
236
|
+
shaderLocation: 8,
|
|
237
|
+
offset: 40,
|
|
238
|
+
format: "float32x2"
|
|
239
|
+
}, {
|
|
240
|
+
shaderLocation: 9,
|
|
241
|
+
offset: 48,
|
|
242
|
+
format: "float32x2"
|
|
243
|
+
}, {
|
|
244
|
+
shaderLocation: 10,
|
|
245
|
+
offset: 56,
|
|
246
|
+
format: "float32"
|
|
247
|
+
}, {
|
|
248
|
+
shaderLocation: 11,
|
|
249
|
+
offset: 60,
|
|
250
|
+
format: "float32x2"
|
|
251
|
+
}]
|
|
252
|
+
}]
|
|
253
|
+
},
|
|
254
|
+
fragment: {
|
|
255
|
+
module: shaderModule,
|
|
256
|
+
entryPoint: "fragmentMain",
|
|
257
|
+
targets: [{
|
|
258
|
+
format: this.format
|
|
259
|
+
}]
|
|
260
|
+
},
|
|
261
|
+
primitive: {
|
|
262
|
+
topology: "triangle-list"
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
this.bindGroup = this.device.createBindGroup({
|
|
266
|
+
layout: this.pipeline.getBindGroupLayout(0),
|
|
267
|
+
entries: [{
|
|
268
|
+
binding: 0,
|
|
269
|
+
resource: {
|
|
270
|
+
buffer: this.uniformBuffer
|
|
271
|
+
}
|
|
272
|
+
}]
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}, {
|
|
276
|
+
key: "toNumber",
|
|
277
|
+
value: function toNumber(value) {
|
|
278
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
279
|
+
var number = typeof value === "string" ? parseFloat(value) : Number(value);
|
|
280
|
+
return Number.isFinite(number) ? number : defaultValue;
|
|
281
|
+
}
|
|
282
|
+
}, {
|
|
283
|
+
key: "getBackgroundColor",
|
|
284
|
+
value: function getBackgroundColor(value) {
|
|
285
|
+
if (Array.isArray(value)) {
|
|
286
|
+
return [this.toNumber(value[0], 1), this.toNumber(value[1], 1), this.toNumber(value[2], 1), this.toNumber(value[3], 1)];
|
|
287
|
+
}
|
|
288
|
+
var color = ColorUtil.color2Integers(value !== null && value !== void 0 ? value : "#fff");
|
|
289
|
+
if (!color) {
|
|
290
|
+
return [1, 1, 1, 1];
|
|
291
|
+
}
|
|
292
|
+
var alpha = this.toNumber(color[3], 1);
|
|
293
|
+
if (alpha > 1) {
|
|
294
|
+
alpha /= 255;
|
|
295
|
+
}
|
|
296
|
+
return [this.toNumber(color[0], 255) / 255, this.toNumber(color[1], 255) / 255, this.toNumber(color[2], 255) / 255, alpha];
|
|
297
|
+
}
|
|
298
|
+
}, {
|
|
299
|
+
key: "getTargetStep",
|
|
300
|
+
value: function getTargetStep(steps, key) {
|
|
301
|
+
if (!steps || !Object.prototype.hasOwnProperty.call(steps, key)) {
|
|
302
|
+
return -1;
|
|
303
|
+
}
|
|
304
|
+
return Math.max(0, this.toNumber(steps[key], 0));
|
|
305
|
+
}
|
|
306
|
+
}, {
|
|
307
|
+
key: "createParticleData",
|
|
308
|
+
value: function createParticleData(values, targetSteps) {
|
|
309
|
+
var particleData = new Float32Array(values.length * 20);
|
|
310
|
+
for (var i = 0; i < values.length; i++) {
|
|
311
|
+
var child = values[i] || {};
|
|
312
|
+
var steps = targetSteps === null || targetSteps === void 0 ? void 0 : targetSteps[i];
|
|
313
|
+
var backgroundColor = this.getBackgroundColor(child.backgroundColor);
|
|
314
|
+
var offset = i * 20;
|
|
315
|
+
particleData[offset] = this.toNumber(child.x, 0);
|
|
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");
|
|
332
|
+
}
|
|
333
|
+
return particleData;
|
|
334
|
+
}
|
|
335
|
+
}, {
|
|
336
|
+
key: "uploadParticleBuffer",
|
|
337
|
+
value: function uploadParticleBuffer(buffer, particleData) {
|
|
338
|
+
if (!particleData.length) {
|
|
339
|
+
var _buffer;
|
|
340
|
+
(_buffer = buffer) === null || _buffer === void 0 || _buffer.destroy();
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
if (!buffer || buffer.size !== particleData.byteLength) {
|
|
344
|
+
var _buffer2;
|
|
345
|
+
(_buffer2 = buffer) === null || _buffer2 === void 0 || _buffer2.destroy();
|
|
346
|
+
buffer = this.device.createBuffer({
|
|
347
|
+
size: particleData.byteLength,
|
|
348
|
+
usage: globalThis.GPUBufferUsage.VERTEX | globalThis.GPUBufferUsage.COPY_DST
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
this.device.queue.writeBuffer(buffer, 0, particleData);
|
|
352
|
+
return buffer;
|
|
353
|
+
}
|
|
354
|
+
}, {
|
|
355
|
+
key: "setParticles",
|
|
356
|
+
value: function () {
|
|
357
|
+
var _setParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(values) {
|
|
358
|
+
var initialized, particleData;
|
|
359
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
360
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
361
|
+
case 0:
|
|
362
|
+
values = Array.isArray(values) ? values : [values];
|
|
363
|
+
_context3.next = 3;
|
|
364
|
+
return this.init();
|
|
365
|
+
case 3:
|
|
366
|
+
initialized = _context3.sent;
|
|
367
|
+
if (initialized) {
|
|
368
|
+
_context3.next = 6;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
return _context3.abrupt("return");
|
|
372
|
+
case 6:
|
|
373
|
+
particleData = this.createParticleData(values);
|
|
374
|
+
this.particleCount = values.length;
|
|
375
|
+
this.particleBuffer = this.uploadParticleBuffer(this.particleBuffer, particleData);
|
|
376
|
+
this.targetParticleBuffer = this.uploadParticleBuffer(this.targetParticleBuffer, particleData);
|
|
377
|
+
this.transitionStep = 0;
|
|
378
|
+
this.transitionActive = false;
|
|
379
|
+
this.render();
|
|
380
|
+
case 13:
|
|
381
|
+
case "end":
|
|
382
|
+
return _context3.stop();
|
|
383
|
+
}
|
|
384
|
+
}, _callee3, this);
|
|
385
|
+
}));
|
|
386
|
+
function setParticles(_x) {
|
|
387
|
+
return _setParticles.apply(this, arguments);
|
|
388
|
+
}
|
|
389
|
+
return setParticles;
|
|
390
|
+
}()
|
|
391
|
+
}, {
|
|
392
|
+
key: "updateParticles",
|
|
393
|
+
value: function () {
|
|
394
|
+
var _updateParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(values) {
|
|
395
|
+
var initialized, particleData;
|
|
396
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
397
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
398
|
+
case 0:
|
|
399
|
+
values = Array.isArray(values) ? values : [values];
|
|
400
|
+
_context4.next = 3;
|
|
401
|
+
return this.init();
|
|
402
|
+
case 3:
|
|
403
|
+
initialized = _context4.sent;
|
|
404
|
+
if (initialized) {
|
|
405
|
+
_context4.next = 6;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
return _context4.abrupt("return");
|
|
409
|
+
case 6:
|
|
410
|
+
particleData = this.createParticleData(values);
|
|
411
|
+
this.particleCount = values.length;
|
|
412
|
+
this.particleBuffer = this.uploadParticleBuffer(this.particleBuffer, particleData);
|
|
413
|
+
if (!this.transitionActive) {
|
|
414
|
+
this.targetParticleBuffer = this.uploadParticleBuffer(this.targetParticleBuffer, particleData);
|
|
415
|
+
}
|
|
416
|
+
this.render();
|
|
417
|
+
case 11:
|
|
418
|
+
case "end":
|
|
419
|
+
return _context4.stop();
|
|
420
|
+
}
|
|
421
|
+
}, _callee4, this);
|
|
422
|
+
}));
|
|
423
|
+
function updateParticles(_x2) {
|
|
424
|
+
return _updateParticles.apply(this, arguments);
|
|
425
|
+
}
|
|
426
|
+
return updateParticles;
|
|
427
|
+
}()
|
|
428
|
+
}, {
|
|
429
|
+
key: "setTargetParticles",
|
|
430
|
+
value: function () {
|
|
431
|
+
var _setTargetParticles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(values, steps) {
|
|
432
|
+
var initialized, particleData;
|
|
433
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
434
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
435
|
+
case 0:
|
|
436
|
+
values = Array.isArray(values) ? values : [values];
|
|
437
|
+
_context5.next = 3;
|
|
438
|
+
return this.init();
|
|
439
|
+
case 3:
|
|
440
|
+
initialized = _context5.sent;
|
|
441
|
+
if (initialized) {
|
|
442
|
+
_context5.next = 6;
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
return _context5.abrupt("return");
|
|
446
|
+
case 6:
|
|
447
|
+
if (!(this.particleCount && values.length !== this.particleCount)) {
|
|
448
|
+
_context5.next = 8;
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
throw new Error("GPU child transition count ".concat(values.length, " does not match current child count ").concat(this.particleCount, "."));
|
|
452
|
+
case 8:
|
|
453
|
+
particleData = this.createParticleData(values, steps);
|
|
454
|
+
this.targetParticleBuffer = this.uploadParticleBuffer(this.targetParticleBuffer, particleData);
|
|
455
|
+
this.transitionStep = 0;
|
|
456
|
+
this.transitionActive = true;
|
|
457
|
+
this.render();
|
|
458
|
+
case 13:
|
|
459
|
+
case "end":
|
|
460
|
+
return _context5.stop();
|
|
461
|
+
}
|
|
462
|
+
}, _callee5, this);
|
|
463
|
+
}));
|
|
464
|
+
function setTargetParticles(_x3, _x4) {
|
|
465
|
+
return _setTargetParticles.apply(this, arguments);
|
|
466
|
+
}
|
|
467
|
+
return setTargetParticles;
|
|
468
|
+
}()
|
|
469
|
+
}, {
|
|
470
|
+
key: "setTransitionStep",
|
|
471
|
+
value: function setTransitionStep(step) {
|
|
472
|
+
this.transitionStep = Math.max(0, this.toNumber(step, 0));
|
|
473
|
+
this.render();
|
|
474
|
+
}
|
|
475
|
+
}, {
|
|
476
|
+
key: "getRenderWidth",
|
|
477
|
+
value: function getRenderWidth() {
|
|
478
|
+
var modelWidth = Number(this.tmodel.getWidth()) || 1;
|
|
479
|
+
var parentWidth = Number(this.tmodel.getParent().getWidth()) || window.innerWidth || 1;
|
|
480
|
+
return Math.max(1, Math.min(modelWidth, parentWidth));
|
|
481
|
+
}
|
|
482
|
+
}, {
|
|
483
|
+
key: "getRenderHeight",
|
|
484
|
+
value: function getRenderHeight() {
|
|
485
|
+
var _this$tmodel$getParen;
|
|
486
|
+
var modelHeight = Number(this.tmodel.getHeight()) || 1;
|
|
487
|
+
var parentHeight = Number((_this$tmodel$getParen = this.tmodel.getParent()) === null || _this$tmodel$getParen === void 0 ? void 0 : _this$tmodel$getParen.getHeight()) || window.innerHeight || 1;
|
|
488
|
+
return Math.max(1, Math.min(modelHeight, parentHeight));
|
|
489
|
+
}
|
|
490
|
+
}, {
|
|
491
|
+
key: "resizeCanvas",
|
|
492
|
+
value: function resizeCanvas() {
|
|
493
|
+
var _this$device$limits;
|
|
494
|
+
if (!this.canvas || !this.device) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
var width = this.getRenderWidth();
|
|
498
|
+
var height = this.getRenderHeight();
|
|
499
|
+
var requestedPixelRatio = window.devicePixelRatio || 1;
|
|
500
|
+
var maxTextureDimension = ((_this$device$limits = this.device.limits) === null || _this$device$limits === void 0 ? void 0 : _this$device$limits.maxTextureDimension2D) || 8192;
|
|
501
|
+
var pixelRatio = Math.min(requestedPixelRatio, maxTextureDimension / width, maxTextureDimension / height);
|
|
502
|
+
var pixelWidth = Math.max(1, Math.round(width * pixelRatio));
|
|
503
|
+
var pixelHeight = Math.max(1, Math.round(height * pixelRatio));
|
|
504
|
+
var cssWidth = "".concat(width, "px");
|
|
505
|
+
var cssHeight = "".concat(height, "px");
|
|
506
|
+
if (this.canvas.style.width !== cssWidth) {
|
|
507
|
+
this.canvas.style.width = cssWidth;
|
|
508
|
+
}
|
|
509
|
+
if (this.canvas.style.height !== cssHeight) {
|
|
510
|
+
this.canvas.style.height = cssHeight;
|
|
511
|
+
}
|
|
512
|
+
if (this.canvas.width !== pixelWidth) {
|
|
513
|
+
this.canvas.width = pixelWidth;
|
|
514
|
+
}
|
|
515
|
+
if (this.canvas.height !== pixelHeight) {
|
|
516
|
+
this.canvas.height = pixelHeight;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}, {
|
|
520
|
+
key: "updateUniforms",
|
|
521
|
+
value: function updateUniforms() {
|
|
522
|
+
var width = this.getRenderWidth();
|
|
523
|
+
var height = this.getRenderHeight();
|
|
524
|
+
var scrollLeft = this.tmodel.getRenderScrollLeft();
|
|
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]));
|
|
527
|
+
}
|
|
528
|
+
}, {
|
|
529
|
+
key: "waitForPresentedFrame",
|
|
530
|
+
value: function () {
|
|
531
|
+
var _waitForPresentedFrame = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
532
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
533
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
534
|
+
case 0:
|
|
535
|
+
if (!this.device) {
|
|
536
|
+
_context6.next = 3;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
_context6.next = 3;
|
|
540
|
+
return this.device.queue.onSubmittedWorkDone();
|
|
541
|
+
case 3:
|
|
542
|
+
_context6.next = 5;
|
|
543
|
+
return new Promise(function (resolve) {
|
|
544
|
+
requestAnimationFrame(function () {
|
|
545
|
+
requestAnimationFrame(resolve);
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
case 5:
|
|
549
|
+
case "end":
|
|
550
|
+
return _context6.stop();
|
|
551
|
+
}
|
|
552
|
+
}, _callee6, this);
|
|
553
|
+
}));
|
|
554
|
+
function waitForPresentedFrame() {
|
|
555
|
+
return _waitForPresentedFrame.apply(this, arguments);
|
|
556
|
+
}
|
|
557
|
+
return waitForPresentedFrame;
|
|
558
|
+
}()
|
|
559
|
+
}, {
|
|
560
|
+
key: "render",
|
|
561
|
+
value: function render() {
|
|
562
|
+
if (!this.device || !this.context || !this.pipeline || !this.particleBuffer || !this.targetParticleBuffer || this.particleCount === 0) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
this.resizeCanvas();
|
|
566
|
+
this.updateUniforms();
|
|
567
|
+
var commandEncoder = this.device.createCommandEncoder();
|
|
568
|
+
var renderPass = commandEncoder.beginRenderPass({
|
|
569
|
+
colorAttachments: [{
|
|
570
|
+
view: this.context.getCurrentTexture().createView(),
|
|
571
|
+
clearValue: {
|
|
572
|
+
r: 0,
|
|
573
|
+
g: 0,
|
|
574
|
+
b: 0,
|
|
575
|
+
a: 0
|
|
576
|
+
},
|
|
577
|
+
loadOp: "clear",
|
|
578
|
+
storeOp: "store"
|
|
579
|
+
}]
|
|
580
|
+
});
|
|
581
|
+
renderPass.setPipeline(this.pipeline);
|
|
582
|
+
renderPass.setBindGroup(0, this.bindGroup);
|
|
583
|
+
renderPass.setVertexBuffer(0, this.particleBuffer);
|
|
584
|
+
renderPass.setVertexBuffer(1, this.targetParticleBuffer);
|
|
585
|
+
renderPass.draw(6, this.particleCount);
|
|
586
|
+
renderPass.end();
|
|
587
|
+
this.device.queue.submit([commandEncoder.finish()]);
|
|
588
|
+
}
|
|
589
|
+
}, {
|
|
590
|
+
key: "completeTransition",
|
|
591
|
+
value: function completeTransition() {
|
|
592
|
+
if (!this.targetParticleBuffer || !this.transitionActive) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
var previousBuffer = this.particleBuffer;
|
|
596
|
+
this.particleBuffer = this.targetParticleBuffer;
|
|
597
|
+
this.targetParticleBuffer = previousBuffer;
|
|
598
|
+
this.transitionStep = 0;
|
|
599
|
+
this.transitionActive = false;
|
|
600
|
+
this.render();
|
|
601
|
+
}
|
|
602
|
+
}, {
|
|
603
|
+
key: "captureBitmap",
|
|
604
|
+
value: function captureBitmap() {
|
|
605
|
+
if (!this.canvas || !this.device) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
this.render();
|
|
609
|
+
return createImageBitmap(this.canvas);
|
|
610
|
+
}
|
|
611
|
+
}, {
|
|
612
|
+
key: "destroy",
|
|
613
|
+
value: function destroy() {
|
|
614
|
+
var _this$particleBuffer, _this$targetParticleB, _this$uniformBuffer, _this$context, _this$canvasLayer;
|
|
615
|
+
(_this$particleBuffer = this.particleBuffer) === null || _this$particleBuffer === void 0 || _this$particleBuffer.destroy();
|
|
616
|
+
(_this$targetParticleB = this.targetParticleBuffer) === null || _this$targetParticleB === void 0 || _this$targetParticleB.destroy();
|
|
617
|
+
(_this$uniformBuffer = this.uniformBuffer) === null || _this$uniformBuffer === void 0 || _this$uniformBuffer.destroy();
|
|
618
|
+
(_this$context = this.context) === null || _this$context === void 0 || _this$context.unconfigure();
|
|
619
|
+
(_this$canvasLayer = this.canvasLayer) === null || _this$canvasLayer === void 0 || _this$canvasLayer.remove();
|
|
620
|
+
this.particleBuffer = undefined;
|
|
621
|
+
this.targetParticleBuffer = undefined;
|
|
622
|
+
this.uniformBuffer = undefined;
|
|
623
|
+
this.bindGroup = undefined;
|
|
624
|
+
this.pipeline = undefined;
|
|
625
|
+
this.context = undefined;
|
|
626
|
+
this.device = undefined;
|
|
627
|
+
this.canvasLayer = undefined;
|
|
628
|
+
this.canvas = undefined;
|
|
629
|
+
this.format = undefined;
|
|
630
|
+
this.transitionStep = 0;
|
|
631
|
+
this.transitionActive = false;
|
|
632
|
+
this.particleCount = 0;
|
|
633
|
+
this.initializationPromise = undefined;
|
|
634
|
+
}
|
|
635
|
+
}]);
|
|
636
|
+
}();
|
|
637
|
+
export { ParticleRenderer };
|