hiss/build/index.js
2024-11-22 23:29:59 -07:00

1556 lines
49 KiB
JavaScript

(function () {
'use strict';
var browser$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
get Cd () { return Cd; },
get Focused () { return Focused; },
get Init () { return Init$1; },
get OnKeydown () { return OnKeydown$1; },
get Open () { return Open; },
get Render () { return Render; },
get View () { return View$1; },
get back () { return back; },
get list () { return list; },
get organizeView () { return organizeView; },
get recurseView () { return _recurseView; }
});
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;
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) return r;
}
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);
}
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);
});
};
}
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
t && (r = t);
var n = 0,
F = function () {};
return {
s: F,
n: function () {
return n >= r.length ? {
done: !0
} : {
done: !1,
value: r[n++]
};
},
e: function (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 () {
t = t.call(r);
},
n: function () {
var r = t.next();
return a = r.done, r;
},
e: function (r) {
u = !0, o = r;
},
f: function () {
try {
a || null == t.return || t.return();
} finally {
if (u) throw o;
}
}
};
}
function _inherits(t, e) {
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
t.prototype = Object.create(e && e.prototype, {
constructor: {
value: t,
writable: !0,
configurable: !0
}
}), Object.defineProperty(t, "prototype", {
writable: !1
}), e && _setPrototypeOf(t, e);
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _regeneratorRuntime() {
_regeneratorRuntime = function () {
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 (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 (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 (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 () {
this.done = !0;
var t = this.tryEntries[0].completion;
if ("throw" === t.type) throw t.arg;
return this.rval;
},
dispatchException: function (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 (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 (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 (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 (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 (e, r, n) {
return this.delegate = {
iterator: values(e),
resultName: r,
nextLoc: n
}, "next" === this.method && (this.arg = t), y;
}
}, e;
}
function _setPrototypeOf(t, e) {
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
return t.__proto__ = e, t;
}, _setPrototypeOf(t, e);
}
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
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;
}
}
function _wrapRegExp() {
_wrapRegExp = function (e, r) {
return new BabelRegExp(e, void 0, r);
};
var e = RegExp.prototype,
r = new WeakMap();
function BabelRegExp(e, t, p) {
var o = RegExp(e, t);
return r.set(o, p || r.get(e)), _setPrototypeOf(o, BabelRegExp.prototype);
}
function buildGroups(e, t) {
var p = r.get(t);
return Object.keys(p).reduce(function (r, t) {
var o = p[t];
if ("number" == typeof o) r[t] = e[o];else {
for (var i = 0; void 0 === e[o[i]] && i + 1 < o.length;) i++;
r[t] = e[o[i]];
}
return r;
}, Object.create(null));
}
return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (r) {
var t = e.exec.call(this, r);
if (t) {
t.groups = buildGroups(t, this);
var p = t.indices;
p && (p.groups = buildGroups(p, this));
}
return t;
}, BabelRegExp.prototype[Symbol.replace] = function (t, p) {
if ("string" == typeof p) {
var o = r.get(this);
return e[Symbol.replace].call(this, t, p.replace(/\$<([^>]+)>/g, function (e, r) {
var t = o[r];
return "$" + (Array.isArray(t) ? t.join("$") : t);
}));
}
if ("function" == typeof p) {
var i = this;
return e[Symbol.replace].call(this, t, function () {
var e = arguments;
return "object" != typeof e[e.length - 1] && (e = [].slice.call(e)).push(buildGroups(e, i)), p.apply(this, e);
});
}
return e[Symbol.replace].call(this, t, p);
}, _wrapRegExp.apply(this, arguments);
}
function Store(objectStoreName) {
var transact = () => {
return this.db.transaction(objectStoreName, "readwrite").objectStore(objectStoreName);
};
this.Get = key => {
return promisify$1(transact().get(key));
};
this.Set = (key, value) => {
return promisify$1(transact().put(value, key));
};
return this;
}
Store.Open = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(dbName, objectStoreName) {
var store, request;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
store = new Store(objectStoreName);
request = indexedDB.open(dbName, 2);
request.onupgradeneeded = event => {
var db = event.target.result;
var objectStore = db.createObjectStore(objectStoreName);
objectStore.createIndex('value', 'value', {
unique: false
});
};
_context.next = 5;
return promisify$1(request);
case 5:
store.db = _context.sent;
return _context.abrupt("return", store);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();
function promisify$1(request) {
return new Promise((resolve, reject) => {
request.onsuccess = event => {
resolve(request.result);
};
request.onerror = event => {
reject(request.error);
};
});
}
var sdcard = navigator.getDeviceStorage('sdcard');
function promisify(request) {
return new Promise((resolve, reject) => {
request.onsuccess = event => {
resolve(request.result);
};
request.onerror = event => {
reject(request.error);
console.error(request.error);
};
});
}
function joinPath(left, right) {
return (left + right).replaceAll(/\/{2,}/g, '/');
}
function handle(sPath, sName) {
return {
name: sName,
path: sPath,
kind: 'directory'
};
}
var filesystemIndex;
function Start$1() {}
var createIndex = () => {
return new Promise(filesystemIndexHandler);
};
var filesystemIndexHandler = (resolve, reject) => {
var cursor = sdcard.enumerate();
filesystemIndex = {};
cursor.onerror = function () {
reject(cursor.error);
};
cursor.onsuccess = function () {
if (!this.result) {
return resolve(filesystemIndex);
}
var cs = this.result.name.split('/').slice(1);
var f = filesystemIndex;
var c;
for (var i = 0; i < cs.length; i++) {
var _f$entries, _c, _f$entries$_c;
c = cs[i];
if (!f.entries) {
f.kind = 'directory';
f.entries = {};
}
f = (_f$entries$_c = (_f$entries = f.entries)[_c = c]) !== null && _f$entries$_c !== void 0 ? _f$entries$_c : _f$entries[_c] = handle('/' + cs.slice(0, i + 1).join('/'), c);
}
f.kind = 'file';
// f.file = this.result
this.continue();
};
};
function Entries$1(_x) {
return _Entries.apply(this, arguments);
}
function _Entries() {
_Entries = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(handle) {
var pool, t, n, _t$entries, h;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (filesystemIndex) {
_context.next = 3;
break;
}
_context.next = 3;
return createIndex();
case 3:
pool = new Map();
t = handle == null ? filesystemIndex : handle;
for (n in (_t$entries = t.entries) !== null && _t$entries !== void 0 ? _t$entries : {}) {
h = t.entries[n];
pool.set(h.name, h);
}
return _context.abrupt("return", pool);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
return _Entries.apply(this, arguments);
}
function Open$3(hFile) {
// return hFile.file
return promisify(sdcard.get(hFile.path));
}
var device = /*#__PURE__*/Object.freeze({
__proto__: null,
Entries: Entries$1,
Open: Open$3,
Start: Start$1,
createIndex: createIndex,
get filesystemIndex () { return filesystemIndex; },
joinPath: joinPath,
promisify: promisify,
sdcard: sdcard
});
function List(view) {
view.element = document.createElement('menu');
view.cursor = 0;
this.Render = function (entries) {
var iResetCursorTo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : view.cursor;
while (view.element.firstChild) {
view.element.removeChild(view.element.lastChild);
}
entries.map(renderEntry).forEach(n => view.element.appendChild(n));
Focus(iResetCursorTo);
};
var renderEntry = (entry, i) => {
var ele = document.createElement('li');
if (entry.entries) {
populateListEntry(entry, ele);
} else {
populateTrackEntry(entry, ele);
}
// ele.addEventListener('mouseenter', (event) => {
// console.log(event)
// if(event.movementX || event.movementY)
// Focus(i, false)
// })
return ele;
};
var populateListEntry = (entry, ele) => {
var a = document.createElement('a');
var header = document.createElement('header');
header.innerText = entry.name;
a.appendChild(header);
ele.appendChild(a);
};
var populateTrackEntry = (entry, ele) => {
// TODO: fix button problem on kaios
var sect = document.createElement('section');
var trackNumber = document.createElement('code');
var title = document.createElement('b');
var artist = document.createElement('cite');
trackNumber.innerText = formatTrackNumber(entry.trackNumber);
title.innerText = entry.name;
artist.innerText = entry.artist;
sect.appendChild(title);
sect.appendChild(artist);
ele.appendChild(trackNumber);
ele.appendChild(sect);
};
var formatTrackNumber = trackNumber => {
return trackNumber == Infinity ? '--' : trackNumber.toString().padStart(2, '0');
};
var Scroll = this.Scroll = distance => {
var children = Array.from(view.element.children);
var i = view.cursor;
i += distance;
if (i >= children.length) {
i = 0;
} else if (i < 0) {
i = children.length - 1;
}
Focus(i);
};
var Focus = this.Focus = function (i) {
var scroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
view.cursor = i;
if (view.element.children.length === 0) {
return;
}
if (view.focus) {
view.focus.classList.remove('focus');
}
view.focus = view.element.children[view.cursor];
view.focus.classList.add('focus');
if (scroll) {
view.element.children[Math.max(0, i - 4)].scrollIntoView();
}
};
this.OnKeydown = event => {
switch (event.key) {
case 'ArrowDown':
Scroll(1);
break;
case 'ArrowUp':
Scroll(-1);
break;
default:
return true;
}
};
return this;
}
var _window$5, _window$app$4, _window2$4, _window2$view$4;
var app$5 = (_window$app$4 = (_window$5 = window).app) !== null && _window$app$4 !== void 0 ? _window$app$4 : _window$5.app = {};
var view$4 = (_window2$view$4 = (_window2$4 = window).view) !== null && _window2$view$4 !== void 0 ? _window2$view$4 : _window2$4.view = {};
// TODO: decouple from app.browser and add loading bar
var Init$5 = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
view$4.loadingStatus = document.getElementById('loading-status');
app$5.trackCount = 0;
_context.next = 4;
return Entries();
case 4:
app$5.index = _context.sent;
case 5:
case "end":
return _context.stop();
}
}, _callee);
}));
return function Init() {
return _ref.apply(this, arguments);
};
}();
var Entries = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(hHandle, eParent) {
var dirE, out, _iterator, _step, _step$value, n, h, e;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return Entries$1(hHandle);
case 2:
dirE = _context2.sent;
out = [];
_iterator = _createForOfIteratorHelper(dirE);
_context2.prev = 5;
_iterator.s();
case 7:
if ((_step = _iterator.n()).done) {
_context2.next = 15;
break;
}
_step$value = _slicedToArray(_step.value, 2), n = _step$value[0], h = _step$value[1];
_context2.next = 11;
return Create(n, h, eParent);
case 11:
e = _context2.sent;
if (e != undefined) {
out.push(e);
displayTrackFound(e);
}
case 13:
_context2.next = 7;
break;
case 15:
_context2.next = 20;
break;
case 17:
_context2.prev = 17;
_context2.t0 = _context2["catch"](5);
_iterator.e(_context2.t0);
case 20:
_context2.prev = 20;
_iterator.f();
return _context2.finish(20);
case 23:
return _context2.abrupt("return", out);
case 24:
case "end":
return _context2.stop();
}
}, _callee2, null, [[5, 17, 20, 23]]);
}));
return function Entries(_x, _x2) {
return _ref2.apply(this, arguments);
};
}();
var displayTrackFound = entry => {
app$5.trackCount++;
view$4.loadingStatus.innerText = `${entry.handle.name}\n(${app$5.trackCount})`;
};
var trackFiletypes = ['.mp3', '.ogg', '.wav', '.flac'];
var Create = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sName, hHandle, eParent) {
var _e$trackNumber;
var e, ext;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
e = {
handle: hHandle
};
if (eParent) {
e.parent = eParent;
}
_context3.t0 = hHandle.kind;
_context3.next = _context3.t0 === 'directory' ? 5 : _context3.t0 === 'file' ? 10 : 17;
break;
case 5:
_context3.next = 7;
return Entries(hHandle, e);
case 7:
e.entries = _context3.sent;
e.name = sName;
return _context3.abrupt("break", 17);
case 10:
ext = sName.slice(sName.lastIndexOf('.'));
if (!trackFiletypes.includes(ext)) {
_context3.next = 16;
break;
}
_context3.next = 14;
return Track(e);
case 14:
_context3.next = 17;
break;
case 16:
return _context3.abrupt("return");
case 17:
e.order = (_e$trackNumber = e.trackNumber) !== null && _e$trackNumber !== void 0 ? _e$trackNumber : 0;
return _context3.abrupt("return", e);
case 19:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return function Create(_x3, _x4, _x5) {
return _ref3.apply(this, arguments);
};
}();
var Track = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(e) {
var _md$artist;
var md;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return Metadata(e);
case 2:
md = _context4.sent;
e.album = md.album;
e.name = md.title;
e.artist = (_md$artist = md.artist) !== null && _md$artist !== void 0 ? _md$artist : "Unknown Artist";
e.trackNumber = md.track ? parseInt(md.track) : Infinity;
case 7:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return function Track(_x6) {
return _ref4.apply(this, arguments);
};
}();
var Metadata = /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(e) {
var d;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return Open$3(e.handle).then(mediaTags).catch(e => console.error(e));
case 2:
d = _context5.sent;
if (d) {
_context5.next = 7;
break;
}
return _context5.abrupt("return", /*#__PURE__*/_wrapRegExp(/((\d+)\s+)?((.+)-\s*)?\s*(.+)\s*\.\w+/, {
track: 2,
artist: 4,
title: 5
}).exec(e.handle.name).groups);
case 7:
return _context5.abrupt("return", d.tags);
case 8:
case "end":
return _context5.stop();
}
}, _callee5);
}));
return function Metadata(_x7) {
return _ref5.apply(this, arguments);
};
}();
var mediaTags = blob => new Promise((resolve, reject) => {
jsmediatags.read(blob, {
onSuccess(tags) {
resolve(tags);
},
onError(err) {
reject(err);
}
});
});
var entry = /*#__PURE__*/Object.freeze({
__proto__: null,
Create: Create,
Entries: Entries,
Init: Init$5,
displayTrackFound: displayTrackFound,
trackFiletypes: trackFiletypes
});
var _window$4, _window$view;
var view$3 = (_window$view = (_window$4 = window).view) !== null && _window$view !== void 0 ? _window$view : _window$4.view = {};
var Init$4 = () => {};
var View$4 = () => {
view$3.player = {
title: document.getElementById('track-title'),
artist: document.getElementById('track-artist'),
timestamp: document.getElementById('timestamp'),
trackLength: document.getElementById('track-length')
};
};
var Render$2 = eTrack => {
marqueeableText(view$3.player.title, eTrack.name);
marqueeableText(view$3.player.artist, eTrack.artist);
};
var marqueeableText = (eElement, sName) => {
while (eElement.firstChild) {
eElement.lastChild.remove();
}
eElement.classList = [];
var s = textContainer(eElement, sName);
if (s.offsetWidth > eElement.offsetWidth) {
eElement.classList = ['marquee'];
textContainer(eElement, sName);
}
};
var textContainer = (eElement, sText) => {
var s = document.createElement('span');
s.innerText = sText;
eElement.appendChild(s);
return s;
};
var Open$2 = () => {
Display('player');
document.body.classList.add('paused');
};
var OnKeydown$4 = event => {
switch (event) {
case 'Enter':
break;
default:
return true;
}
};
var player$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
Init: Init$4,
OnKeydown: OnKeydown$4,
Open: Open$2,
Render: Render$2,
View: View$4,
marqueeableText: marqueeableText,
textContainer: textContainer
});
var OnEntryListKeydown = (list, event, e) => {
switch (event.key) {
case '4':
case 'g':
browser.Open();
browser.Cd(e.parent) && list.Focus(app.browser.view.indexOf(e));
break;
default:
return list.OnKeydown(event);
}
};
var _window$3, _window$app$3, _window2$3, _window2$view$3;
var app$4 = (_window$app$3 = (_window$3 = window).app) !== null && _window$app$3 !== void 0 ? _window$app$3 : _window$3.app = {};
var view$2 = (_window2$view$3 = (_window2$3 = window).view) !== null && _window2$view$3 !== void 0 ? _window2$view$3 : _window2$3.view = {};
var list$1 = new List(view$2.queue = {});
var Init$3 = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
app$4.queue = [];
case 1:
case "end":
return _context.stop();
}
}, _callee);
}));
return function Init() {
return _ref.apply(this, arguments);
};
}();
var View$3 = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
Render$1();
view$2.queue.element.classList = ['queue'];
view$2.main.appendChild(view$2.queue.element);
case 3:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function View() {
return _ref2.apply(this, arguments);
};
}();
var Render$1 = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
list$1.Render(app$4.queue);
case 1:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return function Render() {
return _ref3.apply(this, arguments);
};
}();
var OnKeydown$3 = event => {
var e = Focused$1();
console.log(event.key);
switch (event.key) {
// case 'ArrowLeft':
// back()
// break
// case 'ArrowRight':
// cd(e)
// break
case '[':
case 'SoftLeft':
// Move track up
Move(e, -1);
break;
case ']':
case 'SoftRight':
// Move track down
Move(e, 1);
break;
default:
return OnEntryListKeydown(list$1, event, e);
}
};
var Move = (eTrack, offset) => {
var i = view$2.queue.cursor + offset;
if (i == app$4.queue.length || i < 0) {
return;
}
var n = app$4.queue[i];
app$4.queue[view$2.queue.cursor] = n;
app$4.queue[i] = eTrack;
list$1.Render(app$4.queue, i);
};
var Open$1 = () => {
Render$1();
Display('queue');
};
var Focused$1 = () => {
return app$4.queue[view$2.queue.cursor];
};
var Add = eTrack => {
// TODO: solid way to determine if something is playable
if (!eTrack.entries) app$4.queue.push(eTrack);
};
var queue$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
Add: Add,
Focused: Focused$1,
Init: Init$3,
Move: Move,
OnKeydown: OnKeydown$3,
Open: Open$1,
Render: Render$1,
View: View$3,
list: list$1
});
var _window$2, _window$app$2, _window2$2, _window2$view$2;
var app$3 = (_window$app$2 = (_window$2 = window).app) !== null && _window$app$2 !== void 0 ? _window$app$2 : _window$2.app = {};
(_window2$view$2 = (_window2$2 = window).view) !== null && _window2$view$2 !== void 0 ? _window2$view$2 : _window2$2.view = {};
var modules;
var states = {
PLAYER: 0,
BROWSER: 1,
QUEUE: 2
};
var Init$2 = name => {
app$3.mode = 1;
};
var View$2 = () => {
modules = new Array(3);
modules[states.PLAYER] = player$1;
modules[states.BROWSER] = browser$1;
modules[states.QUEUE] = queue$1;
modules[app$3.mode].Open();
};
var Display = name => {
document.body.classList = [name];
};
var Scroll = distance => {
app$3.mode = Math.min(Math.max(distance + app$3.mode, 0), modules.length);
View$2();
};
var OnKeydown$2 = event => {
return modules[app$3.mode].OnKeydown(event);
};
var mode = /*#__PURE__*/Object.freeze({
__proto__: null,
Display: Display,
Init: Init$2,
OnKeydown: OnKeydown$2,
Scroll: Scroll,
View: View$2,
get modules () { return modules; },
states: states
});
var _window$1, _window$app$1, _window2$1, _window2$view$1;
var app$2 = (_window$app$1 = (_window$1 = window).app) !== null && _window$app$1 !== void 0 ? _window$app$1 : _window$1.app = {};
var view$1 = (_window2$view$1 = (_window2$1 = window).view) !== null && _window2$view$1 !== void 0 ? _window2$view$1 : _window2$1.view = {};
var list = new List(view$1.browser = {});
var Init$1 = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
app$2.browser = {};
app$2.browser.root = {
entries: app$2.index,
root: true
};
app$2.browser.current = app$2.browser.root;
app$2.browser.recursiveView = false;
app$2.browser.view = [];
case 5:
case "end":
return _context.stop();
}
}, _callee);
}));
return function Init() {
return _ref.apply(this, arguments);
};
}();
var View$1 = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
Render();
view$1.browser.element.classList = ['browser'];
view$1.main.appendChild(view$1.browser.element);
case 3:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function View() {
return _ref2.apply(this, arguments);
};
}();
var Render = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
organizeView();
list.Render(app$2.browser.view, 0);
case 2:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return function Render() {
return _ref3.apply(this, arguments);
};
}();
var organizeView = () => {
if (app$2.browser.recursiveView) {
app$2.browser.view = [];
_recurseView();
} else {
app$2.browser.view = app$2.browser.current.entries;
}
app$2.browser.view.sort((a, b) => a.order - b.order);
};
var _recurseView = function recurseView() {
var eaEntries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : app$2.browser.current.entries;
var bIncludeDirectories = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var _iterator = _createForOfIteratorHelper(eaEntries),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var e = _step.value;
if (e.entries) {
_recurseView(e.entries, false);
if (!bIncludeDirectories) continue;
}
app$2.browser.view.push(e);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
};
var Open = () => {
Display('browser');
};
var OnKeydown$1 = event => {
var e = Focused();
switch (event.key) {
case 'SoftLeft':
// PlayTrack()
break;
case 'Escape':
case 'Back':
back();
break;
case ' ':
case 'Enter':
if (e.entries) {
Cd(e);
break;
}
case 'q':
queue.Add(e);
list.Scroll(1);
break;
case 'r':
case '7':
app$2.browser.recursiveView = !app$2.browser.recursiveView;
Render();
break;
default:
return OnEntryListKeydown(list, event, e);
}
};
var back = () => {
var e = app$2.browser.current;
if (e.root) {
return;
}
var s = Cd(e.parent);
if (s) {
list.Focus(app$2.browser.view.indexOf(e));
}
};
var Cd = function Cd() {
var entry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : app$2.browser.root;
if (entry.entries) {
app$2.browser.current = entry;
Render();
return true;
} else {
return false;
}
};
var Focused = () => {
return app$2.browser.view[view$1.browser.cursor];
};
var _window, _window$app, _window2, _window2$view;
var app$1 = (_window$app = (_window = window).app) !== null && _window$app !== void 0 ? _window$app : _window.app = {};
var view = (_window2$view = (_window2 = window).view) !== null && _window2$view !== void 0 ? _window2$view : _window2.view = {};
var store;
var saveTimeout;
var Start = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
var success;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return Store.Open('app', 'data');
case 2:
store = _context2.sent;
_context2.next = 5;
return Start$1();
case 5:
_context2.next = 7;
return loadState();
case 7:
success = _context2.sent;
if (success) {
_context2.next = 11;
break;
}
_context2.next = 11;
return Init();
case 11:
window.addEventListener('visibilitychange', /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!(document.visibilityState !== 'visible')) {
_context.next = 3;
break;
}
_context.next = 3;
return saveState();
case 3:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x) {
return _ref2.apply(this, arguments);
};
}());
_context2.next = 14;
return View();
case 14:
view.loading.remove();
case 15:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function Start() {
return _ref.apply(this, arguments);
};
}();
var Init = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return Init$5();
case 2:
Init$2();
_context3.next = 5;
return Init$1();
case 5:
_context3.next = 7;
return queue.Init();
case 7:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return function Init() {
return _ref3.apply(this, arguments);
};
}();
var View = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
view.main = document.getElementById('main');
view.loading = document.getElementById('loading');
view.loadingStatus = document.getElementById('loading-status');
View$2();
_context4.next = 6;
return View$1();
case 6:
_context4.next = 8;
return queue.View();
case 8:
_context4.next = 10;
return player.View();
case 10:
window.addEventListener('keydown', OnKeydown);
player.Render({
name: 'Timeland, Smoke & Mirrors, The Land Before Timeland, & Hypertension',
artist: 'King Gizzard & The Lizard Wizard'
});
case 12:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return function View() {
return _ref4.apply(this, arguments);
};
}();
var loadState = /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
var state;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return store.Get('state');
case 2:
state = _context5.sent;
Object.assign(app$1, state);
return _context5.abrupt("return", state != undefined);
case 5:
case "end":
return _context5.stop();
}
}, _callee5);
}));
return function loadState() {
return _ref5.apply(this, arguments);
};
}();
var saveState = () => {
app$1.lastSaved = Date.now();
console.log('saving');
return store.Set('state', app$1);
};
var resetSaveTimer = () => {
if (saveTimeout) clearTimeout(saveTimeout);
saveTimeout = setTimeout(() => saveState(), 20 * 1000);
};
var Reload = /*#__PURE__*/function () {
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return store.Set('state', null);
case 2:
window.location.reload();
case 3:
case "end":
return _context6.stop();
}
}, _callee6);
}));
return function Reload() {
return _ref6.apply(this, arguments);
};
}();
var OnKeydown = event => {
switch (event.key) {
case 'EndCall':
saveState().then(() => window.close());
break;
case '2':
Open();
break;
case '3':
queue.Open();
break;
case '0':
main.Reload();
break;
case 'ArrowLeft':
Scroll(-1);
break;
case 'ArrowRight':
Scroll(1);
break;
default:
if (OnKeydown$2(event)) return;
}
console.log('stop');
event.preventDefault();
resetSaveTimer();
};
var main$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
Init: Init,
OnKeydown: OnKeydown,
Reload: Reload,
Start: Start,
View: View,
loadState: loadState,
resetSaveTimer: resetSaveTimer,
saveState: saveState,
get saveTimeout () { return saveTimeout; },
get store () { return store; }
});
window.device = device;
window.browser = browser$1;
window.queue = queue$1;
window.entry = entry;
window.mode = mode;
window.player = player$1;
window.main = main$1;
document.addEventListener('load', Start());
})();