Safely eval js

by Yaroslav Samardak

CSS

body, pre {
	background: #20262e;
	color: #fbfbfb;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif;
}

JavaScript

const log = (key, value) =>
	document.body.innerHTML += `<pre>${key}: ${value}</pre>`

const uuid = function () {
	//// return uuid of form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
	let uuid = ''

	for (let i = 0; i < 32; i += 1) {
		switch (i) {
			case 8:
			case 20:
				uuid += '-'
				uuid += (Math.random() * 16 | 0).toString(16)
				break

			case 12:
				uuid += '-'
				uuid += '4'
				break

			case 16:
				uuid += '-'
				uuid += (Math.random() * 4 | 8).toString(16)
				break

			default:
				uuid += (Math.random() * 16 | 0).toString(16)
		}
	}

	return uuid
}

class BaseScene {
	constructor(name, description, duration, resizable) {
		if (new.target === BaseScene)
		 	throw new TypeError("Cannot construct Abstract instances directly")

		if (!name)
			throw new TypeError("Parameter \"name\" is required!")

		if (!duration)
			throw new TypeError("Parameter \"duration\" is required!")
		if (duration < 1000)
			throw new TypeError("Parameter \"duration\" can't be less than 1000!")

		this.name = name
		this.description = description || ""
		this.duration = duration
		this.resizable = !!resizable
	}

	/**
	 * Clamp value in range min..max
	 * @param value — Current value
	 * @param min — Range minimum
	 * @param max — Range maximum
	 * @return number — interpolated value between min and max
	 */
	clamp(value, min, max) {
		return Math.min(Math.max(value, min), max)
	}

	slope(A, B, a, b, val) {
		return (val - A) * (b - a) / (B - A) + a
	}

	rgbh(r, g, b, h) {
		// return [r, g, b, h * .33]
		return [r, g, b, h]
	}

	hsvh(h, s, v, height) {
		let r, g, b, i, f, p, q, t
		h = h % 360

		// Achromatic (grey)
		if (s === 0) return this.rgbh(v, v, v, height)

		h /= 60 // sector 0 to 5
		i = ~~(h)
		f = h - i // factorial part of h
		p = v * (1 - s)
		q = v * (1 - s * f)
		t = v * (1 - s * (1 - f))

		switch (i) {
			case 0:
				r = v;
				g = t;
				b = p;
				break
			case 1:
				r = q;
				g = v;
				b = p;
				break
			case 2:
				r = p;
				g = v;
				b =...