@@ -20,16 +20,16 @@ const mediaQueryListeners = new Map(); // MediaQuery -> MediaQueryList
20
20
/**
21
21
* Log debug messages
22
22
*/
23
- function log ( ...arguments_ ) {
23
+ const log = ( ...arguments_ ) => {
24
24
if ( polyfillOptions . debug ) {
25
25
console . log ( '[CSS if() Polyfill]' , ...arguments_ ) ;
26
26
}
27
- }
27
+ } ;
28
28
29
29
/**
30
30
* Check if browser has native CSS if() support
31
31
*/
32
- function hasNativeSupport ( ) {
32
+ const hasNativeSupport = ( ) => {
33
33
if ( globalThis . window === undefined || ! globalThis . CSS ) {
34
34
return false ;
35
35
}
@@ -43,17 +43,17 @@ function hasNativeSupport() {
43
43
} catch {
44
44
return false ;
45
45
}
46
- }
46
+ } ;
47
47
48
48
/**
49
49
* Evaluate a condition (style(), media(), supports())
50
50
*/
51
- function evaluateCondition (
51
+ const evaluateCondition = (
52
52
condition ,
53
53
registerForTracking = false ,
54
54
element = null ,
55
55
originalContent = null
56
- ) {
56
+ ) => {
57
57
condition = condition . trim ( ) ;
58
58
59
59
// Handle style() function
@@ -78,12 +78,12 @@ function evaluateCondition(
78
78
79
79
// Direct boolean evaluation
80
80
return evaluateBooleanCondition ( condition ) ;
81
- }
81
+ } ;
82
82
83
83
/**
84
84
* Evaluate style() condition
85
85
*/
86
- function evaluateStyleCondition ( condition ) {
86
+ const evaluateStyleCondition = ( condition ) => {
87
87
const match = condition . match ( / s t y l e \s * \( \s * ( [ ^ ) ] + ) \s * \) / ) ;
88
88
if ( ! match ) {
89
89
return false ;
@@ -115,17 +115,17 @@ function evaluateStyleCondition(condition) {
115
115
} finally {
116
116
testElement . remove ( ) ;
117
117
}
118
- }
118
+ } ;
119
119
120
120
/**
121
121
* Evaluate media() condition
122
122
*/
123
- function evaluateMediaCondition (
123
+ const evaluateMediaCondition = (
124
124
condition ,
125
125
registerForTracking = false ,
126
126
element = null ,
127
127
originalContent = null
128
- ) {
128
+ ) => {
129
129
const match = condition . match ( / m e d i a \s * \( \s * ( [ ^ ) ] + ) \s * \) / ) ;
130
130
if ( ! match ) {
131
131
return false ;
@@ -151,12 +151,12 @@ function evaluateMediaCondition(
151
151
} catch {
152
152
return false ;
153
153
}
154
- }
154
+ } ;
155
155
156
156
/**
157
157
* Evaluate supports() condition
158
158
*/
159
- function evaluateSupportsCondition ( condition ) {
159
+ const evaluateSupportsCondition = ( condition ) => {
160
160
const match = condition . match ( / s u p p o r t s \s * \( \s * ( [ ^ ) ] + ) \s * \) / ) ;
161
161
if ( ! match ) {
162
162
return false ;
@@ -169,12 +169,12 @@ function evaluateSupportsCondition(condition) {
169
169
} catch {
170
170
return false ;
171
171
}
172
- }
172
+ } ;
173
173
174
174
/**
175
175
* Evaluate boolean condition
176
176
*/
177
- function evaluateBooleanCondition ( condition ) {
177
+ const evaluateBooleanCondition = ( condition ) => {
178
178
// Simple boolean evaluation
179
179
const lowerCondition = condition . toLowerCase ( ) ;
180
180
@@ -187,12 +187,12 @@ function evaluateBooleanCondition(condition) {
187
187
}
188
188
189
189
return false ;
190
- }
190
+ } ;
191
191
192
192
/**
193
193
* Parse multiple conditions within a single if() function
194
194
*/
195
- function parseMultipleConditions ( ifContent ) {
195
+ const parseMultipleConditions = ( ifContent ) => {
196
196
const conditions = [ ] ;
197
197
let currentCondition = '' ;
198
198
let depth = 0 ;
@@ -243,12 +243,12 @@ function parseMultipleConditions(ifContent) {
243
243
}
244
244
245
245
return conditions ;
246
- }
246
+ } ;
247
247
248
248
/**
249
249
* Process a single condition within an if() function
250
250
*/
251
- function processSingleCondition ( condition ) {
251
+ const processSingleCondition = ( condition ) => {
252
252
// Check if this is an else clause
253
253
if ( condition . trim ( ) . startsWith ( 'else:' ) ) {
254
254
return {
@@ -305,17 +305,17 @@ function processSingleCondition(condition) {
305
305
condition : conditionPart ,
306
306
value : valuePart
307
307
} ;
308
- }
308
+ } ;
309
309
310
310
/**
311
311
* Process multiple conditions within a single if() function
312
312
*/
313
- function processMultipleConditions (
313
+ const processMultipleConditions = (
314
314
ifContent ,
315
315
registerForTracking = false ,
316
316
element = null ,
317
317
originalContent = null
318
- ) {
318
+ ) => {
319
319
// Handle malformed if() functions that don't contain proper syntax
320
320
if ( ! ifContent || ! ifContent . includes ( ':' ) ) {
321
321
log ( 'Malformed if() function - missing colon separator' ) ;
@@ -355,12 +355,12 @@ function processMultipleConditions(
355
355
// No condition matched, return else value
356
356
log ( `No condition matched, using else value: ${ elseValue } ` ) ;
357
357
return elseValue ;
358
- }
358
+ } ;
359
359
360
360
/**
361
361
* Find and extract if() functions with proper nested parentheses handling
362
362
*/
363
- function findIfFunctions ( text ) {
363
+ const findIfFunctions = ( text ) => {
364
364
const functions = [ ] ;
365
365
let index = 0 ;
366
366
@@ -429,12 +429,12 @@ function findIfFunctions(text) {
429
429
}
430
430
431
431
return functions ;
432
- }
432
+ } ;
433
433
434
434
/**
435
435
* Process CSS text manually
436
436
*/
437
- function processCSSText ( cssText , options = { } , element = null ) {
437
+ const processCSSText = ( cssText , options = { } , element = null ) => {
438
438
// Set options for this processing session
439
439
const originalOptions = { ...polyfillOptions } ;
440
440
polyfillOptions = { ...polyfillOptions , ...options } ;
@@ -488,12 +488,12 @@ function processCSSText(cssText, options = {}, element = null) {
488
488
// Restore original options
489
489
polyfillOptions = originalOptions ;
490
490
}
491
- }
491
+ } ;
492
492
493
493
/**
494
494
* Process a style element by rewriting its content
495
495
*/
496
- function processStyleElement ( styleElement ) {
496
+ const processStyleElement = ( styleElement ) => {
497
497
if ( styleElement . dataset . cssIfPolyfillProcessed ) {
498
498
return ; // Already processed
499
499
}
@@ -510,12 +510,12 @@ function processStyleElement(styleElement) {
510
510
styleElement . dataset . cssIfPolyfillProcessed = 'true' ;
511
511
log ( 'Style element processed, new length:' , processedContent . length ) ;
512
512
}
513
- }
513
+ } ;
514
514
515
515
/**
516
516
* Process all existing style elements
517
517
*/
518
- function processExistingStylesheets ( ) {
518
+ const processExistingStylesheets = ( ) => {
519
519
// Process inline style elements
520
520
const styleElements = document . querySelectorAll (
521
521
'style:not([data-css-if-polyfill-processed])'
@@ -533,7 +533,7 @@ function processExistingStylesheets() {
533
533
// but we can try to fetch and reprocess them if they're same-origin
534
534
processLinkStylesheet ( linkElement ) ;
535
535
}
536
- }
536
+ } ;
537
537
538
538
/**
539
539
* Process external stylesheet (if accessible)
@@ -595,12 +595,12 @@ async function processLinkStylesheet(linkElement) {
595
595
/**
596
596
* Register a media query for change tracking
597
597
*/
598
- function registerMediaQuery (
598
+ const registerMediaQuery = (
599
599
mediaQuery ,
600
600
element ,
601
601
originalContent ,
602
602
mediaQueryList = null
603
- ) {
603
+ ) => {
604
604
if ( ! mediaQueryRegistry . has ( mediaQuery ) ) {
605
605
mediaQueryRegistry . set ( mediaQuery , new Set ( ) ) ;
606
606
}
@@ -632,12 +632,12 @@ function registerMediaQuery(
632
632
) ;
633
633
}
634
634
}
635
- }
635
+ } ;
636
636
637
637
/**
638
638
* Reprocess elements when a media query changes
639
639
*/
640
- function reprocessElementsForMediaQuery ( mediaQuery ) {
640
+ const reprocessElementsForMediaQuery = ( mediaQuery ) => {
641
641
const elements = mediaQueryRegistry . get ( mediaQuery ) ;
642
642
if ( ! elements ) {
643
643
return ;
@@ -659,12 +659,12 @@ function reprocessElementsForMediaQuery(mediaQuery) {
659
659
) ;
660
660
}
661
661
}
662
- }
662
+ } ;
663
663
664
664
/**
665
665
* Clean up media query listeners
666
666
*/
667
- function cleanupMediaQueryListeners ( ) {
667
+ const cleanupMediaQueryListeners = ( ) => {
668
668
for ( const [
669
669
mediaQuery ,
670
670
{ mediaQueryList, listener }
@@ -679,12 +679,12 @@ function cleanupMediaQueryListeners() {
679
679
680
680
mediaQueryListeners . clear ( ) ;
681
681
mediaQueryRegistry . clear ( ) ;
682
- }
682
+ } ;
683
683
684
684
/**
685
685
* Observe stylesheet changes
686
686
*/
687
- function observeStylesheetChanges ( ) {
687
+ const observeStylesheetChanges = ( ) => {
688
688
// Create a MutationObserver to watch for new stylesheets
689
689
const observer = new MutationObserver ( ( mutations ) => {
690
690
for ( const mutation of mutations ) {
@@ -729,12 +729,12 @@ function observeStylesheetChanges() {
729
729
childList : true ,
730
730
subtree : true
731
731
} ) ;
732
- }
732
+ } ;
733
733
734
734
/**
735
735
* Initialize the polyfill
736
736
*/
737
- function init ( options = { } ) {
737
+ const init = ( options = { } ) => {
738
738
if ( globalThis . window === undefined ) {
739
739
throw new TypeError ( 'CSS if() polyfill requires a browser environment' ) ;
740
740
}
@@ -750,14 +750,14 @@ function init(options = {}) {
750
750
log ( 'Initializing CSS if() polyfill' ) ;
751
751
processExistingStylesheets ( ) ;
752
752
observeStylesheetChanges ( ) ;
753
- }
753
+ } ;
754
754
755
755
/**
756
756
* Public API to manually trigger processing
757
757
*/
758
- function refresh ( ) {
758
+ const refresh = ( ) => {
759
759
processExistingStylesheets ( ) ;
760
- }
760
+ } ;
761
761
762
762
// Auto-initialize if in browser and DOMContentLoaded
763
763
if ( globalThis . window !== undefined && typeof document !== 'undefined' ) {
0 commit comments