Subversion Repositories oidplus

Rev

Rev 1469 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1469 Rev 1470
Line 581... Line 581...
581
          https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb
581
          https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb
582
          https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl
582
          https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl
583
        */
583
        */
584
 
584
 
585
        // convert legacy color syntax
585
        // convert legacy color syntax
586
        $content = preg_replace('/(rgb|hsl)a?\(([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*([^\s\)]+)\)/i', '$1($2 $3 $4 / $5)', $content);
586
        $content = preg_replace('/(rgb)a?\(\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*,\s*([0,1]?(?:\.[0-9]*)?)\s*\)/i', '$1($2 $3 $4 / $5)', $content);
587
        $content = preg_replace('/(rgb|hsl)a?\(([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*([^,\s]+)\)/i', '$1($2 $3 $4)', $content);
587
        $content = preg_replace('/(rgb)a?\(\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*\)/i', '$1($2 $3 $4)', $content);
-
 
588
        $content = preg_replace('/(hsl)a?\(\s*([0-9]+(?:deg|grad|rad|turn)?)\s*,\s*([0-9]{1,3}%)\s*,\s*([0-9]{1,3}%)\s*,\s*([0,1]?(?:\.[0-9]*)?)\s*\)/i', '$1($2 $3 $4 / $5)', $content);
-
 
589
        $content = preg_replace('/(hsl)a?\(\s*([0-9]+(?:deg|grad|rad|turn)?)\s*,\s*([0-9]{1,3}%)\s*,\s*([0-9]{1,3}%)\s*\)/i', '$1($2 $3 $4)', $content);
588
 
590
 
589
        // convert `rgb` to `hex`
591
        // convert `rgb` to `hex`
590
        $dec = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])'; // [000-255] THX @ https://www.regular-expressions.info/numericranges.html
592
        $dec = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])';
591
 
-
 
592
        return preg_replace_callback(
593
        return preg_replace_callback(
593
            "/rgb\($dec $dec $dec\)/i",
594
            "/rgb\($dec $dec $dec\)/i",
594
            function ($match) {
595
            function ($match) {
595
                return sprintf('#%02x%02x%02x', $match[1], $match[2], $match[3]);
596
                return sprintf('#%02x%02x%02x', $match[1], $match[2], $match[3]);
596
            },
597
            },
Line 618... Line 619...
618
          https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklab
619
          https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklab
619
        */
620
        */
620
        $tag = '(rgb|hsl|hwb|(?:(?:ok)?(?:lch|lab)))';
621
        $tag = '(rgb|hsl|hwb|(?:(?:ok)?(?:lch|lab)))';
621
 
622
 
622
        // remove alpha channel if it's pointless ..
623
        // remove alpha channel if it's pointless ..
623
        $content = preg_replace('/' . $tag . '\(([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+\/\s+1(?:[\.\d]*|00%)?\)/i', '$1($2 $3 $4)', $content);
624
        $content = preg_replace('/' . $tag . '\(\s*([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+\/\s+1(?:(?:\.\d?)*|00%)?\s*\)/i', '$1($2 $3 $4)', $content);
624
 
625
 
625
        // replace `transparent` with shortcut ..
626
        // replace `transparent` with shortcut ..
626
        $content = preg_replace('/' . $tag . '\([^\s]+\s+[^\s]+\s+[^\s]+\s+\/\s+0(?:[\.0%]*)?\)/i', '#fff0', $content);
627
        $content = preg_replace('/' . $tag . '\(\s*[^\s]+\s+[^\s]+\s+[^\s]+\s+\/\s+0(?:[\.0%]*)?\s*\)/i', '#fff0', $content);
627
 
628
 
628
        return $content;
629
        return $content;
629
    }
630
    }
630
 
631
 
631
    /**
632
    /**