1
1
"use strict" ;
2
2
3
3
const allProperties = require ( "./generated/allProperties" ) ;
4
- const implementedProperties = require ( "./generated/implementedProperties" ) ;
5
- const generatedProperties = require ( "./generated/properties" ) ;
6
4
const {
7
5
borderProperties,
8
6
getPositionValue,
@@ -19,8 +17,6 @@ const {
19
17
prepareValue
20
18
} = require ( "./parsers" ) ;
21
19
const allExtraProperties = require ( "./utils/allExtraProperties" ) ;
22
- const { dashedToCamelCase } = require ( "./utils/camelize" ) ;
23
- const { getPropertyDescriptor } = require ( "./utils/propertyDescriptors" ) ;
24
20
const { asciiLowercase } = require ( "./utils/strings" ) ;
25
21
26
22
/**
@@ -118,6 +114,9 @@ class CSSStyleDeclaration {
118
114
} else if ( context . nodeType === 1 && Object . hasOwn ( context , "style" ) ) {
119
115
this . _global = context . ownerDocument . defaultView ;
120
116
this . _ownerNode = context ;
117
+ if ( typeof opt . onChange === "function" ) {
118
+ this . _onChange = opt . onChange ;
119
+ }
121
120
} else if ( Object . hasOwn ( context , "parentRule" ) ) {
122
121
this . _parentRule = context ;
123
122
// Find Window from the owner node of the StyleSheet.
@@ -127,10 +126,6 @@ class CSSStyleDeclaration {
127
126
}
128
127
}
129
128
}
130
- const { onChange } = opt ;
131
- if ( typeof onChange === "function" ) {
132
- this . _onChange = onChange ;
133
- }
134
129
if ( ! Object . hasOwn ( opt , "format" ) ) {
135
130
opt . format = "specifiedValue" ;
136
131
}
@@ -263,28 +258,6 @@ class CSSStyleDeclaration {
263
258
this . _length = len ;
264
259
}
265
260
266
- // Readonly
267
- get parentRule ( ) {
268
- return this . _parentRule ;
269
- }
270
-
271
- /**
272
- * @param {string } property
273
- */
274
- getPropertyPriority ( property ) {
275
- return this . _priorities . get ( property ) || "" ;
276
- }
277
-
278
- /**
279
- * @param {string } property
280
- */
281
- getPropertyValue ( property ) {
282
- if ( this . _values . has ( property ) ) {
283
- return this . _values . get ( property ) . toString ( ) ;
284
- }
285
- return "" ;
286
- }
287
-
288
261
/**
289
262
* @param {...number } args
290
263
*/
@@ -304,26 +277,18 @@ class CSSStyleDeclaration {
304
277
/**
305
278
* @param {string } property
306
279
*/
307
- removeProperty ( property ) {
308
- if ( this . _readonly ) {
309
- const msg = `Property ${ property } can not be modified.` ;
310
- const name = "NoModificationAllowedError" ;
311
- throw new this . _global . DOMException ( msg , name ) ;
312
- }
313
- if ( ! this . _values . has ( property ) ) {
314
- return "" ;
315
- }
316
- const prevValue = this . _values . get ( property ) ;
317
- this . _values . delete ( property ) ;
318
- this . _priorities . delete ( property ) ;
319
- const index = Array . prototype . indexOf . call ( this , property ) ;
320
- if ( index >= 0 ) {
321
- Array . prototype . splice . call ( this , index , 1 ) ;
322
- if ( typeof this . _onChange === "function" ) {
323
- this . _onChange ( this . cssText ) ;
324
- }
280
+ getPropertyValue ( property ) {
281
+ if ( this . _values . has ( property ) ) {
282
+ return this . _values . get ( property ) . toString ( ) ;
325
283
}
326
- return prevValue ;
284
+ return "" ;
285
+ }
286
+
287
+ /**
288
+ * @param {string } property
289
+ */
290
+ getPropertyPriority ( property ) {
291
+ return this . _priorities . get ( property ) || "" ;
327
292
}
328
293
329
294
/**
@@ -360,6 +325,36 @@ class CSSStyleDeclaration {
360
325
}
361
326
this [ property ] = value ;
362
327
}
328
+
329
+ /**
330
+ * @param {string } property
331
+ */
332
+ removeProperty ( property ) {
333
+ if ( this . _readonly ) {
334
+ const msg = `Property ${ property } can not be modified.` ;
335
+ const name = "NoModificationAllowedError" ;
336
+ throw new this . _global . DOMException ( msg , name ) ;
337
+ }
338
+ if ( ! this . _values . has ( property ) ) {
339
+ return "" ;
340
+ }
341
+ const prevValue = this . _values . get ( property ) ;
342
+ this . _values . delete ( property ) ;
343
+ this . _priorities . delete ( property ) ;
344
+ const index = Array . prototype . indexOf . call ( this , property ) ;
345
+ if ( index >= 0 ) {
346
+ Array . prototype . splice . call ( this , index , 1 ) ;
347
+ if ( typeof this . _onChange === "function" ) {
348
+ this . _onChange ( this . cssText ) ;
349
+ }
350
+ }
351
+ return prevValue ;
352
+ }
353
+
354
+ // Readonly
355
+ get parentRule ( ) {
356
+ return this . _parentRule ;
357
+ }
363
358
}
364
359
365
360
// Internal methods
@@ -614,23 +609,6 @@ Object.defineProperties(CSSStyleDeclaration.prototype, {
614
609
}
615
610
} ) ;
616
611
617
- // Properties
618
- Object . defineProperties ( CSSStyleDeclaration . prototype , generatedProperties ) ;
619
-
620
- // Additional properties
621
- [ ...allProperties , ...allExtraProperties ] . forEach ( ( property ) => {
622
- if ( ! implementedProperties . has ( property ) ) {
623
- const declaration = getPropertyDescriptor ( property ) ;
624
- Object . defineProperty ( CSSStyleDeclaration . prototype , property , declaration ) ;
625
- const camel = dashedToCamelCase ( property ) ;
626
- Object . defineProperty ( CSSStyleDeclaration . prototype , camel , declaration ) ;
627
- if ( / ^ w e b k i t [ A - Z ] / . test ( camel ) ) {
628
- const pascal = camel . replace ( / ^ w e b k i t / , "Webkit" ) ;
629
- Object . defineProperty ( CSSStyleDeclaration . prototype , pascal , declaration ) ;
630
- }
631
- }
632
- } ) ;
633
-
634
612
module . exports = {
635
613
CSSStyleDeclaration
636
614
} ;
0 commit comments