+ ids = ids.filter(id => json[id][1] <= this.preset.level);
+ }
+
+ // keep only wanted ids
+ for (let id in selection) {
+ if (id && !ids.has(id)) {
+ delete selection[id];
+ }
+ }
+
+ // retain orphaned references in grandparent categories
+ for (let id in selection) {
+ selection[id][3] = function subresolve(subs) {
+ //console.log(subs);
+ return (subs || []).flatMap(sub =>
+ sub in selection ? [sub] : json[sub] ? subresolve(json[sub][3]) : []
+ );
+ }(selection[id][3]);
+ }
+ return selection;
+ }
+
+ configure(params) {
+ const opts = new Map(params.map(arg => arg.split(/[:=](.*)/)));
+ for (let [query, val] of opts) {
+ if (query.match(/^\d+$/)) {
+ this.preset.cat = [parseInt(query)];
+ }
+ else if (query === 'level') {
+ this.preset.level = parseInt(val);
+ }
+ else {
+ this.preset[query] = val;
+ }