1 | module.exports =
|
2 | (function(modules) {
|
3 |
|
4 | var installedModules = {};
|
5 |
|
6 |
|
7 | function __webpack_require__(moduleId) {
|
8 |
|
9 |
|
10 | if(installedModules[moduleId]) {
|
11 | return installedModules[moduleId].exports;
|
12 | }
|
13 |
|
14 | var module = installedModules[moduleId] = {
|
15 | i: moduleId,
|
16 | l: false,
|
17 | exports: {}
|
18 | };
|
19 |
|
20 |
|
21 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
22 |
|
23 |
|
24 | module.l = true;
|
25 |
|
26 |
|
27 | return module.exports;
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 | __webpack_require__.m = modules;
|
33 |
|
34 |
|
35 | __webpack_require__.c = installedModules;
|
36 |
|
37 |
|
38 | __webpack_require__.d = function(exports, name, getter) {
|
39 | if(!__webpack_require__.o(exports, name)) {
|
40 | Object.defineProperty(exports, name, {
|
41 | configurable: false,
|
42 | enumerable: true,
|
43 | get: getter
|
44 | /******/ });
|
45 | /******/ }
|
46 | /******/ };
|
47 | /******/
|
48 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
49 | /******/ __webpack_require__.n = function(module) {
|
50 | var getter = module && module.__esModule ?
|
51 | function getDefault() { return module['default']; } :
|
52 | function getModuleExports() { return module; };
|
53 | __webpack_require__.d(getter, 'a', getter);
|
54 | return getter;
|
55 | };
|
56 |
|
57 |
|
58 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
59 |
|
60 |
|
61 | __webpack_require__.p = "";
|
62 |
|
63 |
|
64 | return __webpack_require__(__webpack_require__.s = 0);
|
65 | })
|
66 |
|
67 | ([
|
68 |
|
69 | (function(module, exports, __webpack_require__) {
|
70 |
|
71 | "use strict";
|
72 |
|
73 |
|
74 | Object.defineProperty(exports, "__esModule", {
|
75 | value: true
|
76 | });
|
77 | exports.start = undefined;
|
78 |
|
79 | var _webassembly = __webpack_require__(1);
|
80 |
|
81 | var _webassembly2 = _interopRequireDefault(_webassembly);
|
82 |
|
83 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | var createCanvas = function createCanvas(x, y, width, height) {
|
89 |
|
90 | var canvas = document.createElement('canvas');
|
91 | canvas.width = width;
|
92 | canvas.height = height;
|
93 |
|
94 |
|
95 | canvas.style.position = 'absolute';
|
96 | canvas.style.left = String(x);
|
97 | canvas.style.top = String(y);
|
98 | canvas.style.zIndex = '-1';
|
99 |
|
100 |
|
101 | document.body.appendChild(canvas);
|
102 | return canvas;
|
103 | };
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | var clearCanvas = function clearCanvas(ctx) {
|
110 | var x = 0;
|
111 | var y = 0;
|
112 | ctx.clearRect(x, y, ctx.canvas.width, ctx.canvas.height);
|
113 | };
|
114 |
|
115 | var drawVertex = function drawVertex(ctx, id, x, y, color) {
|
116 | ctx.strokeStyle = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + color.a + ')';
|
117 | ctx.fillStyle = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + color.a / 2 + ')';
|
118 |
|
119 | var r = 12;
|
120 | var startAngle = 0;
|
121 | var endAngle = 2 * Math.PI;
|
122 |
|
123 | ctx.beginPath();
|
124 | ctx.arc(x, y, r, startAngle, endAngle, false);
|
125 | ctx.stroke();
|
126 | ctx.fill();
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | };
|
133 |
|
134 | var drawEdge = function drawEdge(ctx, x1, y1, x2, y2, color) {
|
135 | ctx.strokeStyle = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + color.a + ')';
|
136 |
|
137 | ctx.beginPath();
|
138 | ctx.moveTo(x1, y1);
|
139 | ctx.lineTo(x2, y2);
|
140 | ctx.stroke();
|
141 | };
|
142 |
|
143 | var drawTriangle = function drawTriangle(ctx, x1, y1, x2, y2, x3, y3, color) {
|
144 | ctx.fillStyle = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + color.a + ')';
|
145 |
|
146 | ctx.beginPath();
|
147 | ctx.moveTo(x1, y1);
|
148 | ctx.lineTo(x2, y2);
|
149 | ctx.lineTo(x3, y3);
|
150 |
|
151 | ctx.fill();
|
152 | };
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | var loadWasm = async function loadWasm(wasmPath, ctx, vertexColor, edgeColor, triangleColor) {
|
158 | var wasmModule = await _webassembly2.default.load(wasmPath, {
|
159 | imports: {
|
160 | jsSetInterval: function jsSetInterval(f, n) {
|
161 |
|
162 | setInterval(function () {
|
163 | return wasmModule.exports.runCallback(f);
|
164 | }, n);
|
165 | },
|
166 | jsClearCanvas: function jsClearCanvas() {
|
167 | return clearCanvas(ctx);
|
168 | },
|
169 | jsDrawVertex: function jsDrawVertex(id, x, y) {
|
170 | return drawVertex(ctx, id, x, y, vertexColor);
|
171 | },
|
172 | jsDrawEdge: function jsDrawEdge(x1, y1, x2, y2) {
|
173 | return drawEdge(ctx, x1, y1, x2, y2, edgeColor);
|
174 | },
|
175 | jsDrawTriangle: function jsDrawTriangle(x1, y1, x2, y2, x3, y3) {
|
176 | return drawTriangle(ctx, x1, y1, x2, y2, x3, y3, triangleColor);
|
177 | }
|
178 | }
|
179 | });
|
180 |
|
181 | return wasmModule;
|
182 | };
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | var start = exports.start = async function start(options, version) {
|
188 |
|
189 | var canvas = createCanvas(options.x, options.y, options.width, options.height);
|
190 | var ctx = canvas.getContext('2d');
|
191 |
|
192 |
|
193 | var wasmPath = 'https://unpkg.com/@benwiz/boba.wasm@' + version + '/dist/boba.wasm';
|
194 | var wasmModule = await loadWasm(wasmPath, ctx, options.vertexColor, options.edgeColor, options.triangleColor);
|
195 | wasmModule.exports.start(options.width, options.height, options.vertexMinRadius, options.vertexMaxRadius, options.vertexMinSpeed, options.vertexMaxSpeed, options.drawVertices, options.drawEdges, options.drawTriangles);
|
196 | };
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | }),
|
236 |
|
237 | (function(module, exports, __webpack_require__) {
|
238 |
|
239 | "use strict";
|
240 |
|
241 |
|
242 | module.exports = __webpack_require__(2);
|
243 |
|
244 | }),
|
245 |
|
246 | (function(module, exports, __webpack_require__) {
|
247 |
|
248 | "use strict";
|
249 |
|
250 |
|
251 | if (typeof window !== "undefined" && window) window.webassembly = exports;
|
252 |
|
253 |
|
254 | var getOwnPropertyNames = Object.getOwnPropertyNames;
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | function load(file, options) {
|
290 |
|
291 | |
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | options || (options = {});
|
300 |
|
301 | var imports = options.imports || {};
|
302 |
|
303 |
|
304 |
|
305 | var memory = imports.memory;
|
306 | if (!memory) {
|
307 | var opts = { initial: options.initialMemory || 1 };
|
308 | if (options.maximumMemory) opts.maximum = options.maximumMemory;
|
309 | memory = new WebAssembly.Memory(opts);
|
310 | memory.initial = options.initialMemory || 1;
|
311 | memory.maximum = options.maximumMemory;
|
312 | }
|
313 |
|
314 | var table = imports.table;
|
315 | if (!table) table = new WebAssembly.Table({ initial: 0, element: "anyfunc" });
|
316 |
|
317 | function grow() {
|
318 | var buf = memory.buffer;
|
319 | memory.U8 = new Uint8Array(buf);
|
320 | memory.S32 = new Int32Array(buf);
|
321 | memory.U32 = new Uint32Array(buf);
|
322 | memory.F32 = new Float32Array(buf);
|
323 | memory.F64 = new Float64Array(buf);
|
324 | }
|
325 |
|
326 | grow();
|
327 |
|
328 |
|
329 |
|
330 | |
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 | function getInt(ptr) {
|
338 | return memory.S32[ptr >> 2];
|
339 | }
|
340 |
|
341 | memory.getInt = getInt;
|
342 |
|
343 | |
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 | function getUint(ptr) {
|
351 | return memory.U32[ptr >> 2];
|
352 | }
|
353 |
|
354 | memory.getUint = getUint;
|
355 |
|
356 | |
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 | function getFloat(ptr) {
|
364 | return memory.F32[ptr >> 2];
|
365 | }
|
366 |
|
367 | memory.getFloat = getFloat;
|
368 |
|
369 | |
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 | function getDouble(ptr) {
|
377 | return memory.F64[ptr >> 3];
|
378 | }
|
379 |
|
380 | memory.getDouble = getDouble;
|
381 |
|
382 | |
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 | function getString(ptr) {
|
390 | var start = ptr >>>= 0;
|
391 | while (memory.U8[ptr++]) {}
|
392 | getString.bytes = ptr - start;
|
393 | return String.fromCharCode.apply(null, memory.U8.subarray(start, ptr - 1));
|
394 | }
|
395 |
|
396 | memory.getString = getString;
|
397 |
|
398 |
|
399 |
|
400 | var env = {};
|
401 |
|
402 | env.memoryBase = imports.memoryBase || 0;
|
403 | env.memory = memory;
|
404 | env.tableBase = imports.tableBase || 0;
|
405 | env.table = table;
|
406 |
|
407 |
|
408 |
|
409 | function sprintf(ptr, base) {
|
410 | var s = getString(ptr);
|
411 | return base ? s.replace(/%([dfisu]|lf)/g, function ($0, $1) {
|
412 | var val;
|
413 | return base += $1 === "u" ? (val = getUint(base), 4) : $1 === "f" ? (val = getFloat(base), 4) : $1 === "s" ? (val = getString(getUint(base)), 4) : $1 === "lf" ? (val = getDouble(base), 8) : (val = getInt(base), 4), val;
|
414 | }) : s;
|
415 | }
|
416 |
|
417 | getOwnPropertyNames(console).forEach(function (key) {
|
418 | if (typeof console[key] === "function")
|
419 | env["console_" + key] = function (ptr, base) {
|
420 | console[key](sprintf(ptr, base));
|
421 | };
|
422 | });
|
423 |
|
424 |
|
425 |
|
426 | getOwnPropertyNames(Math).forEach(function (key) {
|
427 | if (typeof Math[key] === "function") env["Math_" + key] = Math[key];
|
428 | });
|
429 |
|
430 |
|
431 |
|
432 | Object.keys(imports).forEach(function (key) {
|
433 | return env[key] = imports[key];
|
434 | });
|
435 |
|
436 |
|
437 |
|
438 | if (!env._abort) env._abort = function (errno) {
|
439 | throw Error("abnormal abort in " + file + ": " + errno);
|
440 | };
|
441 | if (!env._exit) env._exit = function (code) {
|
442 | if (code) throw Error("abnormal exit in " + file + ": " + code);
|
443 | };
|
444 |
|
445 |
|
446 |
|
447 | env._grow = grow;
|
448 |
|
449 | return (typeof fetch === "function" && fetch || fetch_node)(file).then(function (result) {
|
450 | return result.arrayBuffer();
|
451 | }).then(function (buffer) {
|
452 | return WebAssembly.instantiate(buffer, { env: env });
|
453 | }).then(function (module) {
|
454 | var instance = module.instance;
|
455 | instance.imports = imports;
|
456 | instance.memory = memory;
|
457 | instance.env = env;
|
458 | return instance;
|
459 | });
|
460 | }
|
461 |
|
462 | exports.load = load;
|
463 |
|
464 |
|
465 | var fs;
|
466 | function fetch_node(file) {
|
467 | return new Promise(function (resolve, reject) {
|
468 | return (fs || (fs = eval("equire".replace(/^/, "r"))("fs"))).readFile(file, function (err, data) {
|
469 | return err ? reject(err) : resolve({ arrayBuffer: function arrayBuffer() {
|
470 | return data;
|
471 | } });
|
472 | });
|
473 | });
|
474 | }
|
475 |
|
476 | })
|
477 | ]);
|
478 |
|
\ | No newline at end of file |