+ has(id) {
+ return this.visible.has(id);
+ }
+
+ subs(id) {
+ let refs = this.data[id][3];
+ if (!refs) {
+ return [];
+ }
+ for (let ref of refs) {
+ // retain orphaned references in grandparent categories
+ if (!this.has(ref)) {
+ refs = refs.concat(this.subs(ref));
+ }
+ }
+ return refs;
+ }
+
+ get(id) {
+ if (!this.has(id)) {
+ return;
+ }
+ const p = this;
+ const row = this.data[id];
+ return row && {
+ id: id,
+ title: row[0],
+ get label() {
+ return row[0].replace(/\/.*/, ''); // primary form
+ },
+ level: row[1],
+ imgid: row[2],
+ thumb(size = 32) {
+ return `/data/word/${size}/${row[2]}.jpg`;
+ },
+ get subs() {
+ return p.subs(id).map(e => p.get(e));
+ },
+ };
+ }
+}
+
+class WordQuiz {
+ dataselect(json) {
+ this.data = this.datafilter(json);
+ return [...this.data.random()];
+ }
+
+ datafilter(json) {
+ // find viable rows from json data
+ const selection = new Words(json, this.preset.cat);
+
+ if (this.preset.images) {
+ selection.filter(id => json[id][2]);