clarity-js 0.7.41 → 0.7.42

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.
@@ -24,6 +24,8 @@ let mutations: MutationQueue[] = [];
24
24
  let insertRule: (rule: string, index?: number) => number = null;
25
25
  let deleteRule: (index?: number) => void = null;
26
26
  let attachShadow: (init: ShadowRootInit) => ShadowRoot = null;
27
+ let mediaInsertRule: (rule: string, index?: number) => number = null;
28
+ let mediaDeleteRule: (index?: number) => void = null;
27
29
  let queue: Node[] = [];
28
30
  let timeout: number = null;
29
31
  let activePeriod = null;
@@ -48,13 +50,29 @@ export function start(): void {
48
50
  };
49
51
  }
50
52
 
53
+ if (mediaInsertRule === null) {
54
+ mediaInsertRule = CSSMediaRule.prototype.insertRule;
55
+ CSSMediaRule.prototype.insertRule = function(): number {
56
+ if (core.active()) { schedule(this.parentStyleSheet.ownerNode); }
57
+ return mediaInsertRule.apply(this, arguments);
58
+ };
59
+ }
60
+
51
61
  if (deleteRule === null) {
52
62
  deleteRule = CSSStyleSheet.prototype.deleteRule;
53
63
  CSSStyleSheet.prototype.deleteRule = function(): void {
54
64
  if (core.active()) { schedule(this.ownerNode); }
55
65
  return deleteRule.apply(this, arguments);
56
66
  };
57
- }
67
+ }
68
+
69
+ if (mediaDeleteRule === null) {
70
+ mediaDeleteRule = CSSMediaRule.prototype.deleteRule;
71
+ CSSMediaRule.prototype.deleteRule = function(): void {
72
+ if (core.active()) { schedule(this.parentStyleSheet.ownerNode); }
73
+ return mediaDeleteRule.apply(this, arguments);
74
+ };
75
+ }
58
76
 
59
77
  // Add a hook to attachShadow API calls
60
78
  // In case we are unable to add a hook and browser throws an exception,
@@ -214,9 +214,11 @@ function observe(root: Node): void {
214
214
  function getStyleValue(style: HTMLStyleElement): string {
215
215
  // Call trim on the text content to ensure we do not process white spaces ( , \n, \r\n, \t, etc.)
216
216
  // Also, check if stylesheet has any data-* attribute, if so process rules instead of looking up text
217
+ // Additionally, check if style node has an id - if so it's at a high risk to have experienced dynamic
218
+ // style updates which would make the textContent out of date with its true style contribution.
217
219
  let value = style.textContent ? style.textContent.trim() : Constant.Empty;
218
220
  let dataset = style.dataset ? Object.keys(style.dataset).length : 0;
219
- if (value.length === 0 || dataset > 0) {
221
+ if (value.length === 0 || dataset > 0 || style.id.length > 0) {
220
222
  value = getCssRules(style.sheet as CSSStyleSheet);
221
223
  }
222
224
  return value;