@mfcc64/ytms 18.0.0 → 18.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/script.mjs +100 -116
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mfcc64/ytms",
3
- "version": "18.0.0",
3
+ "version": "18.2.0",
4
4
  "description": "YouTube Musical Spectrum",
5
5
  "main": "script.mjs",
6
6
  "scripts": {
package/script.mjs CHANGED
@@ -16,7 +16,7 @@
16
16
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
  */
18
18
 
19
- import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
19
+ import {ShowCQTElement, AutoResumeAudioContext} from "../../showcqt-element@2/showcqt-element.mjs";
20
20
 
21
21
  (async function(){
22
22
  const get_asset = (name) => String(new URL(`../ytms-assets@1.0.0/${name}`, import.meta.url));
@@ -167,23 +167,30 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
167
167
  af_links.shadowRoot.getElementById("message").style.display = "block";
168
168
  });
169
169
 
170
- const media_symbol = Symbol("media_symbol");
171
170
  let svideos = [];
172
171
  if (document.location.hostname == "soundcloud.com") {
173
- await new Promise((res, rej) => {
174
- const old = AudioContext.prototype.createMediaElementSource;
175
- AudioContext.prototype.createMediaElementSource = function(media) {
176
- const retval = old.call(this, media);
177
- ShowCQTElement.global_audio_context = this;
178
- svideos.push(media);
179
- media[media_symbol] = retval;
180
- res();
172
+ ShowCQTElement.global_audio_context = new AutoResumeAudioContext();
173
+ const old = AudioContext.prototype.createMediaElementSource;
174
+ AudioContext.prototype.createMediaElementSource = function(media) {
175
+ const retval = old.call(this, media);
176
+ if (this != ShowCQTElement.global_audio_context) {
177
+ console.warn("audio can't connect to showcqt-element");
181
178
  return retval;
182
- };
183
- });
179
+ }
180
+ retval.connect(cqt.audio_input);
181
+ svideos.push(media);
182
+ return retval;
183
+ };
184
+
185
+ window.AudioContext = function() {
186
+ return ShowCQTElement.global_audio_context;
187
+ };
188
+
189
+ Object.setPrototypeOf(window.AudioContext, AutoResumeAudioContext);
190
+ window.AudioContext.prototype = AutoResumeAudioContext.prototype;
184
191
  }
185
192
 
186
- const cqt = new ShowCQTElement();
193
+ var cqt = new ShowCQTElement();
187
194
  set_fixed_style(cqt, 9999999);
188
195
  let stop_count = 0;
189
196
  const videos = document.getElementsByTagName("video");
@@ -255,7 +262,6 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
255
262
  function soundcloud_layout() {
256
263
  cqt.style.zIndex = 1000;
257
264
  af_links.style.zIndex = 1001;
258
- svideos[0][media_symbol].connect(cqt.audio_input);
259
265
  document.body.style.setProperty("--ytms-cqt-bottom", "var(--play-controls-height, 0px)");
260
266
  }
261
267
 
@@ -334,7 +340,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
334
340
  menu.appendChild(menu_img);
335
341
  var menu_is_hidden = true;
336
342
  var menu_div = document.createElement("div");
337
- var menu_table = document.createElement("table");
343
+ var menu_table = document.createElement("div");
338
344
  set_fixed_style(menu_div, 10000001);
339
345
  menu_div.style.left = "0px";
340
346
  menu_div.style.top = "0px";
@@ -343,70 +349,66 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
343
349
  menu_div.style.color = "white";
344
350
  menu_div.style.fontSize = "10pt";
345
351
  menu_div.style.backgroundColor = "#000000DD";
346
- menu_div.style.verticalAlign = "middle";
347
- menu_div.style.maxHeight = "90%";
348
- menu_div.style.maxWidth = "90%";
352
+ menu_div.style.maxHeight = "100%";
353
+ menu_div.style.maxWidth = "100%";
354
+ menu_div.style.boxSizing = "border-box";
349
355
  menu_div.style.overflow = "auto";
350
356
  menu_div.style.scrollbarWidth = "8px";
351
357
  menu_div.style.scrollbarColor = "#555555 #222222dd";
352
358
  menu_div.style.visibility = "hidden";
353
359
  menu_div.style.cursor = "default";
354
- menu_table.style.width = "860px";
355
360
  menu_div.style.display = "block";
356
-
357
- var current_tr = null;
358
- var current_tr_count = 0;
359
-
360
- function get_menu_table_tr() {
361
- if (current_tr && current_tr_count < 3)
362
- return current_tr_count++, current_tr;
363
- current_tr_count = 1;
364
- current_tr = document.createElement("tr");
365
- menu_table.appendChild(current_tr);
366
- return current_tr;
367
- }
368
-
369
- function set_common_tr_style(tr) {
370
- tr.style.height = "32px";
361
+ menu_table.style.display = "grid";
362
+ menu_table.style.padding = "0px";
363
+ menu_table.style.margin = "0px";
364
+ menu_table.style.border = "0px";
365
+ menu_table.style.gridTemplateColumns = "repeat(3, 48px 80px 80px 40px 32px)";
366
+ menu_table.style.gridAutoRows = "32px";
367
+ menu_table.style.alignItems = "center";
368
+
369
+ function get_grid_item(n) {
370
+ var div = document.createElement("div");
371
+ div.style.display = "block";
372
+ div.style.padding = "0px";
373
+ div.style.margin = "0px";
374
+ div.style.border = "0px";
375
+ div.style.overflow = "hidden";
376
+ div.style.whiteSpace = "nowrap";
377
+ div.style.lineHeight = "1em";
378
+ div.style.gridColumn = "span " + n;
379
+ menu_table.appendChild(div);
380
+ return div;
371
381
  }
372
382
 
373
- function set_common_left_td_style(td) {
374
- td.style.paddingLeft = "48px";
375
- td.style.width = "80px";
383
+ function set_common_stretched_input_style(e) {
384
+ e.style.cursor = "pointer";
385
+ e.style.width = "100%";
386
+ e.style.margin = "0px";
387
+ e.style.outline = "none";
388
+ e.style.boxSizing = "border-box";
376
389
  }
377
390
 
378
391
  function create_child_range_menu(title, name, callback) {
379
- var tr = get_menu_table_tr();
380
- set_common_tr_style(tr);
381
- var td = document.createElement("td");
382
- set_common_left_td_style(td);
383
- td.textContent = title;
384
- tr.appendChild(td);
385
- td = document.createElement("td");
386
- td.style.width = "120px";
387
- td.colSpan = 2;
392
+ get_grid_item(1);
393
+ var label = get_grid_item(1);
394
+ var container = get_grid_item(2);
395
+ var text = get_grid_item(1);
396
+ label.textContent = title;
397
+ text.style.textAlign = "right";
398
+
388
399
  var child = child_menu[name] = document.createElement("input");
389
- var child_text = document.createElement("td");
390
- child.style.cursor = "pointer";
391
- child.style.width = "100%";
400
+ set_common_stretched_input_style(child);
392
401
  child.type = "range";
393
402
  child.min = defaults[name].min;
394
403
  child.max = defaults[name].max;
395
404
  child.step = 1;
396
405
  child.value = get_opt(name);
397
- child.oninput = function() {
398
- child_text.textContent = this.value;
399
- };
400
- child.onchange = function() {
401
- this.oninput();
402
- if (callback)
403
- callback(child);
406
+ child.oninput = () => { text.textContent = child.value; };
407
+ child.onchange = () => {
408
+ child.oninput();
409
+ callback?.(child);
404
410
  };
405
- td.appendChild(child);
406
- tr.appendChild(td);
407
- tr.appendChild(child_text);
408
- child_text.style.textAlign = "right";
409
- child_text.style.width = "32px";
411
+ container.appendChild(child);
410
412
  child.onchange();
411
413
  }
412
414
 
@@ -456,27 +458,27 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
456
458
  create_child_range_menu("Scale Y", "scale_y", (child) => cqt.dataset.scaleY = child.value);
457
459
 
458
460
  function create_child_select_menu(title, name, select_opt, callback) {
459
- var tr = get_menu_table_tr();
460
- set_common_tr_style(tr);
461
- var td = document.createElement("td");
462
- set_common_left_td_style(td);
463
- td.textContent = title;
464
- tr.appendChild(td);
465
- td = document.createElement("td");
466
- td.colSpan = 3;
461
+ get_grid_item(1);
462
+ var label = get_grid_item(1);
463
+ var container = get_grid_item(3);
464
+
465
+ label.textContent = title;
467
466
  var child = document.createElement("select");
468
- if (name) child_menu[name] = child;
469
- child.style.cursor = "pointer";
470
- child.style.width = "100%";
467
+ set_common_stretched_input_style(child);
468
+
471
469
  for (let k = 0; k < select_opt.length; k++) {
472
470
  const opt = document.createElement("option");
473
471
  opt.textContent = select_opt[k];
474
472
  opt.value = k;
475
473
  child.appendChild(opt);
476
474
  }
477
- if (name) child.value = get_opt(name);
478
- td.appendChild(child);
479
- tr.appendChild(td);
475
+
476
+ if (name) {
477
+ child_menu[name] = child;
478
+ child.value = get_opt(name);
479
+ }
480
+
481
+ container.appendChild(child);
480
482
  child.onchange = () => callback?.(child);
481
483
  child.onchange();
482
484
  }
@@ -586,32 +588,24 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
586
588
  const color_rotation = new ColorRotation();
587
589
 
588
590
  function create_child_color_menu(title, name, callback) {
589
- var tr = get_menu_table_tr();
590
- set_common_tr_style(tr);
591
- var td = document.createElement("td");
592
- set_common_left_td_style(td);
593
- td.textContent = title;
594
- tr.appendChild(td);
595
- td = document.createElement("td");
596
- td.style.width = "80px";
597
- var child_text = document.createElement("td");
598
- child_text.style.textAlign = "right";
599
- child_text.colSpan = 2;
591
+ get_grid_item(1);
592
+ var label = get_grid_item(1);
593
+ var container = get_grid_item(1);
594
+ var text = get_grid_item(2);
595
+
596
+ label.textContent = title;
597
+ text.style.textAlign = "right";
600
598
  var child = child_menu[name] = document.createElement("input");
601
- child.style.cursor = "pointer";
602
- child.style.width = "100%";
599
+ set_common_stretched_input_style(child);
603
600
  child.type = "color";
604
601
  child.value = number2color(get_opt(name));
605
- child.onchange = function() {
606
- child_text.textContent = child.value;
607
- child.textContent = child.value;
602
+ child.onchange = () => {
603
+ text.textContent = child.value;
608
604
  callback?.(child);
609
605
  update_color_table();
610
606
  };
611
607
  child.oninput = child.onchange;
612
- td.appendChild(child);
613
- tr.appendChild(td);
614
- tr.appendChild(child_text);
608
+ container.appendChild(child);
615
609
  child.onchange();
616
610
  }
617
611
 
@@ -773,25 +767,19 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
773
767
  cqt.post_render_callback = p => line_visualizer.render(p);
774
768
 
775
769
  function create_child_checkbox_menu(title, name, callback) {
776
- var tr = get_menu_table_tr();
777
- set_common_tr_style(tr);
778
- var td = document.createElement("td");
779
- set_common_left_td_style(td);
780
- td.textContent = title;
781
- tr.appendChild(td);
782
- td = document.createElement("td");
783
- td.colSpan = 3;
770
+ get_grid_item(1);
771
+ var label = get_grid_item(1);
772
+ var container = get_grid_item(3)
773
+
774
+ label.textContent = title;
784
775
  var child = child_menu[name] = document.createElement("input");
785
776
  child.style.cursor = "pointer";
777
+ child.style.outline = "none";
786
778
  child.type = "checkbox";
787
779
  child.checked = get_opt(name) * 1;
788
- child.onchange = function() {
789
- if (callback)
790
- callback(child);
791
- };
780
+ child.onchange = () => callback?.(child);
781
+ container.appendChild(child);
792
782
  child.onchange();
793
- td.appendChild(child);
794
- tr.appendChild(td);
795
783
  }
796
784
 
797
785
  create_child_range_menu("Peak Range", "peak_range");
@@ -900,20 +888,17 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
900
888
  }
901
889
  create_child_select_presets();
902
890
 
903
- current_tr = null;
904
- set_common_tr_style(get_menu_table_tr());
905
- current_tr = null;
891
+ get_grid_item(15);
906
892
 
907
- var child_buttons_td = document.createElement("td");
908
- child_buttons_td.colSpan = 4 * 3;
893
+ var child_buttons_td = get_grid_item(15);
909
894
  child_buttons_td.style.textAlign = "right";
910
- get_menu_table_tr().appendChild(child_buttons_td);
911
895
 
912
896
  function create_child_button_menu(title, callback) {
913
897
  var child = document.createElement("input");
914
898
  child.type = "button";
915
899
  child.value = title;
916
900
  child.style.cursor = "pointer";
901
+ child.style.outline = "none";
917
902
  child.style.fontFamily = "inherit";
918
903
  child.style.fontSize = "inherit";
919
904
  child.style.marginLeft = "8px";
@@ -957,8 +942,7 @@ import {ShowCQTElement} from "../../showcqt-element@2/showcqt-element.mjs";
957
942
  setTimeout(function(){ child.value = "Reset Default Settings"; }, 300);
958
943
  });
959
944
 
960
- menu_div.attachShadow({mode: "open"});
961
- menu_div.shadowRoot.appendChild(menu_table);
945
+ menu_div.appendChild(menu_table);
962
946
  menu.onclick = function() {
963
947
  menu_is_hidden = !menu_is_hidden;
964
948
  if (menu_is_hidden)