@acemir/cssom 0.9.15 → 0.9.17
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.
- package/build/CSSOM.js +562 -88
- package/lib/CSSFontFaceRule.js +21 -2
- package/lib/CSSGroupingRule.js +5 -4
- package/lib/CSSKeyframeRule.js +22 -3
- package/lib/CSSKeyframesRule.js +199 -5
- package/lib/CSSNestedDeclarations.js +23 -2
- package/lib/CSSRule.js +39 -26
- package/lib/CSSStyleRule.js +38 -6
- package/lib/CSSStyleSheet.js +8 -7
- package/lib/StyleSheet.js +8 -1
- package/lib/clone.js +6 -0
- package/lib/cssstyleTryCatchBlock.js +5 -0
- package/lib/errorUtils.js +118 -0
- package/lib/index.js +5 -0
- package/lib/parse.js +36 -30
- package/package.json +1 -1
package/build/CSSOM.js
CHANGED
|
@@ -1,6 +1,123 @@
|
|
|
1
1
|
var CSSOM = {};
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
// Utility functions for CSSOM error handling
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gets the appropriate error constructor from the global object context.
|
|
8
|
+
* Tries to find the error constructor from parentStyleSheet._globalObject,
|
|
9
|
+
* then from _globalObject, then falls back to the native constructor.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} context - The CSSOM object (rule, stylesheet, etc.)
|
|
12
|
+
* @param {string} errorType - The error type ('TypeError', 'RangeError', 'DOMException', etc.)
|
|
13
|
+
* @return {Function} The error constructor
|
|
14
|
+
*/
|
|
15
|
+
function getErrorConstructor(context, errorType) {
|
|
16
|
+
// Try parentStyleSheet._globalObject first
|
|
17
|
+
if (context.parentStyleSheet && context.parentStyleSheet._globalObject && context.parentStyleSheet._globalObject[errorType]) {
|
|
18
|
+
return context.parentStyleSheet._globalObject[errorType];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Try __parentStyleSheet (alternative naming)
|
|
22
|
+
if (context.__parentStyleSheet && context.__parentStyleSheet._globalObject && context.__parentStyleSheet._globalObject[errorType]) {
|
|
23
|
+
return context.__parentStyleSheet._globalObject[errorType];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Try _globalObject on the context itself
|
|
27
|
+
if (context._globalObject && context._globalObject[errorType]) {
|
|
28
|
+
return context._globalObject[errorType];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Fall back to native constructor
|
|
32
|
+
return (typeof global !== 'undefined' && global[errorType]) ||
|
|
33
|
+
(typeof window !== 'undefined' && window[errorType]) ||
|
|
34
|
+
eval(errorType);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates and throws an appropriate error with context-aware constructor.
|
|
39
|
+
*
|
|
40
|
+
* @param {Object} context - The CSSOM object (rule, stylesheet, etc.)
|
|
41
|
+
* @param {string} errorType - The error type ('TypeError', 'RangeError', 'DOMException', etc.)
|
|
42
|
+
* @param {string} message - The error message
|
|
43
|
+
* @param {string} [name] - Optional name for DOMException
|
|
44
|
+
*/
|
|
45
|
+
function throwError(context, errorType, message, name) {
|
|
46
|
+
var ErrorConstructor = getErrorConstructor(context, errorType);
|
|
47
|
+
var error = new ErrorConstructor(message, name);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Throws a TypeError for missing required arguments.
|
|
53
|
+
*
|
|
54
|
+
* @param {Object} context - The CSSOM object
|
|
55
|
+
* @param {string} methodName - The method name (e.g., 'appendRule')
|
|
56
|
+
* @param {string} objectName - The object name (e.g., 'CSSKeyframesRule')
|
|
57
|
+
* @param {number} [required=1] - Number of required arguments
|
|
58
|
+
* @param {number} [provided=0] - Number of provided arguments
|
|
59
|
+
*/
|
|
60
|
+
function throwMissingArguments(context, methodName, objectName, required, provided) {
|
|
61
|
+
required = required || 1;
|
|
62
|
+
provided = provided || 0;
|
|
63
|
+
var message = "Failed to execute '" + methodName + "' on '" + objectName + "': " +
|
|
64
|
+
required + " argument" + (required > 1 ? "s" : "") + " required, but only " +
|
|
65
|
+
provided + " present.";
|
|
66
|
+
throwError(context, 'TypeError', message);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Throws a RangeError for index out of bounds.
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} context - The CSSOM object
|
|
73
|
+
* @param {string} [message] - Optional custom message, defaults to 'INDEX_SIZE_ERR'
|
|
74
|
+
*/
|
|
75
|
+
function throwIndexSizeError(context, message) {
|
|
76
|
+
throwError(context, 'RangeError', message || 'INDEX_SIZE_ERR');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Throws a DOMException for parse errors.
|
|
81
|
+
*
|
|
82
|
+
* @param {Object} context - The CSSOM object
|
|
83
|
+
* @param {string} methodName - The method name
|
|
84
|
+
* @param {string} objectName - The object name
|
|
85
|
+
* @param {string} rule - The rule that failed to parse
|
|
86
|
+
* @param {string} [name='SyntaxError'] - The DOMException name
|
|
87
|
+
*/
|
|
88
|
+
function throwParseError(context, methodName, objectName, rule, name) {
|
|
89
|
+
var message = "Failed to execute '" + methodName + "' on '" + objectName + "': " +
|
|
90
|
+
"Failed to parse the rule '" + rule + "'.";
|
|
91
|
+
throwError(context, 'DOMException', message, name || 'SyntaxError');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Throws a DOMException for index errors.
|
|
96
|
+
*
|
|
97
|
+
* @param {Object} context - The CSSOM object
|
|
98
|
+
* @param {string} methodName - The method name
|
|
99
|
+
* @param {string} objectName - The object name
|
|
100
|
+
* @param {number} index - The invalid index
|
|
101
|
+
* @param {number} maxIndex - The maximum valid index
|
|
102
|
+
* @param {string} [name='IndexSizeError'] - The DOMException name
|
|
103
|
+
*/
|
|
104
|
+
function throwIndexError(context, methodName, objectName, index, maxIndex, name) {
|
|
105
|
+
var message = "Failed to execute '" + methodName + "' on '" + objectName + "': " +
|
|
106
|
+
"The index provided (" + index + ") is larger than the maximum index (" + maxIndex + ").";
|
|
107
|
+
throwError(context, 'DOMException', message, name || 'IndexSizeError');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var errorUtils = {
|
|
111
|
+
getErrorConstructor: getErrorConstructor,
|
|
112
|
+
throwError: throwError,
|
|
113
|
+
throwMissingArguments: throwMissingArguments,
|
|
114
|
+
throwIndexSizeError: throwIndexSizeError,
|
|
115
|
+
throwParseError: throwParseError,
|
|
116
|
+
throwIndexError: throwIndexError
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
4
121
|
// NOTE: Check viability to add a validation for css values or use a dependency like csstree-validator
|
|
5
122
|
/**
|
|
6
123
|
* Regular expression to detect invalid characters in the value portion of a CSS style declaration.
|
|
@@ -179,58 +296,91 @@ CSSOM.CSSStyleDeclaration.prototype = {
|
|
|
179
296
|
|
|
180
297
|
|
|
181
298
|
|
|
299
|
+
try {
|
|
300
|
+
CSSOM.CSSStyleDeclaration = require("cssstyle").CSSStyleDeclaration;
|
|
301
|
+
} catch (e) {
|
|
302
|
+
// ignore
|
|
303
|
+
}
|
|
304
|
+
|
|
182
305
|
/**
|
|
183
306
|
* @constructor
|
|
184
307
|
* @see http://dev.w3.org/csswg/cssom/#the-cssrule-interface
|
|
185
308
|
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule
|
|
186
309
|
*/
|
|
187
310
|
CSSOM.CSSRule = function CSSRule() {
|
|
188
|
-
this.
|
|
189
|
-
this.
|
|
311
|
+
this.__parentRule = null;
|
|
312
|
+
this.__parentStyleSheet = null;
|
|
190
313
|
};
|
|
191
314
|
|
|
192
|
-
CSSOM.CSSRule.
|
|
193
|
-
|
|
194
|
-
CSSOM.CSSRule
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
315
|
+
Object.defineProperties(CSSOM.CSSRule.prototype, {
|
|
316
|
+
|
|
317
|
+
constructor: { value: CSSOM.CSSRule },
|
|
318
|
+
|
|
319
|
+
parentRule: {
|
|
320
|
+
get: function() {
|
|
321
|
+
return this.__parentRule
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
parentStyleSheet: {
|
|
326
|
+
get: function() {
|
|
327
|
+
return this.__parentStyleSheet
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
UNKNOWN_RULE: { value: 0, enumerable: true }, // obsolet
|
|
332
|
+
STYLE_RULE: { value: 1, enumerable: true },
|
|
333
|
+
CHARSET_RULE: { value: 2, enumerable: true }, // obsolet
|
|
334
|
+
IMPORT_RULE: { value: 3, enumerable: true },
|
|
335
|
+
MEDIA_RULE: { value: 4, enumerable: true },
|
|
336
|
+
FONT_FACE_RULE: { value: 5, enumerable: true },
|
|
337
|
+
PAGE_RULE: { value: 6, enumerable: true },
|
|
338
|
+
KEYFRAMES_RULE: { value: 7, enumerable: true },
|
|
339
|
+
KEYFRAME_RULE: { value: 8, enumerable: true },
|
|
340
|
+
MARGIN_RULE: { value: 9, enumerable: true },
|
|
341
|
+
NAMESPACE_RULE: { value: 10, enumerable: true },
|
|
342
|
+
COUNTER_STYLE_RULE: { value: 11, enumerable: true },
|
|
343
|
+
SUPPORTS_RULE: { value: 12, enumerable: true },
|
|
344
|
+
DOCUMENT_RULE: { value: 13, enumerable: true },
|
|
345
|
+
FONT_FEATURE_VALUES_RULE: { value: 14, enumerable: true },
|
|
346
|
+
VIEWPORT_RULE: { value: 15, enumerable: true },
|
|
347
|
+
REGION_STYLE_RULE: { value: 16, enumerable: true },
|
|
348
|
+
CONTAINER_RULE: { value: 17, enumerable: true },
|
|
349
|
+
LAYER_BLOCK_RULE: { value: 18, enumerable: true },
|
|
350
|
+
STARTING_STYLE_RULE: { value: 1002, enumerable: true },
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
217
356
|
|
|
218
|
-
exports.CSSRule = CSSOM.CSSRule;
|
|
219
|
-
///CommonJS
|
|
220
357
|
/**
|
|
221
358
|
* @constructor
|
|
222
359
|
* @see https://drafts.csswg.org/css-nesting-1/
|
|
223
360
|
*/
|
|
224
361
|
CSSOM.CSSNestedDeclarations = function CSSNestedDeclarations() {
|
|
225
362
|
CSSOM.CSSRule.call(this);
|
|
226
|
-
this.
|
|
227
|
-
this.
|
|
363
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
364
|
+
this.__style.parentRule = this;
|
|
228
365
|
};
|
|
229
366
|
|
|
230
367
|
CSSOM.CSSNestedDeclarations.prototype = new CSSOM.CSSRule();
|
|
231
368
|
CSSOM.CSSNestedDeclarations.prototype.constructor = CSSOM.CSSNestedDeclarations;
|
|
232
369
|
CSSOM.CSSNestedDeclarations.prototype.type = 0;
|
|
233
370
|
|
|
371
|
+
Object.defineProperty(CSSOM.CSSNestedDeclarations.prototype, "style", {
|
|
372
|
+
get: function() {
|
|
373
|
+
return this.__style;
|
|
374
|
+
},
|
|
375
|
+
set: function(value) {
|
|
376
|
+
if (typeof value === "string") {
|
|
377
|
+
this.__style.cssText = value;
|
|
378
|
+
} else {
|
|
379
|
+
this.__style = value;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
234
384
|
Object.defineProperty(CSSOM.CSSNestedDeclarations.prototype, "cssText", {
|
|
235
385
|
get: function () {
|
|
236
386
|
return this.style.cssText;
|
|
@@ -239,6 +389,9 @@ Object.defineProperty(CSSOM.CSSNestedDeclarations.prototype, "cssText", {
|
|
|
239
389
|
enumerable: true,
|
|
240
390
|
});
|
|
241
391
|
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
242
395
|
/**
|
|
243
396
|
* @constructor
|
|
244
397
|
* @see https://drafts.csswg.org/cssom/#the-cssgroupingrule-interface
|
|
@@ -270,10 +423,10 @@ CSSOM.CSSGroupingRule.prototype.constructor = CSSOM.CSSGroupingRule;
|
|
|
270
423
|
*/
|
|
271
424
|
CSSOM.CSSGroupingRule.prototype.insertRule = function insertRule(rule, index) {
|
|
272
425
|
if (index < 0 || index > this.cssRules.length) {
|
|
273
|
-
|
|
426
|
+
errorUtils.throwIndexSizeError(this);
|
|
274
427
|
}
|
|
275
428
|
var cssRule = CSSOM.parse(rule).cssRules[0];
|
|
276
|
-
cssRule.
|
|
429
|
+
cssRule.__parentRule = this;
|
|
277
430
|
this.cssRules.splice(index, 0, cssRule);
|
|
278
431
|
return index;
|
|
279
432
|
};
|
|
@@ -292,12 +445,15 @@ CSSOM.CSSGroupingRule.prototype.constructor = CSSOM.CSSGroupingRule;
|
|
|
292
445
|
*/
|
|
293
446
|
CSSOM.CSSGroupingRule.prototype.deleteRule = function deleteRule(index) {
|
|
294
447
|
if (index < 0 || index >= this.cssRules.length) {
|
|
295
|
-
|
|
448
|
+
errorUtils.throwIndexSizeError(this);
|
|
296
449
|
}
|
|
297
|
-
this.cssRules.splice(index, 1)[0].
|
|
450
|
+
this.cssRules.splice(index, 1)[0].__parentRule = null;
|
|
298
451
|
};
|
|
299
452
|
|
|
300
453
|
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
301
457
|
/**
|
|
302
458
|
* @constructor
|
|
303
459
|
* @see https://drafts.csswg.org/css-counter-styles/#the-csscounterstylerule-interface
|
|
@@ -312,6 +468,9 @@ CSSOM.CSSCounterStyleRule.prototype.constructor = CSSOM.CSSCounterStyleRule;
|
|
|
312
468
|
CSSOM.CSSCounterStyleRule.prototype.type = 11;
|
|
313
469
|
|
|
314
470
|
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
315
474
|
/**
|
|
316
475
|
* @constructor
|
|
317
476
|
* @see https://www.w3.org/TR/css-conditional-3/#the-cssconditionrule-interface
|
|
@@ -327,6 +486,9 @@ CSSOM.CSSConditionRule.prototype.conditionText = ''
|
|
|
327
486
|
CSSOM.CSSConditionRule.prototype.cssText = ''
|
|
328
487
|
|
|
329
488
|
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
330
492
|
/**
|
|
331
493
|
* @constructor
|
|
332
494
|
* @see http://dev.w3.org/csswg/cssom/#cssstylerule
|
|
@@ -334,14 +496,40 @@ CSSOM.CSSConditionRule.prototype.cssText = ''
|
|
|
334
496
|
*/
|
|
335
497
|
CSSOM.CSSStyleRule = function CSSStyleRule() {
|
|
336
498
|
CSSOM.CSSGroupingRule.call(this);
|
|
337
|
-
this.
|
|
338
|
-
this.
|
|
339
|
-
this.
|
|
499
|
+
this.__selectorText = "";
|
|
500
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
501
|
+
this.__style.parentRule = this;
|
|
340
502
|
};
|
|
341
503
|
|
|
342
504
|
CSSOM.CSSStyleRule.prototype = new CSSOM.CSSGroupingRule();
|
|
343
505
|
CSSOM.CSSStyleRule.prototype.constructor = CSSOM.CSSStyleRule;
|
|
344
|
-
|
|
506
|
+
|
|
507
|
+
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "type", {
|
|
508
|
+
value: 1,
|
|
509
|
+
writable: false
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "selectorText", {
|
|
513
|
+
get: function() {
|
|
514
|
+
return this.__selectorText;
|
|
515
|
+
},
|
|
516
|
+
set: function(value) {
|
|
517
|
+
this.__selectorText = value;
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "style", {
|
|
522
|
+
get: function() {
|
|
523
|
+
return this.__style;
|
|
524
|
+
},
|
|
525
|
+
set: function(value) {
|
|
526
|
+
if (typeof value === "string") {
|
|
527
|
+
this.__style.cssText = value;
|
|
528
|
+
} else {
|
|
529
|
+
this.__style = value;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
});
|
|
345
533
|
|
|
346
534
|
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", {
|
|
347
535
|
get: function() {
|
|
@@ -364,8 +552,8 @@ Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", {
|
|
|
364
552
|
},
|
|
365
553
|
set: function(cssText) {
|
|
366
554
|
var rule = CSSOM.CSSStyleRule.parse(cssText);
|
|
367
|
-
this.
|
|
368
|
-
this.
|
|
555
|
+
this.__style = rule.style;
|
|
556
|
+
this.__selectorText = rule.selectorText;
|
|
369
557
|
}
|
|
370
558
|
});
|
|
371
559
|
|
|
@@ -516,6 +704,9 @@ CSSOM.CSSStyleRule.parse = function(ruleText) {
|
|
|
516
704
|
|
|
517
705
|
|
|
518
706
|
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
519
710
|
/**
|
|
520
711
|
* @constructor
|
|
521
712
|
* @see http://dev.w3.org/csswg/cssom/#the-medialist-interface
|
|
@@ -570,6 +761,9 @@ CSSOM.MediaList.prototype = {
|
|
|
570
761
|
|
|
571
762
|
|
|
572
763
|
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
573
767
|
/**
|
|
574
768
|
* @constructor
|
|
575
769
|
* @see http://dev.w3.org/csswg/cssom/#cssmediarule
|
|
@@ -611,6 +805,9 @@ Object.defineProperties(CSSOM.CSSMediaRule.prototype, {
|
|
|
611
805
|
|
|
612
806
|
|
|
613
807
|
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
614
811
|
/**
|
|
615
812
|
* @constructor
|
|
616
813
|
* @see https://drafts.csswg.org/css-contain-3/
|
|
@@ -650,6 +847,9 @@ Object.defineProperties(CSSOM.CSSContainerRule.prototype, {
|
|
|
650
847
|
|
|
651
848
|
|
|
652
849
|
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
653
853
|
/**
|
|
654
854
|
* @constructor
|
|
655
855
|
* @see https://drafts.csswg.org/css-conditional-3/#the-csssupportsrule-interface
|
|
@@ -675,6 +875,9 @@ Object.defineProperty(CSSOM.CSSSupportsRule.prototype, "cssText", {
|
|
|
675
875
|
});
|
|
676
876
|
|
|
677
877
|
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
678
881
|
/**
|
|
679
882
|
* @constructor
|
|
680
883
|
* @see http://dev.w3.org/csswg/cssom/#cssimportrule
|
|
@@ -847,6 +1050,9 @@ Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
|
|
|
847
1050
|
|
|
848
1051
|
|
|
849
1052
|
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
850
1056
|
/**
|
|
851
1057
|
* @constructor
|
|
852
1058
|
* @see https://drafts.csswg.org/cssom/#the-cssnamespacerule-interface
|
|
@@ -914,14 +1120,17 @@ Object.defineProperty(CSSOM.CSSNamespaceRule.prototype, "cssText", {
|
|
|
914
1120
|
|
|
915
1121
|
|
|
916
1122
|
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
917
1126
|
/**
|
|
918
1127
|
* @constructor
|
|
919
1128
|
* @see http://dev.w3.org/csswg/cssom/#css-font-face-rule
|
|
920
1129
|
*/
|
|
921
1130
|
CSSOM.CSSFontFaceRule = function CSSFontFaceRule() {
|
|
922
1131
|
CSSOM.CSSRule.call(this);
|
|
923
|
-
this.
|
|
924
|
-
this.
|
|
1132
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
1133
|
+
this.__style.parentRule = this;
|
|
925
1134
|
};
|
|
926
1135
|
|
|
927
1136
|
CSSOM.CSSFontFaceRule.prototype = new CSSOM.CSSRule();
|
|
@@ -931,6 +1140,19 @@ CSSOM.CSSFontFaceRule.prototype.type = 5;
|
|
|
931
1140
|
//CSSOM.CSSFontFaceRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
|
|
932
1141
|
//CSSOM.CSSFontFaceRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
|
|
933
1142
|
|
|
1143
|
+
Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "style", {
|
|
1144
|
+
get: function() {
|
|
1145
|
+
return this.__style;
|
|
1146
|
+
},
|
|
1147
|
+
set: function(value) {
|
|
1148
|
+
if (typeof value === "string") {
|
|
1149
|
+
this.__style.cssText = value;
|
|
1150
|
+
} else {
|
|
1151
|
+
this.__style = value;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
|
|
934
1156
|
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSFontFaceRule.cpp
|
|
935
1157
|
Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "cssText", {
|
|
936
1158
|
get: function() {
|
|
@@ -940,6 +1162,9 @@ Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "cssText", {
|
|
|
940
1162
|
|
|
941
1163
|
|
|
942
1164
|
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
943
1168
|
/**
|
|
944
1169
|
* @constructor
|
|
945
1170
|
* @see http://www.w3.org/TR/shadow-dom/#host-at-rule
|
|
@@ -968,6 +1193,9 @@ Object.defineProperty(CSSOM.CSSHostRule.prototype, "cssText", {
|
|
|
968
1193
|
|
|
969
1194
|
|
|
970
1195
|
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
971
1199
|
/**
|
|
972
1200
|
* @constructor
|
|
973
1201
|
* @see http://www.w3.org/TR/shadow-dom/#host-at-rule
|
|
@@ -996,14 +1224,27 @@ Object.defineProperty(CSSOM.CSSStartingStyleRule.prototype, "cssText", {
|
|
|
996
1224
|
|
|
997
1225
|
|
|
998
1226
|
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
999
1230
|
/**
|
|
1000
1231
|
* @constructor
|
|
1001
1232
|
* @see http://dev.w3.org/csswg/cssom/#the-stylesheet-interface
|
|
1002
1233
|
*/
|
|
1003
1234
|
CSSOM.StyleSheet = function StyleSheet() {
|
|
1004
|
-
this.
|
|
1235
|
+
this.__parentStyleSheet = null;
|
|
1005
1236
|
};
|
|
1006
1237
|
|
|
1238
|
+
Object.defineProperties(CSSOM.StyleSheet.prototype, {
|
|
1239
|
+
parentStyleSheet: {
|
|
1240
|
+
get: function() {
|
|
1241
|
+
return this.__parentStyleSheet;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1007
1248
|
|
|
1008
1249
|
|
|
1009
1250
|
/**
|
|
@@ -1038,13 +1279,13 @@ CSSOM.CSSStyleSheet.prototype.constructor = CSSOM.CSSStyleSheet;
|
|
|
1038
1279
|
*/
|
|
1039
1280
|
CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
|
|
1040
1281
|
if (rule === undefined && index === undefined) {
|
|
1041
|
-
|
|
1282
|
+
errorUtils.throwMissingArguments(this, 'insertRule', 'CSSStyleSheet');
|
|
1042
1283
|
}
|
|
1043
1284
|
if (index === void 0) {
|
|
1044
1285
|
index = 0;
|
|
1045
1286
|
}
|
|
1046
1287
|
if (index < 0 || index > this.cssRules.length) {
|
|
1047
|
-
|
|
1288
|
+
errorUtils.throwIndexSizeError(this);
|
|
1048
1289
|
}
|
|
1049
1290
|
var ruleToParse = String(rule);
|
|
1050
1291
|
var parsedSheet = CSSOM.parse(ruleToParse);
|
|
@@ -1053,10 +1294,10 @@ CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
|
|
|
1053
1294
|
if (ruleToParse.trimStart().startsWith('@namespace')) {
|
|
1054
1295
|
domExceptionName = "InvalidStateError";
|
|
1055
1296
|
}
|
|
1056
|
-
|
|
1297
|
+
errorUtils.throwParseError(this, 'insertRule', 'CSSStyleSheet', ruleToParse, domExceptionName);
|
|
1057
1298
|
}
|
|
1058
1299
|
var cssRule = parsedSheet.cssRules[0];
|
|
1059
|
-
cssRule.
|
|
1300
|
+
cssRule.__parentStyleSheet = this;
|
|
1060
1301
|
this.cssRules.splice(index, 0, cssRule);
|
|
1061
1302
|
return index;
|
|
1062
1303
|
};
|
|
@@ -1077,21 +1318,21 @@ CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
|
|
|
1077
1318
|
*/
|
|
1078
1319
|
CSSOM.CSSStyleSheet.prototype.deleteRule = function(index) {
|
|
1079
1320
|
if (index === undefined) {
|
|
1080
|
-
|
|
1321
|
+
errorUtils.throwMissingArguments(this, 'deleteRule', 'CSSStyleSheet');
|
|
1081
1322
|
}
|
|
1082
1323
|
index = Number(index);
|
|
1083
1324
|
if (index < 0) {
|
|
1084
1325
|
index = 4294967296 + index;
|
|
1085
1326
|
}
|
|
1086
1327
|
if (index >= this.cssRules.length) {
|
|
1087
|
-
|
|
1328
|
+
errorUtils.throwIndexError(this, 'deleteRule', 'CSSStyleSheet', index, this.cssRules.length);
|
|
1088
1329
|
}
|
|
1089
1330
|
if (this.cssRules[index] && this.cssRules[index].constructor.name == "CSSNamespaceRule") {
|
|
1090
1331
|
var shouldContinue = this.cssRules.every(function (rule) {
|
|
1091
1332
|
return ['CSSImportRule','CSSLayerStatementRule','CSSNamespaceRule'].indexOf(rule.constructor.name) !== -1
|
|
1092
1333
|
});
|
|
1093
1334
|
if (!shouldContinue) {
|
|
1094
|
-
|
|
1335
|
+
errorUtils.throwError(this, 'DOMException', "Failed to execute 'deleteRule' on 'CSSStyleSheet': Deleting a CSSNamespaceRule is not allowed when there is rules other than @import, @layer statement, or @namespace.", "InvalidStateError");
|
|
1095
1336
|
}
|
|
1096
1337
|
}
|
|
1097
1338
|
this.cssRules.splice(index, 1);
|
|
@@ -1113,6 +1354,9 @@ CSSOM.CSSStyleSheet.prototype.toString = function() {
|
|
|
1113
1354
|
|
|
1114
1355
|
|
|
1115
1356
|
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1116
1360
|
/**
|
|
1117
1361
|
* @constructor
|
|
1118
1362
|
* @see http://www.w3.org/TR/css3-animations/#DOM-CSSKeyframesRule
|
|
@@ -1121,14 +1365,42 @@ CSSOM.CSSKeyframesRule = function CSSKeyframesRule() {
|
|
|
1121
1365
|
CSSOM.CSSRule.call(this);
|
|
1122
1366
|
this.name = '';
|
|
1123
1367
|
this.cssRules = [];
|
|
1368
|
+
|
|
1369
|
+
// Set up initial indexed access
|
|
1370
|
+
this._setupIndexedAccess();
|
|
1371
|
+
|
|
1372
|
+
// Override cssRules methods after initial setup, store references as non-enumerable properties
|
|
1373
|
+
var self = this;
|
|
1374
|
+
var originalPush = this.cssRules.push;
|
|
1375
|
+
var originalSplice = this.cssRules.splice;
|
|
1376
|
+
|
|
1377
|
+
// Create non-enumerable method overrides
|
|
1378
|
+
Object.defineProperty(this.cssRules, 'push', {
|
|
1379
|
+
value: function() {
|
|
1380
|
+
var result = originalPush.apply(this, arguments);
|
|
1381
|
+
self._setupIndexedAccess();
|
|
1382
|
+
return result;
|
|
1383
|
+
},
|
|
1384
|
+
writable: true,
|
|
1385
|
+
enumerable: false,
|
|
1386
|
+
configurable: true
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
Object.defineProperty(this.cssRules, 'splice', {
|
|
1390
|
+
value: function() {
|
|
1391
|
+
var result = originalSplice.apply(this, arguments);
|
|
1392
|
+
self._setupIndexedAccess();
|
|
1393
|
+
return result;
|
|
1394
|
+
},
|
|
1395
|
+
writable: true,
|
|
1396
|
+
enumerable: false,
|
|
1397
|
+
configurable: true
|
|
1398
|
+
});
|
|
1124
1399
|
};
|
|
1125
1400
|
|
|
1126
1401
|
CSSOM.CSSKeyframesRule.prototype = new CSSOM.CSSRule();
|
|
1127
1402
|
CSSOM.CSSKeyframesRule.prototype.constructor = CSSOM.CSSKeyframesRule;
|
|
1128
1403
|
CSSOM.CSSKeyframesRule.prototype.type = 7;
|
|
1129
|
-
//FIXME
|
|
1130
|
-
//CSSOM.CSSKeyframesRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
|
|
1131
|
-
//CSSOM.CSSKeyframesRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
|
|
1132
1404
|
|
|
1133
1405
|
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframesRule.cpp
|
|
1134
1406
|
Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", {
|
|
@@ -1137,10 +1409,177 @@ Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", {
|
|
|
1137
1409
|
for (var i=0, length=this.cssRules.length; i < length; i++) {
|
|
1138
1410
|
cssTexts.push(this.cssRules[i].cssText);
|
|
1139
1411
|
}
|
|
1140
|
-
|
|
1412
|
+
var cssWideKeywords = ['initial', 'inherit', 'revert', 'revert-layer', 'unset', 'none'];
|
|
1413
|
+
var processedName = cssWideKeywords.includes(this.name) ? '"' + this.name + '"' : this.name;
|
|
1414
|
+
return "@" + (this._vendorPrefix || '') + "keyframes " + processedName + (processedName && " ") + "{" + (cssTexts.length ? "\n " + cssTexts.join("\n ") : "") + "\n}";
|
|
1141
1415
|
}
|
|
1142
1416
|
});
|
|
1143
1417
|
|
|
1418
|
+
/**
|
|
1419
|
+
* Appends a new keyframe rule to the list of keyframes.
|
|
1420
|
+
*
|
|
1421
|
+
* @param {string} rule - The keyframe rule string to append (e.g., "50% { opacity: 0.5; }")
|
|
1422
|
+
* @see https://www.w3.org/TR/css-animations-1/#dom-csskeyframesrule-appendrule
|
|
1423
|
+
*/
|
|
1424
|
+
CSSOM.CSSKeyframesRule.prototype.appendRule = function appendRule(rule) {
|
|
1425
|
+
if (arguments.length === 0) {
|
|
1426
|
+
errorUtils.throwMissingArguments(this, 'appendRule', 'CSSKeyframesRule');
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
var parsedRule;
|
|
1430
|
+
try {
|
|
1431
|
+
// Parse the rule string as a keyframe rule
|
|
1432
|
+
var tempStyleSheet = CSSOM.parse("@keyframes temp { " + rule + " }");
|
|
1433
|
+
if (tempStyleSheet.cssRules.length > 0 && tempStyleSheet.cssRules[0].cssRules.length > 0) {
|
|
1434
|
+
parsedRule = tempStyleSheet.cssRules[0].cssRules[0];
|
|
1435
|
+
} else {
|
|
1436
|
+
throw new Error("Failed to parse keyframe rule");
|
|
1437
|
+
}
|
|
1438
|
+
} catch (e) {
|
|
1439
|
+
errorUtils.throwParseError(this, 'appendRule', 'CSSKeyframesRule', rule);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
parsedRule.__parentRule = this;
|
|
1443
|
+
this.cssRules.push(parsedRule);
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* Deletes a keyframe rule that matches the specified key.
|
|
1448
|
+
*
|
|
1449
|
+
* @param {string} select - The keyframe selector to delete (e.g., "50%", "from", "to")
|
|
1450
|
+
* @see https://www.w3.org/TR/css-animations-1/#dom-csskeyframesrule-deleterule
|
|
1451
|
+
*/
|
|
1452
|
+
CSSOM.CSSKeyframesRule.prototype.deleteRule = function deleteRule(select) {
|
|
1453
|
+
if (arguments.length === 0) {
|
|
1454
|
+
errorUtils.throwMissingArguments(this, 'deleteRule', 'CSSKeyframesRule');
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
var normalizedSelect = this._normalizeKeyText(select);
|
|
1458
|
+
|
|
1459
|
+
for (var i = 0; i < this.cssRules.length; i++) {
|
|
1460
|
+
var rule = this.cssRules[i];
|
|
1461
|
+
if (this._normalizeKeyText(rule.keyText) === normalizedSelect) {
|
|
1462
|
+
rule.__parentRule = null;
|
|
1463
|
+
this.cssRules.splice(i, 1);
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Finds and returns the keyframe rule that matches the specified key.
|
|
1471
|
+
* When multiple rules have the same key, returns the last one.
|
|
1472
|
+
*
|
|
1473
|
+
* @param {string} select - The keyframe selector to find (e.g., "50%", "from", "to")
|
|
1474
|
+
* @return {CSSKeyframeRule|null} The matching keyframe rule, or null if not found
|
|
1475
|
+
* @see https://www.w3.org/TR/css-animations-1/#dom-csskeyframesrule-findrule
|
|
1476
|
+
*/
|
|
1477
|
+
CSSOM.CSSKeyframesRule.prototype.findRule = function findRule(select) {
|
|
1478
|
+
if (arguments.length === 0) {
|
|
1479
|
+
errorUtils.throwMissingArguments(this, 'findRule', 'CSSKeyframesRule');
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
var normalizedSelect = this._normalizeKeyText(select);
|
|
1483
|
+
|
|
1484
|
+
// Iterate backwards to find the last matching rule
|
|
1485
|
+
for (var i = this.cssRules.length - 1; i >= 0; i--) {
|
|
1486
|
+
var rule = this.cssRules[i];
|
|
1487
|
+
if (this._normalizeKeyText(rule.keyText) === normalizedSelect) {
|
|
1488
|
+
return rule;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
return null;
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
/**
|
|
1496
|
+
* Normalizes keyframe selector text for comparison.
|
|
1497
|
+
* Handles "from" -> "0%" and "to" -> "100%" conversions and trims whitespace.
|
|
1498
|
+
*
|
|
1499
|
+
* @private
|
|
1500
|
+
* @param {string} keyText - The keyframe selector text to normalize
|
|
1501
|
+
* @return {string} The normalized keyframe selector text
|
|
1502
|
+
*/
|
|
1503
|
+
CSSOM.CSSKeyframesRule.prototype._normalizeKeyText = function _normalizeKeyText(keyText) {
|
|
1504
|
+
if (!keyText) return '';
|
|
1505
|
+
|
|
1506
|
+
var normalized = keyText.toString().trim().toLowerCase();
|
|
1507
|
+
|
|
1508
|
+
// Convert keywords to percentages for comparison
|
|
1509
|
+
if (normalized === 'from') {
|
|
1510
|
+
return '0%';
|
|
1511
|
+
} else if (normalized === 'to') {
|
|
1512
|
+
return '100%';
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
return normalized;
|
|
1516
|
+
};
|
|
1517
|
+
|
|
1518
|
+
/**
|
|
1519
|
+
* Makes CSSKeyframesRule iterable over its cssRules.
|
|
1520
|
+
* Allows for...of loops and other iterable methods.
|
|
1521
|
+
*/
|
|
1522
|
+
if (typeof Symbol !== 'undefined' && Symbol.iterator) {
|
|
1523
|
+
CSSOM.CSSKeyframesRule.prototype[Symbol.iterator] = function() {
|
|
1524
|
+
var index = 0;
|
|
1525
|
+
var cssRules = this.cssRules;
|
|
1526
|
+
|
|
1527
|
+
return {
|
|
1528
|
+
next: function() {
|
|
1529
|
+
if (index < cssRules.length) {
|
|
1530
|
+
return { value: cssRules[index++], done: false };
|
|
1531
|
+
} else {
|
|
1532
|
+
return { done: true };
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* Adds indexed getters for direct access to cssRules by index.
|
|
1541
|
+
* This enables rule[0], rule[1], etc. access patterns.
|
|
1542
|
+
* Works in environments where Proxy is not available (like jsdom).
|
|
1543
|
+
*/
|
|
1544
|
+
CSSOM.CSSKeyframesRule.prototype._setupIndexedAccess = function() {
|
|
1545
|
+
// Remove any existing indexed properties
|
|
1546
|
+
for (var i = 0; i < 1000; i++) { // reasonable upper limit
|
|
1547
|
+
if (this.hasOwnProperty(i)) {
|
|
1548
|
+
delete this[i];
|
|
1549
|
+
} else {
|
|
1550
|
+
break;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// Add indexed getters for current cssRules
|
|
1555
|
+
for (var i = 0; i < this.cssRules.length; i++) {
|
|
1556
|
+
(function(index) {
|
|
1557
|
+
Object.defineProperty(this, index, {
|
|
1558
|
+
get: function() {
|
|
1559
|
+
return this.cssRules[index];
|
|
1560
|
+
},
|
|
1561
|
+
enumerable: false,
|
|
1562
|
+
configurable: true
|
|
1563
|
+
});
|
|
1564
|
+
}.call(this, i));
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
// Update length property
|
|
1568
|
+
Object.defineProperty(this, 'length', {
|
|
1569
|
+
get: function() {
|
|
1570
|
+
return this.cssRules.length;
|
|
1571
|
+
},
|
|
1572
|
+
enumerable: false,
|
|
1573
|
+
configurable: true
|
|
1574
|
+
});
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1144
1583
|
|
|
1145
1584
|
|
|
1146
1585
|
/**
|
|
@@ -1150,8 +1589,8 @@ Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", {
|
|
|
1150
1589
|
CSSOM.CSSKeyframeRule = function CSSKeyframeRule() {
|
|
1151
1590
|
CSSOM.CSSRule.call(this);
|
|
1152
1591
|
this.keyText = '';
|
|
1153
|
-
this.
|
|
1154
|
-
this.
|
|
1592
|
+
this.__style = new CSSOM.CSSStyleDeclaration();
|
|
1593
|
+
this.__style.parentRule = this;
|
|
1155
1594
|
};
|
|
1156
1595
|
|
|
1157
1596
|
CSSOM.CSSKeyframeRule.prototype = new CSSOM.CSSRule();
|
|
@@ -1161,15 +1600,31 @@ CSSOM.CSSKeyframeRule.prototype.type = 8;
|
|
|
1161
1600
|
//CSSOM.CSSKeyframeRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
|
|
1162
1601
|
//CSSOM.CSSKeyframeRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
|
|
1163
1602
|
|
|
1603
|
+
Object.defineProperty(CSSOM.CSSKeyframeRule.prototype, "style", {
|
|
1604
|
+
get: function() {
|
|
1605
|
+
return this.__style;
|
|
1606
|
+
},
|
|
1607
|
+
set: function(value) {
|
|
1608
|
+
if (typeof value === "string") {
|
|
1609
|
+
this.__style.cssText = value;
|
|
1610
|
+
} else {
|
|
1611
|
+
this.__style = value;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1164
1616
|
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframeRule.cpp
|
|
1165
1617
|
Object.defineProperty(CSSOM.CSSKeyframeRule.prototype, "cssText", {
|
|
1166
1618
|
get: function() {
|
|
1167
|
-
return this.keyText + " { " + this.style.cssText + " }
|
|
1619
|
+
return this.keyText + " { " + this.style.cssText + " }";
|
|
1168
1620
|
}
|
|
1169
1621
|
});
|
|
1170
1622
|
|
|
1171
1623
|
|
|
1172
1624
|
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
|
|
1173
1628
|
/**
|
|
1174
1629
|
* @constructor
|
|
1175
1630
|
* @see https://developer.mozilla.org/en/CSS/@-moz-document
|
|
@@ -1225,6 +1680,9 @@ CSSOM.MatcherList.prototype = {
|
|
|
1225
1680
|
|
|
1226
1681
|
|
|
1227
1682
|
|
|
1683
|
+
|
|
1684
|
+
|
|
1685
|
+
|
|
1228
1686
|
/**
|
|
1229
1687
|
* @constructor
|
|
1230
1688
|
* @see https://developer.mozilla.org/en/CSS/@-moz-document
|
|
@@ -1254,6 +1712,9 @@ Object.defineProperty(CSSOM.CSSDocumentRule.prototype, "cssText", {
|
|
|
1254
1712
|
|
|
1255
1713
|
|
|
1256
1714
|
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
|
|
1257
1718
|
/**
|
|
1258
1719
|
* @constructor
|
|
1259
1720
|
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSValue
|
|
@@ -1290,6 +1751,9 @@ CSSOM.CSSValue.prototype = {
|
|
|
1290
1751
|
|
|
1291
1752
|
|
|
1292
1753
|
|
|
1754
|
+
|
|
1755
|
+
|
|
1756
|
+
|
|
1293
1757
|
/**
|
|
1294
1758
|
* @constructor
|
|
1295
1759
|
* @see http://msdn.microsoft.com/en-us/library/ms537634(v=vs.85).aspx
|
|
@@ -1625,6 +2089,8 @@ CSSOM.CSSValueExpression.prototype._findMatchedIdx = function(token, idx, sep) {
|
|
|
1625
2089
|
|
|
1626
2090
|
|
|
1627
2091
|
|
|
2092
|
+
|
|
2093
|
+
|
|
1628
2094
|
/**
|
|
1629
2095
|
* @constructor
|
|
1630
2096
|
* @see https://drafts.csswg.org/css-cascade-5/#csslayerblockrule
|
|
@@ -1654,6 +2120,8 @@ Object.defineProperties(CSSOM.CSSLayerBlockRule.prototype, {
|
|
|
1654
2120
|
});
|
|
1655
2121
|
|
|
1656
2122
|
|
|
2123
|
+
|
|
2124
|
+
|
|
1657
2125
|
/**
|
|
1658
2126
|
* @constructor
|
|
1659
2127
|
* @see https://drafts.csswg.org/css-cascade-5/#csslayerstatementrule
|
|
@@ -1678,6 +2146,9 @@ Object.defineProperties(CSSOM.CSSLayerStatementRule.prototype, {
|
|
|
1678
2146
|
});
|
|
1679
2147
|
|
|
1680
2148
|
|
|
2149
|
+
|
|
2150
|
+
|
|
2151
|
+
|
|
1681
2152
|
/**
|
|
1682
2153
|
* @param {string} token
|
|
1683
2154
|
*/
|
|
@@ -2463,7 +2934,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2463
2934
|
}
|
|
2464
2935
|
|
|
2465
2936
|
if (parentRule) {
|
|
2466
|
-
styleRule.
|
|
2937
|
+
styleRule.__parentRule = parentRule;
|
|
2467
2938
|
ancestorRules.push(parentRule);
|
|
2468
2939
|
}
|
|
2469
2940
|
|
|
@@ -2473,48 +2944,48 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2473
2944
|
return match;
|
|
2474
2945
|
});
|
|
2475
2946
|
styleRule.style.__starts = i;
|
|
2476
|
-
styleRule.
|
|
2947
|
+
styleRule.__parentStyleSheet = styleSheet;
|
|
2477
2948
|
buffer = "";
|
|
2478
2949
|
state = "before-name";
|
|
2479
2950
|
} else if (state === "atBlock") {
|
|
2480
2951
|
mediaRule.media.mediaText = buffer.trim();
|
|
2481
2952
|
|
|
2482
2953
|
if (parentRule) {
|
|
2483
|
-
mediaRule.
|
|
2954
|
+
mediaRule.__parentRule = parentRule;
|
|
2484
2955
|
ancestorRules.push(parentRule);
|
|
2485
2956
|
}
|
|
2486
2957
|
|
|
2487
2958
|
currentScope = parentRule = mediaRule;
|
|
2488
|
-
mediaRule.
|
|
2959
|
+
mediaRule.__parentStyleSheet = styleSheet;
|
|
2489
2960
|
buffer = "";
|
|
2490
2961
|
state = "before-selector";
|
|
2491
2962
|
} else if (state === "containerBlock") {
|
|
2492
2963
|
containerRule.containerText = buffer.trim();
|
|
2493
2964
|
|
|
2494
2965
|
if (parentRule) {
|
|
2495
|
-
containerRule.
|
|
2966
|
+
containerRule.__parentRule = parentRule;
|
|
2496
2967
|
ancestorRules.push(parentRule);
|
|
2497
2968
|
}
|
|
2498
2969
|
currentScope = parentRule = containerRule;
|
|
2499
|
-
containerRule.
|
|
2970
|
+
containerRule.__parentStyleSheet = styleSheet;
|
|
2500
2971
|
buffer = "";
|
|
2501
2972
|
state = "before-selector";
|
|
2502
2973
|
} else if (state === "counterStyleBlock") {
|
|
2503
2974
|
// TODO: Validate counter-style name. At least that it cannot be empty nor multiple
|
|
2504
2975
|
counterStyleRule.name = buffer.trim().replace(/\n/g, "");
|
|
2505
2976
|
currentScope = parentRule = counterStyleRule;
|
|
2506
|
-
counterStyleRule.
|
|
2977
|
+
counterStyleRule.__parentStyleSheet = styleSheet;
|
|
2507
2978
|
buffer = "";
|
|
2508
2979
|
} else if (state === "conditionBlock") {
|
|
2509
2980
|
supportsRule.conditionText = buffer.trim();
|
|
2510
2981
|
|
|
2511
2982
|
if (parentRule) {
|
|
2512
|
-
supportsRule.
|
|
2983
|
+
supportsRule.__parentRule = parentRule;
|
|
2513
2984
|
ancestorRules.push(parentRule);
|
|
2514
2985
|
}
|
|
2515
2986
|
|
|
2516
2987
|
currentScope = parentRule = supportsRule;
|
|
2517
|
-
supportsRule.
|
|
2988
|
+
supportsRule.__parentStyleSheet = styleSheet;
|
|
2518
2989
|
buffer = "";
|
|
2519
2990
|
state = "before-selector";
|
|
2520
2991
|
} else if (state === "layerBlock") {
|
|
@@ -2524,12 +2995,12 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2524
2995
|
|
|
2525
2996
|
if (isValidName) {
|
|
2526
2997
|
if (parentRule) {
|
|
2527
|
-
layerBlockRule.
|
|
2998
|
+
layerBlockRule.__parentRule = parentRule;
|
|
2528
2999
|
ancestorRules.push(parentRule);
|
|
2529
3000
|
}
|
|
2530
3001
|
|
|
2531
3002
|
currentScope = parentRule = layerBlockRule;
|
|
2532
|
-
layerBlockRule.
|
|
3003
|
+
layerBlockRule.__parentStyleSheet = styleSheet;
|
|
2533
3004
|
}
|
|
2534
3005
|
buffer = "";
|
|
2535
3006
|
state = "before-selector";
|
|
@@ -2539,25 +3010,25 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2539
3010
|
}
|
|
2540
3011
|
|
|
2541
3012
|
currentScope = parentRule = hostRule;
|
|
2542
|
-
hostRule.
|
|
3013
|
+
hostRule.__parentStyleSheet = styleSheet;
|
|
2543
3014
|
buffer = "";
|
|
2544
3015
|
state = "before-selector";
|
|
2545
3016
|
} else if (state === "startingStyleRule-begin") {
|
|
2546
3017
|
if (parentRule) {
|
|
2547
|
-
startingStyleRule.
|
|
3018
|
+
startingStyleRule.__parentRule = parentRule;
|
|
2548
3019
|
ancestorRules.push(parentRule);
|
|
2549
3020
|
}
|
|
2550
3021
|
|
|
2551
3022
|
currentScope = parentRule = startingStyleRule;
|
|
2552
|
-
startingStyleRule.
|
|
3023
|
+
startingStyleRule.__parentStyleSheet = styleSheet;
|
|
2553
3024
|
buffer = "";
|
|
2554
3025
|
state = "before-selector";
|
|
2555
3026
|
|
|
2556
3027
|
} else if (state === "fontFaceRule-begin") {
|
|
2557
3028
|
if (parentRule) {
|
|
2558
|
-
fontFaceRule.
|
|
3029
|
+
fontFaceRule.__parentRule = parentRule;
|
|
2559
3030
|
}
|
|
2560
|
-
fontFaceRule.
|
|
3031
|
+
fontFaceRule.__parentStyleSheet = styleSheet;
|
|
2561
3032
|
styleRule = fontFaceRule;
|
|
2562
3033
|
buffer = "";
|
|
2563
3034
|
state = "before-name";
|
|
@@ -2565,9 +3036,9 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2565
3036
|
keyframesRule.name = buffer.trim();
|
|
2566
3037
|
if (parentRule) {
|
|
2567
3038
|
ancestorRules.push(parentRule);
|
|
2568
|
-
keyframesRule.
|
|
3039
|
+
keyframesRule.__parentRule = parentRule;
|
|
2569
3040
|
}
|
|
2570
|
-
keyframesRule.
|
|
3041
|
+
keyframesRule.__parentStyleSheet = styleSheet;
|
|
2571
3042
|
currentScope = parentRule = keyframesRule;
|
|
2572
3043
|
buffer = "";
|
|
2573
3044
|
state = "keyframeRule-begin";
|
|
@@ -2582,18 +3053,18 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2582
3053
|
documentRule.matcher.matcherText = buffer.trim();
|
|
2583
3054
|
if (parentRule) {
|
|
2584
3055
|
ancestorRules.push(parentRule);
|
|
2585
|
-
documentRule.
|
|
3056
|
+
documentRule.__parentRule = parentRule;
|
|
2586
3057
|
}
|
|
2587
3058
|
currentScope = parentRule = documentRule;
|
|
2588
|
-
documentRule.
|
|
3059
|
+
documentRule.__parentStyleSheet = styleSheet;
|
|
2589
3060
|
buffer = "";
|
|
2590
3061
|
state = "before-selector";
|
|
2591
3062
|
} else if (state === "before-name" || state === "name") {
|
|
2592
3063
|
if (styleRule.constructor.name === "CSSNestedDeclarations") {
|
|
2593
3064
|
if (styleRule.style.length) {
|
|
2594
3065
|
parentRule.cssRules.push(styleRule);
|
|
2595
|
-
styleRule.
|
|
2596
|
-
styleRule.
|
|
3066
|
+
styleRule.__parentRule = parentRule;
|
|
3067
|
+
styleRule.__parentStyleSheet = styleSheet;
|
|
2597
3068
|
ancestorRules.push(parentRule);
|
|
2598
3069
|
} else {
|
|
2599
3070
|
// If the styleRule is empty, we can assume that it's a nested selector
|
|
@@ -2602,7 +3073,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2602
3073
|
} else {
|
|
2603
3074
|
currentScope = parentRule = styleRule;
|
|
2604
3075
|
ancestorRules.push(parentRule);
|
|
2605
|
-
styleRule.
|
|
3076
|
+
styleRule.__parentStyleSheet = styleSheet;
|
|
2606
3077
|
}
|
|
2607
3078
|
|
|
2608
3079
|
styleRule = new CSSOM.CSSStyleRule();
|
|
@@ -2619,7 +3090,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2619
3090
|
}).join(', ');
|
|
2620
3091
|
}
|
|
2621
3092
|
styleRule.style.__starts = i - buffer.length;
|
|
2622
|
-
styleRule.
|
|
3093
|
+
styleRule.__parentRule = parentRule;
|
|
2623
3094
|
nestedSelectorRule = styleRule;
|
|
2624
3095
|
|
|
2625
3096
|
buffer = "";
|
|
@@ -2714,7 +3185,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2714
3185
|
});
|
|
2715
3186
|
if (isValid) {
|
|
2716
3187
|
importRule = new CSSOM.CSSImportRule();
|
|
2717
|
-
importRule.
|
|
3188
|
+
importRule.__parentStyleSheet = importRule.styleSheet.__parentStyleSheet = styleSheet;
|
|
2718
3189
|
importRule.cssText = buffer + character;
|
|
2719
3190
|
styleSheet.cssRules.push(importRule);
|
|
2720
3191
|
}
|
|
@@ -2732,7 +3203,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2732
3203
|
testNamespaceRule.cssText = buffer + character;
|
|
2733
3204
|
|
|
2734
3205
|
namespaceRule = testNamespaceRule;
|
|
2735
|
-
namespaceRule.
|
|
3206
|
+
namespaceRule.__parentStyleSheet = namespaceRule.styleSheet.__parentStyleSheet = styleSheet;
|
|
2736
3207
|
styleSheet.cssRules.push(namespaceRule);
|
|
2737
3208
|
|
|
2738
3209
|
// Track the namespace prefix for validation
|
|
@@ -2756,7 +3227,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2756
3227
|
|
|
2757
3228
|
if (!isInvalid) {
|
|
2758
3229
|
layerStatementRule = new CSSOM.CSSLayerStatementRule();
|
|
2759
|
-
layerStatementRule.
|
|
3230
|
+
layerStatementRule.__parentStyleSheet = styleSheet;
|
|
2760
3231
|
layerStatementRule.__starts = layerBlockRule.__starts;
|
|
2761
3232
|
layerStatementRule.__ends = i;
|
|
2762
3233
|
layerStatementRule.nameList = nameListStr;
|
|
@@ -2796,9 +3267,9 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2796
3267
|
}
|
|
2797
3268
|
|
|
2798
3269
|
if (parentRule) {
|
|
2799
|
-
styleRule.
|
|
3270
|
+
styleRule.__parentRule = parentRule;
|
|
2800
3271
|
}
|
|
2801
|
-
styleRule.
|
|
3272
|
+
styleRule.__parentStyleSheet = styleSheet;
|
|
2802
3273
|
|
|
2803
3274
|
if (currentScope === styleRule) {
|
|
2804
3275
|
currentScope = parentRule || styleSheet;
|
|
@@ -2924,7 +3395,7 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2924
3395
|
|| parentRule.constructor.name === "CSSLayerBlockRule"
|
|
2925
3396
|
|| parentRule.constructor.name === "CSSStartingStyleRule"
|
|
2926
3397
|
) {
|
|
2927
|
-
// parentRule.
|
|
3398
|
+
// parentRule.__parentRule = styleRule;
|
|
2928
3399
|
state = "before-name";
|
|
2929
3400
|
if (styleRule !== parentRule) {
|
|
2930
3401
|
styleRule = new CSSOM.CSSNestedDeclarations();
|
|
@@ -2981,6 +3452,9 @@ CSSOM.parse = function parse(token, errorHandler) {
|
|
|
2981
3452
|
|
|
2982
3453
|
|
|
2983
3454
|
|
|
3455
|
+
|
|
3456
|
+
|
|
3457
|
+
|
|
2984
3458
|
/**
|
|
2985
3459
|
* Produces a deep copy of stylesheet — the instance variables of stylesheet are copied recursively.
|
|
2986
3460
|
* @param {CSSStyleSheet|CSSOM.CSSStyleSheet} stylesheet
|