@jsenv/core 27.4.0 → 27.5.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 (84) hide show
  1. package/dist/js/autoreload.js +359 -0
  2. package/dist/js/execute_using_dynamic_import.js +1 -1
  3. package/dist/js/html_supervisor_installer.js +221 -73
  4. package/dist/js/html_supervisor_setup.js +3 -4
  5. package/dist/js/new_stylesheet.js +26 -58
  6. package/dist/js/server_events_client.js +307 -0
  7. package/dist/main.js +7483 -7281
  8. package/package.json +11 -10
  9. package/{README.md → readme.md} +8 -9
  10. package/src/build/build.js +12 -16
  11. package/src/build/start_build_server.js +24 -28
  12. package/src/dev/start_dev_server.js +30 -94
  13. package/src/execute/execute.js +17 -35
  14. package/src/omega/errors.js +20 -18
  15. package/src/omega/kitchen.js +7 -6
  16. package/src/omega/omega_server.js +96 -127
  17. package/src/omega/server/file_service.js +247 -46
  18. package/src/omega/url_graph.js +33 -20
  19. package/src/plugins/autoreload/client/autoreload.js +201 -0
  20. package/src/plugins/autoreload/{dev_sse/client → client}/autoreload_preference.js +0 -0
  21. package/src/plugins/autoreload/{dev_sse/client → client}/reload.js +29 -10
  22. package/src/plugins/autoreload/{dev_sse/client → client}/url_helpers.js +0 -0
  23. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +4 -4
  24. package/src/plugins/autoreload/{dev_sse/jsenv_plugin_dev_sse_client.js → jsenv_plugin_autoreload_client.js} +8 -8
  25. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +196 -0
  26. package/src/{dev/plugins → plugins}/explorer/client/explorer.html +0 -0
  27. package/src/{dev/plugins → plugins}/explorer/client/jsenv.png +0 -0
  28. package/src/{dev/plugins → plugins}/explorer/jsenv_plugin_explorer.js +1 -3
  29. package/src/plugins/html_supervisor/client/{error_in_document.js → error_overlay.js} +73 -17
  30. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +127 -54
  31. package/src/plugins/html_supervisor/client/html_supervisor_setup.js +3 -4
  32. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +19 -12
  33. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +97 -117
  34. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +66 -58
  35. package/src/plugins/plugin_controller.js +102 -67
  36. package/src/plugins/plugins.js +10 -8
  37. package/src/{helpers/event_source/event_source.js → plugins/server_events/client/event_source_connection.js} +102 -31
  38. package/src/plugins/server_events/client/server_events_client.js +17 -0
  39. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +48 -0
  40. package/src/plugins/server_events/server_events_dispatcher.js +69 -0
  41. package/src/{dev/plugins → plugins}/toolbar/client/animation/toolbar_animation.js +0 -0
  42. package/src/{dev/plugins → plugins}/toolbar/client/eventsource/eventsource.css +0 -0
  43. package/src/{dev/plugins → plugins}/toolbar/client/eventsource/toolbar_eventsource.js +0 -0
  44. package/src/{dev/plugins → plugins}/toolbar/client/execution/execution.css +0 -0
  45. package/src/{dev/plugins → plugins}/toolbar/client/execution/toolbar_execution.js +0 -0
  46. package/src/{dev/plugins → plugins}/toolbar/client/focus/focus.css +0 -0
  47. package/src/{dev/plugins → plugins}/toolbar/client/focus/toolbar_focus.js +0 -0
  48. package/src/{dev/plugins → plugins}/toolbar/client/jsenv_logo.svg +0 -0
  49. package/src/{dev/plugins → plugins}/toolbar/client/notification/toolbar_notification.js +0 -0
  50. package/src/{dev/plugins → plugins}/toolbar/client/responsive/overflow_menu.css +0 -0
  51. package/src/{dev/plugins → plugins}/toolbar/client/responsive/toolbar_responsive.js +0 -0
  52. package/src/{dev/plugins → plugins}/toolbar/client/settings/settings.css +0 -0
  53. package/src/{dev/plugins → plugins}/toolbar/client/settings/toolbar_settings.js +0 -0
  54. package/src/{dev/plugins → plugins}/toolbar/client/theme/jsenv_theme.css +0 -0
  55. package/src/{dev/plugins → plugins}/toolbar/client/theme/light_theme.css +0 -0
  56. package/src/{dev/plugins → plugins}/toolbar/client/theme/toolbar_theme.js +0 -0
  57. package/src/{dev/plugins → plugins}/toolbar/client/toolbar.html +0 -0
  58. package/src/{dev/plugins → plugins}/toolbar/client/toolbar_injector.js +0 -0
  59. package/src/{dev/plugins → plugins}/toolbar/client/toolbar_main.css +0 -0
  60. package/src/{dev/plugins → plugins}/toolbar/client/toolbar_main.js +0 -0
  61. package/src/{dev/plugins → plugins}/toolbar/client/tooltip/tooltip.css +0 -0
  62. package/src/{dev/plugins → plugins}/toolbar/client/tooltip/tooltip.js +0 -0
  63. package/src/{dev/plugins → plugins}/toolbar/client/util/animation.js +0 -0
  64. package/src/{dev/plugins → plugins}/toolbar/client/util/dom.js +0 -0
  65. package/src/{dev/plugins → plugins}/toolbar/client/util/fetch_using_xhr.js +0 -0
  66. package/src/{dev/plugins → plugins}/toolbar/client/util/fetching.js +0 -0
  67. package/src/{dev/plugins → plugins}/toolbar/client/util/iframe_to_parent_href.js +0 -0
  68. package/src/{dev/plugins → plugins}/toolbar/client/util/jsenv_logger.js +0 -0
  69. package/src/{dev/plugins → plugins}/toolbar/client/util/preferences.js +0 -0
  70. package/src/{dev/plugins → plugins}/toolbar/client/util/responsive.js +0 -0
  71. package/src/{dev/plugins → plugins}/toolbar/client/util/util.js +0 -0
  72. package/src/{dev/plugins → plugins}/toolbar/client/variant/variant.js +0 -0
  73. package/src/{dev/plugins → plugins}/toolbar/jsenv_plugin_toolbar.js +0 -0
  74. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +4 -3
  75. package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +25 -55
  76. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +44 -24
  77. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +6 -1
  78. package/src/plugins/url_analysis/html/html_urls.js +8 -8
  79. package/src/test/execute_plan.js +36 -54
  80. package/src/test/execute_test_plan.js +2 -2
  81. package/dist/js/event_source_client.js +0 -549
  82. package/src/helpers/event_source/sse_service.js +0 -53
  83. package/src/plugins/autoreload/dev_sse/client/event_source_client.js +0 -193
  84. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +0 -192
@@ -13,9 +13,12 @@ const unevalException = value => {
13
13
  const JSENV_ERROR_OVERLAY_TAGNAME = "jsenv-error-overlay";
14
14
  const displayErrorInDocument = (error, {
15
15
  rootDirectoryUrl,
16
+ openInEditor,
16
17
  url,
17
18
  line,
18
- column
19
+ column,
20
+ reportedBy,
21
+ requestedRessource
19
22
  }) => {
20
23
  document.querySelectorAll(JSENV_ERROR_OVERLAY_TAGNAME).forEach(node => {
21
24
  node.parentNode.removeChild(node);
@@ -24,40 +27,87 @@ const displayErrorInDocument = (error, {
24
27
  theme,
25
28
  title,
26
29
  message,
27
- stack
30
+ stack,
31
+ tip
28
32
  } = errorToHTML(error, {
29
33
  url,
30
34
  line,
31
- column
35
+ column,
36
+ reportedBy,
37
+ requestedRessource
32
38
  });
33
- const jsenvErrorOverlay = new JsenvErrorOverlay({
39
+ let jsenvErrorOverlay = new JsenvErrorOverlay({
34
40
  theme,
35
41
  title,
36
- stack: stack ? `${replaceLinks(message, {
37
- rootDirectoryUrl
38
- })}\n${replaceLinks(stack, {
39
- rootDirectoryUrl
40
- })}` : replaceLinks(message, {
41
- rootDirectoryUrl
42
- })
42
+ text: createErrorText({
43
+ rootDirectoryUrl,
44
+ openInEditor,
45
+ message,
46
+ stack
47
+ }),
48
+ tip
43
49
  });
44
50
  document.body.appendChild(jsenvErrorOverlay);
51
+
52
+ const removeErrorOverlay = () => {
53
+ if (jsenvErrorOverlay && jsenvErrorOverlay.parentNode) {
54
+ document.body.removeChild(jsenvErrorOverlay);
55
+ jsenvErrorOverlay = null;
56
+ }
57
+ };
58
+
59
+ if (window.__reloader__) {
60
+ window.__reloader__.onstatuschange = () => {
61
+ if (window.__reloader__.status === "reloading") {
62
+ removeErrorOverlay();
63
+ }
64
+ };
65
+ }
66
+
67
+ return removeErrorOverlay;
68
+ };
69
+
70
+ const createErrorText = ({
71
+ rootDirectoryUrl,
72
+ openInEditor,
73
+ message,
74
+ stack
75
+ }) => {
76
+ if (message && stack) {
77
+ return `${replaceLinks(message, {
78
+ rootDirectoryUrl,
79
+ openInEditor
80
+ })}\n${replaceLinks(stack, {
81
+ rootDirectoryUrl,
82
+ openInEditor
83
+ })}`;
84
+ }
85
+
86
+ if (stack) {
87
+ return replaceLinks(stack, {
88
+ rootDirectoryUrl,
89
+ openInEditor
90
+ });
91
+ }
92
+
93
+ return replaceLinks(message, {
94
+ rootDirectoryUrl,
95
+ openInEditor
96
+ });
45
97
  };
46
98
 
47
99
  class JsenvErrorOverlay extends HTMLElement {
48
100
  constructor({
101
+ theme,
49
102
  title,
50
- stack,
51
- theme = "dark"
103
+ text,
104
+ tip
52
105
  }) {
53
106
  super();
54
107
  this.root = this.attachShadow({
55
108
  mode: "open"
56
109
  });
57
110
  this.root.innerHTML = overlayHtml;
58
- this.root.querySelector(".overlay").setAttribute("data-theme", theme);
59
- this.root.querySelector(".title").innerHTML = title;
60
- this.root.querySelector(".stack").innerHTML = stack;
61
111
 
62
112
  this.root.querySelector(".backdrop").onclick = () => {
63
113
  if (!this.parentNode) {
@@ -68,6 +118,11 @@ class JsenvErrorOverlay extends HTMLElement {
68
118
  this.root.querySelector(".backdrop").onclick = null;
69
119
  this.parentNode.removeChild(this);
70
120
  };
121
+
122
+ this.root.querySelector(".overlay").setAttribute("data-theme", theme);
123
+ this.root.querySelector(".title").innerHTML = title;
124
+ this.root.querySelector(".text").innerHTML = text;
125
+ this.root.querySelector(".tip").innerHTML = tip;
71
126
  }
72
127
 
73
128
  }
@@ -156,8 +211,8 @@ pre a {
156
211
  <div class="backdrop"></div>
157
212
  <div class="overlay">
158
213
  <h1 class="title"></h1>
159
- <pre class="stack"></pre>
160
- <div class="tip">Click outside to close.</div>
214
+ <pre class="text"></pre>
215
+ <div class="tip"></div>
161
216
  </div>
162
217
  `;
163
218
 
@@ -242,7 +297,9 @@ const getErrorStackWithoutErrorMessage = error => {
242
297
  const errorToHTML = (error, {
243
298
  url,
244
299
  line,
245
- column
300
+ column,
301
+ reportedBy,
302
+ requestedRessource
246
303
  }) => {
247
304
  let {
248
305
  message,
@@ -258,16 +315,35 @@ const errorToHTML = (error, {
258
315
  }
259
316
  }
260
317
 
318
+ let tip = formatTip({
319
+ reportedBy,
320
+ requestedRessource
321
+ });
261
322
  return {
262
323
  theme: error && error.cause && error.cause.code === "PARSE_ERROR" ? "light" : "dark",
263
324
  title: "An error occured",
264
325
  message,
265
- stack
326
+ stack,
327
+ tip: `${tip}
328
+ <br />
329
+ Click outside to close.`
266
330
  };
267
331
  };
268
332
 
333
+ const formatTip = ({
334
+ reportedBy,
335
+ requestedRessource
336
+ }) => {
337
+ if (reportedBy === "browser") {
338
+ return `Reported by the browser while executing <code>${window.location.pathname}${window.location.search}</code>.`;
339
+ }
340
+
341
+ return `Reported by the server while serving <code>${requestedRessource}</code>`;
342
+ };
343
+
269
344
  const replaceLinks = (string, {
270
- rootDirectoryUrl
345
+ rootDirectoryUrl,
346
+ openInEditor
271
347
  }) => {
272
348
  // normalize line breaks
273
349
  string = string.replace(/\n/g, "\n");
@@ -296,7 +372,7 @@ const replaceLinks = (string, {
296
372
  column
297
373
  });
298
374
  return link({
299
- href: `javascript:window.fetch('/__open_in_editor__/${fileUrl}')`,
375
+ href: openInEditor ? `javascript:window.fetch('/__open_in_editor__/${fileUrl}')` : fileUrl,
300
376
  text: fileUrl
301
377
  });
302
378
  };
@@ -432,10 +508,13 @@ const displayErrorNotification = typeof Notification === "function" ? displayErr
432
508
  const {
433
509
  __html_supervisor__
434
510
  } = window;
511
+ const supervisedScripts = [];
435
512
  const installHtmlSupervisor = ({
513
+ rootDirectoryUrl,
436
514
  logs,
437
515
  measurePerf,
438
- rootDirectoryUrl
516
+ errorOverlay,
517
+ openInEditor
439
518
  }) => {
440
519
 
441
520
  const scriptExecutionResults = {};
@@ -471,8 +550,7 @@ const installHtmlSupervisor = ({
471
550
 
472
551
  const onExecutionError = (executionResult, {
473
552
  currentScript,
474
- errorExposureInNotification = false,
475
- errorExposureInDocument = false
553
+ errorExposureInNotification = false
476
554
  }) => {
477
555
  const error = executionResult.error;
478
556
 
@@ -494,12 +572,6 @@ const installHtmlSupervisor = ({
494
572
  displayErrorNotification(error);
495
573
  }
496
574
 
497
- if (errorExposureInDocument) {
498
- displayErrorInDocument(error, {
499
- rootDirectoryUrl
500
- });
501
- }
502
-
503
575
  executionResult.exceptionSource = unevalException(error);
504
576
  delete executionResult.error;
505
577
  };
@@ -518,7 +590,9 @@ const installHtmlSupervisor = ({
518
590
  currentScript,
519
591
  execute // https://developer.mozilla.org/en-US/docs/web/html/element/script
520
592
 
521
- }) => {
593
+ }, {
594
+ reload = false
595
+ } = {}) => {
522
596
  if (logs) {
523
597
  console.group(`[jsenv] loading ${type} ${src}`);
524
598
  }
@@ -529,7 +603,13 @@ const installHtmlSupervisor = ({
529
603
  let error;
530
604
 
531
605
  try {
532
- result = await execute();
606
+ const urlObject = new URL(src, window.location);
607
+
608
+ if (reload) {
609
+ urlObject.searchParams.set("hmr", Date.now());
610
+ }
611
+
612
+ result = await execute(urlObject.href);
533
613
  completed = true;
534
614
  } catch (e) {
535
615
  completed = false;
@@ -593,12 +673,22 @@ const installHtmlSupervisor = ({
593
673
  }));
594
674
 
595
675
  __html_supervisor__.addScriptToExecute = async scriptToExecute => {
676
+ if (!supervisedScripts.includes(scriptToExecute)) {
677
+ supervisedScripts.push(scriptToExecute);
678
+
679
+ scriptToExecute.reload = () => {
680
+ return performExecution(scriptToExecute, {
681
+ reload: true
682
+ });
683
+ };
684
+ }
685
+
596
686
  if (scriptToExecute.async) {
597
687
  performExecution(scriptToExecute);
598
688
  return;
599
689
  }
600
690
 
601
- const useDeferQueue = scriptToExecute.defer || scriptToExecute.type === "js_module";
691
+ const useDeferQueue = scriptToExecute.defer || scriptToExecute.type === "module";
602
692
 
603
693
  if (useDeferQueue) {
604
694
  // defer must wait for classic script to be done
@@ -652,60 +742,118 @@ const installHtmlSupervisor = ({
652
742
  copy.forEach(scriptToExecute => {
653
743
  __html_supervisor__.addScriptToExecute(scriptToExecute);
654
744
  });
655
- window.addEventListener("error", errorEvent => {
656
- if (!errorEvent.isTrusted) {
657
- // ignore custom error event (not sent by browser)
658
- return;
659
- }
660
745
 
661
- const {
662
- error
663
- } = errorEvent;
664
- displayErrorInDocument(error, {
665
- rootDirectoryUrl,
666
- url: errorEvent.filename,
667
- line: errorEvent.lineno,
668
- column: errorEvent.colno
669
- });
670
- });
746
+ if (errorOverlay) {
747
+ window.addEventListener("error", errorEvent => {
748
+ if (!errorEvent.isTrusted) {
749
+ // ignore custom error event (not sent by browser)
750
+ return;
751
+ }
671
752
 
672
- if (window.__jsenv_event_source_client__) {
673
- const onServerErrorEvent = serverErrorEvent => {
674
753
  const {
675
- reason,
676
- stack,
677
- url,
678
- line,
679
- column,
680
- contentFrame
681
- } = JSON.parse(serverErrorEvent.data);
682
- displayErrorInDocument({
683
- message: reason,
684
- stack: stack ? `${stack}\n\n${contentFrame}` : contentFrame
685
- }, {
754
+ error
755
+ } = errorEvent;
756
+ displayErrorInDocument(error, {
686
757
  rootDirectoryUrl,
687
- url,
688
- line,
689
- column
758
+ openInEditor,
759
+ url: errorEvent.filename,
760
+ line: errorEvent.lineno,
761
+ column: errorEvent.colno,
762
+ reportedBy: "browser"
690
763
  });
691
- };
692
-
693
- window.__jsenv_event_source_client__.addEventCallbacks({
694
- file_not_found: onServerErrorEvent,
695
- parse_error: onServerErrorEvent,
696
- unexpected_error: onServerErrorEvent
697
764
  });
765
+
766
+ if (window.__server_events__) {
767
+ const isExecuting = () => {
768
+ if (pendingExecutionCount > 0) {
769
+ return true;
770
+ }
771
+
772
+ if (document.readyState === "loading" || document.readyState === "interactive") {
773
+ return true;
774
+ }
775
+
776
+ if (window.__reloader__ && window.__reloader__.status === "reloading") {
777
+ return true;
778
+ }
779
+
780
+ return false;
781
+ };
782
+
783
+ window.__server_events__.addEventCallbacks({
784
+ error_while_serving_file: serverErrorEvent => {
785
+ if (!isExecuting()) {
786
+ return;
787
+ }
788
+
789
+ const {
790
+ message,
791
+ stack,
792
+ traceUrl,
793
+ traceLine,
794
+ traceColumn,
795
+ traceMessage,
796
+ requestedRessource,
797
+ isFaviconAutoRequest
798
+ } = JSON.parse(serverErrorEvent.data);
799
+
800
+ if (isFaviconAutoRequest) {
801
+ return;
802
+ } // setTimeout is to ensure the error
803
+ // dispatched on window by browser is displayed first,
804
+ // then the server error replaces it (because it contains more information)
805
+
806
+
807
+ setTimeout(() => {
808
+ displayErrorInDocument({
809
+ message,
810
+ stack: stack && traceMessage ? `${stack}\n\n${traceMessage}` : stack ? stack : traceMessage ? `\n${traceMessage}` : ""
811
+ }, {
812
+ rootDirectoryUrl,
813
+ openInEditor,
814
+ url: traceUrl,
815
+ line: traceLine,
816
+ column: traceColumn,
817
+ reportedBy: "server",
818
+ requestedRessource
819
+ });
820
+ }, 10);
821
+ }
822
+ });
823
+ }
698
824
  }
699
825
  };
826
+
827
+ __html_supervisor__.reloadSupervisedScript = ({
828
+ type,
829
+ src
830
+ }) => {
831
+ const supervisedScript = supervisedScripts.find(supervisedScriptCandidate => {
832
+ if (type && supervisedScriptCandidate.type !== type) {
833
+ return false;
834
+ }
835
+
836
+ if (supervisedScriptCandidate.src !== src) {
837
+ return false;
838
+ }
839
+
840
+ return true;
841
+ });
842
+
843
+ if (supervisedScript) {
844
+ supervisedScript.reload();
845
+ }
846
+ };
847
+
700
848
  const superviseScriptTypeModule = ({
701
849
  src,
702
850
  isInline
703
851
  }) => {
704
852
  __html_supervisor__.addScriptToExecute({
705
853
  src,
706
- type: "js_module",
854
+ type: "module",
707
855
  isInline,
708
- execute: () => import(new URL(src, document.location.href).href)
856
+ execute: url => import(url)
709
857
  });
710
858
  };
711
859
 
@@ -14,7 +14,7 @@ window.__html_supervisor__ = {
14
14
  type: "js_classic",
15
15
  isInline,
16
16
  currentScript: document.currentScript,
17
- execute: () => {
17
+ execute: (url) => {
18
18
  return new Promise((resolve, reject) => {
19
19
  const script = document.createElement("script")
20
20
  if (crossorigin) {
@@ -23,8 +23,7 @@ window.__html_supervisor__ = {
23
23
  if (integrity) {
24
24
  script.integrity = integrity
25
25
  }
26
- script.src = src
27
- const scriptUrl = new URL(src, window.location).href
26
+ script.src = url
28
27
  let lastWindowErrorUrl
29
28
  let lastWindowError
30
29
  const windowErrorCallback = (e) => {
@@ -45,7 +44,7 @@ window.__html_supervisor__ = {
45
44
  })
46
45
  script.addEventListener("load", () => {
47
46
  cleanup()
48
- if (lastWindowErrorUrl === scriptUrl) {
47
+ if (lastWindowErrorUrl === url) {
49
48
  reject(lastWindowError)
50
49
  } else {
51
50
  resolve()
@@ -14,30 +14,6 @@
14
14
 
15
15
  var defineProperty = Object.defineProperty;
16
16
  var forEach = Array.prototype.forEach;
17
-
18
- var hasBrokenRules = function () {
19
- var style = bootstrapper.createElement("style");
20
- style.textContent = '.x{content:"y"}';
21
- bootstrapper.body.appendChild(style);
22
- return style.sheet.cssRules[0].style.content !== '"y"';
23
- }();
24
-
25
- var brokenRulePatterns = [/content:\s*["']/gm];
26
-
27
- function fixBrokenRules(content) {
28
- return brokenRulePatterns.reduce(function (acc, pattern) {
29
- return acc.replace(pattern, "$&%%%");
30
- }, content);
31
- }
32
-
33
- var placeholderPatterns = [/(content:\s*["'])%%%/gm];
34
- var getCssText = hasBrokenRules ? function (rule) {
35
- return placeholderPatterns.reduce(function (acc, pattern) {
36
- return acc.replace(pattern, "$1");
37
- }, rule.cssText);
38
- } : function (rule) {
39
- return rule.cssText;
40
- };
41
17
  var importPattern = /@import.+?;?$/gm;
42
18
 
43
19
  function rejectImports(contents) {
@@ -50,18 +26,6 @@
50
26
  return _contents.trim();
51
27
  }
52
28
 
53
- function clearRules(sheet) {
54
- for (var i = 0; i < sheet.cssRules.length; i++) {
55
- sheet.deleteRule(0);
56
- }
57
- }
58
-
59
- function insertAllRules(from, to) {
60
- forEach.call(from.cssRules, function (rule, i) {
61
- to.insertRule(getCssText(rule), i);
62
- });
63
- }
64
-
65
29
  function isElementConnected(element) {
66
30
  return "isConnected" in element ? element.isConnected : document.contains(element);
67
31
  }
@@ -106,9 +70,10 @@
106
70
  return typeof instance === "object" ? nonConstructedProto.isPrototypeOf(instance) : false;
107
71
  }
108
72
 
109
- var $basicStyleSheet = new WeakMap();
73
+ var $basicStyleElement = new WeakMap();
110
74
  var $locations = new WeakMap();
111
75
  var $adoptersByLocation = new WeakMap();
76
+ var $appliedMethods = new WeakMap();
112
77
 
113
78
  function addAdopterLocation(sheet, location) {
114
79
  var adopter = document.createElement("style");
@@ -130,13 +95,15 @@
130
95
 
131
96
  function restyleAdopter(sheet, adopter) {
132
97
  requestAnimationFrame(function () {
133
- clearRules(adopter.sheet);
134
- insertAllRules($basicStyleSheet.get(sheet), adopter.sheet);
98
+ adopter.textContent = $basicStyleElement.get(sheet).textContent;
99
+ $appliedMethods.get(sheet).forEach(function (command) {
100
+ return adopter.sheet[command.method].apply(adopter.sheet, command.args);
101
+ });
135
102
  });
136
103
  }
137
104
 
138
105
  function checkInvocationCorrectness(self) {
139
- if (!$basicStyleSheet.has(self)) {
106
+ if (!$basicStyleElement.has(self)) {
140
107
  throw new TypeError("Illegal invocation");
141
108
  }
142
109
  }
@@ -145,9 +112,10 @@
145
112
  var self = this;
146
113
  var style = document.createElement("style");
147
114
  bootstrapper.body.appendChild(style);
148
- $basicStyleSheet.set(self, style.sheet);
115
+ $basicStyleElement.set(self, style);
149
116
  $locations.set(self, []);
150
117
  $adoptersByLocation.set(self, new WeakMap());
118
+ $appliedMethods.set(self, []);
151
119
  }
152
120
 
153
121
  var proto$1 = ConstructedStyleSheet.prototype;
@@ -166,9 +134,8 @@
166
134
 
167
135
  if (typeof contents === "string") {
168
136
  var self_1 = this;
169
- var style = $basicStyleSheet.get(self_1).ownerNode;
170
- style.textContent = hasBrokenRules ? fixBrokenRules(rejectImports(contents)) : rejectImports(contents);
171
- $basicStyleSheet.set(self_1, style.sheet);
137
+ $basicStyleElement.get(self_1).textContent = rejectImports(contents);
138
+ $appliedMethods.set(self_1, []);
172
139
  $locations.get(self_1).forEach(function (location) {
173
140
  if (location.isConnected()) {
174
141
  restyleAdopter(self_1, getAdopterByLocation(self_1, location));
@@ -182,7 +149,15 @@
182
149
  enumerable: true,
183
150
  get: function cssRules() {
184
151
  checkInvocationCorrectness(this);
185
- return $basicStyleSheet.get(this).cssRules;
152
+ return $basicStyleElement.get(this).sheet.cssRules;
153
+ }
154
+ });
155
+ defineProperty(proto$1, "media", {
156
+ configurable: true,
157
+ enumerable: true,
158
+ get: function media() {
159
+ checkInvocationCorrectness(this);
160
+ return $basicStyleElement.get(this).sheet.media;
186
161
  }
187
162
  });
188
163
  cssStyleSheetMethods.forEach(function (method) {
@@ -190,25 +165,18 @@
190
165
  var self = this;
191
166
  checkInvocationCorrectness(self);
192
167
  var args = arguments;
168
+ $appliedMethods.get(self).push({
169
+ method: method,
170
+ args: args
171
+ });
193
172
  $locations.get(self).forEach(function (location) {
194
173
  if (location.isConnected()) {
195
174
  var sheet = getAdopterByLocation(self, location).sheet;
196
175
  sheet[method].apply(sheet, args);
197
176
  }
198
177
  });
199
-
200
- if (hasBrokenRules) {
201
- if (method === "insertRule") {
202
- args[0] = fixBrokenRules(args[0]);
203
- }
204
-
205
- if (method === "addRule") {
206
- args[1] = fixBrokenRules(args[1]);
207
- }
208
- }
209
-
210
- var basic = $basicStyleSheet.get(self);
211
- return basic[method].apply(basic, args);
178
+ var basicSheet = $basicStyleElement.get(self).sheet;
179
+ return basicSheet[method].apply(basicSheet, args);
212
180
  };
213
181
  });
214
182
  defineProperty(ConstructedStyleSheet, Symbol.hasInstance, {