Version Description
- Initial version.
=
Download this release
Release Info
| Developer | claudiosanches |
| Plugin | |
| Version | 1.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0
- assets/js/customizer.js +191 -0
- assets/js/customizer.min.js +1 -0
- assets/js/tinycolor.js +1116 -0
- assets/js/tinycolor.min.js +1 -0
- includes/class-wc-colors-customizer.php +194 -0
- includes/libs/class-scss.php +4770 -0
- includes/views/scss.php +330 -0
- languages/woocommerce-colors.pot +67 -0
- readme.txt +62 -0
- screenshot-1.png +0 -0
- woocommerce-colors.php +169 -0
assets/js/customizer.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*global tinycolor */
|
| 2 |
+
( function( $ ) {
|
| 3 |
+
|
| 4 |
+
function isDark( color ) {
|
| 5 |
+
var rgb = tinycolor( color ).toRgb(),
|
| 6 |
+
brightness = ( ( rgb.r * 299 ) + ( rgb.g * 587 ) + ( rgb.b * 114 ) ) / 1000;
|
| 7 |
+
|
| 8 |
+
return brightness < 155;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
function changeColor( color, adjustment, saturation ) {
|
| 12 |
+
if ( isDark( color ) ) {
|
| 13 |
+
return tinycolor( color ).lighten( adjustment ).desaturate( saturation ).toString();
|
| 14 |
+
} else {
|
| 15 |
+
return tinycolor( color ).darken( adjustment ).desaturate( saturation ).toString();
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
function colorZeroPad( number ) {
|
| 20 |
+
total = 6 - number.length;
|
| 21 |
+
|
| 22 |
+
if ( 0 == total ) {
|
| 23 |
+
return number;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
for ( var i = 0; i < total; i++ ) {
|
| 27 |
+
number = '0' + number;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
return number;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function subtractColor( color, subtract ) {
|
| 34 |
+
return '#' + colorZeroPad( Math.abs( parseInt( color.replace( '#', '' ), 16 ) - parseInt( subtract.replace( '#', '' ), 16 ) ).toString( 16 ) );
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// Primary Color.
|
| 38 |
+
wp.customize( 'woocommerce_colors[primary]', function( value ) {
|
| 39 |
+
value.bind( function( primary ) {
|
| 40 |
+
var css = '',
|
| 41 |
+
primaryText = changeColor( primary, 50, 18 );
|
| 42 |
+
|
| 43 |
+
// Buttons.
|
| 44 |
+
css += '.woocommerce p.demo_store, .woocommerce a.button.alt, .woocommerce button.button.alt, .woocommerce input.button.alt, .woocommerce #respond input#submit.alt, .woocommerce #respond input#submit.alt.disabled, .woocommerce #respond input#submit.alt.disabled:hover, .woocommerce #respond input#submit.alt:disabled, .woocommerce #respond input#submit.alt:disabled:hover, .woocommerce #respond input#submit.alt:disabled[disabled], .woocommerce #respond input#submit.alt:disabled[disabled]:hover, .woocommerce a.button.alt.disabled, .woocommerce a.button.alt.disabled:hover, .woocommerce a.button.alt:disabled, .woocommerce a.button.alt:disabled:hover, .woocommerce a.button.alt:disabled[disabled], .woocommerce a.button.alt:disabled[disabled]:hover, .woocommerce button.button.alt.disabled, .woocommerce button.button.alt.disabled:hover, .woocommerce button.button.alt:disabled, .woocommerce button.button.alt:disabled:hover, .woocommerce button.button.alt:disabled[disabled], .woocommerce button.button.alt:disabled[disabled]:hover, .woocommerce input.button.alt.disabled, .woocommerce input.button.alt.disabled:hover, .woocommerce input.button.alt:disabled, .woocommerce input.button.alt:disabled:hover, .woocommerce input.button.alt:disabled[disabled], .woocommerce input.button.alt:disabled[disabled]:hover { background-color: ' + primary + '; color: ' + primaryText + ' }';
|
| 45 |
+
css += '.woocommerce #respond input#submit.alt:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover { background-color: ' + subtractColor( primary, '#111111' ) + '; color: ' + primaryText + ' }';
|
| 46 |
+
|
| 47 |
+
// Widget proce filter.
|
| 48 |
+
css += '.woocommerce .widget_price_filter .ui-slider .ui-slider-handle, .woocommerce .widget_price_filter .ui-slider .ui-slider-range { background-color: ' + primary + ' }';
|
| 49 |
+
css += '.woocommerce .price_slider_wrapper .ui-widget-content { background-color: ' + subtractColor( primary, '#444444' ) + ' }';
|
| 50 |
+
|
| 51 |
+
$( '#woocommerce-colors-primary' ).remove();
|
| 52 |
+
$( 'head' ).append( '<style id="woocommerce-colors-primary">' + css + '</style>' );
|
| 53 |
+
});
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
// Secondary Color.
|
| 57 |
+
wp.customize( 'woocommerce_colors[secondary]', function( value ) {
|
| 58 |
+
value.bind( function( secondary ) {
|
| 59 |
+
var css = '',
|
| 60 |
+
secondaryText = changeColor( secondary, 60, 18 );
|
| 61 |
+
|
| 62 |
+
// Messages.
|
| 63 |
+
css += '.woocommerce .woocommerce-message, .woocommerce .woocommerce-error, .woocommerce .woocommerce-info { background-color: ' + tinycolor( secondary ).lighten( 5 ).toString() + '; color: ' + secondaryText + ' }';
|
| 64 |
+
|
| 65 |
+
// Tabs.
|
| 66 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li { border: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; background-color: ' + secondary + '; }';
|
| 67 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li a { color: ' + secondaryText + '; }';
|
| 68 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li a:hover { color: ' + tinycolor( secondaryText ).lighten( 10 ).toString() + '; }';
|
| 69 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li:before, .woocommerce div.product .woocommerce-tabs ul.tabs li:after { border: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 70 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li:before { box-shadow: 2px 2px 0 ' + secondary + '; }';
|
| 71 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li:after { box-shadow: -2px 2px 0 ' + secondary + '; }';
|
| 72 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs:before { border-bottom: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 73 |
+
|
| 74 |
+
// Pagination.
|
| 75 |
+
css += '.woocommerce nav.woocommerce-pagination ul { border: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 76 |
+
css += '.woocommerce nav.woocommerce-pagination ul li { border-right: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 77 |
+
css += '.woocommerce nav.woocommerce-pagination ul li span.current, .woocommerce nav.woocommerce-pagination ul li a:hover, .woocommerce nav.woocommerce-pagination ul li a:focus { background: ' + secondary + '; color: ' + tinycolor( secondary ).darken( 40 ).toString() + '; }';
|
| 78 |
+
|
| 79 |
+
// Buttons.
|
| 80 |
+
css += '.woocommerce a.button, .woocommerce button.button, .woocommerce input.button, .woocommerce #respond input#submit { color: ' + secondaryText + '; background-color: ' + secondary + '; }';
|
| 81 |
+
css += '.woocommerce a.button:hover, .woocommerce button.button:hover, .woocommerce input.button:hover, .woocommerce #respond input#submit:hover { background-color: ' + subtractColor( secondary, '#111111' ) + '; color: ' + secondaryText + '; }';
|
| 82 |
+
css += '.woocommerce a.button:disabled:hover, .woocommerce a.button.disabled:hover, .woocommerce a.button:disabled[disabled]:hover, .woocommerce button.button:disabled:hover, .woocommerce button.button.disabled:hover, .woocommerce button.button:disabled[disabled]:hover, .woocommerce input.button:disabled:hover, .woocommerce input.button.disabled:hover, .woocommerce input.button:disabled[disabled]:hover, .woocommerce #respond input#submit:disabled:hover, .woocommerce #respond input#submit.disabled:hover, .woocommerce #respond input#submit:disabled[disabled]:hover { background-color: ' + secondary + '; }';
|
| 83 |
+
|
| 84 |
+
// Reviews.
|
| 85 |
+
css += '.woocommerce #reviews #comments ol.commentlist li img.avatar { background: ' + secondary + '; border: 1px solid ' + tinycolor( secondary ).darken( 4 ).toString() + '; }';
|
| 86 |
+
css += '.woocommerce #reviews #comments ol.commentlist li .comment-text { border: 1px solid ' + tinycolor( secondary ).darken( 4 ).toString() + '; }';
|
| 87 |
+
css += '.woocommerce #reviews #comments ol.commentlist #respond { border: 1px solid ' + tinycolor( secondary ).darken( 4 ).toString() + '; }';
|
| 88 |
+
|
| 89 |
+
// Ratings.
|
| 90 |
+
css += '.woocommerce .star-rating:before { color: ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 91 |
+
|
| 92 |
+
// Widget shopping cart.
|
| 93 |
+
css += '.woocommerce.widget_shopping_cart .total, .woocommerce .widget_shopping_cart .total { border-top: 3px double ' + secondary + '; }';
|
| 94 |
+
|
| 95 |
+
// Forms.
|
| 96 |
+
css += '.woocommerce form.login, .woocommerce form.checkout_coupon, .woocommerce form.register { border: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 97 |
+
|
| 98 |
+
// Order page.
|
| 99 |
+
css += '.woocommerce .order_details li { border-right: 1px dashed ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 100 |
+
|
| 101 |
+
// Cart page.
|
| 102 |
+
css += '.woocommerce-cart table.cart td.actions .coupon .input-text { border: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 103 |
+
css += '.woocommerce-cart .cart-collaterals .cart_totals tr td, .woocommerce-cart .cart-collaterals .cart_totals tr th { border-top: 1px solid ' + secondary + '; }';
|
| 104 |
+
|
| 105 |
+
// Checkout page.
|
| 106 |
+
css += '.woocommerce-checkout #payment { background: ' + secondary + '; }';
|
| 107 |
+
css += '.woocommerce-checkout #payment ul.payment_methods { border-bottom: 1px solid ' + tinycolor( secondary ).darken( 10 ).toString() + '; }';
|
| 108 |
+
css += '.woocommerce-checkout #payment div.payment_box { background-color: ' + tinycolor( secondary ).darken( 5 ).toString() + '; color: ' + secondaryText + '; }';
|
| 109 |
+
css += '.woocommerce-checkout #payment div.payment_box input.input-text, .woocommerce-checkout #payment div.payment_box textarea { border-color: ' + tinycolor( secondary ).darken( 15 ).toString() + '; border-top-color: ' + tinycolor( secondary ).darken( 20 ).toString() + '; }';
|
| 110 |
+
css += '.woocommerce-checkout #payment div.payment_box ::-webkit-input-placeholder { color: ' + tinycolor( secondary ).darken( 20 ).toString() + '; }';
|
| 111 |
+
css += '.woocommerce-checkout #payment div.payment_box :-moz-placeholder { color: ' + tinycolor( secondary ).darken( 20 ).toString() + '; }';
|
| 112 |
+
css += '.woocommerce-checkout #payment div.payment_box :-ms-input-placeholder { color: ' + tinycolor( secondary ).darken( 20 ).toString() + '; }';
|
| 113 |
+
css += '.woocommerce-checkout #payment div.payment_box:after { border: 8px solid ' + tinycolor( secondary ).darken( 5 ).toString() + '; }';
|
| 114 |
+
|
| 115 |
+
$( '#woocommerce-colors-secondary' ).remove();
|
| 116 |
+
$( 'head' ).append( '<style id="woocommerce-colors-secondary">' + css + '</style>' );
|
| 117 |
+
|
| 118 |
+
});
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
// Highlight Color.
|
| 122 |
+
wp.customize( 'woocommerce_colors[highlight]', function( value ) {
|
| 123 |
+
value.bind( function( highlight ) {
|
| 124 |
+
var css = '',
|
| 125 |
+
highlightText = changeColor( highlight, 60, 18 );
|
| 126 |
+
|
| 127 |
+
// Product page.
|
| 128 |
+
css += '.woocommerce div.product span.price, .woocommerce div.product p.price { color: ' + highlight + '; }';
|
| 129 |
+
css += '.woocommerce div.product .stock { color: ' + highlight + '; }';
|
| 130 |
+
|
| 131 |
+
// On Sale.
|
| 132 |
+
css += '.woocommerce span.onsale { background-color: ' + highlight + '; color: ' + highlightText + '; }';
|
| 133 |
+
|
| 134 |
+
// Products loop.
|
| 135 |
+
css += '.woocommerce ul.products li.product .price { color: ' + highlight + '; }';
|
| 136 |
+
css += '.woocommerce ul.products li.product .price .from { color: ' + tinycolor( highlight ).desaturate( 75 ).setAlpha( 0.5 ).toString() + '; }';
|
| 137 |
+
|
| 138 |
+
// Cart page.
|
| 139 |
+
css += '.woocommerce-cart .cart-collaterals .cart_totals .discount td { color: ' + highlight + '; }';
|
| 140 |
+
|
| 141 |
+
$( '#woocommerce-colors-highlight' ).remove();
|
| 142 |
+
$( 'head' ).append( '<style id="woocommerce-colors-highlight">' + css + '</style>' );
|
| 143 |
+
});
|
| 144 |
+
});
|
| 145 |
+
|
| 146 |
+
// Content Background Color.
|
| 147 |
+
wp.customize( 'woocommerce_colors[contentbg]', function( value ) {
|
| 148 |
+
value.bind( function( contentbg ) {
|
| 149 |
+
var css = '';
|
| 150 |
+
|
| 151 |
+
// Product page.
|
| 152 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li.active { background: ' + contentbg + '; border-bottom-color: ' + contentbg + '; }';
|
| 153 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li.active:before { box-shadow: 2px 2px 0 ' + contentbg + '; }';
|
| 154 |
+
css += '.woocommerce div.product .woocommerce-tabs ul.tabs li.active:after { box-shadow: -2px 2px 0 ' + contentbg + '; }';
|
| 155 |
+
|
| 156 |
+
$( '#woocommerce-colors-contentbg' ).remove();
|
| 157 |
+
$( 'head' ).append( '<style id="woocommerce-colors-contentbg">' + css + '</style>' );
|
| 158 |
+
});
|
| 159 |
+
});
|
| 160 |
+
|
| 161 |
+
// Subtext Color.
|
| 162 |
+
wp.customize( 'woocommerce_colors[subtext]', function( value ) {
|
| 163 |
+
value.bind( function( subtext ) {
|
| 164 |
+
var css = '';
|
| 165 |
+
|
| 166 |
+
// Notes.
|
| 167 |
+
css += '.woocommerce small.note { color: ' + subtext + '; }';
|
| 168 |
+
|
| 169 |
+
// Breadcrumbs.
|
| 170 |
+
css += '.woocommerce .woocommerce-breadcrumb { color: ' + subtext + '; }';
|
| 171 |
+
css += '.woocommerce .woocommerce-breadcrumb a { color: ' + subtext + '; }';
|
| 172 |
+
|
| 173 |
+
// Reviews.
|
| 174 |
+
css += '.woocommerce #reviews h2 small { color: ' + subtext + '; }';
|
| 175 |
+
css += '.woocommerce #reviews h2 small a { color: ' + subtext + '; }';
|
| 176 |
+
css += '.woocommerce #reviews #comments ol.commentlist li .meta { color: ' + subtext + '; }';
|
| 177 |
+
|
| 178 |
+
// Cart page.
|
| 179 |
+
css += '.woocommerce-cart .cart-collaterals .cart_totals p small { color: ' + subtext + '; }';
|
| 180 |
+
css += '.woocommerce-cart .cart-collaterals .cart_totals table small { color: ' + subtext + '; }';
|
| 181 |
+
|
| 182 |
+
// Checkout page.
|
| 183 |
+
css += '.woocommerce-checkout .checkout .create-account small { color: ' + subtext + '; }';
|
| 184 |
+
css += '.woocommerce-checkout #payment div.payment_box span.help { color: ' + subtext + '; }';
|
| 185 |
+
|
| 186 |
+
$( '#woocommerce-colors-subtext' ).remove();
|
| 187 |
+
$( 'head' ).append( '<style id="woocommerce-colors-subtext">' + css + '</style>' );
|
| 188 |
+
});
|
| 189 |
+
});
|
| 190 |
+
|
| 191 |
+
})( jQuery );
|
assets/js/customizer.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
| 1 |
+
!function(a){function b(a){var b=tinycolor(a).toRgb(),c=(299*b.r+587*b.g+114*b.b)/1e3;return 155>c}function c(a,c,d){return b(a)?tinycolor(a).lighten(c).desaturate(d).toString():tinycolor(a).darken(c).desaturate(d).toString()}function d(a){if(total=6-a.length,0==total)return a;for(var b=0;total>b;b++)a="0"+a;return a}function e(a,b){return"#"+d(Math.abs(parseInt(a.replace("#",""),16)-parseInt(b.replace("#",""),16)).toString(16))}wp.customize("woocommerce_colors[primary]",function(b){b.bind(function(b){var d="",f=c(b,50,18);d+=".woocommerce p.demo_store, .woocommerce a.button.alt, .woocommerce button.button.alt, .woocommerce input.button.alt, .woocommerce #respond input#submit.alt, .woocommerce #respond input#submit.alt.disabled, .woocommerce #respond input#submit.alt.disabled:hover, .woocommerce #respond input#submit.alt:disabled, .woocommerce #respond input#submit.alt:disabled:hover, .woocommerce #respond input#submit.alt:disabled[disabled], .woocommerce #respond input#submit.alt:disabled[disabled]:hover, .woocommerce a.button.alt.disabled, .woocommerce a.button.alt.disabled:hover, .woocommerce a.button.alt:disabled, .woocommerce a.button.alt:disabled:hover, .woocommerce a.button.alt:disabled[disabled], .woocommerce a.button.alt:disabled[disabled]:hover, .woocommerce button.button.alt.disabled, .woocommerce button.button.alt.disabled:hover, .woocommerce button.button.alt:disabled, .woocommerce button.button.alt:disabled:hover, .woocommerce button.button.alt:disabled[disabled], .woocommerce button.button.alt:disabled[disabled]:hover, .woocommerce input.button.alt.disabled, .woocommerce input.button.alt.disabled:hover, .woocommerce input.button.alt:disabled, .woocommerce input.button.alt:disabled:hover, .woocommerce input.button.alt:disabled[disabled], .woocommerce input.button.alt:disabled[disabled]:hover { background-color: "+b+"; color: "+f+" }",d+=".woocommerce #respond input#submit.alt:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover { background-color: "+e(b,"#111111")+"; color: "+f+" }",d+=".woocommerce .widget_price_filter .ui-slider .ui-slider-handle, .woocommerce .widget_price_filter .ui-slider .ui-slider-range { background-color: "+b+" }",d+=".woocommerce .price_slider_wrapper .ui-widget-content { background-color: "+e(b,"#444444")+" }",a("#woocommerce-colors-primary").remove(),a("head").append('<style id="woocommerce-colors-primary">'+d+"</style>")})}),wp.customize("woocommerce_colors[secondary]",function(b){b.bind(function(b){var d="",f=c(b,60,18);d+=".woocommerce .woocommerce-message, .woocommerce .woocommerce-error, .woocommerce .woocommerce-info { background-color: "+tinycolor(b).lighten(5).toString()+"; color: "+f+" }",d+=".woocommerce div.product .woocommerce-tabs ul.tabs li { border: 1px solid "+tinycolor(b).darken(10).toString()+"; background-color: "+b+"; }",d+=".woocommerce div.product .woocommerce-tabs ul.tabs li a { color: "+f+"; }",d+=".woocommerce div.product .woocommerce-tabs ul.tabs li a:hover { color: "+tinycolor(f).lighten(10).toString()+"; }",d+=".woocommerce div.product .woocommerce-tabs ul.tabs li:before, .woocommerce div.product .woocommerce-tabs ul.tabs li:after { border: 1px solid "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce div.product .woocommerce-tabs ul.tabs li:before { box-shadow: 2px 2px 0 "+b+"; }",d+=".woocommerce div.product .woocommerce-tabs ul.tabs li:after { box-shadow: -2px 2px 0 "+b+"; }",d+=".woocommerce div.product .woocommerce-tabs ul.tabs:before { border-bottom: 1px solid "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce nav.woocommerce-pagination ul { border: 1px solid "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce nav.woocommerce-pagination ul li { border-right: 1px solid "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce nav.woocommerce-pagination ul li span.current, .woocommerce nav.woocommerce-pagination ul li a:hover, .woocommerce nav.woocommerce-pagination ul li a:focus { background: "+b+"; color: "+tinycolor(b).darken(40).toString()+"; }",d+=".woocommerce a.button, .woocommerce button.button, .woocommerce input.button, .woocommerce #respond input#submit { color: "+f+"; background-color: "+b+"; }",d+=".woocommerce a.button:hover, .woocommerce button.button:hover, .woocommerce input.button:hover, .woocommerce #respond input#submit:hover { background-color: "+e(b,"#111111")+"; color: "+f+"; }",d+=".woocommerce a.button:disabled:hover, .woocommerce a.button.disabled:hover, .woocommerce a.button:disabled[disabled]:hover, .woocommerce button.button:disabled:hover, .woocommerce button.button.disabled:hover, .woocommerce button.button:disabled[disabled]:hover, .woocommerce input.button:disabled:hover, .woocommerce input.button.disabled:hover, .woocommerce input.button:disabled[disabled]:hover, .woocommerce #respond input#submit:disabled:hover, .woocommerce #respond input#submit.disabled:hover, .woocommerce #respond input#submit:disabled[disabled]:hover { background-color: "+b+"; }",d+=".woocommerce #reviews #comments ol.commentlist li img.avatar { background: "+b+"; border: 1px solid "+tinycolor(b).darken(4).toString()+"; }",d+=".woocommerce #reviews #comments ol.commentlist li .comment-text { border: 1px solid "+tinycolor(b).darken(4).toString()+"; }",d+=".woocommerce #reviews #comments ol.commentlist #respond { border: 1px solid "+tinycolor(b).darken(4).toString()+"; }",d+=".woocommerce .star-rating:before { color: "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce.widget_shopping_cart .total, .woocommerce .widget_shopping_cart .total { border-top: 3px double "+b+"; }",d+=".woocommerce form.login, .woocommerce form.checkout_coupon, .woocommerce form.register { border: 1px solid "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce .order_details li { border-right: 1px dashed "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce-cart table.cart td.actions .coupon .input-text { border: 1px solid "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce-cart .cart-collaterals .cart_totals tr td, .woocommerce-cart .cart-collaterals .cart_totals tr th { border-top: 1px solid "+b+"; }",d+=".woocommerce-checkout #payment { background: "+b+"; }",d+=".woocommerce-checkout #payment ul.payment_methods { border-bottom: 1px solid "+tinycolor(b).darken(10).toString()+"; }",d+=".woocommerce-checkout #payment div.payment_box { background-color: "+tinycolor(b).darken(5).toString()+"; color: "+f+"; }",d+=".woocommerce-checkout #payment div.payment_box input.input-text, .woocommerce-checkout #payment div.payment_box textarea { border-color: "+tinycolor(b).darken(15).toString()+"; border-top-color: "+tinycolor(b).darken(20).toString()+"; }",d+=".woocommerce-checkout #payment div.payment_box ::-webkit-input-placeholder { color: "+tinycolor(b).darken(20).toString()+"; }",d+=".woocommerce-checkout #payment div.payment_box :-moz-placeholder { color: "+tinycolor(b).darken(20).toString()+"; }",d+=".woocommerce-checkout #payment div.payment_box :-ms-input-placeholder { color: "+tinycolor(b).darken(20).toString()+"; }",d+=".woocommerce-checkout #payment div.payment_box:after { border: 8px solid "+tinycolor(b).darken(5).toString()+"; }",a("#woocommerce-colors-secondary").remove(),a("head").append('<style id="woocommerce-colors-secondary">'+d+"</style>")})}),wp.customize("woocommerce_colors[highlight]",function(b){b.bind(function(b){var d="",e=c(b,60,18);d+=".woocommerce div.product span.price, .woocommerce div.product p.price { color: "+b+"; }",d+=".woocommerce div.product .stock { color: "+b+"; }",d+=".woocommerce span.onsale { background-color: "+b+"; color: "+e+"; }",d+=".woocommerce ul.products li.product .price { color: "+b+"; }",d+=".woocommerce ul.products li.product .price .from { color: "+tinycolor(b).desaturate(75).setAlpha(.5).toString()+"; }",d+=".woocommerce-cart .cart-collaterals .cart_totals .discount td { color: "+b+"; }",a("#woocommerce-colors-highlight").remove(),a("head").append('<style id="woocommerce-colors-highlight">'+d+"</style>")})}),wp.customize("woocommerce_colors[contentbg]",function(b){b.bind(function(b){var c="";c+=".woocommerce div.product .woocommerce-tabs ul.tabs li.active { background: "+b+"; border-bottom-color: "+b+"; }",c+=".woocommerce div.product .woocommerce-tabs ul.tabs li.active:before { box-shadow: 2px 2px 0 "+b+"; }",c+=".woocommerce div.product .woocommerce-tabs ul.tabs li.active:after { box-shadow: -2px 2px 0 "+b+"; }",a("#woocommerce-colors-contentbg").remove(),a("head").append('<style id="woocommerce-colors-contentbg">'+c+"</style>")})}),wp.customize("woocommerce_colors[subtext]",function(b){b.bind(function(b){var c="";c+=".woocommerce small.note { color: "+b+"; }",c+=".woocommerce .woocommerce-breadcrumb { color: "+b+"; }",c+=".woocommerce .woocommerce-breadcrumb a { color: "+b+"; }",c+=".woocommerce #reviews h2 small { color: "+b+"; }",c+=".woocommerce #reviews h2 small a { color: "+b+"; }",c+=".woocommerce #reviews #comments ol.commentlist li .meta { color: "+b+"; }",c+=".woocommerce-cart .cart-collaterals .cart_totals p small { color: "+b+"; }",c+=".woocommerce-cart .cart-collaterals .cart_totals table small { color: "+b+"; }",c+=".woocommerce-checkout .checkout .create-account small { color: "+b+"; }",c+=".woocommerce-checkout #payment div.payment_box span.help { color: "+b+"; }",a("#woocommerce-colors-subtext").remove(),a("head").append('<style id="woocommerce-colors-subtext">'+c+"</style>")})})}(jQuery);
|
assets/js/tinycolor.js
ADDED
|
@@ -0,0 +1,1116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// TinyColor v1.1.1
|
| 2 |
+
// https://github.com/bgrins/TinyColor
|
| 3 |
+
// Brian Grinstead, MIT License
|
| 4 |
+
|
| 5 |
+
(function() {
|
| 6 |
+
|
| 7 |
+
var trimLeft = /^[\s,#]+/,
|
| 8 |
+
trimRight = /\s+$/,
|
| 9 |
+
tinyCounter = 0,
|
| 10 |
+
math = Math,
|
| 11 |
+
mathRound = math.round,
|
| 12 |
+
mathMin = math.min,
|
| 13 |
+
mathMax = math.max,
|
| 14 |
+
mathRandom = math.random;
|
| 15 |
+
|
| 16 |
+
var tinycolor = function tinycolor (color, opts) {
|
| 17 |
+
|
| 18 |
+
color = (color) ? color : '';
|
| 19 |
+
opts = opts || { };
|
| 20 |
+
|
| 21 |
+
// If input is already a tinycolor, return itself
|
| 22 |
+
if (color instanceof tinycolor) {
|
| 23 |
+
return color;
|
| 24 |
+
}
|
| 25 |
+
// If we are called as a function, call using new instead
|
| 26 |
+
if (!(this instanceof tinycolor)) {
|
| 27 |
+
return new tinycolor(color, opts);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
var rgb = inputToRGB(color);
|
| 31 |
+
this._originalInput = color,
|
| 32 |
+
this._r = rgb.r,
|
| 33 |
+
this._g = rgb.g,
|
| 34 |
+
this._b = rgb.b,
|
| 35 |
+
this._a = rgb.a,
|
| 36 |
+
this._roundA = mathRound(100*this._a) / 100,
|
| 37 |
+
this._format = opts.format || rgb.format;
|
| 38 |
+
this._gradientType = opts.gradientType;
|
| 39 |
+
|
| 40 |
+
// Don't let the range of [0,255] come back in [0,1].
|
| 41 |
+
// Potentially lose a little bit of precision here, but will fix issues where
|
| 42 |
+
// .5 gets interpreted as half of the total, instead of half of 1
|
| 43 |
+
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
|
| 44 |
+
if (this._r < 1) { this._r = mathRound(this._r); }
|
| 45 |
+
if (this._g < 1) { this._g = mathRound(this._g); }
|
| 46 |
+
if (this._b < 1) { this._b = mathRound(this._b); }
|
| 47 |
+
|
| 48 |
+
this._ok = rgb.ok;
|
| 49 |
+
this._tc_id = tinyCounter++;
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
tinycolor.prototype = {
|
| 53 |
+
isDark: function() {
|
| 54 |
+
return this.getBrightness() < 128;
|
| 55 |
+
},
|
| 56 |
+
isLight: function() {
|
| 57 |
+
return !this.isDark();
|
| 58 |
+
},
|
| 59 |
+
isValid: function() {
|
| 60 |
+
return this._ok;
|
| 61 |
+
},
|
| 62 |
+
getOriginalInput: function() {
|
| 63 |
+
return this._originalInput;
|
| 64 |
+
},
|
| 65 |
+
getFormat: function() {
|
| 66 |
+
return this._format;
|
| 67 |
+
},
|
| 68 |
+
getAlpha: function() {
|
| 69 |
+
return this._a;
|
| 70 |
+
},
|
| 71 |
+
getBrightness: function() {
|
| 72 |
+
var rgb = this.toRgb();
|
| 73 |
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
|
| 74 |
+
},
|
| 75 |
+
setAlpha: function(value) {
|
| 76 |
+
this._a = boundAlpha(value);
|
| 77 |
+
this._roundA = mathRound(100*this._a) / 100;
|
| 78 |
+
return this;
|
| 79 |
+
},
|
| 80 |
+
toHsv: function() {
|
| 81 |
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
| 82 |
+
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
|
| 83 |
+
},
|
| 84 |
+
toHsvString: function() {
|
| 85 |
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
| 86 |
+
var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
|
| 87 |
+
return (this._a == 1) ?
|
| 88 |
+
"hsv(" + h + ", " + s + "%, " + v + "%)" :
|
| 89 |
+
"hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
|
| 90 |
+
},
|
| 91 |
+
toHsl: function() {
|
| 92 |
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
| 93 |
+
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
|
| 94 |
+
},
|
| 95 |
+
toHslString: function() {
|
| 96 |
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
| 97 |
+
var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
|
| 98 |
+
return (this._a == 1) ?
|
| 99 |
+
"hsl(" + h + ", " + s + "%, " + l + "%)" :
|
| 100 |
+
"hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
|
| 101 |
+
},
|
| 102 |
+
toHex: function(allow3Char) {
|
| 103 |
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
| 104 |
+
},
|
| 105 |
+
toHexString: function(allow3Char) {
|
| 106 |
+
return '#' + this.toHex(allow3Char);
|
| 107 |
+
},
|
| 108 |
+
toHex8: function() {
|
| 109 |
+
return rgbaToHex(this._r, this._g, this._b, this._a);
|
| 110 |
+
},
|
| 111 |
+
toHex8String: function() {
|
| 112 |
+
return '#' + this.toHex8();
|
| 113 |
+
},
|
| 114 |
+
toRgb: function() {
|
| 115 |
+
return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
|
| 116 |
+
},
|
| 117 |
+
toRgbString: function() {
|
| 118 |
+
return (this._a == 1) ?
|
| 119 |
+
"rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
|
| 120 |
+
"rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
|
| 121 |
+
},
|
| 122 |
+
toPercentageRgb: function() {
|
| 123 |
+
return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
|
| 124 |
+
},
|
| 125 |
+
toPercentageRgbString: function() {
|
| 126 |
+
return (this._a == 1) ?
|
| 127 |
+
"rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
|
| 128 |
+
"rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
| 129 |
+
},
|
| 130 |
+
toName: function() {
|
| 131 |
+
if (this._a === 0) {
|
| 132 |
+
return "transparent";
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if (this._a < 1) {
|
| 136 |
+
return false;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
| 140 |
+
},
|
| 141 |
+
toFilter: function(secondColor) {
|
| 142 |
+
var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a);
|
| 143 |
+
var secondHex8String = hex8String;
|
| 144 |
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
| 145 |
+
|
| 146 |
+
if (secondColor) {
|
| 147 |
+
var s = tinycolor(secondColor);
|
| 148 |
+
secondHex8String = s.toHex8String();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
|
| 152 |
+
},
|
| 153 |
+
toString: function(format) {
|
| 154 |
+
var formatSet = !!format;
|
| 155 |
+
format = format || this._format;
|
| 156 |
+
|
| 157 |
+
var formattedString = false;
|
| 158 |
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
| 159 |
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "name");
|
| 160 |
+
|
| 161 |
+
if (needsAlphaFormat) {
|
| 162 |
+
// Special case for "transparent", all other non-alpha formats
|
| 163 |
+
// will return rgba when there is transparency.
|
| 164 |
+
if (format === "name" && this._a === 0) {
|
| 165 |
+
return this.toName();
|
| 166 |
+
}
|
| 167 |
+
return this.toRgbString();
|
| 168 |
+
}
|
| 169 |
+
if (format === "rgb") {
|
| 170 |
+
formattedString = this.toRgbString();
|
| 171 |
+
}
|
| 172 |
+
if (format === "prgb") {
|
| 173 |
+
formattedString = this.toPercentageRgbString();
|
| 174 |
+
}
|
| 175 |
+
if (format === "hex" || format === "hex6") {
|
| 176 |
+
formattedString = this.toHexString();
|
| 177 |
+
}
|
| 178 |
+
if (format === "hex3") {
|
| 179 |
+
formattedString = this.toHexString(true);
|
| 180 |
+
}
|
| 181 |
+
if (format === "hex8") {
|
| 182 |
+
formattedString = this.toHex8String();
|
| 183 |
+
}
|
| 184 |
+
if (format === "name") {
|
| 185 |
+
formattedString = this.toName();
|
| 186 |
+
}
|
| 187 |
+
if (format === "hsl") {
|
| 188 |
+
formattedString = this.toHslString();
|
| 189 |
+
}
|
| 190 |
+
if (format === "hsv") {
|
| 191 |
+
formattedString = this.toHsvString();
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
return formattedString || this.toHexString();
|
| 195 |
+
},
|
| 196 |
+
|
| 197 |
+
_applyModification: function(fn, args) {
|
| 198 |
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
| 199 |
+
this._r = color._r;
|
| 200 |
+
this._g = color._g;
|
| 201 |
+
this._b = color._b;
|
| 202 |
+
this.setAlpha(color._a);
|
| 203 |
+
return this;
|
| 204 |
+
},
|
| 205 |
+
lighten: function() {
|
| 206 |
+
return this._applyModification(lighten, arguments);
|
| 207 |
+
},
|
| 208 |
+
brighten: function() {
|
| 209 |
+
return this._applyModification(brighten, arguments);
|
| 210 |
+
},
|
| 211 |
+
darken: function() {
|
| 212 |
+
return this._applyModification(darken, arguments);
|
| 213 |
+
},
|
| 214 |
+
desaturate: function() {
|
| 215 |
+
return this._applyModification(desaturate, arguments);
|
| 216 |
+
},
|
| 217 |
+
saturate: function() {
|
| 218 |
+
return this._applyModification(saturate, arguments);
|
| 219 |
+
},
|
| 220 |
+
greyscale: function() {
|
| 221 |
+
return this._applyModification(greyscale, arguments);
|
| 222 |
+
},
|
| 223 |
+
spin: function() {
|
| 224 |
+
return this._applyModification(spin, arguments);
|
| 225 |
+
},
|
| 226 |
+
|
| 227 |
+
_applyCombination: function(fn, args) {
|
| 228 |
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
| 229 |
+
},
|
| 230 |
+
analogous: function() {
|
| 231 |
+
return this._applyCombination(analogous, arguments);
|
| 232 |
+
},
|
| 233 |
+
complement: function() {
|
| 234 |
+
return this._applyCombination(complement, arguments);
|
| 235 |
+
},
|
| 236 |
+
monochromatic: function() {
|
| 237 |
+
return this._applyCombination(monochromatic, arguments);
|
| 238 |
+
},
|
| 239 |
+
splitcomplement: function() {
|
| 240 |
+
return this._applyCombination(splitcomplement, arguments);
|
| 241 |
+
},
|
| 242 |
+
triad: function() {
|
| 243 |
+
return this._applyCombination(triad, arguments);
|
| 244 |
+
},
|
| 245 |
+
tetrad: function() {
|
| 246 |
+
return this._applyCombination(tetrad, arguments);
|
| 247 |
+
}
|
| 248 |
+
};
|
| 249 |
+
|
| 250 |
+
// If input is an object, force 1 into "1.0" to handle ratios properly
|
| 251 |
+
// String input requires "1.0" as input, so 1 will be treated as 1
|
| 252 |
+
tinycolor.fromRatio = function(color, opts) {
|
| 253 |
+
if (typeof color == "object") {
|
| 254 |
+
var newColor = {};
|
| 255 |
+
for (var i in color) {
|
| 256 |
+
if (color.hasOwnProperty(i)) {
|
| 257 |
+
if (i === "a") {
|
| 258 |
+
newColor[i] = color[i];
|
| 259 |
+
}
|
| 260 |
+
else {
|
| 261 |
+
newColor[i] = convertToPercentage(color[i]);
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
color = newColor;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
return tinycolor(color, opts);
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
// Given a string or object, convert that input to RGB
|
| 272 |
+
// Possible string inputs:
|
| 273 |
+
//
|
| 274 |
+
// "red"
|
| 275 |
+
// "#f00" or "f00"
|
| 276 |
+
// "#ff0000" or "ff0000"
|
| 277 |
+
// "#ff000000" or "ff000000"
|
| 278 |
+
// "rgb 255 0 0" or "rgb (255, 0, 0)"
|
| 279 |
+
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
|
| 280 |
+
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
|
| 281 |
+
// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
|
| 282 |
+
// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
|
| 283 |
+
// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
|
| 284 |
+
// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
|
| 285 |
+
//
|
| 286 |
+
function inputToRGB(color) {
|
| 287 |
+
|
| 288 |
+
var rgb = { r: 0, g: 0, b: 0 };
|
| 289 |
+
var a = 1;
|
| 290 |
+
var ok = false;
|
| 291 |
+
var format = false;
|
| 292 |
+
|
| 293 |
+
if (typeof color == "string") {
|
| 294 |
+
color = stringInputToObject(color);
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
if (typeof color == "object") {
|
| 298 |
+
if (color.hasOwnProperty("r") && color.hasOwnProperty("g") && color.hasOwnProperty("b")) {
|
| 299 |
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
| 300 |
+
ok = true;
|
| 301 |
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
| 302 |
+
}
|
| 303 |
+
else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("v")) {
|
| 304 |
+
color.s = convertToPercentage(color.s);
|
| 305 |
+
color.v = convertToPercentage(color.v);
|
| 306 |
+
rgb = hsvToRgb(color.h, color.s, color.v);
|
| 307 |
+
ok = true;
|
| 308 |
+
format = "hsv";
|
| 309 |
+
}
|
| 310 |
+
else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("l")) {
|
| 311 |
+
color.s = convertToPercentage(color.s);
|
| 312 |
+
color.l = convertToPercentage(color.l);
|
| 313 |
+
rgb = hslToRgb(color.h, color.s, color.l);
|
| 314 |
+
ok = true;
|
| 315 |
+
format = "hsl";
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
if (color.hasOwnProperty("a")) {
|
| 319 |
+
a = color.a;
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
a = boundAlpha(a);
|
| 324 |
+
|
| 325 |
+
return {
|
| 326 |
+
ok: ok,
|
| 327 |
+
format: color.format || format,
|
| 328 |
+
r: mathMin(255, mathMax(rgb.r, 0)),
|
| 329 |
+
g: mathMin(255, mathMax(rgb.g, 0)),
|
| 330 |
+
b: mathMin(255, mathMax(rgb.b, 0)),
|
| 331 |
+
a: a
|
| 332 |
+
};
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
// Conversion Functions
|
| 337 |
+
// --------------------
|
| 338 |
+
|
| 339 |
+
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
|
| 340 |
+
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
|
| 341 |
+
|
| 342 |
+
// `rgbToRgb`
|
| 343 |
+
// Handle bounds / percentage checking to conform to CSS color spec
|
| 344 |
+
// <http://www.w3.org/TR/css3-color/>
|
| 345 |
+
// *Assumes:* r, g, b in [0, 255] or [0, 1]
|
| 346 |
+
// *Returns:* { r, g, b } in [0, 255]
|
| 347 |
+
function rgbToRgb(r, g, b){
|
| 348 |
+
return {
|
| 349 |
+
r: bound01(r, 255) * 255,
|
| 350 |
+
g: bound01(g, 255) * 255,
|
| 351 |
+
b: bound01(b, 255) * 255
|
| 352 |
+
};
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
// `rgbToHsl`
|
| 356 |
+
// Converts an RGB color value to HSL.
|
| 357 |
+
// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
|
| 358 |
+
// *Returns:* { h, s, l } in [0,1]
|
| 359 |
+
function rgbToHsl(r, g, b) {
|
| 360 |
+
|
| 361 |
+
r = bound01(r, 255);
|
| 362 |
+
g = bound01(g, 255);
|
| 363 |
+
b = bound01(b, 255);
|
| 364 |
+
|
| 365 |
+
var max = mathMax(r, g, b), min = mathMin(r, g, b);
|
| 366 |
+
var h, s, l = (max + min) / 2;
|
| 367 |
+
|
| 368 |
+
if(max == min) {
|
| 369 |
+
h = s = 0; // achromatic
|
| 370 |
+
}
|
| 371 |
+
else {
|
| 372 |
+
var d = max - min;
|
| 373 |
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
| 374 |
+
switch(max) {
|
| 375 |
+
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
| 376 |
+
case g: h = (b - r) / d + 2; break;
|
| 377 |
+
case b: h = (r - g) / d + 4; break;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
h /= 6;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
return { h: h, s: s, l: l };
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
// `hslToRgb`
|
| 387 |
+
// Converts an HSL color value to RGB.
|
| 388 |
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
|
| 389 |
+
// *Returns:* { r, g, b } in the set [0, 255]
|
| 390 |
+
function hslToRgb(h, s, l) {
|
| 391 |
+
var r, g, b;
|
| 392 |
+
|
| 393 |
+
h = bound01(h, 360);
|
| 394 |
+
s = bound01(s, 100);
|
| 395 |
+
l = bound01(l, 100);
|
| 396 |
+
|
| 397 |
+
function hue2rgb(p, q, t) {
|
| 398 |
+
if(t < 0) t += 1;
|
| 399 |
+
if(t > 1) t -= 1;
|
| 400 |
+
if(t < 1/6) return p + (q - p) * 6 * t;
|
| 401 |
+
if(t < 1/2) return q;
|
| 402 |
+
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
|
| 403 |
+
return p;
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
if(s === 0) {
|
| 407 |
+
r = g = b = l; // achromatic
|
| 408 |
+
}
|
| 409 |
+
else {
|
| 410 |
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
| 411 |
+
var p = 2 * l - q;
|
| 412 |
+
r = hue2rgb(p, q, h + 1/3);
|
| 413 |
+
g = hue2rgb(p, q, h);
|
| 414 |
+
b = hue2rgb(p, q, h - 1/3);
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
return { r: r * 255, g: g * 255, b: b * 255 };
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
// `rgbToHsv`
|
| 421 |
+
// Converts an RGB color value to HSV
|
| 422 |
+
// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
|
| 423 |
+
// *Returns:* { h, s, v } in [0,1]
|
| 424 |
+
function rgbToHsv(r, g, b) {
|
| 425 |
+
|
| 426 |
+
r = bound01(r, 255);
|
| 427 |
+
g = bound01(g, 255);
|
| 428 |
+
b = bound01(b, 255);
|
| 429 |
+
|
| 430 |
+
var max = mathMax(r, g, b), min = mathMin(r, g, b);
|
| 431 |
+
var h, s, v = max;
|
| 432 |
+
|
| 433 |
+
var d = max - min;
|
| 434 |
+
s = max === 0 ? 0 : d / max;
|
| 435 |
+
|
| 436 |
+
if(max == min) {
|
| 437 |
+
h = 0; // achromatic
|
| 438 |
+
}
|
| 439 |
+
else {
|
| 440 |
+
switch(max) {
|
| 441 |
+
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
| 442 |
+
case g: h = (b - r) / d + 2; break;
|
| 443 |
+
case b: h = (r - g) / d + 4; break;
|
| 444 |
+
}
|
| 445 |
+
h /= 6;
|
| 446 |
+
}
|
| 447 |
+
return { h: h, s: s, v: v };
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
// `hsvToRgb`
|
| 451 |
+
// Converts an HSV color value to RGB.
|
| 452 |
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
|
| 453 |
+
// *Returns:* { r, g, b } in the set [0, 255]
|
| 454 |
+
function hsvToRgb(h, s, v) {
|
| 455 |
+
|
| 456 |
+
h = bound01(h, 360) * 6;
|
| 457 |
+
s = bound01(s, 100);
|
| 458 |
+
v = bound01(v, 100);
|
| 459 |
+
|
| 460 |
+
var i = math.floor(h),
|
| 461 |
+
f = h - i,
|
| 462 |
+
p = v * (1 - s),
|
| 463 |
+
q = v * (1 - f * s),
|
| 464 |
+
t = v * (1 - (1 - f) * s),
|
| 465 |
+
mod = i % 6,
|
| 466 |
+
r = [v, q, p, p, t, v][mod],
|
| 467 |
+
g = [t, v, v, q, p, p][mod],
|
| 468 |
+
b = [p, p, t, v, v, q][mod];
|
| 469 |
+
|
| 470 |
+
return { r: r * 255, g: g * 255, b: b * 255 };
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
// `rgbToHex`
|
| 474 |
+
// Converts an RGB color to hex
|
| 475 |
+
// Assumes r, g, and b are contained in the set [0, 255]
|
| 476 |
+
// Returns a 3 or 6 character hex
|
| 477 |
+
function rgbToHex(r, g, b, allow3Char) {
|
| 478 |
+
|
| 479 |
+
var hex = [
|
| 480 |
+
pad2(mathRound(r).toString(16)),
|
| 481 |
+
pad2(mathRound(g).toString(16)),
|
| 482 |
+
pad2(mathRound(b).toString(16))
|
| 483 |
+
];
|
| 484 |
+
|
| 485 |
+
// Return a 3 character hex if possible
|
| 486 |
+
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
| 487 |
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
return hex.join("");
|
| 491 |
+
}
|
| 492 |
+
// `rgbaToHex`
|
| 493 |
+
// Converts an RGBA color plus alpha transparency to hex
|
| 494 |
+
// Assumes r, g, b and a are contained in the set [0, 255]
|
| 495 |
+
// Returns an 8 character hex
|
| 496 |
+
function rgbaToHex(r, g, b, a) {
|
| 497 |
+
|
| 498 |
+
var hex = [
|
| 499 |
+
pad2(convertDecimalToHex(a)),
|
| 500 |
+
pad2(mathRound(r).toString(16)),
|
| 501 |
+
pad2(mathRound(g).toString(16)),
|
| 502 |
+
pad2(mathRound(b).toString(16))
|
| 503 |
+
];
|
| 504 |
+
|
| 505 |
+
return hex.join("");
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
// `equals`
|
| 509 |
+
// Can be called with any tinycolor input
|
| 510 |
+
tinycolor.equals = function (color1, color2) {
|
| 511 |
+
if (!color1 || !color2) { return false; }
|
| 512 |
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
| 513 |
+
};
|
| 514 |
+
tinycolor.random = function() {
|
| 515 |
+
return tinycolor.fromRatio({
|
| 516 |
+
r: mathRandom(),
|
| 517 |
+
g: mathRandom(),
|
| 518 |
+
b: mathRandom()
|
| 519 |
+
});
|
| 520 |
+
};
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
// Modification Functions
|
| 524 |
+
// ----------------------
|
| 525 |
+
// Thanks to less.js for some of the basics here
|
| 526 |
+
// <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
|
| 527 |
+
|
| 528 |
+
function desaturate(color, amount) {
|
| 529 |
+
amount = (amount === 0) ? 0 : (amount || 10);
|
| 530 |
+
var hsl = tinycolor(color).toHsl();
|
| 531 |
+
hsl.s -= amount / 100;
|
| 532 |
+
hsl.s = clamp01(hsl.s);
|
| 533 |
+
return tinycolor(hsl);
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
function saturate(color, amount) {
|
| 537 |
+
amount = (amount === 0) ? 0 : (amount || 10);
|
| 538 |
+
var hsl = tinycolor(color).toHsl();
|
| 539 |
+
hsl.s += amount / 100;
|
| 540 |
+
hsl.s = clamp01(hsl.s);
|
| 541 |
+
return tinycolor(hsl);
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
function greyscale(color) {
|
| 545 |
+
return tinycolor(color).desaturate(100);
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
function lighten (color, amount) {
|
| 549 |
+
amount = (amount === 0) ? 0 : (amount || 10);
|
| 550 |
+
var hsl = tinycolor(color).toHsl();
|
| 551 |
+
hsl.l += amount / 100;
|
| 552 |
+
hsl.l = clamp01(hsl.l);
|
| 553 |
+
return tinycolor(hsl);
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
function brighten(color, amount) {
|
| 557 |
+
amount = (amount === 0) ? 0 : (amount || 10);
|
| 558 |
+
var rgb = tinycolor(color).toRgb();
|
| 559 |
+
rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
|
| 560 |
+
rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
|
| 561 |
+
rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
|
| 562 |
+
return tinycolor(rgb);
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
function darken (color, amount) {
|
| 566 |
+
amount = (amount === 0) ? 0 : (amount || 10);
|
| 567 |
+
var hsl = tinycolor(color).toHsl();
|
| 568 |
+
hsl.l -= amount / 100;
|
| 569 |
+
hsl.l = clamp01(hsl.l);
|
| 570 |
+
return tinycolor(hsl);
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
// Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
|
| 574 |
+
// Values outside of this range will be wrapped into this range.
|
| 575 |
+
function spin(color, amount) {
|
| 576 |
+
var hsl = tinycolor(color).toHsl();
|
| 577 |
+
var hue = (mathRound(hsl.h) + amount) % 360;
|
| 578 |
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
| 579 |
+
return tinycolor(hsl);
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
// Combination Functions
|
| 583 |
+
// ---------------------
|
| 584 |
+
// Thanks to jQuery xColor for some of the ideas behind these
|
| 585 |
+
// <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
|
| 586 |
+
|
| 587 |
+
function complement(color) {
|
| 588 |
+
var hsl = tinycolor(color).toHsl();
|
| 589 |
+
hsl.h = (hsl.h + 180) % 360;
|
| 590 |
+
return tinycolor(hsl);
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
function triad(color) {
|
| 594 |
+
var hsl = tinycolor(color).toHsl();
|
| 595 |
+
var h = hsl.h;
|
| 596 |
+
return [
|
| 597 |
+
tinycolor(color),
|
| 598 |
+
tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
|
| 599 |
+
tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
|
| 600 |
+
];
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
function tetrad(color) {
|
| 604 |
+
var hsl = tinycolor(color).toHsl();
|
| 605 |
+
var h = hsl.h;
|
| 606 |
+
return [
|
| 607 |
+
tinycolor(color),
|
| 608 |
+
tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
|
| 609 |
+
tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
|
| 610 |
+
tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
|
| 611 |
+
];
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
function splitcomplement(color) {
|
| 615 |
+
var hsl = tinycolor(color).toHsl();
|
| 616 |
+
var h = hsl.h;
|
| 617 |
+
return [
|
| 618 |
+
tinycolor(color),
|
| 619 |
+
tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
|
| 620 |
+
tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
|
| 621 |
+
];
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
function analogous(color, results, slices) {
|
| 625 |
+
results = results || 6;
|
| 626 |
+
slices = slices || 30;
|
| 627 |
+
|
| 628 |
+
var hsl = tinycolor(color).toHsl();
|
| 629 |
+
var part = 360 / slices;
|
| 630 |
+
var ret = [tinycolor(color)];
|
| 631 |
+
|
| 632 |
+
for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
|
| 633 |
+
hsl.h = (hsl.h + part) % 360;
|
| 634 |
+
ret.push(tinycolor(hsl));
|
| 635 |
+
}
|
| 636 |
+
return ret;
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
function monochromatic(color, results) {
|
| 640 |
+
results = results || 6;
|
| 641 |
+
var hsv = tinycolor(color).toHsv();
|
| 642 |
+
var h = hsv.h, s = hsv.s, v = hsv.v;
|
| 643 |
+
var ret = [];
|
| 644 |
+
var modification = 1 / results;
|
| 645 |
+
|
| 646 |
+
while (results--) {
|
| 647 |
+
ret.push(tinycolor({ h: h, s: s, v: v}));
|
| 648 |
+
v = (v + modification) % 1;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
return ret;
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
// Utility Functions
|
| 655 |
+
// ---------------------
|
| 656 |
+
|
| 657 |
+
tinycolor.mix = function(color1, color2, amount) {
|
| 658 |
+
amount = (amount === 0) ? 0 : (amount || 50);
|
| 659 |
+
|
| 660 |
+
var rgb1 = tinycolor(color1).toRgb();
|
| 661 |
+
var rgb2 = tinycolor(color2).toRgb();
|
| 662 |
+
|
| 663 |
+
var p = amount / 100;
|
| 664 |
+
var w = p * 2 - 1;
|
| 665 |
+
var a = rgb2.a - rgb1.a;
|
| 666 |
+
|
| 667 |
+
var w1;
|
| 668 |
+
|
| 669 |
+
if (w * a == -1) {
|
| 670 |
+
w1 = w;
|
| 671 |
+
} else {
|
| 672 |
+
w1 = (w + a) / (1 + w * a);
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
w1 = (w1 + 1) / 2;
|
| 676 |
+
|
| 677 |
+
var w2 = 1 - w1;
|
| 678 |
+
|
| 679 |
+
var rgba = {
|
| 680 |
+
r: rgb2.r * w1 + rgb1.r * w2,
|
| 681 |
+
g: rgb2.g * w1 + rgb1.g * w2,
|
| 682 |
+
b: rgb2.b * w1 + rgb1.b * w2,
|
| 683 |
+
a: rgb2.a * p + rgb1.a * (1 - p)
|
| 684 |
+
};
|
| 685 |
+
|
| 686 |
+
return tinycolor(rgba);
|
| 687 |
+
};
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
// Readability Functions
|
| 691 |
+
// ---------------------
|
| 692 |
+
// <http://www.w3.org/TR/AERT#color-contrast>
|
| 693 |
+
|
| 694 |
+
// `readability`
|
| 695 |
+
// Analyze the 2 colors and returns an object with the following properties:
|
| 696 |
+
// `brightness`: difference in brightness between the two colors
|
| 697 |
+
// `color`: difference in color/hue between the two colors
|
| 698 |
+
tinycolor.readability = function(color1, color2) {
|
| 699 |
+
var c1 = tinycolor(color1);
|
| 700 |
+
var c2 = tinycolor(color2);
|
| 701 |
+
var rgb1 = c1.toRgb();
|
| 702 |
+
var rgb2 = c2.toRgb();
|
| 703 |
+
var brightnessA = c1.getBrightness();
|
| 704 |
+
var brightnessB = c2.getBrightness();
|
| 705 |
+
var colorDiff = (
|
| 706 |
+
Math.max(rgb1.r, rgb2.r) - Math.min(rgb1.r, rgb2.r) +
|
| 707 |
+
Math.max(rgb1.g, rgb2.g) - Math.min(rgb1.g, rgb2.g) +
|
| 708 |
+
Math.max(rgb1.b, rgb2.b) - Math.min(rgb1.b, rgb2.b)
|
| 709 |
+
);
|
| 710 |
+
|
| 711 |
+
return {
|
| 712 |
+
brightness: Math.abs(brightnessA - brightnessB),
|
| 713 |
+
color: colorDiff
|
| 714 |
+
};
|
| 715 |
+
};
|
| 716 |
+
|
| 717 |
+
// `readable`
|
| 718 |
+
// http://www.w3.org/TR/AERT#color-contrast
|
| 719 |
+
// Ensure that foreground and background color combinations provide sufficient contrast.
|
| 720 |
+
// *Example*
|
| 721 |
+
// tinycolor.isReadable("#000", "#111") => false
|
| 722 |
+
tinycolor.isReadable = function(color1, color2) {
|
| 723 |
+
var readability = tinycolor.readability(color1, color2);
|
| 724 |
+
return readability.brightness > 125 && readability.color > 500;
|
| 725 |
+
};
|
| 726 |
+
|
| 727 |
+
// `mostReadable`
|
| 728 |
+
// Given a base color and a list of possible foreground or background
|
| 729 |
+
// colors for that base, returns the most readable color.
|
| 730 |
+
// *Example*
|
| 731 |
+
// tinycolor.mostReadable("#123", ["#fff", "#000"]) => "#000"
|
| 732 |
+
tinycolor.mostReadable = function(baseColor, colorList) {
|
| 733 |
+
var bestColor = null;
|
| 734 |
+
var bestScore = 0;
|
| 735 |
+
var bestIsReadable = false;
|
| 736 |
+
for (var i=0; i < colorList.length; i++) {
|
| 737 |
+
|
| 738 |
+
// We normalize both around the "acceptable" breaking point,
|
| 739 |
+
// but rank brightness constrast higher than hue.
|
| 740 |
+
|
| 741 |
+
var readability = tinycolor.readability(baseColor, colorList[i]);
|
| 742 |
+
var readable = readability.brightness > 125 && readability.color > 500;
|
| 743 |
+
var score = 3 * (readability.brightness / 125) + (readability.color / 500);
|
| 744 |
+
|
| 745 |
+
if ((readable && ! bestIsReadable) ||
|
| 746 |
+
(readable && bestIsReadable && score > bestScore) ||
|
| 747 |
+
((! readable) && (! bestIsReadable) && score > bestScore)) {
|
| 748 |
+
bestIsReadable = readable;
|
| 749 |
+
bestScore = score;
|
| 750 |
+
bestColor = tinycolor(colorList[i]);
|
| 751 |
+
}
|
| 752 |
+
}
|
| 753 |
+
return bestColor;
|
| 754 |
+
};
|
| 755 |
+
|
| 756 |
+
|
| 757 |
+
// Big List of Colors
|
| 758 |
+
// ------------------
|
| 759 |
+
// <http://www.w3.org/TR/css3-color/#svg-color>
|
| 760 |
+
var names = tinycolor.names = {
|
| 761 |
+
aliceblue: "f0f8ff",
|
| 762 |
+
antiquewhite: "faebd7",
|
| 763 |
+
aqua: "0ff",
|
| 764 |
+
aquamarine: "7fffd4",
|
| 765 |
+
azure: "f0ffff",
|
| 766 |
+
beige: "f5f5dc",
|
| 767 |
+
bisque: "ffe4c4",
|
| 768 |
+
black: "000",
|
| 769 |
+
blanchedalmond: "ffebcd",
|
| 770 |
+
blue: "00f",
|
| 771 |
+
blueviolet: "8a2be2",
|
| 772 |
+
brown: "a52a2a",
|
| 773 |
+
burlywood: "deb887",
|
| 774 |
+
burntsienna: "ea7e5d",
|
| 775 |
+
cadetblue: "5f9ea0",
|
| 776 |
+
chartreuse: "7fff00",
|
| 777 |
+
chocolate: "d2691e",
|
| 778 |
+
coral: "ff7f50",
|
| 779 |
+
cornflowerblue: "6495ed",
|
| 780 |
+
cornsilk: "fff8dc",
|
| 781 |
+
crimson: "dc143c",
|
| 782 |
+
cyan: "0ff",
|
| 783 |
+
darkblue: "00008b",
|
| 784 |
+
darkcyan: "008b8b",
|
| 785 |
+
darkgoldenrod: "b8860b",
|
| 786 |
+
darkgray: "a9a9a9",
|
| 787 |
+
darkgreen: "006400",
|
| 788 |
+
darkgrey: "a9a9a9",
|
| 789 |
+
darkkhaki: "bdb76b",
|
| 790 |
+
darkmagenta: "8b008b",
|
| 791 |
+
darkolivegreen: "556b2f",
|
| 792 |
+
darkorange: "ff8c00",
|
| 793 |
+
darkorchid: "9932cc",
|
| 794 |
+
darkred: "8b0000",
|
| 795 |
+
darksalmon: "e9967a",
|
| 796 |
+
darkseagreen: "8fbc8f",
|
| 797 |
+
darkslateblue: "483d8b",
|
| 798 |
+
darkslategray: "2f4f4f",
|
| 799 |
+
darkslategrey: "2f4f4f",
|
| 800 |
+
darkturquoise: "00ced1",
|
| 801 |
+
darkviolet: "9400d3",
|
| 802 |
+
deeppink: "ff1493",
|
| 803 |
+
deepskyblue: "00bfff",
|
| 804 |
+
dimgray: "696969",
|
| 805 |
+
dimgrey: "696969",
|
| 806 |
+
dodgerblue: "1e90ff",
|
| 807 |
+
firebrick: "b22222",
|
| 808 |
+
floralwhite: "fffaf0",
|
| 809 |
+
forestgreen: "228b22",
|
| 810 |
+
fuchsia: "f0f",
|
| 811 |
+
gainsboro: "dcdcdc",
|
| 812 |
+
ghostwhite: "f8f8ff",
|
| 813 |
+
gold: "ffd700",
|
| 814 |
+
goldenrod: "daa520",
|
| 815 |
+
gray: "808080",
|
| 816 |
+
green: "008000",
|
| 817 |
+
greenyellow: "adff2f",
|
| 818 |
+
grey: "808080",
|
| 819 |
+
honeydew: "f0fff0",
|
| 820 |
+
hotpink: "ff69b4",
|
| 821 |
+
indianred: "cd5c5c",
|
| 822 |
+
indigo: "4b0082",
|
| 823 |
+
ivory: "fffff0",
|
| 824 |
+
khaki: "f0e68c",
|
| 825 |
+
lavender: "e6e6fa",
|
| 826 |
+
lavenderblush: "fff0f5",
|
| 827 |
+
lawngreen: "7cfc00",
|
| 828 |
+
lemonchiffon: "fffacd",
|
| 829 |
+
lightblue: "add8e6",
|
| 830 |
+
lightcoral: "f08080",
|
| 831 |
+
lightcyan: "e0ffff",
|
| 832 |
+
lightgoldenrodyellow: "fafad2",
|
| 833 |
+
lightgray: "d3d3d3",
|
| 834 |
+
lightgreen: "90ee90",
|
| 835 |
+
lightgrey: "d3d3d3",
|
| 836 |
+
lightpink: "ffb6c1",
|
| 837 |
+
lightsalmon: "ffa07a",
|
| 838 |
+
lightseagreen: "20b2aa",
|
| 839 |
+
lightskyblue: "87cefa",
|
| 840 |
+
lightslategray: "789",
|
| 841 |
+
lightslategrey: "789",
|
| 842 |
+
lightsteelblue: "b0c4de",
|
| 843 |
+
lightyellow: "ffffe0",
|
| 844 |
+
lime: "0f0",
|
| 845 |
+
limegreen: "32cd32",
|
| 846 |
+
linen: "faf0e6",
|
| 847 |
+
magenta: "f0f",
|
| 848 |
+
maroon: "800000",
|
| 849 |
+
mediumaquamarine: "66cdaa",
|
| 850 |
+
mediumblue: "0000cd",
|
| 851 |
+
mediumorchid: "ba55d3",
|
| 852 |
+
mediumpurple: "9370db",
|
| 853 |
+
mediumseagreen: "3cb371",
|
| 854 |
+
mediumslateblue: "7b68ee",
|
| 855 |
+
mediumspringgreen: "00fa9a",
|
| 856 |
+
mediumturquoise: "48d1cc",
|
| 857 |
+
mediumvioletred: "c71585",
|
| 858 |
+
midnightblue: "191970",
|
| 859 |
+
mintcream: "f5fffa",
|
| 860 |
+
mistyrose: "ffe4e1",
|
| 861 |
+
moccasin: "ffe4b5",
|
| 862 |
+
navajowhite: "ffdead",
|
| 863 |
+
navy: "000080",
|
| 864 |
+
oldlace: "fdf5e6",
|
| 865 |
+
olive: "808000",
|
| 866 |
+
olivedrab: "6b8e23",
|
| 867 |
+
orange: "ffa500",
|
| 868 |
+
orangered: "ff4500",
|
| 869 |
+
orchid: "da70d6",
|
| 870 |
+
palegoldenrod: "eee8aa",
|
| 871 |
+
palegreen: "98fb98",
|
| 872 |
+
paleturquoise: "afeeee",
|
| 873 |
+
palevioletred: "db7093",
|
| 874 |
+
papayawhip: "ffefd5",
|
| 875 |
+
peachpuff: "ffdab9",
|
| 876 |
+
peru: "cd853f",
|
| 877 |
+
pink: "ffc0cb",
|
| 878 |
+
plum: "dda0dd",
|
| 879 |
+
powderblue: "b0e0e6",
|
| 880 |
+
purple: "800080",
|
| 881 |
+
rebeccapurple: "663399",
|
| 882 |
+
red: "f00",
|
| 883 |
+
rosybrown: "bc8f8f",
|
| 884 |
+
royalblue: "4169e1",
|
| 885 |
+
saddlebrown: "8b4513",
|
| 886 |
+
salmon: "fa8072",
|
| 887 |
+
sandybrown: "f4a460",
|
| 888 |
+
seagreen: "2e8b57",
|
| 889 |
+
seashell: "fff5ee",
|
| 890 |
+
sienna: "a0522d",
|
| 891 |
+
silver: "c0c0c0",
|
| 892 |
+
skyblue: "87ceeb",
|
| 893 |
+
slateblue: "6a5acd",
|
| 894 |
+
slategray: "708090",
|
| 895 |
+
slategrey: "708090",
|
| 896 |
+
snow: "fffafa",
|
| 897 |
+
springgreen: "00ff7f",
|
| 898 |
+
steelblue: "4682b4",
|
| 899 |
+
tan: "d2b48c",
|
| 900 |
+
teal: "008080",
|
| 901 |
+
thistle: "d8bfd8",
|
| 902 |
+
tomato: "ff6347",
|
| 903 |
+
turquoise: "40e0d0",
|
| 904 |
+
violet: "ee82ee",
|
| 905 |
+
wheat: "f5deb3",
|
| 906 |
+
white: "fff",
|
| 907 |
+
whitesmoke: "f5f5f5",
|
| 908 |
+
yellow: "ff0",
|
| 909 |
+
yellowgreen: "9acd32"
|
| 910 |
+
};
|
| 911 |
+
|
| 912 |
+
// Make it easy to access colors via `hexNames[hex]`
|
| 913 |
+
var hexNames = tinycolor.hexNames = flip(names);
|
| 914 |
+
|
| 915 |
+
|
| 916 |
+
// Utilities
|
| 917 |
+
// ---------
|
| 918 |
+
|
| 919 |
+
// `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
|
| 920 |
+
function flip(o) {
|
| 921 |
+
var flipped = { };
|
| 922 |
+
for (var i in o) {
|
| 923 |
+
if (o.hasOwnProperty(i)) {
|
| 924 |
+
flipped[o[i]] = i;
|
| 925 |
+
}
|
| 926 |
+
}
|
| 927 |
+
return flipped;
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
+
// Return a valid alpha value [0,1] with all invalid values being set to 1
|
| 931 |
+
function boundAlpha(a) {
|
| 932 |
+
a = parseFloat(a);
|
| 933 |
+
|
| 934 |
+
if (isNaN(a) || a < 0 || a > 1) {
|
| 935 |
+
a = 1;
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
+
return a;
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
// Take input from [0, n] and return it as [0, 1]
|
| 942 |
+
function bound01(n, max) {
|
| 943 |
+
if (isOnePointZero(n)) { n = "100%"; }
|
| 944 |
+
|
| 945 |
+
var processPercent = isPercentage(n);
|
| 946 |
+
n = mathMin(max, mathMax(0, parseFloat(n)));
|
| 947 |
+
|
| 948 |
+
// Automatically convert percentage into number
|
| 949 |
+
if (processPercent) {
|
| 950 |
+
n = parseInt(n * max, 10) / 100;
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
// Handle floating point rounding errors
|
| 954 |
+
if ((math.abs(n - max) < 0.000001)) {
|
| 955 |
+
return 1;
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
// Convert into [0, 1] range if it isn't already
|
| 959 |
+
return (n % max) / parseFloat(max);
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
// Force a number between 0 and 1
|
| 963 |
+
function clamp01(val) {
|
| 964 |
+
return mathMin(1, mathMax(0, val));
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
// Parse a base-16 hex value into a base-10 integer
|
| 968 |
+
function parseIntFromHex(val) {
|
| 969 |
+
return parseInt(val, 16);
|
| 970 |
+
}
|
| 971 |
+
|
| 972 |
+
// Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
|
| 973 |
+
// <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
|
| 974 |
+
function isOnePointZero(n) {
|
| 975 |
+
return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
+
// Check to see if string passed in is a percentage
|
| 979 |
+
function isPercentage(n) {
|
| 980 |
+
return typeof n === "string" && n.indexOf('%') != -1;
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
// Force a hex value to have 2 characters
|
| 984 |
+
function pad2(c) {
|
| 985 |
+
return c.length == 1 ? '0' + c : '' + c;
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
// Replace a decimal with it's percentage value
|
| 989 |
+
function convertToPercentage(n) {
|
| 990 |
+
if (n <= 1) {
|
| 991 |
+
n = (n * 100) + "%";
|
| 992 |
+
}
|
| 993 |
+
|
| 994 |
+
return n;
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
// Converts a decimal to a hex value
|
| 998 |
+
function convertDecimalToHex(d) {
|
| 999 |
+
return Math.round(parseFloat(d) * 255).toString(16);
|
| 1000 |
+
}
|
| 1001 |
+
// Converts a hex value to a decimal
|
| 1002 |
+
function convertHexToDecimal(h) {
|
| 1003 |
+
return (parseIntFromHex(h) / 255);
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
var matchers = (function() {
|
| 1007 |
+
|
| 1008 |
+
// <http://www.w3.org/TR/css3-values/#integers>
|
| 1009 |
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
| 1010 |
+
|
| 1011 |
+
// <http://www.w3.org/TR/css3-values/#number-value>
|
| 1012 |
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
| 1013 |
+
|
| 1014 |
+
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
| 1015 |
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
| 1016 |
+
|
| 1017 |
+
// Actual matching.
|
| 1018 |
+
// Parentheses and commas are optional, but not required.
|
| 1019 |
+
// Whitespace can take the place of commas or opening paren
|
| 1020 |
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
| 1021 |
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
| 1022 |
+
|
| 1023 |
+
return {
|
| 1024 |
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
| 1025 |
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
| 1026 |
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
| 1027 |
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
| 1028 |
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
| 1029 |
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
| 1030 |
+
hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
| 1031 |
+
hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
| 1032 |
+
hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
| 1033 |
+
};
|
| 1034 |
+
})();
|
| 1035 |
+
|
| 1036 |
+
// `stringInputToObject`
|
| 1037 |
+
// Permissive string parsing. Take in a number of formats, and output an object
|
| 1038 |
+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
|
| 1039 |
+
function stringInputToObject(color) {
|
| 1040 |
+
|
| 1041 |
+
color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
|
| 1042 |
+
var named = false;
|
| 1043 |
+
if (names[color]) {
|
| 1044 |
+
color = names[color];
|
| 1045 |
+
named = true;
|
| 1046 |
+
}
|
| 1047 |
+
else if (color == 'transparent') {
|
| 1048 |
+
return { r: 0, g: 0, b: 0, a: 0, format: "name" };
|
| 1049 |
+
}
|
| 1050 |
+
|
| 1051 |
+
// Try to match string input using regular expressions.
|
| 1052 |
+
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
|
| 1053 |
+
// Just return an object and let the conversion functions handle that.
|
| 1054 |
+
// This way the result will be the same whether the tinycolor is initialized with string or object.
|
| 1055 |
+
var match;
|
| 1056 |
+
if ((match = matchers.rgb.exec(color))) {
|
| 1057 |
+
return { r: match[1], g: match[2], b: match[3] };
|
| 1058 |
+
}
|
| 1059 |
+
if ((match = matchers.rgba.exec(color))) {
|
| 1060 |
+
return { r: match[1], g: match[2], b: match[3], a: match[4] };
|
| 1061 |
+
}
|
| 1062 |
+
if ((match = matchers.hsl.exec(color))) {
|
| 1063 |
+
return { h: match[1], s: match[2], l: match[3] };
|
| 1064 |
+
}
|
| 1065 |
+
if ((match = matchers.hsla.exec(color))) {
|
| 1066 |
+
return { h: match[1], s: match[2], l: match[3], a: match[4] };
|
| 1067 |
+
}
|
| 1068 |
+
if ((match = matchers.hsv.exec(color))) {
|
| 1069 |
+
return { h: match[1], s: match[2], v: match[3] };
|
| 1070 |
+
}
|
| 1071 |
+
if ((match = matchers.hsva.exec(color))) {
|
| 1072 |
+
return { h: match[1], s: match[2], v: match[3], a: match[4] };
|
| 1073 |
+
}
|
| 1074 |
+
if ((match = matchers.hex8.exec(color))) {
|
| 1075 |
+
return {
|
| 1076 |
+
a: convertHexToDecimal(match[1]),
|
| 1077 |
+
r: parseIntFromHex(match[2]),
|
| 1078 |
+
g: parseIntFromHex(match[3]),
|
| 1079 |
+
b: parseIntFromHex(match[4]),
|
| 1080 |
+
format: named ? "name" : "hex8"
|
| 1081 |
+
};
|
| 1082 |
+
}
|
| 1083 |
+
if ((match = matchers.hex6.exec(color))) {
|
| 1084 |
+
return {
|
| 1085 |
+
r: parseIntFromHex(match[1]),
|
| 1086 |
+
g: parseIntFromHex(match[2]),
|
| 1087 |
+
b: parseIntFromHex(match[3]),
|
| 1088 |
+
format: named ? "name" : "hex"
|
| 1089 |
+
};
|
| 1090 |
+
}
|
| 1091 |
+
if ((match = matchers.hex3.exec(color))) {
|
| 1092 |
+
return {
|
| 1093 |
+
r: parseIntFromHex(match[1] + '' + match[1]),
|
| 1094 |
+
g: parseIntFromHex(match[2] + '' + match[2]),
|
| 1095 |
+
b: parseIntFromHex(match[3] + '' + match[3]),
|
| 1096 |
+
format: named ? "name" : "hex"
|
| 1097 |
+
};
|
| 1098 |
+
}
|
| 1099 |
+
|
| 1100 |
+
return false;
|
| 1101 |
+
}
|
| 1102 |
+
|
| 1103 |
+
// Node: Export function
|
| 1104 |
+
if (typeof module !== "undefined" && module.exports) {
|
| 1105 |
+
module.exports = tinycolor;
|
| 1106 |
+
}
|
| 1107 |
+
// AMD/requirejs: Define the module
|
| 1108 |
+
else if (typeof define === 'function' && define.amd) {
|
| 1109 |
+
define(function () {return tinycolor;});
|
| 1110 |
+
}
|
| 1111 |
+
// Browser: Expose to window
|
| 1112 |
+
else {
|
| 1113 |
+
window.tinycolor = tinycolor;
|
| 1114 |
+
}
|
| 1115 |
+
|
| 1116 |
+
})();
|
assets/js/tinycolor.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
| 1 |
+
!function(){function a(a){var c={r:0,g:0,b:0},e=1,g=!1,h=!1;return"string"==typeof a&&(a=G(a)),"object"==typeof a&&(a.hasOwnProperty("r")&&a.hasOwnProperty("g")&&a.hasOwnProperty("b")?(c=b(a.r,a.g,a.b),g=!0,h="%"===String(a.r).substr(-1)?"prgb":"rgb"):a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("v")?(a.s=D(a.s),a.v=D(a.v),c=f(a.h,a.s,a.v),g=!0,h="hsv"):a.hasOwnProperty("h")&&a.hasOwnProperty("s")&&a.hasOwnProperty("l")&&(a.s=D(a.s),a.l=D(a.l),c=d(a.h,a.s,a.l),g=!0,h="hsl"),a.hasOwnProperty("a")&&(e=a.a)),e=w(e),{ok:g,format:a.format||h,r:M(255,N(c.r,0)),g:M(255,N(c.g,0)),b:M(255,N(c.b,0)),a:e}}function b(a,b,c){return{r:255*x(a,255),g:255*x(b,255),b:255*x(c,255)}}function c(a,b,c){a=x(a,255),b=x(b,255),c=x(c,255);var d,e,f=N(a,b,c),g=M(a,b,c),h=(f+g)/2;if(f==g)d=e=0;else{var i=f-g;switch(e=h>.5?i/(2-f-g):i/(f+g),f){case a:d=(b-c)/i+(c>b?6:0);break;case b:d=(c-a)/i+2;break;case c:d=(a-b)/i+4}d/=6}return{h:d,s:e,l:h}}function d(a,b,c){function d(a,b,c){return 0>c&&(c+=1),c>1&&(c-=1),1/6>c?a+6*(b-a)*c:.5>c?b:2/3>c?a+(b-a)*(2/3-c)*6:a}var e,f,g;if(a=x(a,360),b=x(b,100),c=x(c,100),0===b)e=f=g=c;else{var h=.5>c?c*(1+b):c+b-c*b,i=2*c-h;e=d(i,h,a+1/3),f=d(i,h,a),g=d(i,h,a-1/3)}return{r:255*e,g:255*f,b:255*g}}function e(a,b,c){a=x(a,255),b=x(b,255),c=x(c,255);var d,e,f=N(a,b,c),g=M(a,b,c),h=f,i=f-g;if(e=0===f?0:i/f,f==g)d=0;else{switch(f){case a:d=(b-c)/i+(c>b?6:0);break;case b:d=(c-a)/i+2;break;case c:d=(a-b)/i+4}d/=6}return{h:d,s:e,v:h}}function f(a,b,c){a=6*x(a,360),b=x(b,100),c=x(c,100);var d=K.floor(a),e=a-d,f=c*(1-b),g=c*(1-e*b),h=c*(1-(1-e)*b),i=d%6,j=[c,g,f,f,h,c][i],k=[h,c,c,g,f,f][i],l=[f,f,h,c,c,g][i];return{r:255*j,g:255*k,b:255*l}}function g(a,b,c,d){var e=[C(L(a).toString(16)),C(L(b).toString(16)),C(L(c).toString(16))];return d&&e[0].charAt(0)==e[0].charAt(1)&&e[1].charAt(0)==e[1].charAt(1)&&e[2].charAt(0)==e[2].charAt(1)?e[0].charAt(0)+e[1].charAt(0)+e[2].charAt(0):e.join("")}function h(a,b,c,d){var e=[C(E(d)),C(L(a).toString(16)),C(L(b).toString(16)),C(L(c).toString(16))];return e.join("")}function i(a,b){b=0===b?0:b||10;var c=P(a).toHsl();return c.s-=b/100,c.s=y(c.s),P(c)}function j(a,b){b=0===b?0:b||10;var c=P(a).toHsl();return c.s+=b/100,c.s=y(c.s),P(c)}function k(a){return P(a).desaturate(100)}function l(a,b){b=0===b?0:b||10;var c=P(a).toHsl();return c.l+=b/100,c.l=y(c.l),P(c)}function m(a,b){b=0===b?0:b||10;var c=P(a).toRgb();return c.r=N(0,M(255,c.r-L(255*-(b/100)))),c.g=N(0,M(255,c.g-L(255*-(b/100)))),c.b=N(0,M(255,c.b-L(255*-(b/100)))),P(c)}function n(a,b){b=0===b?0:b||10;var c=P(a).toHsl();return c.l-=b/100,c.l=y(c.l),P(c)}function o(a,b){var c=P(a).toHsl(),d=(L(c.h)+b)%360;return c.h=0>d?360+d:d,P(c)}function p(a){var b=P(a).toHsl();return b.h=(b.h+180)%360,P(b)}function q(a){var b=P(a).toHsl(),c=b.h;return[P(a),P({h:(c+120)%360,s:b.s,l:b.l}),P({h:(c+240)%360,s:b.s,l:b.l})]}function r(a){var b=P(a).toHsl(),c=b.h;return[P(a),P({h:(c+90)%360,s:b.s,l:b.l}),P({h:(c+180)%360,s:b.s,l:b.l}),P({h:(c+270)%360,s:b.s,l:b.l})]}function s(a){var b=P(a).toHsl(),c=b.h;return[P(a),P({h:(c+72)%360,s:b.s,l:b.l}),P({h:(c+216)%360,s:b.s,l:b.l})]}function t(a,b,c){b=b||6,c=c||30;var d=P(a).toHsl(),e=360/c,f=[P(a)];for(d.h=(d.h-(e*b>>1)+720)%360;--b;)d.h=(d.h+e)%360,f.push(P(d));return f}function u(a,b){b=b||6;for(var c=P(a).toHsv(),d=c.h,e=c.s,f=c.v,g=[],h=1/b;b--;)g.push(P({h:d,s:e,v:f})),f=(f+h)%1;return g}function v(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[a[c]]=c);return b}function w(a){return a=parseFloat(a),(isNaN(a)||0>a||a>1)&&(a=1),a}function x(a,b){A(a)&&(a="100%");var c=B(a);return a=M(b,N(0,parseFloat(a))),c&&(a=parseInt(a*b,10)/100),K.abs(a-b)<1e-6?1:a%b/parseFloat(b)}function y(a){return M(1,N(0,a))}function z(a){return parseInt(a,16)}function A(a){return"string"==typeof a&&-1!=a.indexOf(".")&&1===parseFloat(a)}function B(a){return"string"==typeof a&&-1!=a.indexOf("%")}function C(a){return 1==a.length?"0"+a:""+a}function D(a){return 1>=a&&(a=100*a+"%"),a}function E(a){return Math.round(255*parseFloat(a)).toString(16)}function F(a){return z(a)/255}function G(a){a=a.replace(H,"").replace(I,"").toLowerCase();var b=!1;if(Q[a])a=Q[a],b=!0;else if("transparent"==a)return{r:0,g:0,b:0,a:0,format:"name"};var c;return(c=S.rgb.exec(a))?{r:c[1],g:c[2],b:c[3]}:(c=S.rgba.exec(a))?{r:c[1],g:c[2],b:c[3],a:c[4]}:(c=S.hsl.exec(a))?{h:c[1],s:c[2],l:c[3]}:(c=S.hsla.exec(a))?{h:c[1],s:c[2],l:c[3],a:c[4]}:(c=S.hsv.exec(a))?{h:c[1],s:c[2],v:c[3]}:(c=S.hsva.exec(a))?{h:c[1],s:c[2],v:c[3],a:c[4]}:(c=S.hex8.exec(a))?{a:F(c[1]),r:z(c[2]),g:z(c[3]),b:z(c[4]),format:b?"name":"hex8"}:(c=S.hex6.exec(a))?{r:z(c[1]),g:z(c[2]),b:z(c[3]),format:b?"name":"hex"}:(c=S.hex3.exec(a))?{r:z(c[1]+""+c[1]),g:z(c[2]+""+c[2]),b:z(c[3]+""+c[3]),format:b?"name":"hex"}:!1}var H=/^[\s,#]+/,I=/\s+$/,J=0,K=Math,L=K.round,M=K.min,N=K.max,O=K.random,P=function T(b,c){if(b=b?b:"",c=c||{},b instanceof T)return b;if(!(this instanceof T))return new T(b,c);var d=a(b);this._originalInput=b,this._r=d.r,this._g=d.g,this._b=d.b,this._a=d.a,this._roundA=L(100*this._a)/100,this._format=c.format||d.format,this._gradientType=c.gradientType,this._r<1&&(this._r=L(this._r)),this._g<1&&(this._g=L(this._g)),this._b<1&&(this._b=L(this._b)),this._ok=d.ok,this._tc_id=J++};P.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var a=this.toRgb();return(299*a.r+587*a.g+114*a.b)/1e3},setAlpha:function(a){return this._a=w(a),this._roundA=L(100*this._a)/100,this},toHsv:function(){var a=e(this._r,this._g,this._b);return{h:360*a.h,s:a.s,v:a.v,a:this._a}},toHsvString:function(){var a=e(this._r,this._g,this._b),b=L(360*a.h),c=L(100*a.s),d=L(100*a.v);return 1==this._a?"hsv("+b+", "+c+"%, "+d+"%)":"hsva("+b+", "+c+"%, "+d+"%, "+this._roundA+")"},toHsl:function(){var a=c(this._r,this._g,this._b);return{h:360*a.h,s:a.s,l:a.l,a:this._a}},toHslString:function(){var a=c(this._r,this._g,this._b),b=L(360*a.h),d=L(100*a.s),e=L(100*a.l);return 1==this._a?"hsl("+b+", "+d+"%, "+e+"%)":"hsla("+b+", "+d+"%, "+e+"%, "+this._roundA+")"},toHex:function(a){return g(this._r,this._g,this._b,a)},toHexString:function(a){return"#"+this.toHex(a)},toHex8:function(){return h(this._r,this._g,this._b,this._a)},toHex8String:function(){return"#"+this.toHex8()},toRgb:function(){return{r:L(this._r),g:L(this._g),b:L(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+L(this._r)+", "+L(this._g)+", "+L(this._b)+")":"rgba("+L(this._r)+", "+L(this._g)+", "+L(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:L(100*x(this._r,255))+"%",g:L(100*x(this._g,255))+"%",b:L(100*x(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+L(100*x(this._r,255))+"%, "+L(100*x(this._g,255))+"%, "+L(100*x(this._b,255))+"%)":"rgba("+L(100*x(this._r,255))+"%, "+L(100*x(this._g,255))+"%, "+L(100*x(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":this._a<1?!1:R[g(this._r,this._g,this._b,!0)]||!1},toFilter:function(a){var b="#"+h(this._r,this._g,this._b,this._a),c=b,d=this._gradientType?"GradientType = 1, ":"";if(a){var e=P(a);c=e.toHex8String()}return"progid:DXImageTransform.Microsoft.gradient("+d+"startColorstr="+b+",endColorstr="+c+")"},toString:function(a){var b=!!a;a=a||this._format;var c=!1,d=this._a<1&&this._a>=0,e=!b&&d&&("hex"===a||"hex6"===a||"hex3"===a||"name"===a);return e?"name"===a&&0===this._a?this.toName():this.toRgbString():("rgb"===a&&(c=this.toRgbString()),"prgb"===a&&(c=this.toPercentageRgbString()),("hex"===a||"hex6"===a)&&(c=this.toHexString()),"hex3"===a&&(c=this.toHexString(!0)),"hex8"===a&&(c=this.toHex8String()),"name"===a&&(c=this.toName()),"hsl"===a&&(c=this.toHslString()),"hsv"===a&&(c=this.toHsvString()),c||this.toHexString())},_applyModification:function(a,b){var c=a.apply(null,[this].concat([].slice.call(b)));return this._r=c._r,this._g=c._g,this._b=c._b,this.setAlpha(c._a),this},lighten:function(){return this._applyModification(l,arguments)},brighten:function(){return this._applyModification(m,arguments)},darken:function(){return this._applyModification(n,arguments)},desaturate:function(){return this._applyModification(i,arguments)},saturate:function(){return this._applyModification(j,arguments)},greyscale:function(){return this._applyModification(k,arguments)},spin:function(){return this._applyModification(o,arguments)},_applyCombination:function(a,b){return a.apply(null,[this].concat([].slice.call(b)))},analogous:function(){return this._applyCombination(t,arguments)},complement:function(){return this._applyCombination(p,arguments)},monochromatic:function(){return this._applyCombination(u,arguments)},splitcomplement:function(){return this._applyCombination(s,arguments)},triad:function(){return this._applyCombination(q,arguments)},tetrad:function(){return this._applyCombination(r,arguments)}},P.fromRatio=function(a,b){if("object"==typeof a){var c={};for(var d in a)a.hasOwnProperty(d)&&(c[d]="a"===d?a[d]:D(a[d]));a=c}return P(a,b)},P.equals=function(a,b){return a&&b?P(a).toRgbString()==P(b).toRgbString():!1},P.random=function(){return P.fromRatio({r:O(),g:O(),b:O()})},P.mix=function(a,b,c){c=0===c?0:c||50;var d,e=P(a).toRgb(),f=P(b).toRgb(),g=c/100,h=2*g-1,i=f.a-e.a;d=h*i==-1?h:(h+i)/(1+h*i),d=(d+1)/2;var j=1-d,k={r:f.r*d+e.r*j,g:f.g*d+e.g*j,b:f.b*d+e.b*j,a:f.a*g+e.a*(1-g)};return P(k)},P.readability=function(a,b){var c=P(a),d=P(b),e=c.toRgb(),f=d.toRgb(),g=c.getBrightness(),h=d.getBrightness(),i=Math.max(e.r,f.r)-Math.min(e.r,f.r)+Math.max(e.g,f.g)-Math.min(e.g,f.g)+Math.max(e.b,f.b)-Math.min(e.b,f.b);return{brightness:Math.abs(g-h),color:i}},P.isReadable=function(a,b){var c=P.readability(a,b);return c.brightness>125&&c.color>500},P.mostReadable=function(a,b){for(var c=null,d=0,e=!1,f=0;f<b.length;f++){var g=P.readability(a,b[f]),h=g.brightness>125&&g.color>500,i=3*(g.brightness/125)+g.color/500;(h&&!e||h&&e&&i>d||!h&&!e&&i>d)&&(e=h,d=i,c=P(b[f]))}return c};var Q=P.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},R=P.hexNames=v(Q),S=function(){var a="[-\\+]?\\d+%?",b="[-\\+]?\\d*\\.\\d+%?",c="(?:"+b+")|(?:"+a+")",d="[\\s|\\(]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")\\s*\\)?",e="[\\s|\\(]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")[,|\\s]+("+c+")\\s*\\)?";return{rgb:new RegExp("rgb"+d),rgba:new RegExp("rgba"+e),hsl:new RegExp("hsl"+d),hsla:new RegExp("hsla"+e),hsv:new RegExp("hsv"+d),hsva:new RegExp("hsva"+e),hex3:/^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex8:/^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}}();"undefined"!=typeof module&&module.exports?module.exports=P:"function"==typeof define&&define.amd?define(function(){return P}):window.tinycolor=P}();
|
includes/class-wc-colors-customizer.php
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 3 |
+
exit; // Exit if accessed directly.
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* WooCommerce Colors Customizer.
|
| 8 |
+
*
|
| 9 |
+
* @package WC_Colors/Customizer
|
| 10 |
+
* @category Class
|
| 11 |
+
* @author WooThemes
|
| 12 |
+
*/
|
| 13 |
+
class WC_Colors_Customizer {
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Section slug.
|
| 17 |
+
*
|
| 18 |
+
* @var string
|
| 19 |
+
*/
|
| 20 |
+
public $section_slug = 'woocommerce_colors';
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Initialize the customize actions.
|
| 24 |
+
*/
|
| 25 |
+
public function __construct() {
|
| 26 |
+
add_action( 'customize_register', array( $this, 'register_settings' ) );
|
| 27 |
+
add_action( 'customize_preview_init', array( $this, 'live_preview' ) );
|
| 28 |
+
add_action( 'customize_save_after', array( $this, 'save_after' ) );
|
| 29 |
+
add_action( 'wp_head', array( $this, 'header_output' ), 99999 );
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Register the customizer settings.
|
| 34 |
+
*
|
| 35 |
+
* @param \WP_Customize_Manager $wp_customize
|
| 36 |
+
*/
|
| 37 |
+
public function register_settings( $wp_customize ) {
|
| 38 |
+
|
| 39 |
+
$wp_customize->add_section( $this->section_slug, array(
|
| 40 |
+
'title' => __( 'WooCommerce', 'woocommerce-colors' ),
|
| 41 |
+
'priority' => 60,
|
| 42 |
+
'description' => __( 'WooCommerce Colors.', 'woocommerce-colors' )
|
| 43 |
+
) );
|
| 44 |
+
|
| 45 |
+
// Primary Color.
|
| 46 |
+
$wp_customize->add_setting( $this->section_slug . '[primary]', array(
|
| 47 |
+
'default' => '#a46497',
|
| 48 |
+
'type' => 'option',
|
| 49 |
+
'transport' => 'postMessage',
|
| 50 |
+
'sanitize_callback' => 'sanitize_hex_color',
|
| 51 |
+
) );
|
| 52 |
+
|
| 53 |
+
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'woocommerce_primary', array(
|
| 54 |
+
'label' => __( 'Primary Color', 'woocommerce-colors' ),
|
| 55 |
+
'section' => $this->section_slug,
|
| 56 |
+
'settings' => $this->section_slug . '[primary]',
|
| 57 |
+
'priority' => 1
|
| 58 |
+
) ) );
|
| 59 |
+
|
| 60 |
+
// Secondary Color.
|
| 61 |
+
$wp_customize->add_setting( $this->section_slug . '[secondary]', array(
|
| 62 |
+
'default' => '#ebe9eb',
|
| 63 |
+
'type' => 'option',
|
| 64 |
+
'transport' => 'postMessage',
|
| 65 |
+
'sanitize_callback' => 'sanitize_hex_color',
|
| 66 |
+
) );
|
| 67 |
+
|
| 68 |
+
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'woocommerce_secondary', array(
|
| 69 |
+
'label' => __( 'Secondary Color', 'woocommerce-colors' ),
|
| 70 |
+
'section' => $this->section_slug,
|
| 71 |
+
'settings' => $this->section_slug . '[secondary]',
|
| 72 |
+
'priority' => 1
|
| 73 |
+
) ) );
|
| 74 |
+
|
| 75 |
+
// Highlight Color.
|
| 76 |
+
$wp_customize->add_setting( $this->section_slug . '[highlight]', array(
|
| 77 |
+
'default' => '#77a464',
|
| 78 |
+
'type' => 'option',
|
| 79 |
+
'transport' => 'postMessage',
|
| 80 |
+
'sanitize_callback' => 'sanitize_hex_color',
|
| 81 |
+
) );
|
| 82 |
+
|
| 83 |
+
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'woocommerce_highlight', array(
|
| 84 |
+
'label' => __( 'Highlight Color', 'woocommerce-colors' ),
|
| 85 |
+
'section' => $this->section_slug,
|
| 86 |
+
'settings' => $this->section_slug . '[highlight]',
|
| 87 |
+
'priority' => 1
|
| 88 |
+
) ) );
|
| 89 |
+
|
| 90 |
+
// Content Background Color.
|
| 91 |
+
$wp_customize->add_setting( $this->section_slug . '[contentbg]', array(
|
| 92 |
+
'default' => '#ffffff',
|
| 93 |
+
'type' => 'option',
|
| 94 |
+
'transport' => 'postMessage',
|
| 95 |
+
'sanitize_callback' => 'sanitize_hex_color',
|
| 96 |
+
) );
|
| 97 |
+
|
| 98 |
+
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'woocommerce_contentbg', array(
|
| 99 |
+
'label' => __( 'Content Background Color', 'woocommerce-colors' ),
|
| 100 |
+
'section' => $this->section_slug,
|
| 101 |
+
'settings' => $this->section_slug . '[contentbg]',
|
| 102 |
+
'priority' => 1
|
| 103 |
+
) ) );
|
| 104 |
+
|
| 105 |
+
// Subtext Color.
|
| 106 |
+
$wp_customize->add_setting( $this->section_slug . '[subtext]', array(
|
| 107 |
+
'default' => '#777777',
|
| 108 |
+
'type' => 'option',
|
| 109 |
+
'transport' => 'postMessage',
|
| 110 |
+
'sanitize_callback' => 'sanitize_hex_color',
|
| 111 |
+
) );
|
| 112 |
+
|
| 113 |
+
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'woocommerce_subtext', array(
|
| 114 |
+
'label' => __( 'Subtext Color', 'woocommerce-colors' ),
|
| 115 |
+
'section' => $this->section_slug,
|
| 116 |
+
'settings' => $this->section_slug . '[subtext]',
|
| 117 |
+
'priority' => 1
|
| 118 |
+
) ) );
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* Customizer live preview.
|
| 123 |
+
*/
|
| 124 |
+
public function live_preview() {
|
| 125 |
+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
| 126 |
+
|
| 127 |
+
wp_enqueue_script( 'tinycolor', WC_Colors::get_assets_url() . 'js/tinycolor' . $suffix . '.js', array(), '1.1.1', true );
|
| 128 |
+
wp_enqueue_script( 'woocommerce-colors-customizer', WC_Colors::get_assets_url() . 'js/customizer' . $suffix . '.js', array( 'jquery', 'customize-preview', 'tinycolor' ), WC_Colors::VERSION, true );
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/**
|
| 132 |
+
* Compile the SCSS.
|
| 133 |
+
*
|
| 134 |
+
* @return string
|
| 135 |
+
*/
|
| 136 |
+
protected function compile_scss() {
|
| 137 |
+
include_once 'libs/class-scss.php';
|
| 138 |
+
|
| 139 |
+
// Get options
|
| 140 |
+
$colors = WC_Colors::get_options( get_option( 'woocommerce_colors' ) );
|
| 141 |
+
|
| 142 |
+
ob_start();
|
| 143 |
+
include 'views/scss.php';
|
| 144 |
+
$scss = ob_get_clean();
|
| 145 |
+
|
| 146 |
+
$compiler = new scssc;
|
| 147 |
+
$compiler->setFormatter( 'scss_formatter_compressed' );
|
| 148 |
+
$compiled_css = $compiler->compile( trim( $scss ) );
|
| 149 |
+
|
| 150 |
+
return $compiled_css;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Save the colors.
|
| 155 |
+
*
|
| 156 |
+
* @param WP_Customize_Manager $customize
|
| 157 |
+
*/
|
| 158 |
+
public function save_after( $customize ) {
|
| 159 |
+
if ( ! isset( $_REQUEST['customized'] ) ) {
|
| 160 |
+
return;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
$customized = json_decode( stripslashes( $_REQUEST['customized'] ), true );
|
| 164 |
+
$save = false;
|
| 165 |
+
|
| 166 |
+
foreach ( $customized as $key => $value ) {
|
| 167 |
+
if ( false !== strpos( $key, $this->section_slug ) ) {
|
| 168 |
+
$save = true;
|
| 169 |
+
break;
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
if ( $save ) {
|
| 174 |
+
$css = $this->compile_scss();
|
| 175 |
+
|
| 176 |
+
update_option( 'woocommerce_colors_css', $css );
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/**
|
| 181 |
+
* Header output.
|
| 182 |
+
*/
|
| 183 |
+
public function header_output() {
|
| 184 |
+
$css = get_option( 'woocommerce_colors_css' );
|
| 185 |
+
|
| 186 |
+
echo "<!-- WooCommerce Colors -->\n";
|
| 187 |
+
echo "<style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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
| 3 |
+
// exit; // Exit if accessed directly.
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* SCSS compiler written in PHP
|
| 8 |
+
*
|
| 9 |
+
* @copyright 2012-2014 Leaf Corcoran
|
| 10 |
+
*
|
| 11 |
+
* @license http://opensource.org/licenses/gpl-license GPL-3.0
|
| 12 |
+
* @license http://opensource.org/licenses/MIT MIT
|
| 13 |
+
*
|
| 14 |
+
* @link http://leafo.net/scssphp
|
| 15 |
+
*/
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* The scss compiler and parser.
|
| 19 |
+
*
|
| 20 |
+
* Converting SCSS to CSS is a three stage process. The incoming file is parsed
|
| 21 |
+
* by `scss_parser` into a syntax tree, then it is compiled into another tree
|
| 22 |
+
* representing the CSS structure by `scssc`. The CSS tree is fed into a
|
| 23 |
+
* formatter, like `scss_formatter` which then outputs CSS as a string.
|
| 24 |
+
*
|
| 25 |
+
* During the first compile, all values are *reduced*, which means that their
|
| 26 |
+
* types are brought to the lowest form before being dump as strings. This
|
| 27 |
+
* handles math equations, variable dereferences, and the like.
|
| 28 |
+
*
|
| 29 |
+
* The `parse` function of `scssc` is the entry point.
|
| 30 |
+
*
|
| 31 |
+
* In summary:
|
| 32 |
+
*
|
| 33 |
+
* The `scssc` class creates an instance of the parser, feeds it SCSS code,
|
| 34 |
+
* then transforms the resulting tree to a CSS tree. This class also holds the
|
| 35 |
+
* evaluation context, such as all available mixins and variables at any given
|
| 36 |
+
* time.
|
| 37 |
+
*
|
| 38 |
+
* The `scss_parser` class is only concerned with parsing its input.
|
| 39 |
+
*
|
| 40 |
+
* The `scss_formatter` takes a CSS tree, and dumps it to a formatted string,
|
| 41 |
+
* handling things like indentation.
|
| 42 |
+
*/
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* SCSS compiler
|
| 46 |
+
*
|
| 47 |
+
* @author Leaf Corcoran <leafot@gmail.com>
|
| 48 |
+
*/
|
| 49 |
+
class scssc {
|
| 50 |
+
static public $VERSION = 'v0.0.15';
|
| 51 |
+
|
| 52 |
+
static protected $operatorNames = array(
|
| 53 |
+
'+' => 'add',
|
| 54 |
+
'-' => 'sub',
|
| 55 |
+
'*' => 'mul',
|
| 56 |
+
'/' => 'div',
|
| 57 |
+
'%' => 'mod',
|
| 58 |
+
|
| 59 |
+
'==' => 'eq',
|
| 60 |
+
'!=' => 'neq',
|
| 61 |
+
'<' => 'lt',
|
| 62 |
+
'>' => 'gt',
|
| 63 |
+
|
| 64 |
+
'<=' => 'lte',
|
| 65 |
+
'>=' => 'gte',
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
static protected $namespaces = array(
|
| 69 |
+
'special' => '%',
|
| 70 |
+
'mixin' => '@',
|
| 71 |
+
'function' => '^',
|
| 72 |
+
);
|
| 73 |
+
|
| 74 |
+
static protected $unitTable = array(
|
| 75 |
+
'in' => array(
|
| 76 |
+
'in' => 1,
|
| 77 |
+
'pt' => 72,
|
| 78 |
+
'pc' => 6,
|
| 79 |
+
'cm' => 2.54,
|
| 80 |
+
'mm' => 25.4,
|
| 81 |
+
'px' => 96,
|
| 82 |
+
)
|
| 83 |
+
);
|
| 84 |
+
|
| 85 |
+
static public $true = array('keyword', 'true');
|
| 86 |
+
static public $false = array('keyword', 'false');
|
| 87 |
+
static public $null = array('null');
|
| 88 |
+
|
| 89 |
+
static public $defaultValue = array('keyword', '');
|
| 90 |
+
static public $selfSelector = array('self');
|
| 91 |
+
|
| 92 |
+
protected $importPaths = array('');
|
| 93 |
+
protected $importCache = array();
|
| 94 |
+
|
| 95 |
+
protected $userFunctions = array();
|
| 96 |
+
protected $registeredVars = array();
|
| 97 |
+
|
| 98 |
+
protected $numberPrecision = 5;
|
| 99 |
+
|
| 100 |
+
protected $formatter = 'scss_formatter_nested';
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Compile scss
|
| 104 |
+
*
|
| 105 |
+
* @param string $code
|
| 106 |
+
* @param string $name
|
| 107 |
+
*
|
| 108 |
+
* @return string
|
| 109 |
+
*/
|
| 110 |
+
public function compile($code, $name = null)
|
| 111 |
+
{
|
| 112 |
+
$this->indentLevel = -1;
|
| 113 |
+
$this->commentsSeen = array();
|
| 114 |
+
$this->extends = array();
|
| 115 |
+
$this->extendsMap = array();
|
| 116 |
+
$this->parsedFiles = array();
|
| 117 |
+
$this->env = null;
|
| 118 |
+
$this->scope = null;
|
| 119 |
+
|
| 120 |
+
$locale = setlocale(LC_NUMERIC, 0);
|
| 121 |
+
setlocale(LC_NUMERIC, 'C');
|
| 122 |
+
|
| 123 |
+
$this->parser = new scss_parser($name);
|
| 124 |
+
|
| 125 |
+
$tree = $this->parser->parse($code);
|
| 126 |
+
|
| 127 |
+
$this->formatter = new $this->formatter();
|
| 128 |
+
|
| 129 |
+
$this->pushEnv($tree);
|
| 130 |
+
$this->injectVariables($this->registeredVars);
|
| 131 |
+
$this->compileRoot($tree);
|
| 132 |
+
$this->popEnv();
|
| 133 |
+
|
| 134 |
+
$out = $this->formatter->format($this->scope);
|
| 135 |
+
|
| 136 |
+
setlocale(LC_NUMERIC, $locale);
|
| 137 |
+
|
| 138 |
+
return $out;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
protected function isSelfExtend($target, $origin) {
|
| 142 |
+
foreach ($origin as $sel) {
|
| 143 |
+
if (in_array($target, $sel)) {
|
| 144 |
+
return true;
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
return false;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
protected function pushExtends($target, $origin) {
|
| 152 |
+
if ($this->isSelfExtend($target, $origin)) {
|
| 153 |
+
return;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
$i = count($this->extends);
|
| 157 |
+
$this->extends[] = array($target, $origin);
|
| 158 |
+
|
| 159 |
+
foreach ($target as $part) {
|
| 160 |
+
if (isset($this->extendsMap[$part])) {
|
| 161 |
+
$this->extendsMap[$part][] = $i;
|
| 162 |
+
} else {
|
| 163 |
+
$this->extendsMap[$part] = array($i);
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
protected function makeOutputBlock($type, $selectors = null) {
|
| 169 |
+
$out = new stdClass;
|
| 170 |
+
$out->type = $type;
|
| 171 |
+
$out->lines = array();
|
| 172 |
+
$out->children = array();
|
| 173 |
+
$out->parent = $this->scope;
|
| 174 |
+
$out->selectors = $selectors;
|
| 175 |
+
$out->depth = $this->env->depth;
|
| 176 |
+
|
| 177 |
+
return $out;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
protected function matchExtendsSingle($single, &$outOrigin) {
|
| 181 |
+
$counts = array();
|
| 182 |
+
foreach ($single as $part) {
|
| 183 |
+
if (!is_string($part)) return false; // hmm
|
| 184 |
+
|
| 185 |
+
if (isset($this->extendsMap[$part])) {
|
| 186 |
+
foreach ($this->extendsMap[$part] as $idx) {
|
| 187 |
+
$counts[$idx] =
|
| 188 |
+
isset($counts[$idx]) ? $counts[$idx] + 1 : 1;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
$outOrigin = array();
|
| 194 |
+
$found = false;
|
| 195 |
+
|
| 196 |
+
foreach ($counts as $idx => $count) {
|
| 197 |
+
list($target, $origin) = $this->extends[$idx];
|
| 198 |
+
|
| 199 |
+
// check count
|
| 200 |
+
if ($count != count($target)) continue;
|
| 201 |
+
|
| 202 |
+
// check if target is subset of single
|
| 203 |
+
if (array_diff(array_intersect($single, $target), $target)) continue;
|
| 204 |
+
|
| 205 |
+
$rem = array_diff($single, $target);
|
| 206 |
+
|
| 207 |
+
foreach ($origin as $j => $new) {
|
| 208 |
+
// prevent infinite loop when target extends itself
|
| 209 |
+
foreach ($new as $new_selector) {
|
| 210 |
+
if (!array_diff($single, $new_selector)) {
|
| 211 |
+
continue 2;
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
$origin[$j][count($origin[$j]) - 1] = $this->combineSelectorSingle(end($new), $rem);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
$outOrigin = array_merge($outOrigin, $origin);
|
| 219 |
+
|
| 220 |
+
$found = true;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
return $found;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
protected function combineSelectorSingle($base, $other) {
|
| 227 |
+
$tag = null;
|
| 228 |
+
$out = array();
|
| 229 |
+
|
| 230 |
+
foreach (array($base, $other) as $single) {
|
| 231 |
+
foreach ($single as $part) {
|
| 232 |
+
if (preg_match('/^[^\[.#:]/', $part)) {
|
| 233 |
+
$tag = $part;
|
| 234 |
+
} else {
|
| 235 |
+
$out[] = $part;
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
if ($tag) {
|
| 241 |
+
array_unshift($out, $tag);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
return $out;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
protected function matchExtends($selector, &$out, $from = 0, $initial=true) {
|
| 248 |
+
foreach ($selector as $i => $part) {
|
| 249 |
+
if ($i < $from) continue;
|
| 250 |
+
|
| 251 |
+
if ($this->matchExtendsSingle($part, $origin)) {
|
| 252 |
+
$before = array_slice($selector, 0, $i);
|
| 253 |
+
$after = array_slice($selector, $i + 1);
|
| 254 |
+
|
| 255 |
+
foreach ($origin as $new) {
|
| 256 |
+
$k = 0;
|
| 257 |
+
|
| 258 |
+
// remove shared parts
|
| 259 |
+
if ($initial) {
|
| 260 |
+
foreach ($before as $k => $val) {
|
| 261 |
+
if (!isset($new[$k]) || $val != $new[$k]) {
|
| 262 |
+
break;
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
$result = array_merge(
|
| 268 |
+
$before,
|
| 269 |
+
$k > 0 ? array_slice($new, $k) : $new,
|
| 270 |
+
$after);
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
if ($result == $selector) continue;
|
| 274 |
+
$out[] = $result;
|
| 275 |
+
|
| 276 |
+
// recursively check for more matches
|
| 277 |
+
$this->matchExtends($result, $out, $i, false);
|
| 278 |
+
|
| 279 |
+
// selector sequence merging
|
| 280 |
+
if (!empty($before) && count($new) > 1) {
|
| 281 |
+
$result2 = array_merge(
|
| 282 |
+
array_slice($new, 0, -1),
|
| 283 |
+
$k > 0 ? array_slice($before, $k) : $before,
|
| 284 |
+
array_slice($new, -1),
|
| 285 |
+
$after);
|
| 286 |
+
|
| 287 |
+
$out[] = $result2;
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
protected function flattenSelectors($block, $parentKey = null) {
|
| 295 |
+
if ($block->selectors) {
|
| 296 |
+
$selectors = array();
|
| 297 |
+
foreach ($block->selectors as $s) {
|
| 298 |
+
$selectors[] = $s;
|
| 299 |
+
if (!is_array($s)) continue;
|
| 300 |
+
// check extends
|
| 301 |
+
if (!empty($this->extendsMap)) {
|
| 302 |
+
$this->matchExtends($s, $selectors);
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
$block->selectors = array();
|
| 307 |
+
$placeholderSelector = false;
|
| 308 |
+
foreach ($selectors as $selector) {
|
| 309 |
+
if ($this->hasSelectorPlaceholder($selector)) {
|
| 310 |
+
$placeholderSelector = true;
|
| 311 |
+
continue;
|
| 312 |
+
}
|
| 313 |
+
$block->selectors[] = $this->compileSelector($selector);
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
if ($placeholderSelector && 0 == count($block->selectors) && null !== $parentKey) {
|
| 317 |
+
unset($block->parent->children[$parentKey]);
|
| 318 |
+
return;
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
foreach ($block->children as $key => $child) {
|
| 323 |
+
$this->flattenSelectors($child, $key);
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
protected function compileRoot($rootBlock)
|
| 328 |
+
{
|
| 329 |
+
$this->scope = $this->makeOutputBlock('root');
|
| 330 |
+
|
| 331 |
+
$this->compileChildren($rootBlock->children, $this->scope);
|
| 332 |
+
$this->flattenSelectors($this->scope);
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
protected function compileMedia($media) {
|
| 336 |
+
$this->pushEnv($media);
|
| 337 |
+
|
| 338 |
+
$mediaQuery = $this->compileMediaQuery($this->multiplyMedia($this->env));
|
| 339 |
+
|
| 340 |
+
if (!empty($mediaQuery)) {
|
| 341 |
+
|
| 342 |
+
$this->scope = $this->makeOutputBlock('media', array($mediaQuery));
|
| 343 |
+
|
| 344 |
+
$parentScope = $this->mediaParent($this->scope);
|
| 345 |
+
|
| 346 |
+
$parentScope->children[] = $this->scope;
|
| 347 |
+
|
| 348 |
+
// top level properties in a media cause it to be wrapped
|
| 349 |
+
$needsWrap = false;
|
| 350 |
+
foreach ($media->children as $child) {
|
| 351 |
+
$type = $child[0];
|
| 352 |
+
if ($type !== 'block' && $type !== 'media' && $type !== 'directive') {
|
| 353 |
+
$needsWrap = true;
|
| 354 |
+
break;
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
if ($needsWrap) {
|
| 359 |
+
$wrapped = (object)array(
|
| 360 |
+
'selectors' => array(),
|
| 361 |
+
'children' => $media->children
|
| 362 |
+
);
|
| 363 |
+
$media->children = array(array('block', $wrapped));
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
$this->compileChildren($media->children, $this->scope);
|
| 367 |
+
|
| 368 |
+
$this->scope = $this->scope->parent;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
$this->popEnv();
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
protected function mediaParent($scope) {
|
| 375 |
+
while (!empty($scope->parent)) {
|
| 376 |
+
if (!empty($scope->type) && $scope->type != 'media') {
|
| 377 |
+
break;
|
| 378 |
+
}
|
| 379 |
+
$scope = $scope->parent;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
return $scope;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
// TODO refactor compileNestedBlock and compileMedia into same thing
|
| 386 |
+
protected function compileNestedBlock($block, $selectors) {
|
| 387 |
+
$this->pushEnv($block);
|
| 388 |
+
|
| 389 |
+
$this->scope = $this->makeOutputBlock($block->type, $selectors);
|
| 390 |
+
$this->scope->parent->children[] = $this->scope;
|
| 391 |
+
$this->compileChildren($block->children, $this->scope);
|
| 392 |
+
|
| 393 |
+
$this->scope = $this->scope->parent;
|
| 394 |
+
$this->popEnv();
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
/**
|
| 398 |
+
* Recursively compiles a block.
|
| 399 |
+
*
|
| 400 |
+
* A block is analogous to a CSS block in most cases. A single SCSS document
|
| 401 |
+
* is encapsulated in a block when parsed, but it does not have parent tags
|
| 402 |
+
* so all of its children appear on the root level when compiled.
|
| 403 |
+
*
|
| 404 |
+
* Blocks are made up of selectors and children.
|
| 405 |
+
*
|
| 406 |
+
* The children of a block are just all the blocks that are defined within.
|
| 407 |
+
*
|
| 408 |
+
* Compiling the block involves pushing a fresh environment on the stack,
|
| 409 |
+
* and iterating through the props, compiling each one.
|
| 410 |
+
*
|
| 411 |
+
* @see scss::compileChild()
|
| 412 |
+
*
|
| 413 |
+
* @param \StdClass $block
|
| 414 |
+
*/
|
| 415 |
+
protected function compileBlock($block) {
|
| 416 |
+
$env = $this->pushEnv($block);
|
| 417 |
+
|
| 418 |
+
$env->selectors =
|
| 419 |
+
array_map(array($this, 'evalSelector'), $block->selectors);
|
| 420 |
+
|
| 421 |
+
$out = $this->makeOutputBlock(null, $this->multiplySelectors($env));
|
| 422 |
+
$this->scope->children[] = $out;
|
| 423 |
+
$this->compileChildren($block->children, $out);
|
| 424 |
+
|
| 425 |
+
$this->popEnv();
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
// root level comment
|
| 429 |
+
protected function compileComment($block) {
|
| 430 |
+
$out = $this->makeOutputBlock('comment');
|
| 431 |
+
$out->lines[] = $block[1];
|
| 432 |
+
$this->scope->children[] = $out;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
// joins together .classes and #ids
|
| 436 |
+
protected function flattenSelectorSingle($single) {
|
| 437 |
+
$joined = array();
|
| 438 |
+
foreach ($single as $part) {
|
| 439 |
+
if (empty($joined) ||
|
| 440 |
+
!is_string($part) ||
|
| 441 |
+
preg_match('/[\[.:#%]/', $part))
|
| 442 |
+
{
|
| 443 |
+
$joined[] = $part;
|
| 444 |
+
continue;
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
if (is_array(end($joined))) {
|
| 448 |
+
$joined[] = $part;
|
| 449 |
+
} else {
|
| 450 |
+
$joined[count($joined) - 1] .= $part;
|
| 451 |
+
}
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
return $joined;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
// replaces all the interpolates
|
| 458 |
+
protected function evalSelector($selector) {
|
| 459 |
+
return array_map(array($this, 'evalSelectorPart'), $selector);
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
protected function evalSelectorPart($piece) {
|
| 463 |
+
foreach ($piece as &$p) {
|
| 464 |
+
if (!is_array($p)) continue;
|
| 465 |
+
|
| 466 |
+
switch ($p[0]) {
|
| 467 |
+
case 'interpolate':
|
| 468 |
+
$p = $this->compileValue($p);
|
| 469 |
+
break;
|
| 470 |
+
case 'string':
|
| 471 |
+
$p = $this->compileValue($p);
|
| 472 |
+
break;
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
return $this->flattenSelectorSingle($piece);
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
// compiles to string
|
| 480 |
+
// self(&) should have been replaced by now
|
| 481 |
+
protected function compileSelector($selector) {
|
| 482 |
+
if (!is_array($selector)) return $selector; // media and the like
|
| 483 |
+
|
| 484 |
+
return implode(' ', array_map(
|
| 485 |
+
array($this, 'compileSelectorPart'), $selector));
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
protected function compileSelectorPart($piece) {
|
| 489 |
+
foreach ($piece as &$p) {
|
| 490 |
+
if (!is_array($p)) continue;
|
| 491 |
+
|
| 492 |
+
switch ($p[0]) {
|
| 493 |
+
case 'self':
|
| 494 |
+
$p = '&';
|
| 495 |
+
break;
|
| 496 |
+
default:
|
| 497 |
+
$p = $this->compileValue($p);
|
| 498 |
+
break;
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
return implode($piece);
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
protected function hasSelectorPlaceholder($selector)
|
| 506 |
+
{
|
| 507 |
+
if (!is_array($selector)) return false;
|
| 508 |
+
|
| 509 |
+
foreach ($selector as $parts) {
|
| 510 |
+
foreach ($parts as $part) {
|
| 511 |
+
if ('%' == $part[0]) {
|
| 512 |
+
return true;
|
| 513 |
+
}
|
| 514 |
+
}
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
return false;
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
protected function compileChildren($stms, $out) {
|
| 521 |
+
foreach ($stms as $stm) {
|
| 522 |
+
$ret = $this->compileChild($stm, $out);
|
| 523 |
+
if (isset($ret)) return $ret;
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
protected function compileMediaQuery($queryList) {
|
| 528 |
+
$out = '@media';
|
| 529 |
+
$first = true;
|
| 530 |
+
foreach ($queryList as $query){
|
| 531 |
+
$type = null;
|
| 532 |
+
$parts = array();
|
| 533 |
+
foreach ($query as $q) {
|
| 534 |
+
switch ($q[0]) {
|
| 535 |
+
case 'mediaType':
|
| 536 |
+
if ($type) {
|
| 537 |
+
$type = $this->mergeMediaTypes($type, array_map(array($this, 'compileValue'), array_slice($q, 1)));
|
| 538 |
+
if (empty($type)) { // merge failed
|
| 539 |
+
return null;
|
| 540 |
+
}
|
| 541 |
+
} else {
|
| 542 |
+
$type = array_map(array($this, 'compileValue'), array_slice($q, 1));
|
| 543 |
+
}
|
| 544 |
+
break;
|
| 545 |
+
case 'mediaExp':
|
| 546 |
+
if (isset($q[2])) {
|
| 547 |
+
$parts[] = '('. $this->compileValue($q[1]) . $this->formatter->assignSeparator . $this->compileValue($q[2]) . ')';
|
| 548 |
+
} else {
|
| 549 |
+
$parts[] = '(' . $this->compileValue($q[1]) . ')';
|
| 550 |
+
}
|
| 551 |
+
break;
|
| 552 |
+
}
|
| 553 |
+
}
|
| 554 |
+
if ($type) {
|
| 555 |
+
array_unshift($parts, implode(' ', array_filter($type)));
|
| 556 |
+
}
|
| 557 |
+
if (!empty($parts)) {
|
| 558 |
+
if ($first) {
|
| 559 |
+
$first = false;
|
| 560 |
+
$out .= ' ';
|
| 561 |
+
} else {
|
| 562 |
+
$out .= $this->formatter->tagSeparator;
|
| 563 |
+
}
|
| 564 |
+
$out .= implode(' and ', $parts);
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
return $out;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
protected function mergeMediaTypes($type1, $type2) {
|
| 571 |
+
if (empty($type1)) {
|
| 572 |
+
return $type2;
|
| 573 |
+
}
|
| 574 |
+
if (empty($type2)) {
|
| 575 |
+
return $type1;
|
| 576 |
+
}
|
| 577 |
+
$m1 = '';
|
| 578 |
+
$t1 = '';
|
| 579 |
+
if (count($type1) > 1) {
|
| 580 |
+
$m1= strtolower($type1[0]);
|
| 581 |
+
$t1= strtolower($type1[1]);
|
| 582 |
+
} else {
|
| 583 |
+
$t1 = strtolower($type1[0]);
|
| 584 |
+
}
|
| 585 |
+
$m2 = '';
|
| 586 |
+
$t2 = '';
|
| 587 |
+
if (count($type2) > 1) {
|
| 588 |
+
$m2 = strtolower($type2[0]);
|
| 589 |
+
$t2 = strtolower($type2[1]);
|
| 590 |
+
} else {
|
| 591 |
+
$t2 = strtolower($type2[0]);
|
| 592 |
+
}
|
| 593 |
+
if (($m1 == 'not') ^ ($m2 == 'not')) {
|
| 594 |
+
if ($t1 == $t2) {
|
| 595 |
+
return null;
|
| 596 |
+
}
|
| 597 |
+
return array(
|
| 598 |
+
$m1 == 'not' ? $m2 : $m1,
|
| 599 |
+
$m1 == 'not' ? $t2 : $t1
|
| 600 |
+
);
|
| 601 |
+
} elseif ($m1 == 'not' && $m2 == 'not') {
|
| 602 |
+
# CSS has no way of representing "neither screen nor print"
|
| 603 |
+
if ($t1 != $t2) {
|
| 604 |
+
return null;
|
| 605 |
+
}
|
| 606 |
+
return array('not', $t1);
|
| 607 |
+
} elseif ($t1 != $t2) {
|
| 608 |
+
return null;
|
| 609 |
+
} else { // t1 == t2, neither m1 nor m2 are "not"
|
| 610 |
+
return array(empty($m1)? $m2 : $m1, $t1);
|
| 611 |
+
}
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
// returns true if the value was something that could be imported
|
| 615 |
+
protected function compileImport($rawPath, $out) {
|
| 616 |
+
if ($rawPath[0] == 'string') {
|
| 617 |
+
$path = $this->compileStringContent($rawPath);
|
| 618 |
+
if ($path = $this->findImport($path)) {
|
| 619 |
+
$this->importFile($path, $out);
|
| 620 |
+
return true;
|
| 621 |
+
}
|
| 622 |
+
return false;
|
| 623 |
+
}
|
| 624 |
+
if ($rawPath[0] == 'list') {
|
| 625 |
+
// handle a list of strings
|
| 626 |
+
if (count($rawPath[2]) == 0) return false;
|
| 627 |
+
foreach ($rawPath[2] as $path) {
|
| 628 |
+
if ($path[0] != 'string') return false;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
foreach ($rawPath[2] as $path) {
|
| 632 |
+
$this->compileImport($path, $out);
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
return true;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
return false;
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
// return a value to halt execution
|
| 642 |
+
protected function compileChild($child, $out) {
|
| 643 |
+
$this->sourcePos = isset($child[-1]) ? $child[-1] : -1;
|
| 644 |
+
$this->sourceParser = isset($child[-2]) ? $child[-2] : $this->parser;
|
| 645 |
+
|
| 646 |
+
switch ($child[0]) {
|
| 647 |
+
case 'import':
|
| 648 |
+
list(,$rawPath) = $child;
|
| 649 |
+
$rawPath = $this->reduce($rawPath);
|
| 650 |
+
if (!$this->compileImport($rawPath, $out)) {
|
| 651 |
+
$out->lines[] = '@import ' . $this->compileValue($rawPath) . ';';
|
| 652 |
+
}
|
| 653 |
+
break;
|
| 654 |
+
case 'directive':
|
| 655 |
+
list(, $directive) = $child;
|
| 656 |
+
$s = '@' . $directive->name;
|
| 657 |
+
if (!empty($directive->value)) {
|
| 658 |
+
$s .= ' ' . $this->compileValue($directive->value);
|
| 659 |
+
}
|
| 660 |
+
$this->compileNestedBlock($directive, array($s));
|
| 661 |
+
break;
|
| 662 |
+
case 'media':
|
| 663 |
+
$this->compileMedia($child[1]);
|
| 664 |
+
break;
|
| 665 |
+
case 'block':
|
| 666 |
+
$this->compileBlock($child[1]);
|
| 667 |
+
break;
|
| 668 |
+
case 'charset':
|
| 669 |
+
$out->lines[] = '@charset '.$this->compileValue($child[1]).';';
|
| 670 |
+
break;
|
| 671 |
+
case 'assign':
|
| 672 |
+
list(,$name, $value) = $child;
|
| 673 |
+
if ($name[0] == 'var') {
|
| 674 |
+
$isDefault = !empty($child[3]);
|
| 675 |
+
|
| 676 |
+
if ($isDefault) {
|
| 677 |
+
$existingValue = $this->get($name[1], true);
|
| 678 |
+
$shouldSet = $existingValue === true || $existingValue == self::$null;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
if (!$isDefault || $shouldSet) {
|
| 682 |
+
$this->set($name[1], $this->reduce($value));
|
| 683 |
+
}
|
| 684 |
+
break;
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
// if the value reduces to null from something else then
|
| 688 |
+
// the property should be discarded
|
| 689 |
+
if ($value[0] != 'null') {
|
| 690 |
+
$value = $this->reduce($value);
|
| 691 |
+
if ($value[0] == 'null') {
|
| 692 |
+
break;
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
$compiledValue = $this->compileValue($value);
|
| 697 |
+
$out->lines[] = $this->formatter->property(
|
| 698 |
+
$this->compileValue($name),
|
| 699 |
+
$compiledValue);
|
| 700 |
+
break;
|
| 701 |
+
case 'comment':
|
| 702 |
+
if ($out->type == 'root') {
|
| 703 |
+
$this->compileComment($child);
|
| 704 |
+
break;
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
$out->lines[] = $child[1];
|
| 708 |
+
break;
|
| 709 |
+
case 'mixin':
|
| 710 |
+
case 'function':
|
| 711 |
+
list(,$block) = $child;
|
| 712 |
+
$this->set(self::$namespaces[$block->type] . $block->name, $block);
|
| 713 |
+
break;
|
| 714 |
+
case 'extend':
|
| 715 |
+
list(, $selectors) = $child;
|
| 716 |
+
foreach ($selectors as $sel) {
|
| 717 |
+
// only use the first one
|
| 718 |
+
$sel = current($this->evalSelector($sel));
|
| 719 |
+
$this->pushExtends($sel, $out->selectors);
|
| 720 |
+
}
|
| 721 |
+
break;
|
| 722 |
+
case 'if':
|
| 723 |
+
list(, $if) = $child;
|
| 724 |
+
if ($this->isTruthy($this->reduce($if->cond, true))) {
|
| 725 |
+
return $this->compileChildren($if->children, $out);
|
| 726 |
+
} else {
|
| 727 |
+
foreach ($if->cases as $case) {
|
| 728 |
+
if ($case->type == 'else' ||
|
| 729 |
+
$case->type == 'elseif' && $this->isTruthy($this->reduce($case->cond)))
|
| 730 |
+
{
|
| 731 |
+
return $this->compileChildren($case->children, $out);
|
| 732 |
+
}
|
| 733 |
+
}
|
| 734 |
+
}
|
| 735 |
+
break;
|
| 736 |
+
case 'return':
|
| 737 |
+
return $this->reduce($child[1], true);
|
| 738 |
+
case 'each':
|
| 739 |
+
list(,$each) = $child;
|
| 740 |
+
$list = $this->coerceList($this->reduce($each->list));
|
| 741 |
+
foreach ($list[2] as $item) {
|
| 742 |
+
$this->pushEnv();
|
| 743 |
+
$this->set($each->var, $item);
|
| 744 |
+
// TODO: allow return from here
|
| 745 |
+
$this->compileChildren($each->children, $out);
|
| 746 |
+
$this->popEnv();
|
| 747 |
+
}
|
| 748 |
+
break;
|
| 749 |
+
case 'while':
|
| 750 |
+
list(,$while) = $child;
|
| 751 |
+
while ($this->isTruthy($this->reduce($while->cond, true))) {
|
| 752 |
+
$ret = $this->compileChildren($while->children, $out);
|
| 753 |
+
if ($ret) return $ret;
|
| 754 |
+
}
|
| 755 |
+
break;
|
| 756 |
+
case 'for':
|
| 757 |
+
list(,$for) = $child;
|
| 758 |
+
$start = $this->reduce($for->start, true);
|
| 759 |
+
$start = $start[1];
|
| 760 |
+
$end = $this->reduce($for->end, true);
|
| 761 |
+
$end = $end[1];
|
| 762 |
+
$d = $start < $end ? 1 : -1;
|
| 763 |
+
|
| 764 |
+
while (true) {
|
| 765 |
+
if ((!$for->until && $start - $d == $end) ||
|
| 766 |
+
($for->until && $start == $end))
|
| 767 |
+
{
|
| 768 |
+
break;
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
$this->set($for->var, array('number', $start, ''));
|
| 772 |
+
$start += $d;
|
| 773 |
+
|
| 774 |
+
$ret = $this->compileChildren($for->children, $out);
|
| 775 |
+
if ($ret) return $ret;
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
break;
|
| 779 |
+
case 'nestedprop':
|
| 780 |
+
list(,$prop) = $child;
|
| 781 |
+
$prefixed = array();
|
| 782 |
+
$prefix = $this->compileValue($prop->prefix) . '-';
|
| 783 |
+
foreach ($prop->children as $child) {
|
| 784 |
+
if ($child[0] == 'assign') {
|
| 785 |
+
array_unshift($child[1][2], $prefix);
|
| 786 |
+
}
|
| 787 |
+
if ($child[0] == 'nestedprop') {
|
| 788 |
+
array_unshift($child[1]->prefix[2], $prefix);
|
| 789 |
+
}
|
| 790 |
+
$prefixed[] = $child;
|
| 791 |
+
}
|
| 792 |
+
$this->compileChildren($prefixed, $out);
|
| 793 |
+
break;
|
| 794 |
+
case 'include': // including a mixin
|
| 795 |
+
list(,$name, $argValues, $content) = $child;
|
| 796 |
+
$mixin = $this->get(self::$namespaces['mixin'] . $name, false);
|
| 797 |
+
if (!$mixin) {
|
| 798 |
+
$this->throwError("Undefined mixin $name");
|
| 799 |
+
}
|
| 800 |
+
|
| 801 |
+
$callingScope = $this->env;
|
| 802 |
+
|
| 803 |
+
// push scope, apply args
|
| 804 |
+
$this->pushEnv();
|
| 805 |
+
if ($this->env->depth > 0) {
|
| 806 |
+
$this->env->depth--;
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
if (isset($content)) {
|
| 810 |
+
$content->scope = $callingScope;
|
| 811 |
+
$this->setRaw(self::$namespaces['special'] . 'content', $content);
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
if (isset($mixin->args)) {
|
| 815 |
+
$this->applyArguments($mixin->args, $argValues);
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
foreach ($mixin->children as $child) {
|
| 819 |
+
$this->compileChild($child, $out);
|
| 820 |
+
}
|
| 821 |
+
|
| 822 |
+
$this->popEnv();
|
| 823 |
+
|
| 824 |
+
break;
|
| 825 |
+
case 'mixin_content':
|
| 826 |
+
$content = $this->get(self::$namespaces['special'] . 'content');
|
| 827 |
+
if (!isset($content)) {
|
| 828 |
+
$this->throwError('Expected @content inside of mixin');
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
$strongTypes = array('include', 'block', 'for', 'while');
|
| 832 |
+
foreach ($content->children as $child) {
|
| 833 |
+
$this->storeEnv = (in_array($child[0], $strongTypes))
|
| 834 |
+
? null
|
| 835 |
+
: $content->scope;
|
| 836 |
+
|
| 837 |
+
$this->compileChild($child, $out);
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
unset($this->storeEnv);
|
| 841 |
+
break;
|
| 842 |
+
case 'debug':
|
| 843 |
+
list(,$value, $pos) = $child;
|
| 844 |
+
$line = $this->parser->getLineNo($pos);
|
| 845 |
+
$value = $this->compileValue($this->reduce($value, true));
|
| 846 |
+
fwrite(STDERR, "Line $line DEBUG: $value\n");
|
| 847 |
+
break;
|
| 848 |
+
default:
|
| 849 |
+
$this->throwError("unknown child type: $child[0]");
|
| 850 |
+
}
|
| 851 |
+
}
|
| 852 |
+
|
| 853 |
+
protected function expToString($exp) {
|
| 854 |
+
list(, $op, $left, $right, $inParens, $whiteLeft, $whiteRight) = $exp;
|
| 855 |
+
$content = array($this->reduce($left));
|
| 856 |
+
if ($whiteLeft) $content[] = ' ';
|
| 857 |
+
$content[] = $op;
|
| 858 |
+
if ($whiteRight) $content[] = ' ';
|
| 859 |
+
$content[] = $this->reduce($right);
|
| 860 |
+
return array('string', '', $content);
|
| 861 |
+
}
|
| 862 |
+
|
| 863 |
+
protected function isTruthy($value) {
|
| 864 |
+
return $value != self::$false && $value != self::$null;
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
// should $value cause its operand to eval
|
| 868 |
+
protected function shouldEval($value) {
|
| 869 |
+
switch ($value[0]) {
|
| 870 |
+
case 'exp':
|
| 871 |
+
if ($value[1] == '/') {
|
| 872 |
+
return $this->shouldEval($value[2], $value[3]);
|
| 873 |
+
}
|
| 874 |
+
case 'var':
|
| 875 |
+
case 'fncall':
|
| 876 |
+
return true;
|
| 877 |
+
}
|
| 878 |
+
return false;
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
protected function reduce($value, $inExp = false) {
|
| 882 |
+
list($type) = $value;
|
| 883 |
+
switch ($type) {
|
| 884 |
+
case 'exp':
|
| 885 |
+
list(, $op, $left, $right, $inParens) = $value;
|
| 886 |
+
$opName = isset(self::$operatorNames[$op]) ? self::$operatorNames[$op] : $op;
|
| 887 |
+
|
| 888 |
+
$inExp = $inExp || $this->shouldEval($left) || $this->shouldEval($right);
|
| 889 |
+
|
| 890 |
+
$left = $this->reduce($left, true);
|
| 891 |
+
$right = $this->reduce($right, true);
|
| 892 |
+
|
| 893 |
+
// only do division in special cases
|
| 894 |
+
if ($opName == 'div' && !$inParens && !$inExp) {
|
| 895 |
+
if ($left[0] != 'color' && $right[0] != 'color') {
|
| 896 |
+
return $this->expToString($value);
|
| 897 |
+
}
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
$left = $this->coerceForExpression($left);
|
| 901 |
+
$right = $this->coerceForExpression($right);
|
| 902 |
+
|
| 903 |
+
$ltype = $left[0];
|
| 904 |
+
$rtype = $right[0];
|
| 905 |
+
|
| 906 |
+
// this tries:
|
| 907 |
+
// 1. op_[op name]_[left type]_[right type]
|
| 908 |
+
// 2. op_[left type]_[right type] (passing the op as first arg
|
| 909 |
+
// 3. op_[op name]
|
| 910 |
+
$fn = "op_${opName}_${ltype}_${rtype}";
|
| 911 |
+
if (is_callable(array($this, $fn)) ||
|
| 912 |
+
(($fn = "op_${ltype}_${rtype}") &&
|
| 913 |
+
is_callable(array($this, $fn)) &&
|
| 914 |
+
$passOp = true) ||
|
| 915 |
+
(($fn = "op_${opName}") &&
|
| 916 |
+
is_callable(array($this, $fn)) &&
|
| 917 |
+
$genOp = true))
|
| 918 |
+
{
|
| 919 |
+
$unitChange = false;
|
| 920 |
+
if (!isset($genOp) &&
|
| 921 |
+
$left[0] == 'number' && $right[0] == 'number')
|
| 922 |
+
{
|
| 923 |
+
if ($opName == 'mod' && $right[2] != '') {
|
| 924 |
+
$this->throwError("Cannot modulo by a number with units: $right[1]$right[2].");
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
$unitChange = true;
|
| 928 |
+
$emptyUnit = $left[2] == '' || $right[2] == '';
|
| 929 |
+
$targetUnit = '' != $left[2] ? $left[2] : $right[2];
|
| 930 |
+
|
| 931 |
+
if ($opName != 'mul') {
|
| 932 |
+
$left[2] = '' != $left[2] ? $left[2] : $targetUnit;
|
| 933 |
+
$right[2] = '' != $right[2] ? $right[2] : $targetUnit;
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
if ($opName != 'mod') {
|
| 937 |
+
$left = $this->normalizeNumber($left);
|
| 938 |
+
$right = $this->normalizeNumber($right);
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
if ($opName == 'div' && !$emptyUnit && $left[2] == $right[2]) {
|
| 942 |
+
$targetUnit = '';
|
| 943 |
+
}
|
| 944 |
+
|
| 945 |
+
if ($opName == 'mul') {
|
| 946 |
+
$left[2] = '' != $left[2] ? $left[2] : $right[2];
|
| 947 |
+
$right[2] = '' != $right[2] ? $right[2] : $left[2];
|
| 948 |
+
} elseif ($opName == 'div' && $left[2] == $right[2]) {
|
| 949 |
+
$left[2] = '';
|
| 950 |
+
$right[2] = '';
|
| 951 |
+
}
|
| 952 |
+
}
|
| 953 |
+
|
| 954 |
+
$shouldEval = $inParens || $inExp;
|
| 955 |
+
if (isset($passOp)) {
|
| 956 |
+
$out = $this->$fn($op, $left, $right, $shouldEval);
|
| 957 |
+
} else {
|
| 958 |
+
$out = $this->$fn($left, $right, $shouldEval);
|
| 959 |
+
}
|
| 960 |
+
|
| 961 |
+
if (isset($out)) {
|
| 962 |
+
if ($unitChange && $out[0] == 'number') {
|
| 963 |
+
$out = $this->coerceUnit($out, $targetUnit);
|
| 964 |
+
}
|
| 965 |
+
return $out;
|
| 966 |
+
}
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
+
return $this->expToString($value);
|
| 970 |
+
case 'unary':
|
| 971 |
+
list(, $op, $exp, $inParens) = $value;
|
| 972 |
+
$inExp = $inExp || $this->shouldEval($exp);
|
| 973 |
+
|
| 974 |
+
$exp = $this->reduce($exp);
|
| 975 |
+
if ($exp[0] == 'number') {
|
| 976 |
+
switch ($op) {
|
| 977 |
+
case '+':
|
| 978 |
+
return $exp;
|
| 979 |
+
case '-':
|
| 980 |
+
$exp[1] *= -1;
|
| 981 |
+
return $exp;
|
| 982 |
+
}
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
if ($op == 'not') {
|
| 986 |
+
if ($inExp || $inParens) {
|
| 987 |
+
if ($exp == self::$false) {
|
| 988 |
+
return self::$true;
|
| 989 |
+
} else {
|
| 990 |
+
return self::$false;
|
| 991 |
+
}
|
| 992 |
+
} else {
|
| 993 |
+
$op = $op . ' ';
|
| 994 |
+
}
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
return array('string', '', array($op, $exp));
|
| 998 |
+
case 'var':
|
| 999 |
+
list(, $name) = $value;
|
| 1000 |
+
return $this->reduce($this->get($name));
|
| 1001 |
+
case 'list':
|
| 1002 |
+
foreach ($value[2] as &$item) {
|
| 1003 |
+
$item = $this->reduce($item);
|
| 1004 |
+
}
|
| 1005 |
+
return $value;
|
| 1006 |
+
case 'string':
|
| 1007 |
+
foreach ($value[2] as &$item) {
|
| 1008 |
+
if (is_array($item)) {
|
| 1009 |
+
$item = $this->reduce($item);
|
| 1010 |
+
}
|
| 1011 |
+
}
|
| 1012 |
+
return $value;
|
| 1013 |
+
case 'interpolate':
|
| 1014 |
+
$value[1] = $this->reduce($value[1]);
|
| 1015 |
+
return $value;
|
| 1016 |
+
case 'fncall':
|
| 1017 |
+
list(,$name, $argValues) = $value;
|
| 1018 |
+
|
| 1019 |
+
// user defined function?
|
| 1020 |
+
$func = $this->get(self::$namespaces['function'] . $name, false);
|
| 1021 |
+
if ($func) {
|
| 1022 |
+
$this->pushEnv();
|
| 1023 |
+
|
| 1024 |
+
// set the args
|
| 1025 |
+
if (isset($func->args)) {
|
| 1026 |
+
$this->applyArguments($func->args, $argValues);
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
// throw away lines and children
|
| 1030 |
+
$tmp = (object)array(
|
| 1031 |
+
'lines' => array(),
|
| 1032 |
+
'children' => array()
|
| 1033 |
+
);
|
| 1034 |
+
$ret = $this->compileChildren($func->children, $tmp);
|
| 1035 |
+
$this->popEnv();
|
| 1036 |
+
|
| 1037 |
+
return !isset($ret) ? self::$defaultValue : $ret;
|
| 1038 |
+
}
|
| 1039 |
+
|
| 1040 |
+
// built in function
|
| 1041 |
+
if ($this->callBuiltin($name, $argValues, $returnValue)) {
|
| 1042 |
+
return $returnValue;
|
| 1043 |
+
}
|
| 1044 |
+
|
| 1045 |
+
// need to flatten the arguments into a list
|
| 1046 |
+
$listArgs = array();
|
| 1047 |
+
foreach ((array)$argValues as $arg) {
|
| 1048 |
+
if (empty($arg[0])) {
|
| 1049 |
+
$listArgs[] = $this->reduce($arg[1]);
|
| 1050 |
+
}
|
| 1051 |
+
}
|
| 1052 |
+
return array('function', $name, array('list', ',', $listArgs));
|
| 1053 |
+
default:
|
| 1054 |
+
return $value;
|
| 1055 |
+
}
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
public function normalizeValue($value) {
|
| 1059 |
+
$value = $this->coerceForExpression($this->reduce($value));
|
| 1060 |
+
list($type) = $value;
|
| 1061 |
+
|
| 1062 |
+
switch ($type) {
|
| 1063 |
+
case 'list':
|
| 1064 |
+
$value = $this->extractInterpolation($value);
|
| 1065 |
+
if ($value[0] != 'list') {
|
| 1066 |
+
return array('keyword', $this->compileValue($value));
|
| 1067 |
+
}
|
| 1068 |
+
foreach ($value[2] as $key => $item) {
|
| 1069 |
+
$value[2][$key] = $this->normalizeValue($item);
|
| 1070 |
+
}
|
| 1071 |
+
return $value;
|
| 1072 |
+
case 'number':
|
| 1073 |
+
return $this->normalizeNumber($value);
|
| 1074 |
+
default:
|
| 1075 |
+
return $value;
|
| 1076 |
+
}
|
| 1077 |
+
}
|
| 1078 |
+
|
| 1079 |
+
// just does physical lengths for now
|
| 1080 |
+
protected function normalizeNumber($number) {
|
| 1081 |
+
list(, $value, $unit) = $number;
|
| 1082 |
+
if (isset(self::$unitTable['in'][$unit])) {
|
| 1083 |
+
$conv = self::$unitTable['in'][$unit];
|
| 1084 |
+
return array('number', $value / $conv, 'in');
|
| 1085 |
+
}
|
| 1086 |
+
return $number;
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
// $number should be normalized
|
| 1090 |
+
protected function coerceUnit($number, $unit) {
|
| 1091 |
+
list(, $value, $baseUnit) = $number;
|
| 1092 |
+
if (isset(self::$unitTable[$baseUnit][$unit])) {
|
| 1093 |
+
$value = $value * self::$unitTable[$baseUnit][$unit];
|
| 1094 |
+
}
|
| 1095 |
+
|
| 1096 |
+
return array('number', $value, $unit);
|
| 1097 |
+
}
|
| 1098 |
+
|
| 1099 |
+
protected function op_add_number_number($left, $right) {
|
| 1100 |
+
return array('number', $left[1] + $right[1], $left[2]);
|
| 1101 |
+
}
|
| 1102 |
+
|
| 1103 |
+
protected function op_mul_number_number($left, $right) {
|
| 1104 |
+
return array('number', $left[1] * $right[1], $left[2]);
|
| 1105 |
+
}
|
| 1106 |
+
|
| 1107 |
+
protected function op_sub_number_number($left, $right) {
|
| 1108 |
+
return array('number', $left[1] - $right[1], $left[2]);
|
| 1109 |
+
}
|
| 1110 |
+
|
| 1111 |
+
protected function op_div_number_number($left, $right) {
|
| 1112 |
+
return array('number', $left[1] / $right[1], $left[2]);
|
| 1113 |
+
}
|
| 1114 |
+
|
| 1115 |
+
protected function op_mod_number_number($left, $right) {
|
| 1116 |
+
return array('number', $left[1] % $right[1], $left[2]);
|
| 1117 |
+
}
|
| 1118 |
+
|
| 1119 |
+
// adding strings
|
| 1120 |
+
protected function op_add($left, $right) {
|
| 1121 |
+
if ($strLeft = $this->coerceString($left)) {
|
| 1122 |
+
if ($right[0] == 'string') {
|
| 1123 |
+
$right[1] = '';
|
| 1124 |
+
}
|
| 1125 |
+
$strLeft[2][] = $right;
|
| 1126 |
+
return $strLeft;
|
| 1127 |
+
}
|
| 1128 |
+
|
| 1129 |
+
if ($strRight = $this->coerceString($right)) {
|
| 1130 |
+
if ($left[0] == 'string') {
|
| 1131 |
+
$left[1] = '';
|
| 1132 |
+
}
|
| 1133 |
+
array_unshift($strRight[2], $left);
|
| 1134 |
+
return $strRight;
|
| 1135 |
+
}
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
protected function op_and($left, $right, $shouldEval) {
|
| 1139 |
+
if (!$shouldEval) return;
|
| 1140 |
+
if ($left != self::$false) return $right;
|
| 1141 |
+
return $left;
|
| 1142 |
+
}
|
| 1143 |
+
|
| 1144 |
+
protected function op_or($left, $right, $shouldEval) {
|
| 1145 |
+
if (!$shouldEval) return;
|
| 1146 |
+
if ($left != self::$false) return $left;
|
| 1147 |
+
return $right;
|
| 1148 |
+
}
|
| 1149 |
+
|
| 1150 |
+
protected function op_color_color($op, $left, $right) {
|
| 1151 |
+
$out = array('color');
|
| 1152 |
+
foreach (range(1, 3) as $i) {
|
| 1153 |
+
$lval = isset($left[$i]) ? $left[$i] : 0;
|
| 1154 |
+
$rval = isset($right[$i]) ? $right[$i] : 0;
|
| 1155 |
+
switch ($op) {
|
| 1156 |
+
case '+':
|
| 1157 |
+
$out[] = $lval + $rval;
|
| 1158 |
+
break;
|
| 1159 |
+
case '-':
|
| 1160 |
+
$out[] = $lval - $rval;
|
| 1161 |
+
break;
|
| 1162 |
+
case '*':
|
| 1163 |
+
$out[] = $lval * $rval;
|
| 1164 |
+
break;
|
| 1165 |
+
case '%':
|
| 1166 |
+
$out[] = $lval % $rval;
|
| 1167 |
+
break;
|
| 1168 |
+
case '/':
|
| 1169 |
+
if ($rval == 0) {
|
| 1170 |
+
$this->throwError("color: Can't divide by zero");
|
| 1171 |
+
}
|
| 1172 |
+
$out[] = $lval / $rval;
|
| 1173 |
+
break;
|
| 1174 |
+
case '==':
|
| 1175 |
+
return $this->op_eq($left, $right);
|
| 1176 |
+
case '!=':
|
| 1177 |
+
return $this->op_neq($left, $right);
|
| 1178 |
+
default:
|
| 1179 |
+
$this->throwError("color: unknown op $op");
|
| 1180 |
+
}
|
| 1181 |
+
}
|
| 1182 |
+
|
| 1183 |
+
if (isset($left[4])) $out[4] = $left[4];
|
| 1184 |
+
elseif (isset($right[4])) $out[4] = $right[4];
|
| 1185 |
+
|
| 1186 |
+
return $this->fixColor($out);
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
+
protected function op_color_number($op, $left, $right) {
|
| 1190 |
+
$value = $right[1];
|
| 1191 |
+
return $this->op_color_color($op, $left,
|
| 1192 |
+
array('color', $value, $value, $value));
|
| 1193 |
+
}
|
| 1194 |
+
|
| 1195 |
+
protected function op_number_color($op, $left, $right) {
|
| 1196 |
+
$value = $left[1];
|
| 1197 |
+
return $this->op_color_color($op,
|
| 1198 |
+
array('color', $value, $value, $value), $right);
|
| 1199 |
+
}
|
| 1200 |
+
|
| 1201 |
+
protected function op_eq($left, $right) {
|
| 1202 |
+
if (($lStr = $this->coerceString($left)) && ($rStr = $this->coerceString($right))) {
|
| 1203 |
+
$lStr[1] = '';
|
| 1204 |
+
$rStr[1] = '';
|
| 1205 |
+
return $this->toBool($this->compileValue($lStr) == $this->compileValue($rStr));
|
| 1206 |
+
}
|
| 1207 |
+
|
| 1208 |
+
return $this->toBool($left == $right);
|
| 1209 |
+
}
|
| 1210 |
+
|
| 1211 |
+
protected function op_neq($left, $right) {
|
| 1212 |
+
return $this->toBool($left != $right);
|
| 1213 |
+
}
|
| 1214 |
+
|
| 1215 |
+
protected function op_gte_number_number($left, $right) {
|
| 1216 |
+
return $this->toBool($left[1] >= $right[1]);
|
| 1217 |
+
}
|
| 1218 |
+
|
| 1219 |
+
protected function op_gt_number_number($left, $right) {
|
| 1220 |
+
return $this->toBool($left[1] > $right[1]);
|
| 1221 |
+
}
|
| 1222 |
+
|
| 1223 |
+
protected function op_lte_number_number($left, $right) {
|
| 1224 |
+
return $this->toBool($left[1] <= $right[1]);
|
| 1225 |
+
}
|
| 1226 |
+
|
| 1227 |
+
protected function op_lt_number_number($left, $right) {
|
| 1228 |
+
return $this->toBool($left[1] < $right[1]);
|
| 1229 |
+
}
|
| 1230 |
+
|
| 1231 |
+
public function toBool($thing) {
|
| 1232 |
+
return $thing ? self::$true : self::$false;
|
| 1233 |
+
}
|
| 1234 |
+
|
| 1235 |
+
/**
|
| 1236 |
+
* Compiles a primitive value into a CSS property value.
|
| 1237 |
+
*
|
| 1238 |
+
* Values in scssphp are typed by being wrapped in arrays, their format is
|
| 1239 |
+
* typically:
|
| 1240 |
+
*
|
| 1241 |
+
* array(type, contents [, additional_contents]*)
|
| 1242 |
+
*
|
| 1243 |
+
* The input is expected to be reduced. This function will not work on
|
| 1244 |
+
* things like expressions and variables.
|
| 1245 |
+
*
|
| 1246 |
+
* @param array $value
|
| 1247 |
+
*/
|
| 1248 |
+
protected function compileValue($value) {
|
| 1249 |
+
$value = $this->reduce($value);
|
| 1250 |
+
|
| 1251 |
+
list($type) = $value;
|
| 1252 |
+
switch ($type) {
|
| 1253 |
+
case 'keyword':
|
| 1254 |
+
return $value[1];
|
| 1255 |
+
case 'color':
|
| 1256 |
+
// [1] - red component (either number for a %)
|
| 1257 |
+
// [2] - green component
|
| 1258 |
+
// [3] - blue component
|
| 1259 |
+
// [4] - optional alpha component
|
| 1260 |
+
list(, $r, $g, $b) = $value;
|
| 1261 |
+
|
| 1262 |
+
$r = round($r);
|
| 1263 |
+
$g = round($g);
|
| 1264 |
+
$b = round($b);
|
| 1265 |
+
|
| 1266 |
+
if (count($value) == 5 && $value[4] != 1) { // rgba
|
| 1267 |
+
return 'rgba('.$r.', '.$g.', '.$b.', '.$value[4].')';
|
| 1268 |
+
}
|
| 1269 |
+
|
| 1270 |
+
$h = sprintf('#%02x%02x%02x', $r, $g, $b);
|
| 1271 |
+
|
| 1272 |
+
// Converting hex color to short notation (e.g. #003399 to #039)
|
| 1273 |
+
if ($h[1] === $h[2] && $h[3] === $h[4] && $h[5] === $h[6]) {
|
| 1274 |
+
$h = '#' . $h[1] . $h[3] . $h[5];
|
| 1275 |
+
}
|
| 1276 |
+
|
| 1277 |
+
return $h;
|
| 1278 |
+
case 'number':
|
| 1279 |
+
return round($value[1], $this->numberPrecision) . $value[2];
|
| 1280 |
+
case 'string':
|
| 1281 |
+
return $value[1] . $this->compileStringContent($value) . $value[1];
|
| 1282 |
+
case 'function':
|
| 1283 |
+
$args = !empty($value[2]) ? $this->compileValue($value[2]) : '';
|
| 1284 |
+
return "$value[1]($args)";
|
| 1285 |
+
case 'list':
|
| 1286 |
+
$value = $this->extractInterpolation($value);
|
| 1287 |
+
if ($value[0] != 'list') return $this->compileValue($value);
|
| 1288 |
+
|
| 1289 |
+
list(, $delim, $items) = $value;
|
| 1290 |
+
|
| 1291 |
+
$filtered = array();
|
| 1292 |
+
foreach ($items as $item) {
|
| 1293 |
+
if ($item[0] == 'null') continue;
|
| 1294 |
+
$filtered[] = $this->compileValue($item);
|
| 1295 |
+
}
|
| 1296 |
+
|
| 1297 |
+
return implode("$delim ", $filtered);
|
| 1298 |
+
case 'interpolated': # node created by extractInterpolation
|
| 1299 |
+
list(, $interpolate, $left, $right) = $value;
|
| 1300 |
+
list(,, $whiteLeft, $whiteRight) = $interpolate;
|
| 1301 |
+
|
| 1302 |
+
$left = count($left[2]) > 0 ?
|
| 1303 |
+
$this->compileValue($left).$whiteLeft : '';
|
| 1304 |
+
|
| 1305 |
+
$right = count($right[2]) > 0 ?
|
| 1306 |
+
$whiteRight.$this->compileValue($right) : '';
|
| 1307 |
+
|
| 1308 |
+
return $left.$this->compileValue($interpolate).$right;
|
| 1309 |
+
|
| 1310 |
+
case 'interpolate': # raw parse node
|
| 1311 |
+
list(, $exp) = $value;
|
| 1312 |
+
|
| 1313 |
+
// strip quotes if it's a string
|
| 1314 |
+
$reduced = $this->reduce($exp);
|
| 1315 |
+
switch ($reduced[0]) {
|
| 1316 |
+
case 'string':
|
| 1317 |
+
$reduced = array('keyword',
|
| 1318 |
+
$this->compileStringContent($reduced));
|
| 1319 |
+
break;
|
| 1320 |
+
case 'null':
|
| 1321 |
+
$reduced = array('keyword', '');
|
| 1322 |
+
}
|
| 1323 |
+
|
| 1324 |
+
return $this->compileValue($reduced);
|
| 1325 |
+
case 'null':
|
| 1326 |
+
return 'null';
|
| 1327 |
+
default:
|
| 1328 |
+
$this->throwError("unknown value type: $type");
|
| 1329 |
+
}
|
| 1330 |
+
}
|
| 1331 |
+
|
| 1332 |
+
protected function compileStringContent($string) {
|
| 1333 |
+
$parts = array();
|
| 1334 |
+
foreach ($string[2] as $part) {
|
| 1335 |
+
if (is_array($part)) {
|
| 1336 |
+
$parts[] = $this->compileValue($part);
|
| 1337 |
+
} else {
|
| 1338 |
+
$parts[] = $part;
|
| 1339 |
+
}
|
| 1340 |
+
}
|
| 1341 |
+
|
| 1342 |
+
return implode($parts);
|
| 1343 |
+
}
|
| 1344 |
+
|
| 1345 |
+
// doesn't need to be recursive, compileValue will handle that
|
| 1346 |
+
protected function extractInterpolation($list) {
|
| 1347 |
+
$items = $list[2];
|
| 1348 |
+
foreach ($items as $i => $item) {
|
| 1349 |
+
if ($item[0] == 'interpolate') {
|
| 1350 |
+
$before = array('list', $list[1], array_slice($items, 0, $i));
|
| 1351 |
+
$after = array('list', $list[1], array_slice($items, $i + 1));
|
| 1352 |
+
return array('interpolated', $item, $before, $after);
|
| 1353 |
+
}
|
| 1354 |
+
}
|
| 1355 |
+
return $list;
|
| 1356 |
+
}
|
| 1357 |
+
|
| 1358 |
+
// find the final set of selectors
|
| 1359 |
+
protected function multiplySelectors($env) {
|
| 1360 |
+
$envs = array();
|
| 1361 |
+
while (null !== $env) {
|
| 1362 |
+
if (!empty($env->selectors)) {
|
| 1363 |
+
$envs[] = $env;
|
| 1364 |
+
}
|
| 1365 |
+
$env = $env->parent;
|
| 1366 |
+
};
|
| 1367 |
+
|
| 1368 |
+
$selectors = array();
|
| 1369 |
+
$parentSelectors = array(array());
|
| 1370 |
+
while ($env = array_pop($envs)) {
|
| 1371 |
+
$selectors = array();
|
| 1372 |
+
foreach ($env->selectors as $selector) {
|
| 1373 |
+
foreach ($parentSelectors as $parent) {
|
| 1374 |
+
$selectors[] = $this->joinSelectors($parent, $selector);
|
| 1375 |
+
}
|
| 1376 |
+
}
|
| 1377 |
+
$parentSelectors = $selectors;
|
| 1378 |
+
}
|
| 1379 |
+
|
| 1380 |
+
return $selectors;
|
| 1381 |
+
}
|
| 1382 |
+
|
| 1383 |
+
// looks for & to replace, or append parent before child
|
| 1384 |
+
protected function joinSelectors($parent, $child) {
|
| 1385 |
+
$setSelf = false;
|
| 1386 |
+
$out = array();
|
| 1387 |
+
foreach ($child as $part) {
|
| 1388 |
+
$newPart = array();
|
| 1389 |
+
foreach ($part as $p) {
|
| 1390 |
+
if ($p == self::$selfSelector) {
|
| 1391 |
+
$setSelf = true;
|
| 1392 |
+
foreach ($parent as $i => $parentPart) {
|
| 1393 |
+
if ($i > 0) {
|
| 1394 |
+
$out[] = $newPart;
|
| 1395 |
+
$newPart = array();
|
| 1396 |
+
}
|
| 1397 |
+
|
| 1398 |
+
foreach ($parentPart as $pp) {
|
| 1399 |
+
$newPart[] = $pp;
|
| 1400 |
+
}
|
| 1401 |
+
}
|
| 1402 |
+
} else {
|
| 1403 |
+
$newPart[] = $p;
|
| 1404 |
+
}
|
| 1405 |
+
}
|
| 1406 |
+
|
| 1407 |
+
$out[] = $newPart;
|
| 1408 |
+
}
|
| 1409 |
+
|
| 1410 |
+
return $setSelf ? $out : array_merge($parent, $child);
|
| 1411 |
+
}
|
| 1412 |
+
|
| 1413 |
+
protected function multiplyMedia($env, $childQueries = null) {
|
| 1414 |
+
if (!isset($env) ||
|
| 1415 |
+
!empty($env->block->type) && $env->block->type != 'media')
|
| 1416 |
+
{
|
| 1417 |
+
return $childQueries;
|
| 1418 |
+
}
|
| 1419 |
+
|
| 1420 |
+
// plain old block, skip
|
| 1421 |
+
if (empty($env->block->type)) {
|
| 1422 |
+
return $this->multiplyMedia($env->parent, $childQueries);
|
| 1423 |
+
}
|
| 1424 |
+
|
| 1425 |
+
$parentQueries = $env->block->queryList;
|
| 1426 |
+
if ($childQueries == null) {
|
| 1427 |
+
$childQueries = $parentQueries;
|
| 1428 |
+
} else {
|
| 1429 |
+
$originalQueries = $childQueries;
|
| 1430 |
+
$childQueries = array();
|
| 1431 |
+
|
| 1432 |
+
foreach ($parentQueries as $parentQuery){
|
| 1433 |
+
foreach ($originalQueries as $childQuery) {
|
| 1434 |
+
$childQueries []= array_merge($parentQuery, $childQuery);
|
| 1435 |
+
}
|
| 1436 |
+
}
|
| 1437 |
+
}
|
| 1438 |
+
|
| 1439 |
+
return $this->multiplyMedia($env->parent, $childQueries);
|
| 1440 |
+
}
|
| 1441 |
+
|
| 1442 |
+
// convert something to list
|
| 1443 |
+
protected function coerceList($item, $delim = ',') {
|
| 1444 |
+
if (isset($item) && $item[0] == 'list') {
|
| 1445 |
+
return $item;
|
| 1446 |
+
}
|
| 1447 |
+
|
| 1448 |
+
return array('list', $delim, !isset($item) ? array(): array($item));
|
| 1449 |
+
}
|
| 1450 |
+
|
| 1451 |
+
protected function applyArguments($argDef, $argValues) {
|
| 1452 |
+
$storeEnv = $this->getStoreEnv();
|
| 1453 |
+
|
| 1454 |
+
$env = new stdClass;
|
| 1455 |
+
$env->store = $storeEnv->store;
|
| 1456 |
+
|
| 1457 |
+
$hasVariable = false;
|
| 1458 |
+
$args = array();
|
| 1459 |
+
foreach ($argDef as $i => $arg) {
|
| 1460 |
+
list($name, $default, $isVariable) = $argDef[$i];
|
| 1461 |
+
$args[$name] = array($i, $name, $default, $isVariable);
|
| 1462 |
+
$hasVariable |= $isVariable;
|
| 1463 |
+
}
|
| 1464 |
+
|
| 1465 |
+
$keywordArgs = array();
|
| 1466 |
+
$deferredKeywordArgs = array();
|
| 1467 |
+
$remaining = array();
|
| 1468 |
+
// assign the keyword args
|
| 1469 |
+
foreach ((array) $argValues as $arg) {
|
| 1470 |
+
if (!empty($arg[0])) {
|
| 1471 |
+
if (!isset($args[$arg[0][1]])) {
|
| 1472 |
+
if ($hasVariable) {
|
| 1473 |
+
$deferredKeywordArgs[$arg[0][1]] = $arg[1];
|
| 1474 |
+
} else {
|
| 1475 |
+
$this->throwError("Mixin or function doesn't have an argument named $%s.", $arg[0][1]);
|
| 1476 |
+
}
|
| 1477 |
+
} elseif ($args[$arg[0][1]][0] < count($remaining)) {
|
| 1478 |
+
$this->throwError("The argument $%s was passed both by position and by name.", $arg[0][1]);
|
| 1479 |
+
} else {
|
| 1480 |
+
$keywordArgs[$arg[0][1]] = $arg[1];
|
| 1481 |
+
}
|
| 1482 |
+
} elseif (count($keywordArgs)) {
|
| 1483 |
+
$this->throwError('Positional arguments must come before keyword arguments.');
|
| 1484 |
+
} elseif ($arg[2] == true) {
|
| 1485 |
+
$val = $this->reduce($arg[1], true);
|
| 1486 |
+
if ($val[0] == 'list') {
|
| 1487 |
+
foreach ($val[2] as $name => $item) {
|
| 1488 |
+
if (!is_numeric($name)) {
|
| 1489 |
+
$keywordArgs[$name] = $item;
|
| 1490 |
+
} else {
|
| 1491 |
+
$remaining[] = $item;
|
| 1492 |
+
}
|
| 1493 |
+
}
|
| 1494 |
+
} else {
|
| 1495 |
+
$remaining[] = $val;
|
| 1496 |
+
}
|
| 1497 |
+
} else {
|
| 1498 |
+
$remaining[] = $arg[1];
|
| 1499 |
+
}
|
| 1500 |
+
}
|
| 1501 |
+
|
| 1502 |
+
foreach ($args as $arg) {
|
| 1503 |
+
list($i, $name, $default, $isVariable) = $arg;
|
| 1504 |
+
|
| 1505 |
+
if ($isVariable) {
|
| 1506 |
+
$val = array('list', ',', array());
|
| 1507 |
+
for ($count = count($remaining); $i < $count; $i++) {
|
| 1508 |
+
$val[2][] = $remaining[$i];
|
| 1509 |
+
}
|
| 1510 |
+
foreach ($deferredKeywordArgs as $itemName => $item) {
|
| 1511 |
+
$val[2][$itemName] = $item;
|
| 1512 |
+
}
|
| 1513 |
+
} elseif (isset($remaining[$i])) {
|
| 1514 |
+
$val = $remaining[$i];
|
| 1515 |
+
} elseif (isset($keywordArgs[$name])) {
|
| 1516 |
+
$val = $keywordArgs[$name];
|
| 1517 |
+
} elseif (!empty($default)) {
|
| 1518 |
+
continue;
|
| 1519 |
+
} else {
|
| 1520 |
+
$this->throwError("Missing argument $name");
|
| 1521 |
+
}
|
| 1522 |
+
|
| 1523 |
+
$this->set($name, $this->reduce($val, true), true, $env);
|
| 1524 |
+
}
|
| 1525 |
+
|
| 1526 |
+
$storeEnv->store = $env->store;
|
| 1527 |
+
|
| 1528 |
+
foreach ($args as $arg) {
|
| 1529 |
+
list($i, $name, $default, $isVariable) = $arg;
|
| 1530 |
+
|
| 1531 |
+
if ($isVariable || isset($remaining[$i]) || isset($keywordArgs[$name]) || empty($default)) {
|
| 1532 |
+
continue;
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
$this->set($name, $this->reduce($default, true), true);
|
| 1536 |
+
}
|
| 1537 |
+
}
|
| 1538 |
+
|
| 1539 |
+
protected function pushEnv($block=null) {
|
| 1540 |
+
$env = new stdClass;
|
| 1541 |
+
$env->parent = $this->env;
|
| 1542 |
+
$env->store = array();
|
| 1543 |
+
$env->block = $block;
|
| 1544 |
+
$env->depth = isset($this->env->depth) ? $this->env->depth + 1 : 0;
|
| 1545 |
+
|
| 1546 |
+
$this->env = $env;
|
| 1547 |
+
return $env;
|
| 1548 |
+
}
|
| 1549 |
+
|
| 1550 |
+
protected function normalizeName($name) {
|
| 1551 |
+
return str_replace('-', '_', $name);
|
| 1552 |
+
}
|
| 1553 |
+
|
| 1554 |
+
protected function getStoreEnv() {
|
| 1555 |
+
return isset($this->storeEnv) ? $this->storeEnv : $this->env;
|
| 1556 |
+
}
|
| 1557 |
+
|
| 1558 |
+
protected function set($name, $value, $shadow=false, $env = null) {
|
| 1559 |
+
$name = $this->normalizeName($name);
|
| 1560 |
+
|
| 1561 |
+
if ($shadow) {
|
| 1562 |
+
$this->setRaw($name, $value, $env);
|
| 1563 |
+
} else {
|
| 1564 |
+
$this->setExisting($name, $value, $env);
|
| 1565 |
+
}
|
| 1566 |
+
}
|
| 1567 |
+
|
| 1568 |
+
protected function setExisting($name, $value, $env = null) {
|
| 1569 |
+
if (!isset($env)) $env = $this->getStoreEnv();
|
| 1570 |
+
|
| 1571 |
+
if (isset($env->store[$name]) || !isset($env->parent)) {
|
| 1572 |
+
$env->store[$name] = $value;
|
| 1573 |
+
} else {
|
| 1574 |
+
$this->setExisting($name, $value, $env->parent);
|
| 1575 |
+
}
|
| 1576 |
+
}
|
| 1577 |
+
|
| 1578 |
+
protected function setRaw($name, $value, $env = null) {
|
| 1579 |
+
if (!isset($env)) $env = $this->getStoreEnv();
|
| 1580 |
+
|
| 1581 |
+
$env->store[$name] = $value;
|
| 1582 |
+
}
|
| 1583 |
+
|
| 1584 |
+
public function get($name, $defaultValue = null, $env = null) {
|
| 1585 |
+
$name = $this->normalizeName($name);
|
| 1586 |
+
|
| 1587 |
+
if (!isset($env)) $env = $this->getStoreEnv();
|
| 1588 |
+
if (!isset($defaultValue)) $defaultValue = self::$defaultValue;
|
| 1589 |
+
|
| 1590 |
+
if (isset($env->store[$name])) {
|
| 1591 |
+
return $env->store[$name];
|
| 1592 |
+
} elseif (isset($env->parent)) {
|
| 1593 |
+
return $this->get($name, $defaultValue, $env->parent);
|
| 1594 |
+
}
|
| 1595 |
+
|
| 1596 |
+
return $defaultValue; // found nothing
|
| 1597 |
+
}
|
| 1598 |
+
|
| 1599 |
+
protected function injectVariables(array $args)
|
| 1600 |
+
{
|
| 1601 |
+
if (empty($args)) {
|
| 1602 |
+
return;
|
| 1603 |
+
}
|
| 1604 |
+
|
| 1605 |
+
$parser = new scss_parser(__METHOD__, false);
|
| 1606 |
+
|
| 1607 |
+
foreach ($args as $name => $strValue) {
|
| 1608 |
+
if ($name[0] === '$') {
|
| 1609 |
+
$name = substr($name, 1);
|
| 1610 |
+
}
|
| 1611 |
+
|
| 1612 |
+
$parser->env = null;
|
| 1613 |
+
$parser->count = 0;
|
| 1614 |
+
$parser->buffer = (string) $strValue;
|
| 1615 |
+
$parser->inParens = false;
|
| 1616 |
+
$parser->eatWhiteDefault = true;
|
| 1617 |
+
$parser->insertComments = true;
|
| 1618 |
+
|
| 1619 |
+
if ( ! $parser->valueList($value)) {
|
| 1620 |
+
throw new Exception("failed to parse passed in variable $name: $strValue");
|
| 1621 |
+
}
|
| 1622 |
+
|
| 1623 |
+
$this->set($name, $value);
|
| 1624 |
+
}
|
| 1625 |
+
}
|
| 1626 |
+
|
| 1627 |
+
/**
|
| 1628 |
+
* Set variables
|
| 1629 |
+
*
|
| 1630 |
+
* @param array $variables
|
| 1631 |
+
*/
|
| 1632 |
+
public function setVariables(array $variables)
|
| 1633 |
+
{
|
| 1634 |
+
$this->registeredVars = array_merge($this->registeredVars, $variables);
|
| 1635 |
+
}
|
| 1636 |
+
|
| 1637 |
+
/**
|
| 1638 |
+
* Unset variable
|
| 1639 |
+
*
|
| 1640 |
+
* @param string $name
|
| 1641 |
+
*/
|
| 1642 |
+
public function unsetVariable($name)
|
| 1643 |
+
{
|
| 1644 |
+
unset($this->registeredVars[$name]);
|
| 1645 |
+
}
|
| 1646 |
+
|
| 1647 |
+
protected function popEnv() {
|
| 1648 |
+
$env = $this->env;
|
| 1649 |
+
$this->env = $this->env->parent;
|
| 1650 |
+
return $env;
|
| 1651 |
+
}
|
| 1652 |
+
|
| 1653 |
+
public function getParsedFiles() {
|
| 1654 |
+
return $this->parsedFiles;
|
| 1655 |
+
}
|
| 1656 |
+
|
| 1657 |
+
public function addImportPath($path) {
|
| 1658 |
+
$this->importPaths[] = $path;
|
| 1659 |
+
}
|
| 1660 |
+
|
| 1661 |
+
public function setImportPaths($path) {
|
| 1662 |
+
$this->importPaths = (array)$path;
|
| 1663 |
+
}
|
| 1664 |
+
|
| 1665 |
+
public function setNumberPrecision($numberPrecision) {
|
| 1666 |
+
$this->numberPrecision = $numberPrecision;
|
| 1667 |
+
}
|
| 1668 |
+
|
| 1669 |
+
public function setFormatter($formatterName) {
|
| 1670 |
+
$this->formatter = $formatterName;
|
| 1671 |
+
}
|
| 1672 |
+
|
| 1673 |
+
public function registerFunction($name, $func) {
|
| 1674 |
+
$this->userFunctions[$this->normalizeName($name)] = $func;
|
| 1675 |
+
}
|
| 1676 |
+
|
| 1677 |
+
public function unregisterFunction($name) {
|
| 1678 |
+
unset($this->userFunctions[$this->normalizeName($name)]);
|
| 1679 |
+
}
|
| 1680 |
+
|
| 1681 |
+
protected function importFile($path, $out) {
|
| 1682 |
+
// see if tree is cached
|
| 1683 |
+
$realPath = realpath($path);
|
| 1684 |
+
if (isset($this->importCache[$realPath])) {
|
| 1685 |
+
$tree = $this->importCache[$realPath];
|
| 1686 |
+
} else {
|
| 1687 |
+
$code = file_get_contents($path);
|
| 1688 |
+
$parser = new scss_parser($path, false);
|
| 1689 |
+
$tree = $parser->parse($code);
|
| 1690 |
+
$this->parsedFiles[] = $path;
|
| 1691 |
+
|
| 1692 |
+
$this->importCache[$realPath] = $tree;
|
| 1693 |
+
}
|
| 1694 |
+
|
| 1695 |
+
$pi = pathinfo($path);
|
| 1696 |
+
array_unshift($this->importPaths, $pi['dirname']);
|
| 1697 |
+
$this->compileChildren($tree->children, $out);
|
| 1698 |
+
array_shift($this->importPaths);
|
| 1699 |
+
}
|
| 1700 |
+
|
| 1701 |
+
// results the file path for an import url if it exists
|
| 1702 |
+
public function findImport($url) {
|
| 1703 |
+
$urls = array();
|
| 1704 |
+
|
| 1705 |
+
// for "normal" scss imports (ignore vanilla css and external requests)
|
| 1706 |
+
if (!preg_match('/\.css|^http:\/\/$/', $url)) {
|
| 1707 |
+
// try both normal and the _partial filename
|
| 1708 |
+
$urls = array($url, preg_replace('/[^\/]+$/', '_\0', $url));
|
| 1709 |
+
}
|
| 1710 |
+
|
| 1711 |
+
foreach ($this->importPaths as $dir) {
|
| 1712 |
+
if (is_string($dir)) {
|
| 1713 |
+
// check urls for normal import paths
|
| 1714 |
+
foreach ($urls as $full) {
|
| 1715 |
+
$full = $dir .
|
| 1716 |
+
(!empty($dir) && substr($dir, -1) != '/' ? '/' : '') .
|
| 1717 |
+
$full;
|
| 1718 |
+
|
| 1719 |
+
if ($this->fileExists($file = $full.'.scss') ||
|
| 1720 |
+
$this->fileExists($file = $full))
|
| 1721 |
+
{
|
| 1722 |
+
return $file;
|
| 1723 |
+
}
|
| 1724 |
+
}
|
| 1725 |
+
} else {
|
| 1726 |
+
// check custom callback for import path
|
| 1727 |
+
$file = call_user_func($dir,$url,$this);
|
| 1728 |
+
if ($file !== null) {
|
| 1729 |
+
return $file;
|
| 1730 |
+
}
|
| 1731 |
+
}
|
| 1732 |
+
}
|
| 1733 |
+
|
| 1734 |
+
return null;
|
| 1735 |
+
}
|
| 1736 |
+
|
| 1737 |
+
protected function fileExists($name) {
|
| 1738 |
+
return is_file($name);
|
| 1739 |
+
}
|
| 1740 |
+
|
| 1741 |
+
protected function callBuiltin($name, $args, &$returnValue) {
|
| 1742 |
+
// try a lib function
|
| 1743 |
+
$name = $this->normalizeName($name);
|
| 1744 |
+
$libName = 'lib_'.$name;
|
| 1745 |
+
$f = array($this, $libName);
|
| 1746 |
+
if (is_callable($f)) {
|
| 1747 |
+
$prototype = isset(self::$$libName) ? self::$$libName : null;
|
| 1748 |
+
$sorted = $this->sortArgs($prototype, $args);
|
| 1749 |
+
foreach ($sorted as &$val) {
|
| 1750 |
+
$val = $this->reduce($val, true);
|
| 1751 |
+
}
|
| 1752 |
+
$returnValue = call_user_func($f, $sorted, $this);
|
| 1753 |
+
} elseif (isset($this->userFunctions[$name])) {
|
| 1754 |
+
// see if we can find a user function
|
| 1755 |
+
$fn = $this->userFunctions[$name];
|
| 1756 |
+
|
| 1757 |
+
foreach ($args as &$val) {
|
| 1758 |
+
$val = $this->reduce($val[1], true);
|
| 1759 |
+
}
|
| 1760 |
+
|
| 1761 |
+
$returnValue = call_user_func($fn, $args, $this);
|
| 1762 |
+
}
|
| 1763 |
+
|
| 1764 |
+
if (isset($returnValue)) {
|
| 1765 |
+
// coerce a php value into a scss one
|
| 1766 |
+
if (is_numeric($returnValue)) {
|
| 1767 |
+
$returnValue = array('number', $returnValue, '');
|
| 1768 |
+
} elseif (is_bool($returnValue)) {
|
| 1769 |
+
$returnValue = $returnValue ? self::$true : self::$false;
|
| 1770 |
+
} elseif (!is_array($returnValue)) {
|
| 1771 |
+
$returnValue = array('keyword', $returnValue);
|
| 1772 |
+
}
|
| 1773 |
+
|
| 1774 |
+
return true;
|
| 1775 |
+
}
|
| 1776 |
+
|
| 1777 |
+
return false;
|
| 1778 |
+
}
|
| 1779 |
+
|
| 1780 |
+
// sorts any keyword arguments
|
| 1781 |
+
// TODO: merge with apply arguments
|
| 1782 |
+
protected function sortArgs($prototype, $args) {
|
| 1783 |
+
$keyArgs = array();
|
| 1784 |
+
$posArgs = array();
|
| 1785 |
+
|
| 1786 |
+
foreach ($args as $arg) {
|
| 1787 |
+
list($key, $value) = $arg;
|
| 1788 |
+
$key = $key[1];
|
| 1789 |
+
if (empty($key)) {
|
| 1790 |
+
$posArgs[] = $value;
|
| 1791 |
+
} else {
|
| 1792 |
+
$keyArgs[$key] = $value;
|
| 1793 |
+
}
|
| 1794 |
+
}
|
| 1795 |
+
|
| 1796 |
+
if (!isset($prototype)) return $posArgs;
|
| 1797 |
+
|
| 1798 |
+
$finalArgs = array();
|
| 1799 |
+
foreach ($prototype as $i => $names) {
|
| 1800 |
+
if (isset($posArgs[$i])) {
|
| 1801 |
+
$finalArgs[] = $posArgs[$i];
|
| 1802 |
+
continue;
|
| 1803 |
+
}
|
| 1804 |
+
|
| 1805 |
+
$set = false;
|
| 1806 |
+
foreach ((array)$names as $name) {
|
| 1807 |
+
if (isset($keyArgs[$name])) {
|
| 1808 |
+
$finalArgs[] = $keyArgs[$name];
|
| 1809 |
+
$set = true;
|
| 1810 |
+
break;
|
| 1811 |
+
}
|
| 1812 |
+
}
|
| 1813 |
+
|
| 1814 |
+
if (!$set) {
|
| 1815 |
+
$finalArgs[] = null;
|
| 1816 |
+
}
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
return $finalArgs;
|
| 1820 |
+
}
|
| 1821 |
+
|
| 1822 |
+
protected function coerceForExpression($value) {
|
| 1823 |
+
if ($color = $this->coerceColor($value)) {
|
| 1824 |
+
return $color;
|
| 1825 |
+
}
|
| 1826 |
+
|
| 1827 |
+
return $value;
|
| 1828 |
+
}
|
| 1829 |
+
|
| 1830 |
+
protected function coerceColor($value) {
|
| 1831 |
+
switch ($value[0]) {
|
| 1832 |
+
case 'color': return $value;
|
| 1833 |
+
case 'keyword':
|
| 1834 |
+
$name = $value[1];
|
| 1835 |
+
if (isset(self::$cssColors[$name])) {
|
| 1836 |
+
$rgba = explode(',', self::$cssColors[$name]);
|
| 1837 |
+
return isset($rgba[3])
|
| 1838 |
+
? array('color', (int) $rgba[0], (int) $rgba[1], (int) $rgba[2], (int) $rgba[3])
|
| 1839 |
+
: array('color', (int) $rgba[0], (int) $rgba[1], (int) $rgba[2]);
|
| 1840 |
+
}
|
| 1841 |
+
return null;
|
| 1842 |
+
}
|
| 1843 |
+
|
| 1844 |
+
return null;
|
| 1845 |
+
}
|
| 1846 |
+
|
| 1847 |
+
protected function coerceString($value) {
|
| 1848 |
+
switch ($value[0]) {
|
| 1849 |
+
case 'string':
|
| 1850 |
+
return $value;
|
| 1851 |
+
case 'keyword':
|
| 1852 |
+
return array('string', '', array($value[1]));
|
| 1853 |
+
}
|
| 1854 |
+
return null;
|
| 1855 |
+
}
|
| 1856 |
+
|
| 1857 |
+
public function assertList($value) {
|
| 1858 |
+
if ($value[0] != 'list')
|
| 1859 |
+
$this->throwError('expecting list');
|
| 1860 |
+
return $value;
|
| 1861 |
+
}
|
| 1862 |
+
|
| 1863 |
+
public function assertColor($value) {
|
| 1864 |
+
if ($color = $this->coerceColor($value)) return $color;
|
| 1865 |
+
$this->throwError('expecting color');
|
| 1866 |
+
}
|
| 1867 |
+
|
| 1868 |
+
public function assertNumber($value) {
|
| 1869 |
+
if ($value[0] != 'number')
|
| 1870 |
+
$this->throwError('expecting number');
|
| 1871 |
+
return $value[1];
|
| 1872 |
+
}
|
| 1873 |
+
|
| 1874 |
+
protected function coercePercent($value) {
|
| 1875 |
+
if ($value[0] == 'number') {
|
| 1876 |
+
if ($value[2] == '%') {
|
| 1877 |
+
return $value[1] / 100;
|
| 1878 |
+
}
|
| 1879 |
+
return $value[1];
|
| 1880 |
+
}
|
| 1881 |
+
return 0;
|
| 1882 |
+
}
|
| 1883 |
+
|
| 1884 |
+
// make sure a color's components don't go out of bounds
|
| 1885 |
+
protected function fixColor($c) {
|
| 1886 |
+
foreach (range(1, 3) as $i) {
|
| 1887 |
+
if ($c[$i] < 0) $c[$i] = 0;
|
| 1888 |
+
if ($c[$i] > 255) $c[$i] = 255;
|
| 1889 |
+
}
|
| 1890 |
+
|
| 1891 |
+
return $c;
|
| 1892 |
+
}
|
| 1893 |
+
|
| 1894 |
+
public function toHSL($red, $green, $blue) {
|
| 1895 |
+
$min = min($red, $green, $blue);
|
| 1896 |
+
$max = max($red, $green, $blue);
|
| 1897 |
+
|
| 1898 |
+
$l = $min + $max;
|
| 1899 |
+
|
| 1900 |
+
if ($min == $max) {
|
| 1901 |
+
$s = $h = 0;
|
| 1902 |
+
} else {
|
| 1903 |
+
$d = $max - $min;
|
| 1904 |
+
|
| 1905 |
+
if ($l < 255)
|
| 1906 |
+
$s = $d / $l;
|
| 1907 |
+
else
|
| 1908 |
+
$s = $d / (510 - $l);
|
| 1909 |
+
|
| 1910 |
+
if ($red == $max)
|
| 1911 |
+
$h = 60 * ($green - $blue) / $d;
|
| 1912 |
+
elseif ($green == $max)
|
| 1913 |
+
$h = 60 * ($blue - $red) / $d + 120;
|
| 1914 |
+
elseif ($blue == $max)
|
| 1915 |
+
$h = 60 * ($red - $green) / $d + 240;
|
| 1916 |
+
}
|
| 1917 |
+
|
| 1918 |
+
return array('hsl', fmod($h, 360), $s * 100, $l / 5.1);
|
| 1919 |
+
}
|
| 1920 |
+
|
| 1921 |
+
public function hueToRGB($m1, $m2, $h) {
|
| 1922 |
+
if ($h < 0)
|
| 1923 |
+
$h += 1;
|
| 1924 |
+
elseif ($h > 1)
|
| 1925 |
+
$h -= 1;
|
| 1926 |
+
|
| 1927 |
+
if ($h * 6 < 1)
|
| 1928 |
+
return $m1 + ($m2 - $m1) * $h * 6;
|
| 1929 |
+
|
| 1930 |
+
if ($h * 2 < 1)
|
| 1931 |
+
return $m2;
|
| 1932 |
+
|
| 1933 |
+
if ($h * 3 < 2)
|
| 1934 |
+
return $m1 + ($m2 - $m1) * (2/3 - $h) * 6;
|
| 1935 |
+
|
| 1936 |
+
return $m1;
|
| 1937 |
+
}
|
| 1938 |
+
|
| 1939 |
+
// H from 0 to 360, S and L from 0 to 100
|
| 1940 |
+
public function toRGB($hue, $saturation, $lightness) {
|
| 1941 |
+
if ($hue < 0) {
|
| 1942 |
+
$hue += 360;
|
| 1943 |
+
}
|
| 1944 |
+
|
| 1945 |
+
$h = $hue / 360;
|
| 1946 |
+
$s = min(100, max(0, $saturation)) / 100;
|
| 1947 |
+
$l = min(100, max(0, $lightness)) / 100;
|
| 1948 |
+
|
| 1949 |
+
$m2 = $l <= 0.5 ? $l * ($s + 1) : $l + $s - $l * $s;
|
| 1950 |
+
$m1 = $l * 2 - $m2;
|
| 1951 |
+
|
| 1952 |
+
$r = $this->hueToRGB($m1, $m2, $h + 1/3) * 255;
|
| 1953 |
+
$g = $this->hueToRGB($m1, $m2, $h) * 255;
|
| 1954 |
+
$b = $this->hueToRGB($m1, $m2, $h - 1/3) * 255;
|
| 1955 |
+
|
| 1956 |
+
$out = array('color', $r, $g, $b);
|
| 1957 |
+
return $out;
|
| 1958 |
+
}
|
| 1959 |
+
|
| 1960 |
+
// Built in functions
|
| 1961 |
+
|
| 1962 |
+
protected static $lib_if = array('condition', 'if-true', 'if-false');
|
| 1963 |
+
protected function lib_if($args) {
|
| 1964 |
+
list($cond,$t, $f) = $args;
|
| 1965 |
+
if (!$this->isTruthy($cond)) return $f;
|
| 1966 |
+
return $t;
|
| 1967 |
+
}
|
| 1968 |
+
|
| 1969 |
+
protected static $lib_index = array('list', 'value');
|
| 1970 |
+
protected function lib_index($args) {
|
| 1971 |
+
list($list, $value) = $args;
|
| 1972 |
+
$list = $this->assertList($list);
|
| 1973 |
+
|
| 1974 |
+
$values = array();
|
| 1975 |
+
foreach ($list[2] as $item) {
|
| 1976 |
+
$values[] = $this->normalizeValue($item);
|
| 1977 |
+
}
|
| 1978 |
+
$key = array_search($this->normalizeValue($value), $values);
|
| 1979 |
+
|
| 1980 |
+
return false === $key ? false : $key + 1;
|
| 1981 |
+
}
|
| 1982 |
+
|
| 1983 |
+
protected static $lib_rgb = array('red', 'green', 'blue');
|
| 1984 |
+
protected function lib_rgb($args) {
|
| 1985 |
+
list($r,$g,$b) = $args;
|
| 1986 |
+
return array('color', $r[1], $g[1], $b[1]);
|
| 1987 |
+
}
|
| 1988 |
+
|
| 1989 |
+
protected static $lib_rgba = array(
|
| 1990 |
+
array('red', 'color'),
|
| 1991 |
+
'green', 'blue', 'alpha');
|
| 1992 |
+
protected function lib_rgba($args) {
|
| 1993 |
+
if ($color = $this->coerceColor($args[0])) {
|
| 1994 |
+
$num = !isset($args[1]) ? $args[3] : $args[1];
|
| 1995 |
+
$alpha = $this->assertNumber($num);
|
| 1996 |
+
$color[4] = $alpha;
|
| 1997 |
+
return $color;
|
| 1998 |
+
}
|
| 1999 |
+
|
| 2000 |
+
list($r,$g,$b, $a) = $args;
|
| 2001 |
+
return array('color', $r[1], $g[1], $b[1], $a[1]);
|
| 2002 |
+
}
|
| 2003 |
+
|
| 2004 |
+
// helper function for adjust_color, change_color, and scale_color
|
| 2005 |
+
protected function alter_color($args, $fn) {
|
| 2006 |
+
$color = $this->assertColor($args[0]);
|
| 2007 |
+
|
| 2008 |
+
foreach (array(1,2,3,7) as $i) {
|
| 2009 |
+
if (isset($args[$i])) {
|
| 2010 |
+
$val = $this->assertNumber($args[$i]);
|
| 2011 |
+
$ii = $i == 7 ? 4 : $i; // alpha
|
| 2012 |
+
$color[$ii] =
|
| 2013 |
+
$this->$fn(isset($color[$ii]) ? $color[$ii] : 0, $val, $i);
|
| 2014 |
+
}
|
| 2015 |
+
}
|
| 2016 |
+
|
| 2017 |
+
if (isset($args[4]) || isset($args[5]) || isset($args[6])) {
|
| 2018 |
+
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
|
| 2019 |
+
foreach (array(4,5,6) as $i) {
|
| 2020 |
+
if (isset($args[$i])) {
|
| 2021 |
+
$val = $this->assertNumber($args[$i]);
|
| 2022 |
+
$hsl[$i - 3] = $this->$fn($hsl[$i - 3], $val, $i);
|
| 2023 |
+
}
|
| 2024 |
+
}
|
| 2025 |
+
|
| 2026 |
+
$rgb = $this->toRGB($hsl[1], $hsl[2], $hsl[3]);
|
| 2027 |
+
if (isset($color[4])) $rgb[4] = $color[4];
|
| 2028 |
+
$color = $rgb;
|
| 2029 |
+
}
|
| 2030 |
+
|
| 2031 |
+
return $color;
|
| 2032 |
+
}
|
| 2033 |
+
|
| 2034 |
+
protected static $lib_adjust_color = array(
|
| 2035 |
+
'color', 'red', 'green', 'blue',
|
| 2036 |
+
'hue', 'saturation', 'lightness', 'alpha'
|
| 2037 |
+
);
|
| 2038 |
+
protected function adjust_color_helper($base, $alter, $i) {
|
| 2039 |
+
return $base += $alter;
|
| 2040 |
+
}
|
| 2041 |
+
protected function lib_adjust_color($args) {
|
| 2042 |
+
return $this->alter_color($args, 'adjust_color_helper');
|
| 2043 |
+
}
|
| 2044 |
+
|
| 2045 |
+
protected static $lib_change_color = array(
|
| 2046 |
+
'color', 'red', 'green', 'blue',
|
| 2047 |
+
'hue', 'saturation', 'lightness', 'alpha'
|
| 2048 |
+
);
|
| 2049 |
+
protected function change_color_helper($base, $alter, $i) {
|
| 2050 |
+
return $alter;
|
| 2051 |
+
}
|
| 2052 |
+
protected function lib_change_color($args) {
|
| 2053 |
+
return $this->alter_color($args, 'change_color_helper');
|
| 2054 |
+
}
|
| 2055 |
+
|
| 2056 |
+
protected static $lib_scale_color = array(
|
| 2057 |
+
'color', 'red', 'green', 'blue',
|
| 2058 |
+
'hue', 'saturation', 'lightness', 'alpha'
|
| 2059 |
+
);
|
| 2060 |
+
protected function scale_color_helper($base, $scale, $i) {
|
| 2061 |
+
// 1,2,3 - rgb
|
| 2062 |
+
// 4, 5, 6 - hsl
|
| 2063 |
+
// 7 - a
|
| 2064 |
+
switch ($i) {
|
| 2065 |
+
case 1:
|
| 2066 |
+
case 2:
|
| 2067 |
+
case 3:
|
| 2068 |
+
$max = 255; break;
|
| 2069 |
+
case 4:
|
| 2070 |
+
$max = 360; break;
|
| 2071 |
+
case 7:
|
| 2072 |
+
$max = 1; break;
|
| 2073 |
+
default:
|
| 2074 |
+
$max = 100;
|
| 2075 |
+
}
|
| 2076 |
+
|
| 2077 |
+
$scale = $scale / 100;
|
| 2078 |
+
if ($scale < 0) {
|
| 2079 |
+
return $base * $scale + $base;
|
| 2080 |
+
} else {
|
| 2081 |
+
return ($max - $base) * $scale + $base;
|
| 2082 |
+
}
|
| 2083 |
+
}
|
| 2084 |
+
protected function lib_scale_color($args) {
|
| 2085 |
+
return $this->alter_color($args, 'scale_color_helper');
|
| 2086 |
+
}
|
| 2087 |
+
|
| 2088 |
+
protected static $lib_ie_hex_str = array('color');
|
| 2089 |
+
protected function lib_ie_hex_str($args) {
|
| 2090 |
+
$color = $this->coerceColor($args[0]);
|
| 2091 |
+
$color[4] = isset($color[4]) ? round(255*$color[4]) : 255;
|
| 2092 |
+
|
| 2093 |
+
return sprintf('#%02X%02X%02X%02X', $color[4], $color[1], $color[2], $color[3]);
|
| 2094 |
+
}
|
| 2095 |
+
|
| 2096 |
+
protected static $lib_red = array('color');
|
| 2097 |
+
protected function lib_red($args) {
|
| 2098 |
+
$color = $this->coerceColor($args[0]);
|
| 2099 |
+
return $color[1];
|
| 2100 |
+
}
|
| 2101 |
+
|
| 2102 |
+
protected static $lib_green = array('color');
|
| 2103 |
+
protected function lib_green($args) {
|
| 2104 |
+
$color = $this->coerceColor($args[0]);
|
| 2105 |
+
return $color[2];
|
| 2106 |
+
}
|
| 2107 |
+
|
| 2108 |
+
protected static $lib_blue = array('color');
|
| 2109 |
+
protected function lib_blue($args) {
|
| 2110 |
+
$color = $this->coerceColor($args[0]);
|
| 2111 |
+
return $color[3];
|
| 2112 |
+
}
|
| 2113 |
+
|
| 2114 |
+
protected static $lib_alpha = array('color');
|
| 2115 |
+
protected function lib_alpha($args) {
|
| 2116 |
+
if ($color = $this->coerceColor($args[0])) {
|
| 2117 |
+
return isset($color[4]) ? $color[4] : 1;
|
| 2118 |
+
}
|
| 2119 |
+
|
| 2120 |
+
// this might be the IE function, so return value unchanged
|
| 2121 |
+
return null;
|
| 2122 |
+
}
|
| 2123 |
+
|
| 2124 |
+
protected static $lib_opacity = array('color');
|
| 2125 |
+
protected function lib_opacity($args) {
|
| 2126 |
+
$value = $args[0];
|
| 2127 |
+
if ($value[0] === 'number') return null;
|
| 2128 |
+
return $this->lib_alpha($args);
|
| 2129 |
+
}
|
| 2130 |
+
|
| 2131 |
+
// mix two colors
|
| 2132 |
+
protected static $lib_mix = array('color-1', 'color-2', 'weight');
|
| 2133 |
+
protected function lib_mix($args) {
|
| 2134 |
+
list($first, $second, $weight) = $args;
|
| 2135 |
+
$first = $this->assertColor($first);
|
| 2136 |
+
$second = $this->assertColor($second);
|
| 2137 |
+
|
| 2138 |
+
if (!isset($weight)) {
|
| 2139 |
+
$weight = 0.5;
|
| 2140 |
+
} else {
|
| 2141 |
+
$weight = $this->coercePercent($weight);
|
| 2142 |
+
}
|
| 2143 |
+
|
| 2144 |
+
$firstAlpha = isset($first[4]) ? $first[4] : 1;
|
| 2145 |
+
$secondAlpha = isset($second[4]) ? $second[4] : 1;
|
| 2146 |
+
|
| 2147 |
+
$w = $weight * 2 - 1;
|
| 2148 |
+
$a = $firstAlpha - $secondAlpha;
|
| 2149 |
+
|
| 2150 |
+
$w1 = (($w * $a == -1 ? $w : ($w + $a)/(1 + $w * $a)) + 1) / 2.0;
|
| 2151 |
+
$w2 = 1.0 - $w1;
|
| 2152 |
+
|
| 2153 |
+
$new = array('color',
|
| 2154 |
+
$w1 * $first[1] + $w2 * $second[1],
|
| 2155 |
+
$w1 * $first[2] + $w2 * $second[2],
|
| 2156 |
+
$w1 * $first[3] + $w2 * $second[3],
|
| 2157 |
+
);
|
| 2158 |
+
|
| 2159 |
+
if ($firstAlpha != 1.0 || $secondAlpha != 1.0) {
|
| 2160 |
+
$new[] = $firstAlpha * $weight + $secondAlpha * ($weight - 1);
|
| 2161 |
+
}
|
| 2162 |
+
|
| 2163 |
+
return $this->fixColor($new);
|
| 2164 |
+
}
|
| 2165 |
+
|
| 2166 |
+
protected static $lib_hsl = array('hue', 'saturation', 'lightness');
|
| 2167 |
+
protected function lib_hsl($args) {
|
| 2168 |
+
list($h, $s, $l) = $args;
|
| 2169 |
+
return $this->toRGB($h[1], $s[1], $l[1]);
|
| 2170 |
+
}
|
| 2171 |
+
|
| 2172 |
+
protected static $lib_hsla = array('hue', 'saturation',
|
| 2173 |
+
'lightness', 'alpha');
|
| 2174 |
+
protected function lib_hsla($args) {
|
| 2175 |
+
list($h, $s, $l, $a) = $args;
|
| 2176 |
+
$color = $this->toRGB($h[1], $s[1], $l[1]);
|
| 2177 |
+
$color[4] = $a[1];
|
| 2178 |
+
return $color;
|
| 2179 |
+
}
|
| 2180 |
+
|
| 2181 |
+
protected static $lib_hue = array('color');
|
| 2182 |
+
protected function lib_hue($args) {
|
| 2183 |
+
$color = $this->assertColor($args[0]);
|
| 2184 |
+
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
|
| 2185 |
+
return array('number', $hsl[1], 'deg');
|
| 2186 |
+
}
|
| 2187 |
+
|
| 2188 |
+
protected static $lib_saturation = array('color');
|
| 2189 |
+
protected function lib_saturation($args) {
|
| 2190 |
+
$color = $this->assertColor($args[0]);
|
| 2191 |
+
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
|
| 2192 |
+
return array('number', $hsl[2], '%');
|
| 2193 |
+
}
|
| 2194 |
+
|
| 2195 |
+
protected static $lib_lightness = array('color');
|
| 2196 |
+
protected function lib_lightness($args) {
|
| 2197 |
+
$color = $this->assertColor($args[0]);
|
| 2198 |
+
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
|
| 2199 |
+
return array('number', $hsl[3], '%');
|
| 2200 |
+
}
|
| 2201 |
+
|
| 2202 |
+
protected function adjustHsl($color, $idx, $amount) {
|
| 2203 |
+
$hsl = $this->toHSL($color[1], $color[2], $color[3]);
|
| 2204 |
+
$hsl[$idx] += $amount;
|
| 2205 |
+
$out = $this->toRGB($hsl[1], $hsl[2], $hsl[3]);
|
| 2206 |
+
if (isset($color[4])) $out[4] = $color[4];
|
| 2207 |
+
return $out;
|
| 2208 |
+
}
|
| 2209 |
+
|
| 2210 |
+
protected static $lib_adjust_hue = array('color', 'degrees');
|
| 2211 |
+
protected function lib_adjust_hue($args) {
|
| 2212 |
+
$color = $this->assertColor($args[0]);
|
| 2213 |
+
$degrees = $this->assertNumber($args[1]);
|
| 2214 |
+
return $this->adjustHsl($color, 1, $degrees);
|
| 2215 |
+
}
|
| 2216 |
+
|
| 2217 |
+
protected static $lib_lighten = array('color', 'amount');
|
| 2218 |
+
protected function lib_lighten($args) {
|
| 2219 |
+
$color = $this->assertColor($args[0]);
|
| 2220 |
+
$amount = 100*$this->coercePercent($args[1]);
|
| 2221 |
+
return $this->adjustHsl($color, 3, $amount);
|
| 2222 |
+
}
|
| 2223 |
+
|
| 2224 |
+
protected static $lib_darken = array('color', 'amount');
|
| 2225 |
+
protected function lib_darken($args) {
|
| 2226 |
+
$color = $this->assertColor($args[0]);
|
| 2227 |
+
$amount = 100*$this->coercePercent($args[1]);
|
| 2228 |
+
return $this->adjustHsl($color, 3, -$amount);
|
| 2229 |
+
}
|
| 2230 |
+
|
| 2231 |
+
protected static $lib_saturate = array('color', 'amount');
|
| 2232 |
+
protected function lib_saturate($args) {
|
| 2233 |
+
$value = $args[0];
|
| 2234 |
+
if ($value[0] === 'number') return null;
|
| 2235 |
+
$color = $this->assertColor($value);
|
| 2236 |
+
$amount = 100*$this->coercePercent($args[1]);
|
| 2237 |
+
return $this->adjustHsl($color, 2, $amount);
|
| 2238 |
+
}
|
| 2239 |
+
|
| 2240 |
+
protected static $lib_desaturate = array('color', 'amount');
|
| 2241 |
+
protected function lib_desaturate($args) {
|
| 2242 |
+
$color = $this->assertColor($args[0]);
|
| 2243 |
+
$amount = 100*$this->coercePercent($args[1]);
|
| 2244 |
+
return $this->adjustHsl($color, 2, -$amount);
|
| 2245 |
+
}
|
| 2246 |
+
|
| 2247 |
+
protected static $lib_grayscale = array('color');
|
| 2248 |
+
protected function lib_grayscale($args) {
|
| 2249 |
+
$value = $args[0];
|
| 2250 |
+
if ($value[0] === 'number') return null;
|
| 2251 |
+
return $this->adjustHsl($this->assertColor($value), 2, -100);
|
| 2252 |
+
}
|
| 2253 |
+
|
| 2254 |
+
protected static $lib_complement = array('color');
|
| 2255 |
+
protected function lib_complement($args) {
|
| 2256 |
+
return $this->adjustHsl($this->assertColor($args[0]), 1, 180);
|
| 2257 |
+
}
|
| 2258 |
+
|
| 2259 |
+
protected static $lib_invert = array('color');
|
| 2260 |
+
protected function lib_invert($args) {
|
| 2261 |
+
$value = $args[0];
|
| 2262 |
+
if ($value[0] === 'number') return null;
|
| 2263 |
+
$color = $this->assertColor($value);
|
| 2264 |
+
$color[1] = 255 - $color[1];
|
| 2265 |
+
$color[2] = 255 - $color[2];
|
| 2266 |
+
$color[3] = 255 - $color[3];
|
| 2267 |
+
return $color;
|
| 2268 |
+
}
|
| 2269 |
+
|
| 2270 |
+
// increases opacity by amount
|
| 2271 |
+
protected static $lib_opacify = array('color', 'amount');
|
| 2272 |
+
protected function lib_opacify($args) {
|
| 2273 |
+
$color = $this->assertColor($args[0]);
|
| 2274 |
+
$amount = $this->coercePercent($args[1]);
|
| 2275 |
+
|
| 2276 |
+
$color[4] = (isset($color[4]) ? $color[4] : 1) + $amount;
|
| 2277 |
+
$color[4] = min(1, max(0, $color[4]));
|
| 2278 |
+
return $color;
|
| 2279 |
+
}
|
| 2280 |
+
|
| 2281 |
+
protected static $lib_fade_in = array('color', 'amount');
|
| 2282 |
+
protected function lib_fade_in($args) {
|
| 2283 |
+
return $this->lib_opacify($args);
|
| 2284 |
+
}
|
| 2285 |
+
|
| 2286 |
+
// decreases opacity by amount
|
| 2287 |
+
protected static $lib_transparentize = array('color', 'amount');
|
| 2288 |
+
protected function lib_transparentize($args) {
|
| 2289 |
+
$color = $this->assertColor($args[0]);
|
| 2290 |
+
$amount = $this->coercePercent($args[1]);
|
| 2291 |
+
|
| 2292 |
+
$color[4] = (isset($color[4]) ? $color[4] : 1) - $amount;
|
| 2293 |
+
$color[4] = min(1, max(0, $color[4]));
|
| 2294 |
+
return $color;
|
| 2295 |
+
}
|
| 2296 |
+
|
| 2297 |
+
protected static $lib_fade_out = array('color', 'amount');
|
| 2298 |
+
protected function lib_fade_out($args) {
|
| 2299 |
+
return $this->lib_transparentize($args);
|
| 2300 |
+
}
|
| 2301 |
+
|
| 2302 |
+
protected static $lib_unquote = array('string');
|
| 2303 |
+
protected function lib_unquote($args) {
|
| 2304 |
+
$str = $args[0];
|
| 2305 |
+
if ($str[0] == 'string') $str[1] = '';
|
| 2306 |
+
return $str;
|
| 2307 |
+
}
|
| 2308 |
+
|
| 2309 |
+
protected static $lib_quote = array('string');
|
| 2310 |
+
protected function lib_quote($args) {
|
| 2311 |
+
$value = $args[0];
|
| 2312 |
+
if ($value[0] == 'string' && !empty($value[1]))
|
| 2313 |
+
return $value;
|
| 2314 |
+
return array('string', '"', array($value));
|
| 2315 |
+
}
|
| 2316 |
+
|
| 2317 |
+
protected static $lib_percentage = array('value');
|
| 2318 |
+
protected function lib_percentage($args) {
|
| 2319 |
+
return array('number',
|
| 2320 |
+
$this->coercePercent($args[0]) * 100,
|
| 2321 |
+
'%');
|
| 2322 |
+
}
|
| 2323 |
+
|
| 2324 |
+
protected static $lib_round = array('value');
|
| 2325 |
+
protected function lib_round($args) {
|
| 2326 |
+
$num = $args[0];
|
| 2327 |
+
$num[1] = round($num[1]);
|
| 2328 |
+
return $num;
|
| 2329 |
+
}
|
| 2330 |
+
|
| 2331 |
+
protected static $lib_floor = array('value');
|
| 2332 |
+
protected function lib_floor($args) {
|
| 2333 |
+
$num = $args[0];
|
| 2334 |
+
$num[1] = floor($num[1]);
|
| 2335 |
+
return $num;
|
| 2336 |
+
}
|
| 2337 |
+
|
| 2338 |
+
protected static $lib_ceil = array('value');
|
| 2339 |
+
protected function lib_ceil($args) {
|
| 2340 |
+
$num = $args[0];
|
| 2341 |
+
$num[1] = ceil($num[1]);
|
| 2342 |
+
return $num;
|
| 2343 |
+
}
|
| 2344 |
+
|
| 2345 |
+
protected static $lib_abs = array('value');
|
| 2346 |
+
protected function lib_abs($args) {
|
| 2347 |
+
$num = $args[0];
|
| 2348 |
+
$num[1] = abs($num[1]);
|
| 2349 |
+
return $num;
|
| 2350 |
+
}
|
| 2351 |
+
|
| 2352 |
+
protected function lib_min($args) {
|
| 2353 |
+
$numbers = $this->getNormalizedNumbers($args);
|
| 2354 |
+
$min = null;
|
| 2355 |
+
foreach ($numbers as $key => $number) {
|
| 2356 |
+
if (null === $min || $number[1] <= $min[1]) {
|
| 2357 |
+
$min = array($key, $number[1]);
|
| 2358 |
+
}
|
| 2359 |
+
}
|
| 2360 |
+
|
| 2361 |
+
return $args[$min[0]];
|
| 2362 |
+
}
|
| 2363 |
+
|
| 2364 |
+
protected function lib_max($args) {
|
| 2365 |
+
$numbers = $this->getNormalizedNumbers($args);
|
| 2366 |
+
$max = null;
|
| 2367 |
+
foreach ($numbers as $key => $number) {
|
| 2368 |
+
if (null === $max || $number[1] >= $max[1]) {
|
| 2369 |
+
$max = array($key, $number[1]);
|
| 2370 |
+
}
|
| 2371 |
+
}
|
| 2372 |
+
|
| 2373 |
+
return $args[$max[0]];
|
| 2374 |
+
}
|
| 2375 |
+
|
| 2376 |
+
protected function getNormalizedNumbers($args) {
|
| 2377 |
+
$unit = null;
|
| 2378 |
+
$originalUnit = null;
|
| 2379 |
+
$numbers = array();
|
| 2380 |
+
foreach ($args as $key => $item) {
|
| 2381 |
+
if ('number' != $item[0]) {
|
| 2382 |
+
$this->throwError('%s is not a number', $item[0]);
|
| 2383 |
+
}
|
| 2384 |
+
$number = $this->normalizeNumber($item);
|
| 2385 |
+
|
| 2386 |
+
if (null === $unit) {
|
| 2387 |
+
$unit = $number[2];
|
| 2388 |
+
$originalUnit = $item[2];
|
| 2389 |
+
} elseif ($unit !== $number[2]) {
|
| 2390 |
+
$this->throwError('Incompatible units: "%s" and "%s".', $originalUnit, $item[2]);
|
| 2391 |
+
}
|
| 2392 |
+
|
| 2393 |
+
$numbers[$key] = $number;
|
| 2394 |
+
}
|
| 2395 |
+
|
| 2396 |
+
return $numbers;
|
| 2397 |
+
}
|
| 2398 |
+
|
| 2399 |
+
protected static $lib_length = array('list');
|
| 2400 |
+
protected function lib_length($args) {
|
| 2401 |
+
$list = $this->coerceList($args[0]);
|
| 2402 |
+
return count($list[2]);
|
| 2403 |
+
}
|
| 2404 |
+
|
| 2405 |
+
protected static $lib_nth = array('list', 'n');
|
| 2406 |
+
protected function lib_nth($args) {
|
| 2407 |
+
$list = $this->coerceList($args[0]);
|
| 2408 |
+
$n = $this->assertNumber($args[1]) - 1;
|
| 2409 |
+
return isset($list[2][$n]) ? $list[2][$n] : self::$defaultValue;
|
| 2410 |
+
}
|
| 2411 |
+
|
| 2412 |
+
protected function listSeparatorForJoin($list1, $sep) {
|
| 2413 |
+
if (!isset($sep)) return $list1[1];
|
| 2414 |
+
switch ($this->compileValue($sep)) {
|
| 2415 |
+
case 'comma':
|
| 2416 |
+
return ',';
|
| 2417 |
+
case 'space':
|
| 2418 |
+
return '';
|
| 2419 |
+
default:
|
| 2420 |
+
return $list1[1];
|
| 2421 |
+
}
|
| 2422 |
+
}
|
| 2423 |
+
|
| 2424 |
+
protected static $lib_join = array('list1', 'list2', 'separator');
|
| 2425 |
+
protected function lib_join($args) {
|
| 2426 |
+
list($list1, $list2, $sep) = $args;
|
| 2427 |
+
$list1 = $this->coerceList($list1, ' ');
|
| 2428 |
+
$list2 = $this->coerceList($list2, ' ');
|
| 2429 |
+
$sep = $this->listSeparatorForJoin($list1, $sep);
|
| 2430 |
+
return array('list', $sep, array_merge($list1[2], $list2[2]));
|
| 2431 |
+
}
|
| 2432 |
+
|
| 2433 |
+
protected static $lib_append = array('list', 'val', 'separator');
|
| 2434 |
+
protected function lib_append($args) {
|
| 2435 |
+
list($list1, $value, $sep) = $args;
|
| 2436 |
+
$list1 = $this->coerceList($list1, ' ');
|
| 2437 |
+
$sep = $this->listSeparatorForJoin($list1, $sep);
|
| 2438 |
+
return array('list', $sep, array_merge($list1[2], array($value)));
|
| 2439 |
+
}
|
| 2440 |
+
|
| 2441 |
+
protected function lib_zip($args) {
|
| 2442 |
+
foreach ($args as $arg) {
|
| 2443 |
+
$this->assertList($arg);
|
| 2444 |
+
}
|
| 2445 |
+
|
| 2446 |
+
$lists = array();
|
| 2447 |
+
$firstList = array_shift($args);
|
| 2448 |
+
foreach ($firstList[2] as $key => $item) {
|
| 2449 |
+
$list = array('list', '', array($item));
|
| 2450 |
+
foreach ($args as $arg) {
|
| 2451 |
+
if (isset($arg[2][$key])) {
|
| 2452 |
+
$list[2][] = $arg[2][$key];
|
| 2453 |
+
} else {
|
| 2454 |
+
break 2;
|
| 2455 |
+
}
|
| 2456 |
+
}
|
| 2457 |
+
$lists[] = $list;
|
| 2458 |
+
}
|
| 2459 |
+
|
| 2460 |
+
return array('list', ',', $lists);
|
| 2461 |
+
}
|
| 2462 |
+
|
| 2463 |
+
protected static $lib_type_of = array('value');
|
| 2464 |
+
protected function lib_type_of($args) {
|
| 2465 |
+
$value = $args[0];
|
| 2466 |
+
switch ($value[0]) {
|
| 2467 |
+
case 'keyword':
|
| 2468 |
+
if ($value == self::$true || $value == self::$false) {
|
| 2469 |
+
return 'bool';
|
| 2470 |
+
}
|
| 2471 |
+
|
| 2472 |
+
if ($this->coerceColor($value)) {
|
| 2473 |
+
return 'color';
|
| 2474 |
+
}
|
| 2475 |
+
|
| 2476 |
+
return 'string';
|
| 2477 |
+
default:
|
| 2478 |
+
return $value[0];
|
| 2479 |
+
}
|
| 2480 |
+
}
|
| 2481 |
+
|
| 2482 |
+
protected static $lib_unit = array('number');
|
| 2483 |
+
protected function lib_unit($args) {
|
| 2484 |
+
$num = $args[0];
|
| 2485 |
+
if ($num[0] == 'number') {
|
| 2486 |
+
return array('string', '"', array($num[2]));
|
| 2487 |
+
}
|
| 2488 |
+
return '';
|
| 2489 |
+
}
|
| 2490 |
+
|
| 2491 |
+
protected static $lib_unitless = array('number');
|
| 2492 |
+
protected function lib_unitless($args) {
|
| 2493 |
+
$value = $args[0];
|
| 2494 |
+
return $value[0] == 'number' && empty($value[2]);
|
| 2495 |
+
}
|
| 2496 |
+
|
| 2497 |
+
protected static $lib_comparable = array('number-1', 'number-2');
|
| 2498 |
+
protected function lib_comparable($args) {
|
| 2499 |
+
list($number1, $number2) = $args;
|
| 2500 |
+
if (!isset($number1[0]) || $number1[0] != 'number' || !isset($number2[0]) || $number2[0] != 'number') {
|
| 2501 |
+
$this->throwError('Invalid argument(s) for "comparable"');
|
| 2502 |
+
}
|
| 2503 |
+
|
| 2504 |
+
$number1 = $this->normalizeNumber($number1);
|
| 2505 |
+
$number2 = $this->normalizeNumber($number2);
|
| 2506 |
+
|
| 2507 |
+
return $number1[2] == $number2[2] || $number1[2] == '' || $number2[2] == '';
|
| 2508 |
+
}
|
| 2509 |
+
|
| 2510 |
+
/**
|
| 2511 |
+
* Workaround IE7's content counter bug.
|
| 2512 |
+
*
|
| 2513 |
+
* @param array $args
|
| 2514 |
+
*/
|
| 2515 |
+
protected function lib_counter($args) {
|
| 2516 |
+
$list = array_map(array($this, 'compileValue'), $args);
|
| 2517 |
+
return array('string', '', array('counter(' . implode(',', $list) . ')'));
|
| 2518 |
+
}
|
| 2519 |
+
|
| 2520 |
+
public function throwError($msg = null) {
|
| 2521 |
+
if (func_num_args() > 1) {
|
| 2522 |
+
$msg = call_user_func_array('sprintf', func_get_args());
|
| 2523 |
+
}
|
| 2524 |
+
|
| 2525 |
+
if ($this->sourcePos >= 0 && isset($this->sourceParser)) {
|
| 2526 |
+
$this->sourceParser->throwParseError($msg, $this->sourcePos);
|
| 2527 |
+
}
|
| 2528 |
+
|
| 2529 |
+
throw new Exception($msg);
|
| 2530 |
+
}
|
| 2531 |
+
|
| 2532 |
+
/**
|
| 2533 |
+
* CSS Colors
|
| 2534 |
+
*
|
| 2535 |
+
* @see http://www.w3.org/TR/css3-color
|
| 2536 |
+
*/
|
| 2537 |
+
static protected $cssColors = array(
|
| 2538 |
+
'aliceblue' => '240,248,255',
|
| 2539 |
+
'antiquewhite' => '250,235,215',
|
| 2540 |
+
'aqua' => '0,255,255',
|
| 2541 |
+
'aquamarine' => '127,255,212',
|
| 2542 |
+
'azure' => '240,255,255',
|
| 2543 |
+
'beige' => '245,245,220',
|
| 2544 |
+
'bisque' => '255,228,196',
|
| 2545 |
+
'black' => '0,0,0',
|
| 2546 |
+
'blanchedalmond' => '255,235,205',
|
| 2547 |
+
'blue' => '0,0,255',
|
| 2548 |
+
'blueviolet' => '138,43,226',
|
| 2549 |
+
'brown' => '165,42,42',
|
| 2550 |
+
'burlywood' => '222,184,135',
|
| 2551 |
+
'cadetblue' => '95,158,160',
|
| 2552 |
+
'chartreuse' => '127,255,0',
|
| 2553 |
+
'chocolate' => '210,105,30',
|
| 2554 |
+
'coral' => '255,127,80',
|
| 2555 |
+
'cornflowerblue' => '100,149,237',
|
| 2556 |
+
'cornsilk' => '255,248,220',
|
| 2557 |
+
'crimson' => '220,20,60',
|
| 2558 |
+
'cyan' => '0,255,255',
|
| 2559 |
+
'darkblue' => '0,0,139',
|
| 2560 |
+
'darkcyan' => '0,139,139',
|
| 2561 |
+
'darkgoldenrod' => '184,134,11',
|
| 2562 |
+
'darkgray' => '169,169,169',
|
| 2563 |
+
'darkgreen' => '0,100,0',
|
| 2564 |
+
'darkgrey' => '169,169,169',
|
| 2565 |
+
'darkkhaki' => '189,183,107',
|
| 2566 |
+
'darkmagenta' => '139,0,139',
|
| 2567 |
+
'darkolivegreen' => '85,107,47',
|
| 2568 |
+
'darkorange' => '255,140,0',
|
| 2569 |
+
'darkorchid' => '153,50,204',
|
| 2570 |
+
'darkred' => '139,0,0',
|
| 2571 |
+
'darksalmon' => '233,150,122',
|
| 2572 |
+
'darkseagreen' => '143,188,143',
|
| 2573 |
+
'darkslateblue' => '72,61,139',
|
| 2574 |
+
'darkslategray' => '47,79,79',
|
| 2575 |
+
'darkslategrey' => '47,79,79',
|
| 2576 |
+
'darkturquoise' => '0,206,209',
|
| 2577 |
+
'darkviolet' => '148,0,211',
|
| 2578 |
+
'deeppink' => '255,20,147',
|
| 2579 |
+
'deepskyblue' => '0,191,255',
|
| 2580 |
+
'dimgray' => '105,105,105',
|
| 2581 |
+
'dimgrey' => '105,105,105',
|
| 2582 |
+
'dodgerblue' => '30,144,255',
|
| 2583 |
+
'firebrick' => '178,34,34',
|
| 2584 |
+
'floralwhite' => '255,250,240',
|
| 2585 |
+
'forestgreen' => '34,139,34',
|
| 2586 |
+
'fuchsia' => '255,0,255',
|
| 2587 |
+
'gainsboro' => '220,220,220',
|
| 2588 |
+
'ghostwhite' => '248,248,255',
|
| 2589 |
+
'gold' => '255,215,0',
|
| 2590 |
+
'goldenrod' => '218,165,32',
|
| 2591 |
+
'gray' => '128,128,128',
|
| 2592 |
+
'green' => '0,128,0',
|
| 2593 |
+
'greenyellow' => '173,255,47',
|
| 2594 |
+
'grey' => '128,128,128',
|
| 2595 |
+
'honeydew' => '240,255,240',
|
| 2596 |
+
'hotpink' => '255,105,180',
|
| 2597 |
+
'indianred' => '205,92,92',
|
| 2598 |
+
'indigo' => '75,0,130',
|
| 2599 |
+
'ivory' => '255,255,240',
|
| 2600 |
+
'khaki' => '240,230,140',
|
| 2601 |
+
'lavender' => '230,230,250',
|
| 2602 |
+
'lavenderblush' => '255,240,245',
|
| 2603 |
+
'lawngreen' => '124,252,0',
|
| 2604 |
+
'lemonchiffon' => '255,250,205',
|
| 2605 |
+
'lightblue' => '173,216,230',
|
| 2606 |
+
'lightcoral' => '240,128,128',
|
| 2607 |
+
'lightcyan' => '224,255,255',
|
| 2608 |
+
'lightgoldenrodyellow' => '250,250,210',
|
| 2609 |
+
'lightgray' => '211,211,211',
|
| 2610 |
+
'lightgreen' => '144,238,144',
|
| 2611 |
+
'lightgrey' => '211,211,211',
|
| 2612 |
+
'lightpink' => '255,182,193',
|
| 2613 |
+
'lightsalmon' => '255,160,122',
|
| 2614 |
+
'lightseagreen' => '32,178,170',
|
| 2615 |
+
'lightskyblue' => '135,206,250',
|
| 2616 |
+
'lightslategray' => '119,136,153',
|
| 2617 |
+
'lightslategrey' => '119,136,153',
|
| 2618 |
+
'lightsteelblue' => '176,196,222',
|
| 2619 |
+
'lightyellow' => '255,255,224',
|
| 2620 |
+
'lime' => '0,255,0',
|
| 2621 |
+
'limegreen' => '50,205,50',
|
| 2622 |
+
'linen' => '250,240,230',
|
| 2623 |
+
'magenta' => '255,0,255',
|
| 2624 |
+
'maroon' => '128,0,0',
|
| 2625 |
+
'mediumaquamarine' => '102,205,170',
|
| 2626 |
+
'mediumblue' => '0,0,205',
|
| 2627 |
+
'mediumorchid' => '186,85,211',
|
| 2628 |
+
'mediumpurple' => '147,112,219',
|
| 2629 |
+
'mediumseagreen' => '60,179,113',
|
| 2630 |
+
'mediumslateblue' => '123,104,238',
|
| 2631 |
+
'mediumspringgreen' => '0,250,154',
|
| 2632 |
+
'mediumturquoise' => '72,209,204',
|
| 2633 |
+
'mediumvioletred' => '199,21,133',
|
| 2634 |
+
'midnightblue' => '25,25,112',
|
| 2635 |
+
'mintcream' => '245,255,250',
|
| 2636 |
+
'mistyrose' => '255,228,225',
|
| 2637 |
+
'moccasin' => '255,228,181',
|
| 2638 |
+
'navajowhite' => '255,222,173',
|
| 2639 |
+
'navy' => '0,0,128',
|
| 2640 |
+
'oldlace' => '253,245,230',
|
| 2641 |
+
'olive' => '128,128,0',
|
| 2642 |
+
'olivedrab' => '107,142,35',
|
| 2643 |
+
'orange' => '255,165,0',
|
| 2644 |
+
'orangered' => '255,69,0',
|
| 2645 |
+
'orchid' => '218,112,214',
|
| 2646 |
+
'palegoldenrod' => '238,232,170',
|
| 2647 |
+
'palegreen' => '152,251,152',
|
| 2648 |
+
'paleturquoise' => '175,238,238',
|
| 2649 |
+
'palevioletred' => '219,112,147',
|
| 2650 |
+
'papayawhip' => '255,239,213',
|
| 2651 |
+
'peachpuff' => '255,218,185',
|
| 2652 |
+
'peru' => '205,133,63',
|
| 2653 |
+
'pink' => '255,192,203',
|
| 2654 |
+
'plum' => '221,160,221',
|
| 2655 |
+
'powderblue' => '176,224,230',
|
| 2656 |
+
'purple' => '128,0,128',
|
| 2657 |
+
'red' => '255,0,0',
|
| 2658 |
+
'rosybrown' => '188,143,143',
|
| 2659 |
+
'royalblue' => '65,105,225',
|
| 2660 |
+
'saddlebrown' => '139,69,19',
|
| 2661 |
+
'salmon' => '250,128,114',
|
| 2662 |
+
'sandybrown' => '244,164,96',
|
| 2663 |
+
'seagreen' => '46,139,87',
|
| 2664 |
+
'seashell' => '255,245,238',
|
| 2665 |
+
'sienna' => '160,82,45',
|
| 2666 |
+
'silver' => '192,192,192',
|
| 2667 |
+
'skyblue' => '135,206,235',
|
| 2668 |
+
'slateblue' => '106,90,205',
|
| 2669 |
+
'slategray' => '112,128,144',
|
| 2670 |
+
'slategrey' => '112,128,144',
|
| 2671 |
+
'snow' => '255,250,250',
|
| 2672 |
+
'springgreen' => '0,255,127',
|
| 2673 |
+
'steelblue' => '70,130,180',
|
| 2674 |
+
'tan' => '210,180,140',
|
| 2675 |
+
'teal' => '0,128,128',
|
| 2676 |
+
'thistle' => '216,191,216',
|
| 2677 |
+
'tomato' => '255,99,71',
|
| 2678 |
+
'transparent' => '0,0,0,0',
|
| 2679 |
+
'turquoise' => '64,224,208',
|
| 2680 |
+
'violet' => '238,130,238',
|
| 2681 |
+
'wheat' => '245,222,179',
|
| 2682 |
+
'white' => '255,255,255',
|
| 2683 |
+
'whitesmoke' => '245,245,245',
|
| 2684 |
+
'yellow' => '255,255,0',
|
| 2685 |
+
'yellowgreen' => '154,205,50'
|
| 2686 |
+
);
|
| 2687 |
+
}
|
| 2688 |
+
|
| 2689 |
+
/**
|
| 2690 |
+
* SCSS parser
|
| 2691 |
+
*
|
| 2692 |
+
* @author Leaf Corcoran <leafot@gmail.com>
|
| 2693 |
+
*/
|
| 2694 |
+
class scss_parser {
|
| 2695 |
+
static protected $precedence = array(
|
| 2696 |
+
'or' => 0,
|
| 2697 |
+
'and' => 1,
|
| 2698 |
+
|
| 2699 |
+
'==' => 2,
|
| 2700 |
+
'!=' => 2,
|
| 2701 |
+
'<=' => 2,
|
| 2702 |
+
'>=' => 2,
|
| 2703 |
+
'=' => 2,
|
| 2704 |
+
'<' => 3,
|
| 2705 |
+
'>' => 2,
|
| 2706 |
+
|
| 2707 |
+
'+' => 3,
|
| 2708 |
+
'-' => 3,
|
| 2709 |
+
'*' => 4,
|
| 2710 |
+
'/' => 4,
|
| 2711 |
+
'%' => 4,
|
| 2712 |
+
);
|
| 2713 |
+
|
| 2714 |
+
static protected $operators = array('+', '-', '*', '/', '%',
|
| 2715 |
+
'==', '!=', '<=', '>=', '<', '>', 'and', 'or');
|
| 2716 |
+
|
| 2717 |
+
static protected $operatorStr;
|
| 2718 |
+
static protected $whitePattern;
|
| 2719 |
+
static protected $commentMulti;
|
| 2720 |
+
|
| 2721 |
+
static protected $commentSingle = '//';
|
| 2722 |
+
static protected $commentMultiLeft = '/*';
|
| 2723 |
+
static protected $commentMultiRight = '*/';
|
| 2724 |
+
|
| 2725 |
+
/**
|
| 2726 |
+
* Constructor
|
| 2727 |
+
*
|
| 2728 |
+
* @param string $sourceName
|
| 2729 |
+
* @param boolean $rootParser
|
| 2730 |
+
*/
|
| 2731 |
+
public function __construct($sourceName = null, $rootParser = true) {
|
| 2732 |
+
$this->sourceName = $sourceName;
|
| 2733 |
+
$this->rootParser = $rootParser;
|
| 2734 |
+
|
| 2735 |
+
if (empty(self::$operatorStr)) {
|
| 2736 |
+
self::$operatorStr = $this->makeOperatorStr(self::$operators);
|
| 2737 |
+
|
| 2738 |
+
$commentSingle = $this->preg_quote(self::$commentSingle);
|
| 2739 |
+
$commentMultiLeft = $this->preg_quote(self::$commentMultiLeft);
|
| 2740 |
+
$commentMultiRight = $this->preg_quote(self::$commentMultiRight);
|
| 2741 |
+
self::$commentMulti = $commentMultiLeft.'.*?'.$commentMultiRight;
|
| 2742 |
+
self::$whitePattern = '/'.$commentSingle.'[^\n]*\s*|('.self::$commentMulti.')\s*|\s+/Ais';
|
| 2743 |
+
}
|
| 2744 |
+
}
|
| 2745 |
+
|
| 2746 |
+
static protected function makeOperatorStr($operators) {
|
| 2747 |
+
return '('.implode('|', array_map(array('scss_parser','preg_quote'),
|
| 2748 |
+
$operators)).')';
|
| 2749 |
+
}
|
| 2750 |
+
|
| 2751 |
+
/**
|
| 2752 |
+
* Parser buffer
|
| 2753 |
+
*
|
| 2754 |
+
* @param string $buffer;
|
| 2755 |
+
*
|
| 2756 |
+
* @return \StdClass
|
| 2757 |
+
*/
|
| 2758 |
+
public function parse($buffer)
|
| 2759 |
+
{
|
| 2760 |
+
$this->count = 0;
|
| 2761 |
+
$this->env = null;
|
| 2762 |
+
$this->inParens = false;
|
| 2763 |
+
$this->eatWhiteDefault = true;
|
| 2764 |
+
$this->buffer = $buffer;
|
| 2765 |
+
|
| 2766 |
+
$this->pushBlock(null); // root block
|
| 2767 |
+
|
| 2768 |
+
$this->whitespace();
|
| 2769 |
+
$this->pushBlock(null);
|
| 2770 |
+
$this->popBlock();
|
| 2771 |
+
|
| 2772 |
+
while (false !== $this->parseChunk())
|
| 2773 |
+
;
|
| 2774 |
+
|
| 2775 |
+
if ($this->count != strlen($this->buffer)) {
|
| 2776 |
+
$this->throwParseError();
|
| 2777 |
+
}
|
| 2778 |
+
|
| 2779 |
+
if (!empty($this->env->parent)) {
|
| 2780 |
+
$this->throwParseError('unclosed block');
|
| 2781 |
+
}
|
| 2782 |
+
|
| 2783 |
+
$this->env->isRoot = true;
|
| 2784 |
+
|
| 2785 |
+
return $this->env;
|
| 2786 |
+
}
|
| 2787 |
+
|
| 2788 |
+
/**
|
| 2789 |
+
* Parse a single chunk off the head of the buffer and append it to the
|
| 2790 |
+
* current parse environment.
|
| 2791 |
+
*
|
| 2792 |
+
* Returns false when the buffer is empty, or when there is an error.
|
| 2793 |
+
*
|
| 2794 |
+
* This function is called repeatedly until the entire document is
|
| 2795 |
+
* parsed.
|
| 2796 |
+
*
|
| 2797 |
+
* This parser is most similar to a recursive descent parser. Single
|
| 2798 |
+
* functions represent discrete grammatical rules for the language, and
|
| 2799 |
+
* they are able to capture the text that represents those rules.
|
| 2800 |
+
*
|
| 2801 |
+
* Consider the function scssc::keyword(). (All parse functions are
|
| 2802 |
+
* structured the same.)
|
| 2803 |
+
*
|
| 2804 |
+
* The function takes a single reference argument. When calling the
|
| 2805 |
+
* function it will attempt to match a keyword on the head of the buffer.
|
| 2806 |
+
* If it is successful, it will place the keyword in the referenced
|
| 2807 |
+
* argument, advance the position in the buffer, and return true. If it
|
| 2808 |
+
* fails then it won't advance the buffer and it will return false.
|
| 2809 |
+
*
|
| 2810 |
+
* All of these parse functions are powered by scssc::match(), which behaves
|
| 2811 |
+
* the same way, but takes a literal regular expression. Sometimes it is
|
| 2812 |
+
* more convenient to use match instead of creating a new function.
|
| 2813 |
+
*
|
| 2814 |
+
* Because of the format of the functions, to parse an entire string of
|
| 2815 |
+
* grammatical rules, you can chain them together using &&.
|
| 2816 |
+
*
|
| 2817 |
+
* But, if some of the rules in the chain succeed before one fails, then
|
| 2818 |
+
* the buffer position will be left at an invalid state. In order to
|
| 2819 |
+
* avoid this, scssc::seek() is used to remember and set buffer positions.
|
| 2820 |
+
*
|
| 2821 |
+
* Before parsing a chain, use $s = $this->seek() to remember the current
|
| 2822 |
+
* position into $s. Then if a chain fails, use $this->seek($s) to
|
| 2823 |
+
* go back where we started.
|
| 2824 |
+
*
|
| 2825 |
+
* @return boolean
|
| 2826 |
+
*/
|
| 2827 |
+
protected function parseChunk() {
|
| 2828 |
+
$s = $this->seek();
|
| 2829 |
+
|
| 2830 |
+
// the directives
|
| 2831 |
+
if (isset($this->buffer[$this->count]) && $this->buffer[$this->count] == '@') {
|
| 2832 |
+
if ($this->literal('@media') && $this->mediaQueryList($mediaQueryList) && $this->literal('{')) {
|
| 2833 |
+
$media = $this->pushSpecialBlock('media');
|
| 2834 |
+
$media->queryList = $mediaQueryList[2];
|
| 2835 |
+
return true;
|
| 2836 |
+
} else {
|
| 2837 |
+
$this->seek($s);
|
| 2838 |
+
}
|
| 2839 |
+
|
| 2840 |
+
if ($this->literal('@mixin') &&
|
| 2841 |
+
$this->keyword($mixinName) &&
|
| 2842 |
+
($this->argumentDef($args) || true) &&
|
| 2843 |
+
$this->literal('{'))
|
| 2844 |
+
{
|
| 2845 |
+
$mixin = $this->pushSpecialBlock('mixin');
|
| 2846 |
+
$mixin->name = $mixinName;
|
| 2847 |
+
$mixin->args = $args;
|
| 2848 |
+
return true;
|
| 2849 |
+
} else {
|
| 2850 |
+
$this->seek($s);
|
| 2851 |
+
}
|
| 2852 |
+
|
| 2853 |
+
if ($this->literal('@include') &&
|
| 2854 |
+
$this->keyword($mixinName) &&
|
| 2855 |
+
($this->literal('(') &&
|
| 2856 |
+
($this->argValues($argValues) || true) &&
|
| 2857 |
+
$this->literal(')') || true) &&
|
| 2858 |
+
($this->end() ||
|
| 2859 |
+
$this->literal('{') && $hasBlock = true))
|
| 2860 |
+
{
|
| 2861 |
+
$child = array('include',
|
| 2862 |
+
$mixinName, isset($argValues) ? $argValues : null, null);
|
| 2863 |
+
|
| 2864 |
+
if (!empty($hasBlock)) {
|
| 2865 |
+
$include = $this->pushSpecialBlock('include');
|
| 2866 |
+
$include->child = $child;
|
| 2867 |
+
} else {
|
| 2868 |
+
$this->append($child, $s);
|
| 2869 |
+
}
|
| 2870 |
+
|
| 2871 |
+
return true;
|
| 2872 |
+
} else {
|
| 2873 |
+
$this->seek($s);
|
| 2874 |
+
}
|
| 2875 |
+
|
| 2876 |
+
if ($this->literal('@import') &&
|
| 2877 |
+
$this->valueList($importPath) &&
|
| 2878 |
+
$this->end())
|
| 2879 |
+
{
|
| 2880 |
+
$this->append(array('import', $importPath), $s);
|
| 2881 |
+
return true;
|
| 2882 |
+
} else {
|
| 2883 |
+
$this->seek($s);
|
| 2884 |
+
}
|
| 2885 |
+
|
| 2886 |
+
if ($this->literal('@extend') &&
|
| 2887 |
+
$this->selectors($selector) &&
|
| 2888 |
+
$this->end())
|
| 2889 |
+
{
|
| 2890 |
+
$this->append(array('extend', $selector), $s);
|
| 2891 |
+
return true;
|
| 2892 |
+
} else {
|
| 2893 |
+
$this->seek($s);
|
| 2894 |
+
}
|
| 2895 |
+
|
| 2896 |
+
if ($this->literal('@function') &&
|
| 2897 |
+
$this->keyword($fnName) &&
|
| 2898 |
+
$this->argumentDef($args) &&
|
| 2899 |
+
$this->literal('{'))
|
| 2900 |
+
{
|
| 2901 |
+
$func = $this->pushSpecialBlock('function');
|
| 2902 |
+
$func->name = $fnName;
|
| 2903 |
+
$func->args = $args;
|
| 2904 |
+
return true;
|
| 2905 |
+
} else {
|
| 2906 |
+
$this->seek($s);
|
| 2907 |
+
}
|
| 2908 |
+
|
| 2909 |
+
if ($this->literal('@return') && $this->valueList($retVal) && $this->end()) {
|
| 2910 |
+
$this->append(array('return', $retVal), $s);
|
| 2911 |
+
return true;
|
| 2912 |
+
} else {
|
| 2913 |
+
$this->seek($s);
|
| 2914 |
+
}
|
| 2915 |
+
|
| 2916 |
+
if ($this->literal('@each') &&
|
| 2917 |
+
$this->variable($varName) &&
|
| 2918 |
+
$this->literal('in') &&
|
| 2919 |
+
$this->valueList($list) &&
|
| 2920 |
+
$this->literal('{'))
|
| 2921 |
+
{
|
| 2922 |
+
$each = $this->pushSpecialBlock('each');
|
| 2923 |
+
$each->var = $varName[1];
|
| 2924 |
+
$each->list = $list;
|
| 2925 |
+
return true;
|
| 2926 |
+
} else {
|
| 2927 |
+
$this->seek($s);
|
| 2928 |
+
}
|
| 2929 |
+
|
| 2930 |
+
if ($this->literal('@while') &&
|
| 2931 |
+
$this->expression($cond) &&
|
| 2932 |
+
$this->literal('{'))
|
| 2933 |
+
{
|
| 2934 |
+
$while = $this->pushSpecialBlock('while');
|
| 2935 |
+
$while->cond = $cond;
|
| 2936 |
+
return true;
|
| 2937 |
+
} else {
|
| 2938 |
+
$this->seek($s);
|
| 2939 |
+
}
|
| 2940 |
+
|
| 2941 |
+
if ($this->literal('@for') &&
|
| 2942 |
+
$this->variable($varName) &&
|
| 2943 |
+
$this->literal('from') &&
|
| 2944 |
+
$this->expression($start) &&
|
| 2945 |
+
($this->literal('through') ||
|
| 2946 |
+
($forUntil = true && $this->literal('to'))) &&
|
| 2947 |
+
$this->expression($end) &&
|
| 2948 |
+
$this->literal('{'))
|
| 2949 |
+
{
|
| 2950 |
+
$for = $this->pushSpecialBlock('for');
|
| 2951 |
+
$for->var = $varName[1];
|
| 2952 |
+
$for->start = $start;
|
| 2953 |
+
$for->end = $end;
|
| 2954 |
+
$for->until = isset($forUntil);
|
| 2955 |
+
return true;
|
| 2956 |
+
} else {
|
| 2957 |
+
$this->seek($s);
|
| 2958 |
+
}
|
| 2959 |
+
|
| 2960 |
+
if ($this->literal('@if') && $this->valueList($cond) && $this->literal('{')) {
|
| 2961 |
+
$if = $this->pushSpecialBlock('if');
|
| 2962 |
+
$if->cond = $cond;
|
| 2963 |
+
$if->cases = array();
|
| 2964 |
+
return true;
|
| 2965 |
+
} else {
|
| 2966 |
+
$this->seek($s);
|
| 2967 |
+
}
|
| 2968 |
+
|
| 2969 |
+
if (($this->literal('@debug') || $this->literal('@warn')) &&
|
| 2970 |
+
$this->valueList($value) &&
|
| 2971 |
+
$this->end()) {
|
| 2972 |
+
$this->append(array('debug', $value, $s), $s);
|
| 2973 |
+
return true;
|
| 2974 |
+
} else {
|
| 2975 |
+
$this->seek($s);
|
| 2976 |
+
}
|
| 2977 |
+
|
| 2978 |
+
if ($this->literal('@content') && $this->end()) {
|
| 2979 |
+
$this->append(array('mixin_content'), $s);
|
| 2980 |
+
return true;
|
| 2981 |
+
} else {
|
| 2982 |
+
$this->seek($s);
|
| 2983 |
+
}
|
| 2984 |
+
|
| 2985 |
+
$last = $this->last();
|
| 2986 |
+
if (isset($last) && $last[0] == 'if') {
|
| 2987 |
+
list(, $if) = $last;
|
| 2988 |
+
if ($this->literal('@else')) {
|
| 2989 |
+
if ($this->literal('{')) {
|
| 2990 |
+
$else = $this->pushSpecialBlock('else');
|
| 2991 |
+
} elseif ($this->literal('if') && $this->valueList($cond) && $this->literal('{')) {
|
| 2992 |
+
$else = $this->pushSpecialBlock('elseif');
|
| 2993 |
+
$else->cond = $cond;
|
| 2994 |
+
}
|
| 2995 |
+
|
| 2996 |
+
if (isset($else)) {
|
| 2997 |
+
$else->dontAppend = true;
|
| 2998 |
+
$if->cases[] = $else;
|
| 2999 |
+
return true;
|
| 3000 |
+
}
|
| 3001 |
+
}
|
| 3002 |
+
|
| 3003 |
+
$this->seek($s);
|
| 3004 |
+
}
|
| 3005 |
+
|
| 3006 |
+
if ($this->literal('@charset') &&
|
| 3007 |
+
$this->valueList($charset) && $this->end())
|
| 3008 |
+
{
|
| 3009 |
+
$this->append(array('charset', $charset), $s);
|
| 3010 |
+
return true;
|
| 3011 |
+
} else {
|
| 3012 |
+
$this->seek($s);
|
| 3013 |
+
}
|
| 3014 |
+
|
| 3015 |
+
// doesn't match built in directive, do generic one
|
| 3016 |
+
if ($this->literal('@', false) && $this->keyword($dirName) &&
|
| 3017 |
+
($this->variable($dirValue) || $this->openString('{', $dirValue) || true) &&
|
| 3018 |
+
$this->literal('{'))
|
| 3019 |
+
{
|
| 3020 |
+
$directive = $this->pushSpecialBlock('directive');
|
| 3021 |
+
$directive->name = $dirName;
|
| 3022 |
+
if (isset($dirValue)) $directive->value = $dirValue;
|
| 3023 |
+
return true;
|
| 3024 |
+
}
|
| 3025 |
+
|
| 3026 |
+
$this->seek($s);
|
| 3027 |
+
return false;
|
| 3028 |
+
}
|
| 3029 |
+
|
| 3030 |
+
// property shortcut
|
| 3031 |
+
// captures most properties before having to parse a selector
|
| 3032 |
+
if ($this->keyword($name, false) &&
|
| 3033 |
+
$this->literal(': ') &&
|
| 3034 |
+
$this->valueList($value) &&
|
| 3035 |
+
$this->end())
|
| 3036 |
+
{
|
| 3037 |
+
$name = array('string', '', array($name));
|
| 3038 |
+
$this->append(array('assign', $name, $value), $s);
|
| 3039 |
+
return true;
|
| 3040 |
+
} else {
|
| 3041 |
+
$this->seek($s);
|
| 3042 |
+
}
|
| 3043 |
+
|
| 3044 |
+
// variable assigns
|
| 3045 |
+
if ($this->variable($name) &&
|
| 3046 |
+
$this->literal(':') &&
|
| 3047 |
+
$this->valueList($value) && $this->end())
|
| 3048 |
+
{
|
| 3049 |
+
// check for !default
|
| 3050 |
+
$defaultVar = $value[0] == 'list' && $this->stripDefault($value);
|
| 3051 |
+
$this->append(array('assign', $name, $value, $defaultVar), $s);
|
| 3052 |
+
return true;
|
| 3053 |
+
} else {
|
| 3054 |
+
$this->seek($s);
|
| 3055 |
+
}
|
| 3056 |
+
|
| 3057 |
+
// misc
|
| 3058 |
+
if ($this->literal('-->')) {
|
| 3059 |
+
return true;
|
| 3060 |
+
}
|
| 3061 |
+
|
| 3062 |
+
// opening css block
|
| 3063 |
+
if ($this->selectors($selectors) && $this->literal('{')) {
|
| 3064 |
+
$b = $this->pushBlock($selectors);
|
| 3065 |
+
return true;
|
| 3066 |
+
} else {
|
| 3067 |
+
$this->seek($s);
|
| 3068 |
+
}
|
| 3069 |
+
|
| 3070 |
+
// property assign, or nested assign
|
| 3071 |
+
if ($this->propertyName($name) && $this->literal(':')) {
|
| 3072 |
+
$foundSomething = false;
|
| 3073 |
+
if ($this->valueList($value)) {
|
| 3074 |
+
$this->append(array('assign', $name, $value), $s);
|
| 3075 |
+
$foundSomething = true;
|
| 3076 |
+
}
|
| 3077 |
+
|
| 3078 |
+
if ($this->literal('{')) {
|
| 3079 |
+
$propBlock = $this->pushSpecialBlock('nestedprop');
|
| 3080 |
+
$propBlock->prefix = $name;
|
| 3081 |
+
$foundSomething = true;
|
| 3082 |
+
} elseif ($foundSomething) {
|
| 3083 |
+
$foundSomething = $this->end();
|
| 3084 |
+
}
|
| 3085 |
+
|
| 3086 |
+
if ($foundSomething) {
|
| 3087 |
+
return true;
|
| 3088 |
+
}
|
| 3089 |
+
|
| 3090 |
+
$this->seek($s);
|
| 3091 |
+
} else {
|
| 3092 |
+
$this->seek($s);
|
| 3093 |
+
}
|
| 3094 |
+
|
| 3095 |
+
// closing a block
|
| 3096 |
+
if ($this->literal('}')) {
|
| 3097 |
+
$block = $this->popBlock();
|
| 3098 |
+
if (isset($block->type) && $block->type == 'include') {
|
| 3099 |
+
$include = $block->child;
|
| 3100 |
+
unset($block->child);
|
| 3101 |
+
$include[3] = $block;
|
| 3102 |
+
$this->append($include, $s);
|
| 3103 |
+
} elseif (empty($block->dontAppend)) {
|
| 3104 |
+
$type = isset($block->type) ? $block->type : 'block';
|
| 3105 |
+
$this->append(array($type, $block), $s);
|
| 3106 |
+
}
|
| 3107 |
+
return true;
|
| 3108 |
+
}
|
| 3109 |
+
|
| 3110 |
+
// extra stuff
|
| 3111 |
+
if ($this->literal(';') ||
|
| 3112 |
+
$this->literal('<!--'))
|
| 3113 |
+
{
|
| 3114 |
+
return true;
|
| 3115 |
+
}
|
| 3116 |
+
|
| 3117 |
+
return false;
|
| 3118 |
+
}
|
| 3119 |
+
|
| 3120 |
+
protected function stripDefault(&$value) {
|
| 3121 |
+
$def = end($value[2]);
|
| 3122 |
+
if ($def[0] == 'keyword' && $def[1] == '!default') {
|
| 3123 |
+
array_pop($value[2]);
|
| 3124 |
+
$value = $this->flattenList($value);
|
| 3125 |
+
return true;
|
| 3126 |
+
}
|
| 3127 |
+
|
| 3128 |
+
if ($def[0] == 'list') {
|
| 3129 |
+
return $this->stripDefault($value[2][count($value[2]) - 1]);
|
| 3130 |
+
}
|
| 3131 |
+
|
| 3132 |
+
return false;
|
| 3133 |
+
}
|
| 3134 |
+
|
| 3135 |
+
protected function literal($what, $eatWhitespace = null) {
|
| 3136 |
+
if (!isset($eatWhitespace)) $eatWhitespace = $this->eatWhiteDefault;
|
| 3137 |
+
|
| 3138 |
+
// shortcut on single letter
|
| 3139 |
+
if (!isset($what[1]) && isset($this->buffer[$this->count])) {
|
| 3140 |
+
if ($this->buffer[$this->count] == $what) {
|
| 3141 |
+
if (!$eatWhitespace) {
|
| 3142 |
+
$this->count++;
|
| 3143 |
+
return true;
|
| 3144 |
+
}
|
| 3145 |
+
// goes below...
|
| 3146 |
+
} else {
|
| 3147 |
+
return false;
|
| 3148 |
+
}
|
| 3149 |
+
}
|
| 3150 |
+
|
| 3151 |
+
return $this->match($this->preg_quote($what), $m, $eatWhitespace);
|
| 3152 |
+
}
|
| 3153 |
+
|
| 3154 |
+
// tree builders
|
| 3155 |
+
|
| 3156 |
+
protected function pushBlock($selectors) {
|
| 3157 |
+
$b = new stdClass;
|
| 3158 |
+
$b->parent = $this->env; // not sure if we need this yet
|
| 3159 |
+
|
| 3160 |
+
$b->selectors = $selectors;
|
| 3161 |
+
$b->comments = array();
|
| 3162 |
+
|
| 3163 |
+
if (!$this->env) {
|
| 3164 |
+
$b->children = array();
|
| 3165 |
+
} elseif (empty($this->env->children)) {
|
| 3166 |
+
$this->env->children = $this->env->comments;
|
| 3167 |
+
$b->children = array();
|
| 3168 |
+
$this->env->comments = array();
|
| 3169 |
+
} else {
|
| 3170 |
+
$b->children = $this->env->comments;
|
| 3171 |
+
$this->env->comments = array();
|
| 3172 |
+
}
|
| 3173 |
+
|
| 3174 |
+
$this->env = $b;
|
| 3175 |
+
return $b;
|
| 3176 |
+
}
|
| 3177 |
+
|
| 3178 |
+
protected function pushSpecialBlock($type) {
|
| 3179 |
+
$block = $this->pushBlock(null);
|
| 3180 |
+
$block->type = $type;
|
| 3181 |
+
return $block;
|
| 3182 |
+
}
|
| 3183 |
+
|
| 3184 |
+
protected function popBlock() {
|
| 3185 |
+
$block = $this->env;
|
| 3186 |
+
|
| 3187 |
+
if (empty($block->parent)) {
|
| 3188 |
+
$this->throwParseError('unexpected }');
|
| 3189 |
+
}
|
| 3190 |
+
|
| 3191 |
+
$this->env = $block->parent;
|
| 3192 |
+
unset($block->parent);
|
| 3193 |
+
|
| 3194 |
+
$comments = $block->comments;
|
| 3195 |
+
if (count($comments)) {
|
| 3196 |
+
$this->env->comments = $comments;
|
| 3197 |
+
unset($block->comments);
|
| 3198 |
+
}
|
| 3199 |
+
|
| 3200 |
+
return $block;
|
| 3201 |
+
}
|
| 3202 |
+
|
| 3203 |
+
protected function appendComment($comment) {
|
| 3204 |
+
$comment[1] = substr(preg_replace(array('/^\s+/m', '/^(.)/m'), array('', ' \1'), $comment[1]), 1);
|
| 3205 |
+
|
| 3206 |
+
$this->env->comments[] = $comment;
|
| 3207 |
+
}
|
| 3208 |
+
|
| 3209 |
+
protected function append($statement, $pos=null) {
|
| 3210 |
+
if ($pos !== null) {
|
| 3211 |
+
$statement[-1] = $pos;
|
| 3212 |
+
if (!$this->rootParser) $statement[-2] = $this;
|
| 3213 |
+
}
|
| 3214 |
+
|
| 3215 |
+
$this->env->children[] = $statement;
|
| 3216 |
+
|
| 3217 |
+
$comments = $this->env->comments;
|
| 3218 |
+
if (count($comments)) {
|
| 3219 |
+
$this->env->children = array_merge($this->env->children, $comments);
|
| 3220 |
+
$this->env->comments = array();
|
| 3221 |
+
}
|
| 3222 |
+
}
|
| 3223 |
+
|
| 3224 |
+
// last child that was appended
|
| 3225 |
+
protected function last() {
|
| 3226 |
+
$i = count($this->env->children) - 1;
|
| 3227 |
+
if (isset($this->env->children[$i]))
|
| 3228 |
+
return $this->env->children[$i];
|
| 3229 |
+
}
|
| 3230 |
+
|
| 3231 |
+
// high level parsers (they return parts of ast)
|
| 3232 |
+
|
| 3233 |
+
protected function mediaQueryList(&$out) {
|
| 3234 |
+
return $this->genericList($out, 'mediaQuery', ',', false);
|
| 3235 |
+
}
|
| 3236 |
+
|
| 3237 |
+
protected function mediaQuery(&$out) {
|
| 3238 |
+
$s = $this->seek();
|
| 3239 |
+
|
| 3240 |
+
$expressions = null;
|
| 3241 |
+
$parts = array();
|
| 3242 |
+
|
| 3243 |
+
if (($this->literal('only') && ($only = true) || $this->literal('not') && ($not = true) || true) && $this->mixedKeyword($mediaType)) {
|
| 3244 |
+
$prop = array('mediaType');
|
| 3245 |
+
if (isset($only)) $prop[] = array('keyword', 'only');
|
| 3246 |
+
if (isset($not)) $prop[] = array('keyword', 'not');
|
| 3247 |
+
$media = array('list', '', array());
|
| 3248 |
+
foreach ((array)$mediaType as $type) {
|
| 3249 |
+
if (is_array($type)) {
|
| 3250 |
+
$media[2][] = $type;
|
| 3251 |
+
} else {
|
| 3252 |
+
$media[2][] = array('keyword', $type);
|
| 3253 |
+
}
|
| 3254 |
+
}
|
| 3255 |
+
$prop[] = $media;
|
| 3256 |
+
$parts[] = $prop;
|
| 3257 |
+
}
|
| 3258 |
+
|
| 3259 |
+
if (empty($parts) || $this->literal('and')) {
|
| 3260 |
+
$this->genericList($expressions, 'mediaExpression', 'and', false);
|
| 3261 |
+
if (is_array($expressions)) $parts = array_merge($parts, $expressions[2]);
|
| 3262 |
+
}
|
| 3263 |
+
|
| 3264 |
+
$out = $parts;
|
| 3265 |
+
return true;
|
| 3266 |
+
}
|
| 3267 |
+
|
| 3268 |
+
protected function mediaExpression(&$out) {
|
| 3269 |
+
$s = $this->seek();
|
| 3270 |
+
$value = null;
|
| 3271 |
+
if ($this->literal('(') &&
|
| 3272 |
+
$this->expression($feature) &&
|
| 3273 |
+
($this->literal(':') && $this->expression($value) || true) &&
|
| 3274 |
+
$this->literal(')'))
|
| 3275 |
+
{
|
| 3276 |
+
$out = array('mediaExp', $feature);
|
| 3277 |
+
if ($value) $out[] = $value;
|
| 3278 |
+
return true;
|
| 3279 |
+
}
|
| 3280 |
+
|
| 3281 |
+
$this->seek($s);
|
| 3282 |
+
return false;
|
| 3283 |
+
}
|
| 3284 |
+
|
| 3285 |
+
protected function argValues(&$out) {
|
| 3286 |
+
if ($this->genericList($list, 'argValue', ',', false)) {
|
| 3287 |
+
$out = $list[2];
|
| 3288 |
+
return true;
|
| 3289 |
+
}
|
| 3290 |
+
return false;
|
| 3291 |
+
}
|
| 3292 |
+
|
| 3293 |
+
protected function argValue(&$out) {
|
| 3294 |
+
$s = $this->seek();
|
| 3295 |
+
|
| 3296 |
+
$keyword = null;
|
| 3297 |
+
if (!$this->variable($keyword) || !$this->literal(':')) {
|
| 3298 |
+
$this->seek($s);
|
| 3299 |
+
$keyword = null;
|
| 3300 |
+
}
|
| 3301 |
+
|
| 3302 |
+
if ($this->genericList($value, 'expression')) {
|
| 3303 |
+
$out = array($keyword, $value, false);
|
| 3304 |
+
$s = $this->seek();
|
| 3305 |
+
if ($this->literal('...')) {
|
| 3306 |
+
$out[2] = true;
|
| 3307 |
+
} else {
|
| 3308 |
+
$this->seek($s);
|
| 3309 |
+
}
|
| 3310 |
+
return true;
|
| 3311 |
+
}
|
| 3312 |
+
|
| 3313 |
+
return false;
|
| 3314 |
+
}
|
| 3315 |
+
|
| 3316 |
+
/**
|
| 3317 |
+
* Parse list
|
| 3318 |
+
*
|
| 3319 |
+
* @param string $out
|
| 3320 |
+
*
|
| 3321 |
+
* @return boolean
|
| 3322 |
+
*/
|
| 3323 |
+
public function valueList(&$out)
|
| 3324 |
+
{
|
| 3325 |
+
return $this->genericList($out, 'spaceList', ',');
|
| 3326 |
+
}
|
| 3327 |
+
|
| 3328 |
+
protected function spaceList(&$out)
|
| 3329 |
+
{
|
| 3330 |
+
return $this->genericList($out, 'expression');
|
| 3331 |
+
}
|
| 3332 |
+
|
| 3333 |
+
protected function genericList(&$out, $parseItem, $delim='', $flatten=true) {
|
| 3334 |
+
$s = $this->seek();
|
| 3335 |
+
$items = array();
|
| 3336 |
+
while ($this->$parseItem($value)) {
|
| 3337 |
+
$items[] = $value;
|
| 3338 |
+
if ($delim) {
|
| 3339 |
+
if (!$this->literal($delim)) break;
|
| 3340 |
+
}
|
| 3341 |
+
}
|
| 3342 |
+
|
| 3343 |
+
if (count($items) == 0) {
|
| 3344 |
+
$this->seek($s);
|
| 3345 |
+
return false;
|
| 3346 |
+
}
|
| 3347 |
+
|
| 3348 |
+
if ($flatten && count($items) == 1) {
|
| 3349 |
+
$out = $items[0];
|
| 3350 |
+
} else {
|
| 3351 |
+
$out = array('list', $delim, $items);
|
| 3352 |
+
}
|
| 3353 |
+
|
| 3354 |
+
return true;
|
| 3355 |
+
}
|
| 3356 |
+
|
| 3357 |
+
protected function expression(&$out) {
|
| 3358 |
+
$s = $this->seek();
|
| 3359 |
+
|
| 3360 |
+
if ($this->literal('(')) {
|
| 3361 |
+
if ($this->literal(')')) {
|
| 3362 |
+
$out = array('list', '', array());
|
| 3363 |
+
return true;
|
| 3364 |
+
}
|
| 3365 |
+
|
| 3366 |
+
if ($this->valueList($out) && $this->literal(')') && $out[0] == 'list') {
|
| 3367 |
+
return true;
|
| 3368 |
+
}
|
| 3369 |
+
|
| 3370 |
+
$this->seek($s);
|
| 3371 |
+
}
|
| 3372 |
+
|
| 3373 |
+
if ($this->value($lhs)) {
|
| 3374 |
+
$out = $this->expHelper($lhs, 0);
|
| 3375 |
+
return true;
|
| 3376 |
+
}
|
| 3377 |
+
|
| 3378 |
+
return false;
|
| 3379 |
+
}
|
| 3380 |
+
|
| 3381 |
+
protected function expHelper($lhs, $minP) {
|
| 3382 |
+
$opstr = self::$operatorStr;
|
| 3383 |
+
|
| 3384 |
+
$ss = $this->seek();
|
| 3385 |
+
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
|
| 3386 |
+
ctype_space($this->buffer[$this->count - 1]);
|
| 3387 |
+
while ($this->match($opstr, $m) && self::$precedence[$m[1]] >= $minP) {
|
| 3388 |
+
$whiteAfter = isset($this->buffer[$this->count - 1]) &&
|
| 3389 |
+
ctype_space($this->buffer[$this->count - 1]);
|
| 3390 |
+
|
| 3391 |
+
$op = $m[1];
|
| 3392 |
+
|
| 3393 |
+
// don't turn negative numbers into expressions
|
| 3394 |
+
if ($op == '-' && $whiteBefore) {
|
| 3395 |
+
if (!$whiteAfter) break;
|
| 3396 |
+
}
|
| 3397 |
+
|
| 3398 |
+
if (!$this->value($rhs)) break;
|
| 3399 |
+
|
| 3400 |
+
// peek and see if rhs belongs to next operator
|
| 3401 |
+
if ($this->peek($opstr, $next) && self::$precedence[$next[1]] > self::$precedence[$op]) {
|
| 3402 |
+
$rhs = $this->expHelper($rhs, self::$precedence[$next[1]]);
|
| 3403 |
+
}
|
| 3404 |
+
|
| 3405 |
+
$lhs = array('exp', $op, $lhs, $rhs, $this->inParens, $whiteBefore, $whiteAfter);
|
| 3406 |
+
$ss = $this->seek();
|
| 3407 |
+
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
|
| 3408 |
+
ctype_space($this->buffer[$this->count - 1]);
|
| 3409 |
+
}
|
| 3410 |
+
|
| 3411 |
+
$this->seek($ss);
|
| 3412 |
+
return $lhs;
|
| 3413 |
+
}
|
| 3414 |
+
|
| 3415 |
+
protected function value(&$out) {
|
| 3416 |
+
$s = $this->seek();
|
| 3417 |
+
|
| 3418 |
+
if ($this->literal('not', false) && $this->whitespace() && $this->value($inner)) {
|
| 3419 |
+
$out = array('unary', 'not', $inner, $this->inParens);
|
| 3420 |
+
return true;
|
| 3421 |
+
} else {
|
| 3422 |
+
$this->seek($s);
|
| 3423 |
+
}
|
| 3424 |
+
|
| 3425 |
+
if ($this->literal('+') && $this->value($inner)) {
|
| 3426 |
+
$out = array('unary', '+', $inner, $this->inParens);
|
| 3427 |
+
return true;
|
| 3428 |
+
} else {
|
| 3429 |
+
$this->seek($s);
|
| 3430 |
+
}
|
| 3431 |
+
|
| 3432 |
+
// negation
|
| 3433 |
+
if ($this->literal('-', false) &&
|
| 3434 |
+
($this->variable($inner) ||
|
| 3435 |
+
$this->unit($inner) ||
|
| 3436 |
+
$this->parenValue($inner)))
|
| 3437 |
+
{
|
| 3438 |
+
$out = array('unary', '-', $inner, $this->inParens);
|
| 3439 |
+
return true;
|
| 3440 |
+
} else {
|
| 3441 |
+
$this->seek($s);
|
| 3442 |
+
}
|
| 3443 |
+
|
| 3444 |
+
if ($this->parenValue($out)) return true;
|
| 3445 |
+
if ($this->interpolation($out)) return true;
|
| 3446 |
+
if ($this->variable($out)) return true;
|
| 3447 |
+
if ($this->color($out)) return true;
|
| 3448 |
+
if ($this->unit($out)) return true;
|
| 3449 |
+
if ($this->string($out)) return true;
|
| 3450 |
+
if ($this->func($out)) return true;
|
| 3451 |
+
if ($this->progid($out)) return true;
|
| 3452 |
+
|
| 3453 |
+
if ($this->keyword($keyword)) {
|
| 3454 |
+
if ($keyword == 'null') {
|
| 3455 |
+
$out = array('null');
|
| 3456 |
+
} else {
|
| 3457 |
+
$out = array('keyword', $keyword);
|
| 3458 |
+
}
|
| 3459 |
+
return true;
|
| 3460 |
+
}
|
| 3461 |
+
|
| 3462 |
+
return false;
|
| 3463 |
+
}
|
| 3464 |
+
|
| 3465 |
+
// value wrappen in parentheses
|
| 3466 |
+
protected function parenValue(&$out) {
|
| 3467 |
+
$s = $this->seek();
|
| 3468 |
+
|
| 3469 |
+
$inParens = $this->inParens;
|
| 3470 |
+
if ($this->literal('(') &&
|
| 3471 |
+
($this->inParens = true) && $this->expression($exp) &&
|
| 3472 |
+
$this->literal(')'))
|
| 3473 |
+
{
|
| 3474 |
+
$out = $exp;
|
| 3475 |
+
$this->inParens = $inParens;
|
| 3476 |
+
return true;
|
| 3477 |
+
} else {
|
| 3478 |
+
$this->inParens = $inParens;
|
| 3479 |
+
$this->seek($s);
|
| 3480 |
+
}
|
| 3481 |
+
|
| 3482 |
+
return false;
|
| 3483 |
+
}
|
| 3484 |
+
|
| 3485 |
+
protected function progid(&$out) {
|
| 3486 |
+
$s = $this->seek();
|
| 3487 |
+
if ($this->literal('progid:', false) &&
|
| 3488 |
+
$this->openString('(', $fn) &&
|
| 3489 |
+
$this->literal('('))
|
| 3490 |
+
{
|
| 3491 |
+
$this->openString(')', $args, '(');
|
| 3492 |
+
if ($this->literal(')')) {
|
| 3493 |
+
$out = array('string', '', array(
|
| 3494 |
+
'progid:', $fn, '(', $args, ')'
|
| 3495 |
+
));
|
| 3496 |
+
return true;
|
| 3497 |
+
}
|
| 3498 |
+
}
|
| 3499 |
+
|
| 3500 |
+
$this->seek($s);
|
| 3501 |
+
return false;
|
| 3502 |
+
}
|
| 3503 |
+
|
| 3504 |
+
protected function func(&$func) {
|
| 3505 |
+
$s = $this->seek();
|
| 3506 |
+
|
| 3507 |
+
if ($this->keyword($name, false) &&
|
| 3508 |
+
$this->literal('('))
|
| 3509 |
+
{
|
| 3510 |
+
if ($name == 'alpha' && $this->argumentList($args)) {
|
| 3511 |
+
$func = array('function', $name, array('string', '', $args));
|
| 3512 |
+
return true;
|
| 3513 |
+
}
|
| 3514 |
+
|
| 3515 |
+
if ($name != 'expression' && !preg_match('/^(-[a-z]+-)?calc$/', $name)) {
|
| 3516 |
+
$ss = $this->seek();
|
| 3517 |
+
if ($this->argValues($args) && $this->literal(')')) {
|
| 3518 |
+
$func = array('fncall', $name, $args);
|
| 3519 |
+
return true;
|
| 3520 |
+
}
|
| 3521 |
+
$this->seek($ss);
|
| 3522 |
+
}
|
| 3523 |
+
|
| 3524 |
+
if (($this->openString(')', $str, '(') || true ) &&
|
| 3525 |
+
$this->literal(')'))
|
| 3526 |
+
{
|
| 3527 |
+
$args = array();
|
| 3528 |
+
if (!empty($str)) {
|
| 3529 |
+
$args[] = array(null, array('string', '', array($str)));
|
| 3530 |
+
}
|
| 3531 |
+
|
| 3532 |
+
$func = array('fncall', $name, $args);
|
| 3533 |
+
return true;
|
| 3534 |
+
}
|
| 3535 |
+
}
|
| 3536 |
+
|
| 3537 |
+
$this->seek($s);
|
| 3538 |
+
return false;
|
| 3539 |
+
}
|
| 3540 |
+
|
| 3541 |
+
protected function argumentList(&$out) {
|
| 3542 |
+
$s = $this->seek();
|
| 3543 |
+
$this->literal('(');
|
| 3544 |
+
|
| 3545 |
+
$args = array();
|
| 3546 |
+
while ($this->keyword($var)) {
|
| 3547 |
+
$ss = $this->seek();
|
| 3548 |
+
|
| 3549 |
+
if ($this->literal('=') && $this->expression($exp)) {
|
| 3550 |
+
$args[] = array('string', '', array($var.'='));
|
| 3551 |
+
$arg = $exp;
|
| 3552 |
+
} else {
|
| 3553 |
+
break;
|
| 3554 |
+
}
|
| 3555 |
+
|
| 3556 |
+
$args[] = $arg;
|
| 3557 |
+
|
| 3558 |
+
if (!$this->literal(',')) break;
|
| 3559 |
+
|
| 3560 |
+
$args[] = array('string', '', array(', '));
|
| 3561 |
+
}
|
| 3562 |
+
|
| 3563 |
+
if (!$this->literal(')') || !count($args)) {
|
| 3564 |
+
$this->seek($s);
|
| 3565 |
+
return false;
|
| 3566 |
+
}
|
| 3567 |
+
|
| 3568 |
+
$out = $args;
|
| 3569 |
+
return true;
|
| 3570 |
+
}
|
| 3571 |
+
|
| 3572 |
+
protected function argumentDef(&$out) {
|
| 3573 |
+
$s = $this->seek();
|
| 3574 |
+
$this->literal('(');
|
| 3575 |
+
|
| 3576 |
+
$args = array();
|
| 3577 |
+
while ($this->variable($var)) {
|
| 3578 |
+
$arg = array($var[1], null, false);
|
| 3579 |
+
|
| 3580 |
+
$ss = $this->seek();
|
| 3581 |
+
if ($this->literal(':') && $this->genericList($defaultVal, 'expression')) {
|
| 3582 |
+
$arg[1] = $defaultVal;
|
| 3583 |
+
} else {
|
| 3584 |
+
$this->seek($ss);
|
| 3585 |
+
}
|
| 3586 |
+
|
| 3587 |
+
$ss = $this->seek();
|
| 3588 |
+
if ($this->literal('...')) {
|
| 3589 |
+
$sss = $this->seek();
|
| 3590 |
+
if (!$this->literal(')')) {
|
| 3591 |
+
$this->throwParseError('... has to be after the final argument');
|
| 3592 |
+
}
|
| 3593 |
+
$arg[2] = true;
|
| 3594 |
+
$this->seek($sss);
|
| 3595 |
+
} else {
|
| 3596 |
+
$this->seek($ss);
|
| 3597 |
+
}
|
| 3598 |
+
|
| 3599 |
+
$args[] = $arg;
|
| 3600 |
+
if (!$this->literal(',')) break;
|
| 3601 |
+
}
|
| 3602 |
+
|
| 3603 |
+
if (!$this->literal(')')) {
|
| 3604 |
+
$this->seek($s);
|
| 3605 |
+
return false;
|
| 3606 |
+
}
|
| 3607 |
+
|
| 3608 |
+
$out = $args;
|
| 3609 |
+
return true;
|
| 3610 |
+
}
|
| 3611 |
+
|
| 3612 |
+
protected function color(&$out) {
|
| 3613 |
+
$color = array('color');
|
| 3614 |
+
|
| 3615 |
+
if ($this->match('(#([0-9a-f]{6})|#([0-9a-f]{3}))', $m)) {
|
| 3616 |
+
if (isset($m[3])) {
|
| 3617 |
+
$num = $m[3];
|
| 3618 |
+
$width = 16;
|
| 3619 |
+
} else {
|
| 3620 |
+
$num = $m[2];
|
| 3621 |
+
$width = 256;
|
| 3622 |
+
}
|
| 3623 |
+
|
| 3624 |
+
$num = hexdec($num);
|
| 3625 |
+
foreach (array(3,2,1) as $i) {
|
| 3626 |
+
$t = $num % $width;
|
| 3627 |
+
$num /= $width;
|
| 3628 |
+
|
| 3629 |
+
$color[$i] = $t * (256/$width) + $t * floor(16/$width);
|
| 3630 |
+
}
|
| 3631 |
+
|
| 3632 |
+
$out = $color;
|
| 3633 |
+
return true;
|
| 3634 |
+
}
|
| 3635 |
+
|
| 3636 |
+
return false;
|
| 3637 |
+
}
|
| 3638 |
+
|
| 3639 |
+
protected function unit(&$unit) {
|
| 3640 |
+
if ($this->match('([0-9]*(\.)?[0-9]+)([%a-zA-Z]+)?', $m)) {
|
| 3641 |
+
$unit = array('number', $m[1], empty($m[3]) ? '' : $m[3]);
|
| 3642 |
+
return true;
|
| 3643 |
+
}
|
| 3644 |
+
return false;
|
| 3645 |
+
}
|
| 3646 |
+
|
| 3647 |
+
protected function string(&$out) {
|
| 3648 |
+
$s = $this->seek();
|
| 3649 |
+
if ($this->literal('"', false)) {
|
| 3650 |
+
$delim = '"';
|
| 3651 |
+
} elseif ($this->literal('\'', false)) {
|
| 3652 |
+
$delim = '\'';
|
| 3653 |
+
} else {
|
| 3654 |
+
return false;
|
| 3655 |
+
}
|
| 3656 |
+
|
| 3657 |
+
$content = array();
|
| 3658 |
+
$oldWhite = $this->eatWhiteDefault;
|
| 3659 |
+
$this->eatWhiteDefault = false;
|
| 3660 |
+
|
| 3661 |
+
while ($this->matchString($m, $delim)) {
|
| 3662 |
+
$content[] = $m[1];
|
| 3663 |
+
if ($m[2] == '#{') {
|
| 3664 |
+
$this->count -= strlen($m[2]);
|
| 3665 |
+
if ($this->interpolation($inter, false)) {
|
| 3666 |
+
$content[] = $inter;
|
| 3667 |
+
} else {
|
| 3668 |
+
$this->count += strlen($m[2]);
|
| 3669 |
+
$content[] = '#{'; // ignore it
|
| 3670 |
+
}
|
| 3671 |
+
} elseif ($m[2] == '\\') {
|
| 3672 |
+
$content[] = $m[2];
|
| 3673 |
+
if ($this->literal($delim, false)) {
|
| 3674 |
+
$content[] = $delim;
|
| 3675 |
+
}
|
| 3676 |
+
} else {
|
| 3677 |
+
$this->count -= strlen($delim);
|
| 3678 |
+
break; // delim
|
| 3679 |
+
}
|
| 3680 |
+
}
|
| 3681 |
+
|
| 3682 |
+
$this->eatWhiteDefault = $oldWhite;
|
| 3683 |
+
|
| 3684 |
+
if ($this->literal($delim)) {
|
| 3685 |
+
$out = array('string', $delim, $content);
|
| 3686 |
+
return true;
|
| 3687 |
+
}
|
| 3688 |
+
|
| 3689 |
+
$this->seek($s);
|
| 3690 |
+
return false;
|
| 3691 |
+
}
|
| 3692 |
+
|
| 3693 |
+
protected function mixedKeyword(&$out) {
|
| 3694 |
+
$s = $this->seek();
|
| 3695 |
+
|
| 3696 |
+
$parts = array();
|
| 3697 |
+
|
| 3698 |
+
$oldWhite = $this->eatWhiteDefault;
|
| 3699 |
+
$this->eatWhiteDefault = false;
|
| 3700 |
+
|
| 3701 |
+
while (true) {
|
| 3702 |
+
if ($this->keyword($key)) {
|
| 3703 |
+
$parts[] = $key;
|
| 3704 |
+
continue;
|
| 3705 |
+
}
|
| 3706 |
+
|
| 3707 |
+
if ($this->interpolation($inter)) {
|
| 3708 |
+
$parts[] = $inter;
|
| 3709 |
+
continue;
|
| 3710 |
+
}
|
| 3711 |
+
|
| 3712 |
+
break;
|
| 3713 |
+
}
|
| 3714 |
+
|
| 3715 |
+
$this->eatWhiteDefault = $oldWhite;
|
| 3716 |
+
|
| 3717 |
+
if (count($parts) == 0) return false;
|
| 3718 |
+
|
| 3719 |
+
if ($this->eatWhiteDefault) {
|
| 3720 |
+
$this->whitespace();
|
| 3721 |
+
}
|
| 3722 |
+
|
| 3723 |
+
$out = $parts;
|
| 3724 |
+
return true;
|
| 3725 |
+
}
|
| 3726 |
+
|
| 3727 |
+
// an unbounded string stopped by $end
|
| 3728 |
+
protected function openString($end, &$out, $nestingOpen=null) {
|
| 3729 |
+
$oldWhite = $this->eatWhiteDefault;
|
| 3730 |
+
$this->eatWhiteDefault = false;
|
| 3731 |
+
|
| 3732 |
+
$stop = array('\'', '"', '#{', $end);
|
| 3733 |
+
$stop = array_map(array($this, 'preg_quote'), $stop);
|
| 3734 |
+
$stop[] = self::$commentMulti;
|
| 3735 |
+
|
| 3736 |
+
$patt = '(.*?)('.implode('|', $stop).')';
|
| 3737 |
+
|
| 3738 |
+
$nestingLevel = 0;
|
| 3739 |
+
|
| 3740 |
+
$content = array();
|
| 3741 |
+
while ($this->match($patt, $m, false)) {
|
| 3742 |
+
if (isset($m[1]) && $m[1] !== '') {
|
| 3743 |
+
$content[] = $m[1];
|
| 3744 |
+
if ($nestingOpen) {
|
| 3745 |
+
$nestingLevel += substr_count($m[1], $nestingOpen);
|
| 3746 |
+
}
|
| 3747 |
+
}
|
| 3748 |
+
|
| 3749 |
+
$tok = $m[2];
|
| 3750 |
+
|
| 3751 |
+
$this->count-= strlen($tok);
|
| 3752 |
+
if ($tok == $end) {
|
| 3753 |
+
if ($nestingLevel == 0) {
|
| 3754 |
+
break;
|
| 3755 |
+
} else {
|
| 3756 |
+
$nestingLevel--;
|
| 3757 |
+
}
|
| 3758 |
+
}
|
| 3759 |
+
|
| 3760 |
+
if (($tok == '\'' || $tok == '"') && $this->string($str)) {
|
| 3761 |
+
$content[] = $str;
|
| 3762 |
+
continue;
|
| 3763 |
+
}
|
| 3764 |
+
|
| 3765 |
+
if ($tok == '#{' && $this->interpolation($inter)) {
|
| 3766 |
+
$content[] = $inter;
|
| 3767 |
+
continue;
|
| 3768 |
+
}
|
| 3769 |
+
|
| 3770 |
+
$content[] = $tok;
|
| 3771 |
+
$this->count+= strlen($tok);
|
| 3772 |
+
}
|
| 3773 |
+
|
| 3774 |
+
$this->eatWhiteDefault = $oldWhite;
|
| 3775 |
+
|
| 3776 |
+
if (count($content) == 0) return false;
|
| 3777 |
+
|
| 3778 |
+
// trim the end
|
| 3779 |
+
if (is_string(end($content))) {
|
| 3780 |
+
$content[count($content) - 1] = rtrim(end($content));
|
| 3781 |
+
}
|
| 3782 |
+
|
| 3783 |
+
$out = array('string', '', $content);
|
| 3784 |
+
return true;
|
| 3785 |
+
}
|
| 3786 |
+
|
| 3787 |
+
// $lookWhite: save information about whitespace before and after
|
| 3788 |
+
protected function interpolation(&$out, $lookWhite=true) {
|
| 3789 |
+
$oldWhite = $this->eatWhiteDefault;
|
| 3790 |
+
$this->eatWhiteDefault = true;
|
| 3791 |
+
|
| 3792 |
+
$s = $this->seek();
|
| 3793 |
+
if ($this->literal('#{') && $this->valueList($value) && $this->literal('}', false)) {
|
| 3794 |
+
|
| 3795 |
+
// TODO: don't error if out of bounds
|
| 3796 |
+
|
| 3797 |
+
if ($lookWhite) {
|
| 3798 |
+
$left = preg_match('/\s/', $this->buffer[$s - 1]) ? ' ' : '';
|
| 3799 |
+
$right = preg_match('/\s/', $this->buffer[$this->count]) ? ' ': '';
|
| 3800 |
+
} else {
|
| 3801 |
+
$left = $right = false;
|
| 3802 |
+
}
|
| 3803 |
+
|
| 3804 |
+
$out = array('interpolate', $value, $left, $right);
|
| 3805 |
+
$this->eatWhiteDefault = $oldWhite;
|
| 3806 |
+
if ($this->eatWhiteDefault) {
|
| 3807 |
+
$this->whitespace();
|
| 3808 |
+
}
|
| 3809 |
+
return true;
|
| 3810 |
+
}
|
| 3811 |
+
|
| 3812 |
+
$this->seek($s);
|
| 3813 |
+
$this->eatWhiteDefault = $oldWhite;
|
| 3814 |
+
return false;
|
| 3815 |
+
}
|
| 3816 |
+
|
| 3817 |
+
// low level parsers
|
| 3818 |
+
|
| 3819 |
+
// returns an array of parts or a string
|
| 3820 |
+
protected function propertyName(&$out) {
|
| 3821 |
+
$s = $this->seek();
|
| 3822 |
+
$parts = array();
|
| 3823 |
+
|
| 3824 |
+
$oldWhite = $this->eatWhiteDefault;
|
| 3825 |
+
$this->eatWhiteDefault = false;
|
| 3826 |
+
|
| 3827 |
+
while (true) {
|
| 3828 |
+
if ($this->interpolation($inter)) {
|
| 3829 |
+
$parts[] = $inter;
|
| 3830 |
+
} elseif ($this->keyword($text)) {
|
| 3831 |
+
$parts[] = $text;
|
| 3832 |
+
} elseif (count($parts) == 0 && $this->match('[:.#]', $m, false)) {
|
| 3833 |
+
// css hacks
|
| 3834 |
+
$parts[] = $m[0];
|
| 3835 |
+
} else {
|
| 3836 |
+
break;
|
| 3837 |
+
}
|
| 3838 |
+
}
|
| 3839 |
+
|
| 3840 |
+
$this->eatWhiteDefault = $oldWhite;
|
| 3841 |
+
if (count($parts) == 0) return false;
|
| 3842 |
+
|
| 3843 |
+
// match comment hack
|
| 3844 |
+
if (preg_match(self::$whitePattern,
|
| 3845 |
+
$this->buffer, $m, null, $this->count))
|
| 3846 |
+
{
|
| 3847 |
+
if (!empty($m[0])) {
|
| 3848 |
+
$parts[] = $m[0];
|
| 3849 |
+
$this->count += strlen($m[0]);
|
| 3850 |
+
}
|
| 3851 |
+
}
|
| 3852 |
+
|
| 3853 |
+
$this->whitespace(); // get any extra whitespace
|
| 3854 |
+
|
| 3855 |
+
$out = array('string', '', $parts);
|
| 3856 |
+
return true;
|
| 3857 |
+
}
|
| 3858 |
+
|
| 3859 |
+
// comma separated list of selectors
|
| 3860 |
+
protected function selectors(&$out) {
|
| 3861 |
+
$s = $this->seek();
|
| 3862 |
+
$selectors = array();
|
| 3863 |
+
while ($this->selector($sel)) {
|
| 3864 |
+
$selectors[] = $sel;
|
| 3865 |
+
if (!$this->literal(',')) break;
|
| 3866 |
+
while ($this->literal(',')); // ignore extra
|
| 3867 |
+
}
|
| 3868 |
+
|
| 3869 |
+
if (count($selectors) == 0) {
|
| 3870 |
+
$this->seek($s);
|
| 3871 |
+
return false;
|
| 3872 |
+
}
|
| 3873 |
+
|
| 3874 |
+
$out = $selectors;
|
| 3875 |
+
return true;
|
| 3876 |
+
}
|
| 3877 |
+
|
| 3878 |
+
// whitespace separated list of selectorSingle
|
| 3879 |
+
protected function selector(&$out) {
|
| 3880 |
+
$selector = array();
|
| 3881 |
+
|
| 3882 |
+
while (true) {
|
| 3883 |
+
if ($this->match('[>+~]+', $m)) {
|
| 3884 |
+
$selector[] = array($m[0]);
|
| 3885 |
+
} elseif ($this->selectorSingle($part)) {
|
| 3886 |
+
$selector[] = $part;
|
| 3887 |
+
$this->match('\s+', $m);
|
| 3888 |
+
} elseif ($this->match('\/[^\/]+\/', $m)) {
|
| 3889 |
+
$selector[] = array($m[0]);
|
| 3890 |
+
} else {
|
| 3891 |
+
break;
|
| 3892 |
+
}
|
| 3893 |
+
|
| 3894 |
+
}
|
| 3895 |
+
|
| 3896 |
+
if (count($selector) == 0) {
|
| 3897 |
+
return false;
|
| 3898 |
+
}
|
| 3899 |
+
|
| 3900 |
+
$out = $selector;
|
| 3901 |
+
return true;
|
| 3902 |
+
}
|
| 3903 |
+
|
| 3904 |
+
// the parts that make up
|
| 3905 |
+
// div[yes=no]#something.hello.world:nth-child(-2n+1)%placeholder
|
| 3906 |
+
protected function selectorSingle(&$out) {
|
| 3907 |
+
$oldWhite = $this->eatWhiteDefault;
|
| 3908 |
+
$this->eatWhiteDefault = false;
|
| 3909 |
+
|
| 3910 |
+
$parts = array();
|
| 3911 |
+
|
| 3912 |
+
if ($this->literal('*', false)) {
|
| 3913 |
+
$parts[] = '*';
|
| 3914 |
+
}
|
| 3915 |
+
|
| 3916 |
+
while (true) {
|
| 3917 |
+
// see if we can stop early
|
| 3918 |
+
if ($this->match('\s*[{,]', $m)) {
|
| 3919 |
+
$this->count--;
|
| 3920 |
+
break;
|
| 3921 |
+
}
|
| 3922 |
+
|
| 3923 |
+
$s = $this->seek();
|
| 3924 |
+
// self
|
| 3925 |
+
if ($this->literal('&', false)) {
|
| 3926 |
+
$parts[] = scssc::$selfSelector;
|
| 3927 |
+
continue;
|
| 3928 |
+
}
|
| 3929 |
+
|
| 3930 |
+
if ($this->literal('.', false)) {
|
| 3931 |
+
$parts[] = '.';
|
| 3932 |
+
continue;
|
| 3933 |
+
}
|
| 3934 |
+
|
| 3935 |
+
if ($this->literal('|', false)) {
|
| 3936 |
+
$parts[] = '|';
|
| 3937 |
+
continue;
|
| 3938 |
+
}
|
| 3939 |
+
|
| 3940 |
+
if ($this->match('\\\\\S', $m)) {
|
| 3941 |
+
$parts[] = $m[0];
|
| 3942 |
+
continue;
|
| 3943 |
+
}
|
| 3944 |
+
|
| 3945 |
+
// for keyframes
|
| 3946 |
+
if ($this->unit($unit)) {
|
| 3947 |
+
$parts[] = $unit;
|
| 3948 |
+
continue;
|
| 3949 |
+
}
|
| 3950 |
+
|
| 3951 |
+
if ($this->keyword($name)) {
|
| 3952 |
+
$parts[] = $name;
|
| 3953 |
+
continue;
|
| 3954 |
+
}
|
| 3955 |
+
|
| 3956 |
+
if ($this->interpolation($inter)) {
|
| 3957 |
+
$parts[] = $inter;
|
| 3958 |
+
continue;
|
| 3959 |
+
}
|
| 3960 |
+
|
| 3961 |
+
if ($this->literal('%', false) && $this->placeholder($placeholder)) {
|
| 3962 |
+
$parts[] = '%';
|
| 3963 |
+
$parts[] = $placeholder;
|
| 3964 |
+
continue;
|
| 3965 |
+
}
|
| 3966 |
+
|
| 3967 |
+
if ($this->literal('#', false)) {
|
| 3968 |
+
$parts[] = '#';
|
| 3969 |
+
continue;
|
| 3970 |
+
}
|
| 3971 |
+
|
| 3972 |
+
// a pseudo selector
|
| 3973 |
+
if ($this->match('::?', $m) && $this->mixedKeyword($nameParts)) {
|
| 3974 |
+
$parts[] = $m[0];
|
| 3975 |
+
foreach ($nameParts as $sub) {
|
| 3976 |
+
$parts[] = $sub;
|
| 3977 |
+
}
|
| 3978 |
+
|
| 3979 |
+
$ss = $this->seek();
|
| 3980 |
+
if ($this->literal('(') &&
|
| 3981 |
+
($this->openString(')', $str, '(') || true ) &&
|
| 3982 |
+
$this->literal(')'))
|
| 3983 |
+
{
|
| 3984 |
+
$parts[] = '(';
|
| 3985 |
+
if (!empty($str)) $parts[] = $str;
|
| 3986 |
+
$parts[] = ')';
|
| 3987 |
+
} else {
|
| 3988 |
+
$this->seek($ss);
|
| 3989 |
+
}
|
| 3990 |
+
|
| 3991 |
+
continue;
|
| 3992 |
+
} else {
|
| 3993 |
+
$this->seek($s);
|
| 3994 |
+
}
|
| 3995 |
+
|
| 3996 |
+
// attribute selector
|
| 3997 |
+
// TODO: replace with open string?
|
| 3998 |
+
if ($this->literal('[', false)) {
|
| 3999 |
+
$attrParts = array('[');
|
| 4000 |
+
// keyword, string, operator
|
| 4001 |
+
while (true) {
|
| 4002 |
+
if ($this->literal(']', false)) {
|
| 4003 |
+
$this->count--;
|
| 4004 |
+
break; // get out early
|
| 4005 |
+
}
|
| 4006 |
+
|
| 4007 |
+
if ($this->match('\s+', $m)) {
|
| 4008 |
+
$attrParts[] = ' ';
|
| 4009 |
+
continue;
|
| 4010 |
+
}
|
| 4011 |
+
if ($this->string($str)) {
|
| 4012 |
+
$attrParts[] = $str;
|
| 4013 |
+
continue;
|
| 4014 |
+
}
|
| 4015 |
+
|
| 4016 |
+
if ($this->keyword($word)) {
|
| 4017 |
+
$attrParts[] = $word;
|
| 4018 |
+
continue;
|
| 4019 |
+
}
|
| 4020 |
+
|
| 4021 |
+
if ($this->interpolation($inter, false)) {
|
| 4022 |
+
$attrParts[] = $inter;
|
| 4023 |
+
continue;
|
| 4024 |
+
}
|
| 4025 |
+
|
| 4026 |
+
// operator, handles attr namespace too
|
| 4027 |
+
if ($this->match('[|-~\$\*\^=]+', $m)) {
|
| 4028 |
+
$attrParts[] = $m[0];
|
| 4029 |
+
continue;
|
| 4030 |
+
}
|
| 4031 |
+
|
| 4032 |
+
break;
|
| 4033 |
+
}
|
| 4034 |
+
|
| 4035 |
+
if ($this->literal(']', false)) {
|
| 4036 |
+
$attrParts[] = ']';
|
| 4037 |
+
foreach ($attrParts as $part) {
|
| 4038 |
+
$parts[] = $part;
|
| 4039 |
+
}
|
| 4040 |
+
continue;
|
| 4041 |
+
}
|
| 4042 |
+
$this->seek($s);
|
| 4043 |
+
// should just break here?
|
| 4044 |
+
}
|
| 4045 |
+
|
| 4046 |
+
break;
|
| 4047 |
+
}
|
| 4048 |
+
|
| 4049 |
+
$this->eatWhiteDefault = $oldWhite;
|
| 4050 |
+
|
| 4051 |
+
if (count($parts) == 0) return false;
|
| 4052 |
+
|
| 4053 |
+
$out = $parts;
|
| 4054 |
+
return true;
|
| 4055 |
+
}
|
| 4056 |
+
|
| 4057 |
+
protected function variable(&$out) {
|
| 4058 |
+
$s = $this->seek();
|
| 4059 |
+
if ($this->literal('$', false) && $this->keyword($name)) {
|
| 4060 |
+
$out = array('var', $name);
|
| 4061 |
+
return true;
|
| 4062 |
+
}
|
| 4063 |
+
$this->seek($s);
|
| 4064 |
+
return false;
|
| 4065 |
+
}
|
| 4066 |
+
|
| 4067 |
+
protected function keyword(&$word, $eatWhitespace = null) {
|
| 4068 |
+
if ($this->match('(([\w_\-\*!"\']|[\\\\].)([\w\-_"\']|[\\\\].)*)',
|
| 4069 |
+
$m, $eatWhitespace))
|
| 4070 |
+
{
|
| 4071 |
+
$word = $m[1];
|
| 4072 |
+
return true;
|
| 4073 |
+
}
|
| 4074 |
+
return false;
|
| 4075 |
+
}
|
| 4076 |
+
|
| 4077 |
+
protected function placeholder(&$placeholder) {
|
| 4078 |
+
if ($this->match('([\w\-_]+)', $m)) {
|
| 4079 |
+
$placeholder = $m[1];
|
| 4080 |
+
return true;
|
| 4081 |
+
}
|
| 4082 |
+
return false;
|
| 4083 |
+
}
|
| 4084 |
+
|
| 4085 |
+
// consume an end of statement delimiter
|
| 4086 |
+
protected function end() {
|
| 4087 |
+
if ($this->literal(';')) {
|
| 4088 |
+
return true;
|
| 4089 |
+
} elseif ($this->count == strlen($this->buffer) || $this->buffer[$this->count] == '}') {
|
| 4090 |
+
// if there is end of file or a closing block next then we don't need a ;
|
| 4091 |
+
return true;
|
| 4092 |
+
}
|
| 4093 |
+
return false;
|
| 4094 |
+
}
|
| 4095 |
+
|
| 4096 |
+
// advance counter to next occurrence of $what
|
| 4097 |
+
// $until - don't include $what in advance
|
| 4098 |
+
// $allowNewline, if string, will be used as valid char set
|
| 4099 |
+
protected function to($what, &$out, $until = false, $allowNewline = false) {
|
| 4100 |
+
if (is_string($allowNewline)) {
|
| 4101 |
+
$validChars = $allowNewline;
|
| 4102 |
+
} else {
|
| 4103 |
+
$validChars = $allowNewline ? '.' : "[^\n]";
|
| 4104 |
+
}
|
| 4105 |
+
if (!$this->match('('.$validChars.'*?)'.$this->preg_quote($what), $m, !$until)) return false;
|
| 4106 |
+
if ($until) $this->count -= strlen($what); // give back $what
|
| 4107 |
+
$out = $m[1];
|
| 4108 |
+
return true;
|
| 4109 |
+
}
|
| 4110 |
+
|
| 4111 |
+
public function throwParseError($msg = 'parse error', $count = null) {
|
| 4112 |
+
$count = !isset($count) ? $this->count : $count;
|
| 4113 |
+
|
| 4114 |
+
$line = $this->getLineNo($count);
|
| 4115 |
+
|
| 4116 |
+
if (!empty($this->sourceName)) {
|
| 4117 |
+
$loc = "$this->sourceName on line $line";
|
| 4118 |
+
} else {
|
| 4119 |
+
$loc = "line: $line";
|
| 4120 |
+
}
|
| 4121 |
+
|
| 4122 |
+
if ($this->peek("(.*?)(\n|$)", $m, $count)) {
|
| 4123 |
+
throw new Exception("$msg: failed at `$m[1]` $loc");
|
| 4124 |
+
} else {
|
| 4125 |
+
throw new Exception("$msg: $loc");
|
| 4126 |
+
}
|
| 4127 |
+
}
|
| 4128 |
+
|
| 4129 |
+
public function getLineNo($pos) {
|
| 4130 |
+
return 1 + substr_count(substr($this->buffer, 0, $pos), "\n");
|
| 4131 |
+
}
|
| 4132 |
+
|
| 4133 |
+
/**
|
| 4134 |
+
* Match string looking for either ending delim, escape, or string interpolation
|
| 4135 |
+
*
|
| 4136 |
+
* {@internal This is a workaround for preg_match's 250K string match limit. }}
|
| 4137 |
+
*
|
| 4138 |
+
* @param array $m Matches (passed by reference)
|
| 4139 |
+
* @param string $delim Delimeter
|
| 4140 |
+
*
|
| 4141 |
+
* @return boolean True if match; false otherwise
|
| 4142 |
+
*/
|
| 4143 |
+
protected function matchString(&$m, $delim) {
|
| 4144 |
+
$token = null;
|
| 4145 |
+
|
| 4146 |
+
$end = strpos($this->buffer, "\n", $this->count);
|
| 4147 |
+
if ($end === false || $this->buffer[$end - 1] == '\\' || $this->buffer[$end - 2] == '\\' && $this->buffer[$end - 1] == "\r") {
|
| 4148 |
+
$end = strlen($this->buffer);
|
| 4149 |
+
}
|
| 4150 |
+
|
| 4151 |
+
// look for either ending delim, escape, or string interpolation
|
| 4152 |
+
foreach (array('#{', '\\', $delim) as $lookahead) {
|
| 4153 |
+
$pos = strpos($this->buffer, $lookahead, $this->count);
|
| 4154 |
+
if ($pos !== false && $pos < $end) {
|
| 4155 |
+
$end = $pos;
|
| 4156 |
+
$token = $lookahead;
|
| 4157 |
+
}
|
| 4158 |
+
}
|
| 4159 |
+
|
| 4160 |
+
if (!isset($token)) {
|
| 4161 |
+
return false;
|
| 4162 |
+
}
|
| 4163 |
+
|
| 4164 |
+
$match = substr($this->buffer, $this->count, $end - $this->count);
|
| 4165 |
+
$m = array(
|
| 4166 |
+
$match . $token,
|
| 4167 |
+
$match,
|
| 4168 |
+
$token
|
| 4169 |
+
);
|
| 4170 |
+
$this->count = $end + strlen($token);
|
| 4171 |
+
|
| 4172 |
+
return true;
|
| 4173 |
+
}
|
| 4174 |
+
|
| 4175 |
+
// try to match something on head of buffer
|
| 4176 |
+
protected function match($regex, &$out, $eatWhitespace = null) {
|
| 4177 |
+
if (!isset($eatWhitespace)) $eatWhitespace = $this->eatWhiteDefault;
|
| 4178 |
+
|
| 4179 |
+
$r = '/'.$regex.'/Ais';
|
| 4180 |
+
if (preg_match($r, $this->buffer, $out, null, $this->count)) {
|
| 4181 |
+
$this->count += strlen($out[0]);
|
| 4182 |
+
if ($eatWhitespace) {
|
| 4183 |
+
$this->whitespace();
|
| 4184 |
+
}
|
| 4185 |
+
return true;
|
| 4186 |
+
}
|
| 4187 |
+
return false;
|
| 4188 |
+
}
|
| 4189 |
+
|
| 4190 |
+
// match some whitespace
|
| 4191 |
+
protected function whitespace() {
|
| 4192 |
+
$gotWhite = false;
|
| 4193 |
+
while (preg_match(self::$whitePattern, $this->buffer, $m, null, $this->count)) {
|
| 4194 |
+
if (isset($m[1]) && empty($this->commentsSeen[$this->count])) {
|
| 4195 |
+
$this->appendComment(array('comment', $m[1]));
|
| 4196 |
+
$this->commentsSeen[$this->count] = true;
|
| 4197 |
+
}
|
| 4198 |
+
$this->count += strlen($m[0]);
|
| 4199 |
+
$gotWhite = true;
|
| 4200 |
+
}
|
| 4201 |
+
return $gotWhite;
|
| 4202 |
+
}
|
| 4203 |
+
|
| 4204 |
+
protected function peek($regex, &$out, $from=null) {
|
| 4205 |
+
if (!isset($from)) $from = $this->count;
|
| 4206 |
+
|
| 4207 |
+
$r = '/'.$regex.'/Ais';
|
| 4208 |
+
$result = preg_match($r, $this->buffer, $out, null, $from);
|
| 4209 |
+
|
| 4210 |
+
return $result;
|
| 4211 |
+
}
|
| 4212 |
+
|
| 4213 |
+
protected function seek($where = null) {
|
| 4214 |
+
if ($where === null) return $this->count;
|
| 4215 |
+
else $this->count = $where;
|
| 4216 |
+
return true;
|
| 4217 |
+
}
|
| 4218 |
+
|
| 4219 |
+
static function preg_quote($what) {
|
| 4220 |
+
return preg_quote($what, '/');
|
| 4221 |
+
}
|
| 4222 |
+
|
| 4223 |
+
protected function show() {
|
| 4224 |
+
if ($this->peek("(.*?)(\n|$)", $m, $this->count)) {
|
| 4225 |
+
return $m[1];
|
| 4226 |
+
}
|
| 4227 |
+
return '';
|
| 4228 |
+
}
|
| 4229 |
+
|
| 4230 |
+
// turn list of length 1 into value type
|
| 4231 |
+
protected function flattenList($value) {
|
| 4232 |
+
if ($value[0] == 'list' && count($value[2]) == 1) {
|
| 4233 |
+
return $this->flattenList($value[2][0]);
|
| 4234 |
+
}
|
| 4235 |
+
return $value;
|
| 4236 |
+
}
|
| 4237 |
+
}
|
| 4238 |
+
|
| 4239 |
+
/**
|
| 4240 |
+
* SCSS base formatter
|
| 4241 |
+
*
|
| 4242 |
+
* @author Leaf Corcoran <leafot@gmail.com>
|
| 4243 |
+
*/
|
| 4244 |
+
class scss_formatter {
|
| 4245 |
+
public $indentChar = ' ';
|
| 4246 |
+
|
| 4247 |
+
public $break = "\n";
|
| 4248 |
+
public $open = ' {';
|
| 4249 |
+
public $close = '}';
|
| 4250 |
+
public $tagSeparator = ', ';
|
| 4251 |
+
public $assignSeparator = ': ';
|
| 4252 |
+
|
| 4253 |
+
public function __construct() {
|
| 4254 |
+
$this->indentLevel = 0;
|
| 4255 |
+
}
|
| 4256 |
+
|
| 4257 |
+
public function indentStr($n = 0) {
|
| 4258 |
+
return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
|
| 4259 |
+
}
|
| 4260 |
+
|
| 4261 |
+
public function property($name, $value) {
|
| 4262 |
+
return $name . $this->assignSeparator . $value . ';';
|
| 4263 |
+
}
|
| 4264 |
+
|
| 4265 |
+
protected function blockLines($inner, $block)
|
| 4266 |
+
{
|
| 4267 |
+
$glue = $this->break.$inner;
|
| 4268 |
+
echo $inner . implode($glue, $block->lines);
|
| 4269 |
+
|
| 4270 |
+
if (!empty($block->children)) {
|
| 4271 |
+
echo $this->break;
|
| 4272 |
+
}
|
| 4273 |
+
}
|
| 4274 |
+
|
| 4275 |
+
protected function block($block) {
|
| 4276 |
+
if (empty($block->lines) && empty($block->children)) return;
|
| 4277 |
+
|
| 4278 |
+
$inner = $pre = $this->indentStr();
|
| 4279 |
+
|
| 4280 |
+
if (!empty($block->selectors)) {
|
| 4281 |
+
echo $pre .
|
| 4282 |
+
implode($this->tagSeparator, $block->selectors) .
|
| 4283 |
+
$this->open . $this->break;
|
| 4284 |
+
$this->indentLevel++;
|
| 4285 |
+
$inner = $this->indentStr();
|
| 4286 |
+
}
|
| 4287 |
+
|
| 4288 |
+
if (!empty($block->lines)) {
|
| 4289 |
+
$this->blockLines($inner, $block);
|
| 4290 |
+
}
|
| 4291 |
+
|
| 4292 |
+
foreach ($block->children as $child) {
|
| 4293 |
+
$this->block($child);
|
| 4294 |
+
}
|
| 4295 |
+
|
| 4296 |
+
if (!empty($block->selectors)) {
|
| 4297 |
+
$this->indentLevel--;
|
| 4298 |
+
if (empty($block->children)) echo $this->break;
|
| 4299 |
+
echo $pre . $this->close . $this->break;
|
| 4300 |
+
}
|
| 4301 |
+
}
|
| 4302 |
+
|
| 4303 |
+
public function format($block) {
|
| 4304 |
+
ob_start();
|
| 4305 |
+
$this->block($block);
|
| 4306 |
+
$out = ob_get_clean();
|
| 4307 |
+
|
| 4308 |
+
return $out;
|
| 4309 |
+
}
|
| 4310 |
+
}
|
| 4311 |
+
|
| 4312 |
+
/**
|
| 4313 |
+
* SCSS nested formatter
|
| 4314 |
+
*
|
| 4315 |
+
* @author Leaf Corcoran <leafot@gmail.com>
|
| 4316 |
+
*/
|
| 4317 |
+
class scss_formatter_nested extends scss_formatter {
|
| 4318 |
+
public $close = ' }';
|
| 4319 |
+
|
| 4320 |
+
// adjust the depths of all children, depth first
|
| 4321 |
+
public function adjustAllChildren($block) {
|
| 4322 |
+
// flatten empty nested blocks
|
| 4323 |
+
$children = array();
|
| 4324 |
+
foreach ($block->children as $i => $child) {
|
| 4325 |
+
if (empty($child->lines) && empty($child->children)) {
|
| 4326 |
+
if (isset($block->children[$i + 1])) {
|
| 4327 |
+
$block->children[$i + 1]->depth = $child->depth;
|
| 4328 |
+
}
|
| 4329 |
+
continue;
|
| 4330 |
+
}
|
| 4331 |
+
$children[] = $child;
|
| 4332 |
+
}
|
| 4333 |
+
|
| 4334 |
+
$count = count($children);
|
| 4335 |
+
for ($i = 0; $i < $count; $i++) {
|
| 4336 |
+
$depth = $children[$i]->depth;
|
| 4337 |
+
$j = $i + 1;
|
| 4338 |
+
if (isset($children[$j]) && $depth < $children[$j]->depth) {
|
| 4339 |
+
$childDepth = $children[$j]->depth;
|
| 4340 |
+
for (; $j < $count; $j++) {
|
| 4341 |
+
if ($depth < $children[$j]->depth && $childDepth >= $children[$j]->depth) {
|
| 4342 |
+
$children[$j]->depth = $depth + 1;
|
| 4343 |
+
}
|
| 4344 |
+
}
|
| 4345 |
+
}
|
| 4346 |
+
}
|
| 4347 |
+
|
| 4348 |
+
$block->children = $children;
|
| 4349 |
+
|
| 4350 |
+
// make relative to parent
|
| 4351 |
+
foreach ($block->children as $child) {
|
| 4352 |
+
$this->adjustAllChildren($child);
|
| 4353 |
+
$child->depth = $child->depth - $block->depth;
|
| 4354 |
+
}
|
| 4355 |
+
}
|
| 4356 |
+
|
| 4357 |
+
protected function blockLines($inner, $block)
|
| 4358 |
+
{
|
| 4359 |
+
$glue = $this->break . $inner;
|
| 4360 |
+
|
| 4361 |
+
foreach ($block->lines as $index => $line) {
|
| 4362 |
+
if (substr($line, 0, 2) === '/*') {
|
| 4363 |
+
$block->lines[$index] = preg_replace('/(\r|\n)+/', $glue, $line);
|
| 4364 |
+
}
|
| 4365 |
+
}
|
| 4366 |
+
|
| 4367 |
+
echo $inner . implode($glue, $block->lines);
|
| 4368 |
+
|
| 4369 |
+
if (!empty($block->children)) {
|
| 4370 |
+
echo $this->break;
|
| 4371 |
+
}
|
| 4372 |
+
}
|
| 4373 |
+
|
| 4374 |
+
protected function block($block) {
|
| 4375 |
+
if ($block->type == 'root') {
|
| 4376 |
+
$this->adjustAllChildren($block);
|
| 4377 |
+
}
|
| 4378 |
+
|
| 4379 |
+
$inner = $pre = $this->indentStr($block->depth - 1);
|
| 4380 |
+
if (!empty($block->selectors)) {
|
| 4381 |
+
echo $pre .
|
| 4382 |
+
implode($this->tagSeparator, $block->selectors) .
|
| 4383 |
+
$this->open . $this->break;
|
| 4384 |
+
$this->indentLevel++;
|
| 4385 |
+
$inner = $this->indentStr($block->depth - 1);
|
| 4386 |
+
}
|
| 4387 |
+
|
| 4388 |
+
if (!empty($block->lines)) {
|
| 4389 |
+
$this->blockLines($inner, $block);
|
| 4390 |
+
}
|
| 4391 |
+
|
| 4392 |
+
foreach ($block->children as $i => $child) {
|
| 4393 |
+
// echo "*** block: ".$block->depth." child: ".$child->depth."\n";
|
| 4394 |
+
$this->block($child);
|
| 4395 |
+
if ($i < count($block->children) - 1) {
|
| 4396 |
+
echo $this->break;
|
| 4397 |
+
|
| 4398 |
+
if (isset($block->children[$i + 1])) {
|
| 4399 |
+
$next = $block->children[$i + 1];
|
| 4400 |
+
if ($next->depth == max($block->depth, 1) && $child->depth >= $next->depth) {
|
| 4401 |
+
echo $this->break;
|
| 4402 |
+
}
|
| 4403 |
+
}
|
| 4404 |
+
}
|
| 4405 |
+
}
|
| 4406 |
+
|
| 4407 |
+
if (!empty($block->selectors)) {
|
| 4408 |
+
$this->indentLevel--;
|
| 4409 |
+
echo $this->close;
|
| 4410 |
+
}
|
| 4411 |
+
|
| 4412 |
+
if ($block->type == 'root') {
|
| 4413 |
+
echo $this->break;
|
| 4414 |
+
}
|
| 4415 |
+
}
|
| 4416 |
+
}
|
| 4417 |
+
|
| 4418 |
+
/**
|
| 4419 |
+
* SCSS compressed formatter
|
| 4420 |
+
*
|
| 4421 |
+
* @author Leaf Corcoran <leafot@gmail.com>
|
| 4422 |
+
*/
|
| 4423 |
+
class scss_formatter_compressed extends scss_formatter {
|
| 4424 |
+
public $open = '{';
|
| 4425 |
+
public $tagSeparator = ',';
|
| 4426 |
+
public $assignSeparator = ':';
|
| 4427 |
+
public $break = '';
|
| 4428 |
+
|
| 4429 |
+
public function indentStr($n = 0) {
|
| 4430 |
+
return '';
|
| 4431 |
+
}
|
| 4432 |
+
|
| 4433 |
+
public function blockLines($inner, $block)
|
| 4434 |
+
{
|
| 4435 |
+
$glue = $this->break.$inner;
|
| 4436 |
+
|
| 4437 |
+
foreach ($block->lines as $index => $line) {
|
| 4438 |
+
if (substr($line, 0, 2) === '/*' && substr($line, 2, 1) !== '!') {
|
| 4439 |
+
unset($block->lines[$index]);
|
| 4440 |
+
} elseif (substr($line, 0, 3) === '/*!') {
|
| 4441 |
+
$block->lines[$index] = '/*' . substr($line, 3);
|
| 4442 |
+
}
|
| 4443 |
+
}
|
| 4444 |
+
|
| 4445 |
+
echo $inner . implode($glue, $block->lines);
|
| 4446 |
+
|
| 4447 |
+
if (!empty($block->children)) {
|
| 4448 |
+
echo $this->break;
|
| 4449 |
+
}
|
| 4450 |
+
}
|
| 4451 |
+
}
|
| 4452 |
+
|
| 4453 |
+
/**
|
| 4454 |
+
* SCSS crunched formatter
|
| 4455 |
+
*
|
| 4456 |
+
* @author Anthon Pang <anthon.pang@gmail.com>
|
| 4457 |
+
*/
|
| 4458 |
+
class scss_formatter_crunched extends scss_formatter {
|
| 4459 |
+
public $open = '{';
|
| 4460 |
+
public $tagSeparator = ',';
|
| 4461 |
+
public $assignSeparator = ':';
|
| 4462 |
+
public $break = '';
|
| 4463 |
+
|
| 4464 |
+
public function indentStr($n = 0) {
|
| 4465 |
+
return '';
|
| 4466 |
+
}
|
| 4467 |
+
|
| 4468 |
+
public function blockLines($inner, $block)
|
| 4469 |
+
{
|
| 4470 |
+
$glue = $this->break.$inner;
|
| 4471 |
+
|
| 4472 |
+
foreach ($block->lines as $index => $line) {
|
| 4473 |
+
if (substr($line, 0, 2) === '/*') {
|
| 4474 |
+
unset($block->lines[$index]);
|
| 4475 |
+
}
|
| 4476 |
+
}
|
| 4477 |
+
|
| 4478 |
+
echo $inner . implode($glue, $block->lines);
|
| 4479 |
+
|
| 4480 |
+
if (!empty($block->children)) {
|
| 4481 |
+
echo $this->break;
|
| 4482 |
+
}
|
| 4483 |
+
}
|
| 4484 |
+
}
|
| 4485 |
+
|
| 4486 |
+
/**
|
| 4487 |
+
* SCSS server
|
| 4488 |
+
*
|
| 4489 |
+
* @author Leaf Corcoran <leafot@gmail.com>
|
| 4490 |
+
*/
|
| 4491 |
+
class scss_server {
|
| 4492 |
+
/**
|
| 4493 |
+
* Join path components
|
| 4494 |
+
*
|
| 4495 |
+
* @param string $left Path component, left of the directory separator
|
| 4496 |
+
* @param string $right Path component, right of the directory separator
|
| 4497 |
+
*
|
| 4498 |
+
* @return string
|
| 4499 |
+
*/
|
| 4500 |
+
protected function join($left, $right) {
|
| 4501 |
+
return rtrim($left, '/\\') . DIRECTORY_SEPARATOR . ltrim($right, '/\\');
|
| 4502 |
+
}
|
| 4503 |
+
|
| 4504 |
+
/**
|
| 4505 |
+
* Get name of requested .scss file
|
| 4506 |
+
*
|
| 4507 |
+
* @return string|null
|
| 4508 |
+
*/
|
| 4509 |
+
protected function inputName() {
|
| 4510 |
+
switch (true) {
|
| 4511 |
+
case isset($_GET['p']):
|
| 4512 |
+
return $_GET['p'];
|
| 4513 |
+
case isset($_SERVER['PATH_INFO']):
|
| 4514 |
+
return $_SERVER['PATH_INFO'];
|
| 4515 |
+
case isset($_SERVER['DOCUMENT_URI']):
|
| 4516 |
+
return substr($_SERVER['DOCUMENT_URI'], strlen($_SERVER['SCRIPT_NAME']));
|
| 4517 |
+
}
|
| 4518 |
+
}
|
| 4519 |
+
|
| 4520 |
+
/**
|
| 4521 |
+
* Get path to requested .scss file
|
| 4522 |
+
*
|
| 4523 |
+
* @return string
|
| 4524 |
+
*/
|
| 4525 |
+
protected function findInput() {
|
| 4526 |
+
if (($input = $this->inputName())
|
| 4527 |
+
&& strpos($input, '..') === false
|
| 4528 |
+
&& substr($input, -5) === '.scss'
|
| 4529 |
+
) {
|
| 4530 |
+
$name = $this->join($this->dir, $input);
|
| 4531 |
+
|
| 4532 |
+
if (is_file($name) && is_readable($name)) {
|
| 4533 |
+
return $name;
|
| 4534 |
+
}
|
| 4535 |
+
}
|
| 4536 |
+
|
| 4537 |
+
return false;
|
| 4538 |
+
}
|
| 4539 |
+
|
| 4540 |
+
/**
|
| 4541 |
+
* Get path to cached .css file
|
| 4542 |
+
*
|
| 4543 |
+
* @return string
|
| 4544 |
+
*/
|
| 4545 |
+
protected function cacheName($fname) {
|
| 4546 |
+
return $this->join($this->cacheDir, md5($fname) . '.css');
|
| 4547 |
+
}
|
| 4548 |
+
|
| 4549 |
+
/**
|
| 4550 |
+
* Get path to meta data
|
| 4551 |
+
*
|
| 4552 |
+
* @return string
|
| 4553 |
+
*/
|
| 4554 |
+
protected function metadataName($out) {
|
| 4555 |
+
return $out . '.meta';
|
| 4556 |
+
}
|
| 4557 |
+
|
| 4558 |
+
/**
|
| 4559 |
+
* Determine whether .scss file needs to be re-compiled.
|
| 4560 |
+
*
|
| 4561 |
+
* @param string $in Input path
|
| 4562 |
+
* @param string $out Output path
|
| 4563 |
+
* @param string $etag ETag
|
| 4564 |
+
*
|
| 4565 |
+
* @return boolean True if compile required.
|
| 4566 |
+
*/
|
| 4567 |
+
protected function needsCompile($in, $out, &$etag) {
|
| 4568 |
+
if ( ! is_file($out)) {
|
| 4569 |
+
return true;
|
| 4570 |
+
}
|
| 4571 |
+
|
| 4572 |
+
$mtime = filemtime($out);
|
| 4573 |
+
|
| 4574 |
+
if (filemtime($in) > $mtime) {
|
| 4575 |
+
return true;
|
| 4576 |
+
}
|
| 4577 |
+
|
| 4578 |
+
$metadataName = $this->metadataName($out);
|
| 4579 |
+
|
| 4580 |
+
if (is_readable($metadataName)) {
|
| 4581 |
+
$metadata = unserialize(file_get_contents($metadataName));
|
| 4582 |
+
|
| 4583 |
+
if ($metadata['etag'] === $etag) {
|
| 4584 |
+
return false;
|
| 4585 |
+
}
|
| 4586 |
+
|
| 4587 |
+
foreach ($metadata['imports'] as $import) {
|
| 4588 |
+
if (filemtime($import) > $mtime) {
|
| 4589 |
+
return true;
|
| 4590 |
+
}
|
| 4591 |
+
}
|
| 4592 |
+
|
| 4593 |
+
$etag = $metadata['etag'];
|
| 4594 |
+
|
| 4595 |
+
return false;
|
| 4596 |
+
}
|
| 4597 |
+
|
| 4598 |
+
return true;
|
| 4599 |
+
}
|
| 4600 |
+
|
| 4601 |
+
/**
|
| 4602 |
+
* Get If-Modified-Since header from client request
|
| 4603 |
+
*
|
| 4604 |
+
* @return string|null
|
| 4605 |
+
*/
|
| 4606 |
+
protected function getIfModifiedSinceHeader()
|
| 4607 |
+
{
|
| 4608 |
+
$modifiedSince = null;
|
| 4609 |
+
|
| 4610 |
+
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
|
| 4611 |
+
$modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
|
| 4612 |
+
|
| 4613 |
+
if (false !== ($semicolonPos = strpos($modifiedSince, ';'))) {
|
| 4614 |
+
$modifiedSince = substr($modifiedSince, 0, $semicolonPos);
|
| 4615 |
+
}
|
| 4616 |
+
}
|
| 4617 |
+
|
| 4618 |
+
return $modifiedSince;
|
| 4619 |
+
}
|
| 4620 |
+
|
| 4621 |
+
/**
|
| 4622 |
+
* Get If-None-Match header from client request
|
| 4623 |
+
*
|
| 4624 |
+
* @return string|null
|
| 4625 |
+
*/
|
| 4626 |
+
protected function getIfNoneMatchHeader()
|
| 4627 |
+
{
|
| 4628 |
+
$noneMatch = null;
|
| 4629 |
+
|
| 4630 |
+
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
| 4631 |
+
$noneMatch = $_SERVER['HTTP_IF_NONE_MATCH'];
|
| 4632 |
+
}
|
| 4633 |
+
|
| 4634 |
+
return $noneMatch;
|
| 4635 |
+
}
|
| 4636 |
+
|
| 4637 |
+
/**
|
| 4638 |
+
* Compile .scss file
|
| 4639 |
+
*
|
| 4640 |
+
* @param string $in Input path (.scss)
|
| 4641 |
+
* @param string $out Output path (.css)
|
| 4642 |
+
*
|
| 4643 |
+
* @return array
|
| 4644 |
+
*/
|
| 4645 |
+
protected function compile($in, $out)
|
| 4646 |
+
{
|
| 4647 |
+
$start = microtime(true);
|
| 4648 |
+
$css = $this->scss->compile(file_get_contents($in), $in);
|
| 4649 |
+
$elapsed = round((microtime(true) - $start), 4);
|
| 4650 |
+
|
| 4651 |
+
$v = scssc::$VERSION;
|
| 4652 |
+
$t = @date('r');
|
| 4653 |
+
$css = "/* compiled by scssphp $v on $t (${elapsed}s) */\n\n" . $css;
|
| 4654 |
+
$etag = md5($css);
|
| 4655 |
+
|
| 4656 |
+
file_put_contents($out, $css);
|
| 4657 |
+
file_put_contents(
|
| 4658 |
+
$this->metadataName($out),
|
| 4659 |
+
serialize(array(
|
| 4660 |
+
'etag' => $etag,
|
| 4661 |
+
'imports' => $this->scss->getParsedFiles(),
|
| 4662 |
+
))
|
| 4663 |
+
);
|
| 4664 |
+
|
| 4665 |
+
return array($css, $etag);
|
| 4666 |
+
}
|
| 4667 |
+
|
| 4668 |
+
/**
|
| 4669 |
+
* Compile requested scss and serve css. Outputs HTTP response.
|
| 4670 |
+
*
|
| 4671 |
+
* @param string $salt Prefix a string to the filename for creating the cache name hash
|
| 4672 |
+
*/
|
| 4673 |
+
public function serve($salt = '') {
|
| 4674 |
+
$protocol = isset($_SERVER['SERVER_PROTOCOL'])
|
| 4675 |
+
? $_SERVER['SERVER_PROTOCOL']
|
| 4676 |
+
: 'HTTP/1.0';
|
| 4677 |
+
|
| 4678 |
+
if ($input = $this->findInput()) {
|
| 4679 |
+
$output = $this->cacheName($salt . $input);
|
| 4680 |
+
$etag = $noneMatch = trim($this->getIfNoneMatchHeader(), '"');
|
| 4681 |
+
|
| 4682 |
+
if ($this->needsCompile($input, $output, $etag)) {
|
| 4683 |
+
try {
|
| 4684 |
+
list($css, $etag) = $this->compile($input, $output);
|
| 4685 |
+
|
| 4686 |
+
$lastModified = gmdate('D, d M Y H:i:s', filemtime($output)) . ' GMT';
|
| 4687 |
+
|
| 4688 |
+
header('Last-Modified: ' . $lastModified);
|
| 4689 |
+
header('Content-type: text/css');
|
| 4690 |
+
header('ETag: "' . $etag . '"');
|
| 4691 |
+
|
| 4692 |
+
echo $css;
|
| 4693 |
+
|
| 4694 |
+
return;
|
| 4695 |
+
} catch (Exception $e) {
|
| 4696 |
+
header($protocol . ' 500 Internal Server Error');
|
| 4697 |
+
header('Content-type: text/plain');
|
| 4698 |
+
|
| 4699 |
+
echo 'Parse error: ' . $e->getMessage() . "\n";
|
| 4700 |
+
}
|
| 4701 |
+
}
|
| 4702 |
+
|
| 4703 |
+
header('X-SCSS-Cache: true');
|
| 4704 |
+
header('Content-type: text/css');
|
| 4705 |
+
header('ETag: "' . $etag . '"');
|
| 4706 |
+
|
| 4707 |
+
if ($etag === $noneMatch) {
|
| 4708 |
+
header($protocol . ' 304 Not Modified');
|
| 4709 |
+
|
| 4710 |
+
return;
|
| 4711 |
+
}
|
| 4712 |
+
|
| 4713 |
+
$modifiedSince = $this->getIfModifiedSinceHeader();
|
| 4714 |
+
$mtime = filemtime($output);
|
| 4715 |
+
|
| 4716 |
+
if (@strtotime($modifiedSince) === $mtime) {
|
| 4717 |
+
header($protocol . ' 304 Not Modified');
|
| 4718 |
+
|
| 4719 |
+
return;
|
| 4720 |
+
}
|
| 4721 |
+
|
| 4722 |
+
$lastModified = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
|
| 4723 |
+
header('Last-Modified: ' . $lastModified);
|
| 4724 |
+
|
| 4725 |
+
echo file_get_contents($output);
|
| 4726 |
+
|
| 4727 |
+
return;
|
| 4728 |
+
}
|
| 4729 |
+
|
| 4730 |
+
header($protocol . ' 404 Not Found');
|
| 4731 |
+
header('Content-type: text/plain');
|
| 4732 |
+
|
| 4733 |
+
$v = scssc::$VERSION;
|
| 4734 |
+
echo "/* INPUT NOT FOUND scss $v */\n";
|
| 4735 |
+
}
|
| 4736 |
+
|
| 4737 |
+
/**
|
| 4738 |
+
* Constructor
|
| 4739 |
+
*
|
| 4740 |
+
* @param string $dir Root directory to .scss files
|
| 4741 |
+
* @param string $cacheDir Cache directory
|
| 4742 |
+
* @param \scssc|null $scss SCSS compiler instance
|
| 4743 |
+
*/
|
| 4744 |
+
public function __construct($dir, $cacheDir=null, $scss=null) {
|
| 4745 |
+
$this->dir = $dir;
|
| 4746 |
+
|
| 4747 |
+
if (!isset($cacheDir)) {
|
| 4748 |
+
$cacheDir = $this->join($dir, 'scss_cache');
|
| 4749 |
+
}
|
| 4750 |
+
|
| 4751 |
+
$this->cacheDir = $cacheDir;
|
| 4752 |
+
if (!is_dir($this->cacheDir)) mkdir($this->cacheDir, 0755, true);
|
| 4753 |
+
|
| 4754 |
+
if (!isset($scss)) {
|
| 4755 |
+
$scss = new scssc();
|
| 4756 |
+
$scss->setImportPaths($this->dir);
|
| 4757 |
+
}
|
| 4758 |
+
$this->scss = $scss;
|
| 4759 |
+
}
|
| 4760 |
+
|
| 4761 |
+
/**
|
| 4762 |
+
* Helper method to serve compiled scss
|
| 4763 |
+
*
|
| 4764 |
+
* @param string $path Root path
|
| 4765 |
+
*/
|
| 4766 |
+
static public function serveFrom($path) {
|
| 4767 |
+
$server = new self($path);
|
| 4768 |
+
$server->serve();
|
| 4769 |
+
}
|
| 4770 |
+
}
|
includes/views/scss.php
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
| 9 |
+
$primarytext: <?php echo wc_light_or_dark( $colors['primary'], 'desaturate(darken($primary,50%),18%)', 'desaturate(lighten($primary,50%),18%)' ) ?>;
|
| 10 |
+
$secondary: <?php echo $colors['secondary']; ?>;
|
| 11 |
+
$secondarytext: <?php echo wc_light_or_dark( $colors['secondary'], 'desaturate(darken($secondary,60%),18%)', 'desaturate(lighten($secondary,60%),18%)' ); ?>;
|
| 12 |
+
$highlight: <?php echo $colors['highlight']; ?>;
|
| 13 |
+
$highlightext: <?php echo wc_light_or_dark( $colors['highlight'], 'desaturate(darken($highlight,60%),18%)', 'desaturate(lighten($highlight,60%),18%)' ) ?>;
|
| 14 |
+
$contentbg: <?php echo $colors['content_bg']; ?>;
|
| 15 |
+
$subtext: <?php echo $colors['subtext']; ?>;
|
| 16 |
+
|
| 17 |
+
p.demo_store {
|
| 18 |
+
background-color: $primary;
|
| 19 |
+
color: $primarytext;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.woocommerce {
|
| 23 |
+
|
| 24 |
+
.woocommerce-message,
|
| 25 |
+
.woocommerce-error,
|
| 26 |
+
.woocommerce-info {
|
| 27 |
+
background-color: lighten($secondary,5%);
|
| 28 |
+
color: $secondarytext;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
small.note {
|
| 32 |
+
color: $subtext;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.woocommerce-breadcrumb{
|
| 36 |
+
color: $subtext;
|
| 37 |
+
|
| 38 |
+
a {
|
| 39 |
+
color: $subtext;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
div.product {
|
| 44 |
+
span.price,
|
| 45 |
+
p.price {
|
| 46 |
+
color: $highlight;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.stock {
|
| 50 |
+
color: $highlight;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.woocommerce-tabs {
|
| 54 |
+
ul.tabs {
|
| 55 |
+
li {
|
| 56 |
+
border: 1px solid darken( $secondary, 10% );
|
| 57 |
+
background-color: $secondary;
|
| 58 |
+
|
| 59 |
+
a {
|
| 60 |
+
color: $secondarytext;
|
| 61 |
+
|
| 62 |
+
&:hover {
|
| 63 |
+
color: lighten( $secondarytext, 10% );
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
&.active {
|
| 68 |
+
background: $contentbg;
|
| 69 |
+
border-bottom-color: $contentbg;
|
| 70 |
+
|
| 71 |
+
&:before {
|
| 72 |
+
box-shadow: 2px 2px 0 $contentbg;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
&:after {
|
| 76 |
+
box-shadow: -2px 2px 0 $contentbg;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
&:before,
|
| 81 |
+
&:after {
|
| 82 |
+
border: 1px solid darken( $secondary, 10% );
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
&:before {
|
| 86 |
+
box-shadow: 2px 2px 0 $secondary;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
&:after {
|
| 90 |
+
box-shadow: -2px 2px 0 $secondary;
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
&:before {
|
| 95 |
+
border-bottom: 1px solid darken( $secondary, 10% );
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
span.onsale {
|
| 102 |
+
background-color: $highlight;
|
| 103 |
+
color: $highlightext;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
ul.products {
|
| 107 |
+
li.product {
|
| 108 |
+
.price {
|
| 109 |
+
color: $highlight;
|
| 110 |
+
|
| 111 |
+
.from {
|
| 112 |
+
color: rgba(desaturate($highlight, 75%), 0.5);
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
nav.woocommerce-pagination {
|
| 119 |
+
ul {
|
| 120 |
+
border: 1px solid darken( $secondary, 10% );
|
| 121 |
+
|
| 122 |
+
li {
|
| 123 |
+
border-right: 1px solid darken( $secondary, 10% );
|
| 124 |
+
|
| 125 |
+
span.current,
|
| 126 |
+
a:hover,
|
| 127 |
+
a:focus {
|
| 128 |
+
background: $secondary;
|
| 129 |
+
color: darken( $secondary, 40% );
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
a.button,
|
| 136 |
+
button.button,
|
| 137 |
+
input.button,
|
| 138 |
+
#respond input#submit {
|
| 139 |
+
color: $secondarytext;
|
| 140 |
+
background-color: $secondary;
|
| 141 |
+
|
| 142 |
+
&:hover {
|
| 143 |
+
background-color: $secondary - #111;
|
| 144 |
+
color: $secondarytext;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
&.alt {
|
| 148 |
+
background-color: $primary;
|
| 149 |
+
color: $primarytext;
|
| 150 |
+
|
| 151 |
+
&:hover {
|
| 152 |
+
background-color: $primary - #111;
|
| 153 |
+
color: $primarytext;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
&.disabled,
|
| 157 |
+
&:disabled,
|
| 158 |
+
&:disabled[disabled],
|
| 159 |
+
&.disabled:hover,
|
| 160 |
+
&:disabled:hover,
|
| 161 |
+
&:disabled[disabled]:hover {
|
| 162 |
+
background-color: $primary;
|
| 163 |
+
color: $primarytext;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
&:disabled,
|
| 168 |
+
&.disabled,
|
| 169 |
+
&:disabled[disabled] {
|
| 170 |
+
&:hover {
|
| 171 |
+
background-color: $secondary;
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
#reviews {
|
| 177 |
+
h2 small {
|
| 178 |
+
color: $subtext;
|
| 179 |
+
|
| 180 |
+
a {
|
| 181 |
+
color: $subtext;
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
#comments {
|
| 186 |
+
ol.commentlist {
|
| 187 |
+
li {
|
| 188 |
+
.meta {
|
| 189 |
+
color: $subtext;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
img.avatar {
|
| 193 |
+
background: $secondary;
|
| 194 |
+
border: 1px solid darken( $secondary, 3% );
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.comment-text {
|
| 198 |
+
border: 1px solid darken( $secondary, 3% );
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
#respond {
|
| 203 |
+
border: 1px solid darken( $secondary, 3% );
|
| 204 |
+
}
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.star-rating {
|
| 210 |
+
&:before {
|
| 211 |
+
color: darken( $secondary, 10% );
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
&.widget_shopping_cart,
|
| 216 |
+
.widget_shopping_cart {
|
| 217 |
+
.total {
|
| 218 |
+
border-top: 3px double $secondary;
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
form.login,
|
| 223 |
+
form.checkout_coupon,
|
| 224 |
+
form.register {
|
| 225 |
+
border: 1px solid darken( $secondary, 10% );
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.order_details {
|
| 229 |
+
li {
|
| 230 |
+
border-right: 1px dashed darken( $secondary, 10% );
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
.widget_price_filter {
|
| 235 |
+
.ui-slider .ui-slider-handle {
|
| 236 |
+
background-color: $primary;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
.ui-slider .ui-slider-range {
|
| 240 |
+
background-color: $primary;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
.price_slider_wrapper .ui-widget-content {
|
| 244 |
+
background-color: $primary - #444;
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
.woocommerce-cart {
|
| 250 |
+
table.cart {
|
| 251 |
+
td.actions {
|
| 252 |
+
.coupon {
|
| 253 |
+
.input-text {
|
| 254 |
+
border: 1px solid darken( $secondary, 10% );
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
.cart-collaterals {
|
| 261 |
+
.cart_totals {
|
| 262 |
+
p {
|
| 263 |
+
small {
|
| 264 |
+
color: $subtext;
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
table {
|
| 269 |
+
small {
|
| 270 |
+
color: $subtext;
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
.discount td {
|
| 275 |
+
color: $highlight;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
tr td,
|
| 279 |
+
tr th {
|
| 280 |
+
border-top: 1px solid $secondary;
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
.woocommerce-checkout {
|
| 287 |
+
.checkout {
|
| 288 |
+
.create-account small {
|
| 289 |
+
color: $subtext;
|
| 290 |
+
}
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
#payment {
|
| 294 |
+
background: $secondary;
|
| 295 |
+
|
| 296 |
+
ul.payment_methods {
|
| 297 |
+
border-bottom: 1px solid darken( $secondary, 10% );
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
div.payment_box {
|
| 301 |
+
background-color: darken( $secondary, 5% );
|
| 302 |
+
color: $secondarytext;
|
| 303 |
+
|
| 304 |
+
input.input-text, textarea {
|
| 305 |
+
border-color: darken( $secondary, 15% );
|
| 306 |
+
border-top-color: darken( $secondary, 20% );
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
::-webkit-input-placeholder {
|
| 310 |
+
color: darken( $secondary, 20% );
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
:-moz-placeholder {
|
| 314 |
+
color: darken( $secondary, 20% );
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
:-ms-input-placeholder {
|
| 318 |
+
color: darken( $secondary, 20% );
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
span.help {
|
| 322 |
+
color: $subtext;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
&:after {
|
| 326 |
+
border: 8px solid darken( $secondary, 5% );
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
}
|
languages/woocommerce-colors.pot
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (C) 2014 WooThemes
|
| 2 |
+
# This file is distributed under the GPLv2 or later.
|
| 3 |
+
msgid ""
|
| 4 |
+
msgstr ""
|
| 5 |
+
"Project-Id-Version: WooCommerce Colors 1.0.0\n"
|
| 6 |
+
"Report-Msgid-Bugs-To: "
|
| 7 |
+
"http://wordpress.org/support/plugin/woocommerce-frontend-styles/\n"
|
| 8 |
+
"POT-Creation-Date: 2014-12-15 16:45:45+00:00\n"
|
| 9 |
+
"MIME-Version: 1.0\n"
|
| 10 |
+
"Content-Type: text/plain; charset=utf-8\n"
|
| 11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
| 12 |
+
"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
|
| 13 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
| 14 |
+
"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
|
| 15 |
+
"X-Generator: grunt-wp-i18n 0.4.9\n"
|
| 16 |
+
|
| 17 |
+
#: includes/class-wc-colors-customizer.php:40
|
| 18 |
+
msgid "WooCommerce"
|
| 19 |
+
msgstr ""
|
| 20 |
+
|
| 21 |
+
#. Description of the plugin/theme
|
| 22 |
+
msgid "WooCommerce Colors."
|
| 23 |
+
msgstr ""
|
| 24 |
+
|
| 25 |
+
#: includes/class-wc-colors-customizer.php:54
|
| 26 |
+
msgid "Primary Color"
|
| 27 |
+
msgstr ""
|
| 28 |
+
|
| 29 |
+
#: includes/class-wc-colors-customizer.php:69
|
| 30 |
+
msgid "Secondary Color"
|
| 31 |
+
msgstr ""
|
| 32 |
+
|
| 33 |
+
#: includes/class-wc-colors-customizer.php:84
|
| 34 |
+
msgid "Highlight Color"
|
| 35 |
+
msgstr ""
|
| 36 |
+
|
| 37 |
+
#: includes/class-wc-colors-customizer.php:99
|
| 38 |
+
msgid "Content Background Color"
|
| 39 |
+
msgstr ""
|
| 40 |
+
|
| 41 |
+
#: includes/class-wc-colors-customizer.php:114
|
| 42 |
+
msgid "Subtext Color"
|
| 43 |
+
msgstr ""
|
| 44 |
+
|
| 45 |
+
#: woocommerce-colors.php:160
|
| 46 |
+
msgid "WooCommerce Colors depends on the last version of %s or later to work!"
|
| 47 |
+
msgstr ""
|
| 48 |
+
|
| 49 |
+
#: woocommerce-colors.php:160
|
| 50 |
+
msgid "WooCommerce 2.3"
|
| 51 |
+
msgstr ""
|
| 52 |
+
|
| 53 |
+
#. Plugin Name of the plugin/theme
|
| 54 |
+
msgid "WooCommerce Colors"
|
| 55 |
+
msgstr ""
|
| 56 |
+
|
| 57 |
+
#. Plugin URI of the plugin/theme
|
| 58 |
+
msgid "http://wordpress.org/plugins/woocommerce-colors/"
|
| 59 |
+
msgstr ""
|
| 60 |
+
|
| 61 |
+
#. Author of the plugin/theme
|
| 62 |
+
msgid "WooThemes"
|
| 63 |
+
msgstr ""
|
| 64 |
+
|
| 65 |
+
#. Author URI of the plugin/theme
|
| 66 |
+
msgid "http://woothemes.com"
|
| 67 |
+
msgstr ""
|
readme.txt
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=== WooCommerce Colors ===
|
| 2 |
+
Contributors: woothemes, claudiosanches
|
| 3 |
+
Tags: woocommerce, shortcodes
|
| 4 |
+
Requires at least: 3.9
|
| 5 |
+
Tested up to: 4.1
|
| 6 |
+
Stable tag: 1.0.0
|
| 7 |
+
License: GPLv2 or later
|
| 8 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 9 |
+
|
| 10 |
+
Allows you to change the buttons color and other elements of WooCommerce. Beautifully.
|
| 11 |
+
|
| 12 |
+
== Description ==
|
| 13 |
+
|
| 14 |
+
This plugin adds a new session called WooCommerce on the Customize menu, allowing you to easily change color of buttons and [WooCommerce](http://wordpress.org/plugins/woocommerce/) elements.
|
| 15 |
+
|
| 16 |
+
Starting WooCommerce 2.3 the Frontend styles options will no longer be part of WooCommerce and will only be available by using this plugin.
|
| 17 |
+
|
| 18 |
+
= Requeriments =
|
| 19 |
+
|
| 20 |
+
* WordPress 3.9 or later.
|
| 21 |
+
* WooCommerce 2.3 or later.
|
| 22 |
+
|
| 23 |
+
= Contribute =
|
| 24 |
+
|
| 25 |
+
You can contribute to the source code in our [GitHub](https://github.com/woothemes/woocommerce-colors/) page.
|
| 26 |
+
|
| 27 |
+
== Installation ==
|
| 28 |
+
|
| 29 |
+
* Upload plugin files to your plugins folder, or install using WordPress built-in Add New Plugin installer;
|
| 30 |
+
* Activate the plugin;
|
| 31 |
+
* This ready! You can now use change the colors of your store on the Customize menu.
|
| 32 |
+
|
| 33 |
+
== Frequently Asked Questions ==
|
| 34 |
+
|
| 35 |
+
= What is the plugin license? =
|
| 36 |
+
|
| 37 |
+
* This plugin is released under a GPL license.
|
| 38 |
+
|
| 39 |
+
= What is needed to use this plugin? =
|
| 40 |
+
|
| 41 |
+
* WordPress 3.9 or later.
|
| 42 |
+
* WooCommerce 2.2 or later.
|
| 43 |
+
|
| 44 |
+
= How this plugin works? =
|
| 45 |
+
|
| 46 |
+
* Works just adding new colors options on the Customize menu.
|
| 47 |
+
|
| 48 |
+
== Screenshots ==
|
| 49 |
+
|
| 50 |
+
1. WooCommerce Colors on Customizer menu.
|
| 51 |
+
|
| 52 |
+
== Changelog ==
|
| 53 |
+
|
| 54 |
+
= 1.0.0 =
|
| 55 |
+
|
| 56 |
+
* Initial version.
|
| 57 |
+
|
| 58 |
+
== Upgrade Notice ==
|
| 59 |
+
|
| 60 |
+
= 1.0.0 =
|
| 61 |
+
|
| 62 |
+
* Initial version.
|
screenshot-1.png
ADDED
|
Binary file
|
woocommerce-colors.php
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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erce Colors.
|
| 6 |
+
* Author: WooThemes
|
| 7 |
+
* Author URI: http://woothemes.com
|
| 8 |
+
* Version: 1.0.0
|
| 9 |
+
* License: GPLv2 or later
|
| 10 |
+
* Text Domain: woocommerce-colors
|
| 11 |
+
* Domain Path: languages/
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
| 15 |
+
exit;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
if ( ! class_exists( 'WC_Colors' ) ) :
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* WooCommerce Colors main class.
|
| 22 |
+
*/
|
| 23 |
+
class WC_Colors {
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Plugin version.
|
| 27 |
+
*
|
| 28 |
+
* @var string
|
| 29 |
+
*/
|
| 30 |
+
const VERSION = '1.0.0';
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* Instance of this class.
|
| 34 |
+
*
|
| 35 |
+
* @var object
|
| 36 |
+
*/
|
| 37 |
+
protected static $instance = null;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Initialize the plugin.
|
| 41 |
+
*/
|
| 42 |
+
private function __construct() {
|
| 43 |
+
// Load plugin text domain
|
| 44 |
+
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
|
| 45 |
+
|
| 46 |
+
// Checks with WooCommerce is installed.
|
| 47 |
+
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) {
|
| 48 |
+
$this->includes();
|
| 49 |
+
} else {
|
| 50 |
+
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
/**
|
| 55 |
+
* Return an instance of this class.
|
| 56 |
+
*
|
| 57 |
+
* @return object A single instance of this class.
|
| 58 |
+
*/
|
| 59 |
+
public static function get_instance() {
|
| 60 |
+
// If the single instance hasn't been set, set it now.
|
| 61 |
+
if ( null == self::$instance ) {
|
| 62 |
+
self::$instance = new self;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
return self::$instance;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* Get assets url.
|
| 70 |
+
*
|
| 71 |
+
* @return string
|
| 72 |
+
*/
|
| 73 |
+
public static function get_assets_url() {
|
| 74 |
+
return plugins_url( 'assets/', __FILE__ );
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* Load the plugin text domain for translation.
|
| 79 |
+
*/
|
| 80 |
+
public function load_plugin_textdomain() {
|
| 81 |
+
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-colors' );
|
| 82 |
+
|
| 83 |
+
load_textdomain( 'woocommerce-colors', trailingslashit( WP_LANG_DIR ) . 'woocommerce-colors/woocommerce-colors-' . $locale . '.mo' );
|
| 84 |
+
load_plugin_textdomain( 'woocommerce-colors', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Includes.
|
| 89 |
+
*/
|
| 90 |
+
private function includes() {
|
| 91 |
+
include_once 'includes/class-wc-colors-customizer.php';
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Get the plugin options.
|
| 96 |
+
*
|
| 97 |
+
* @param array $colors
|
| 98 |
+
*
|
| 99 |
+
* @return array
|
| 100 |
+
*/
|
| 101 |
+
public static function get_options( $colors ) {
|
| 102 |
+
$colors = array_map( 'esc_attr', (array) $colors );
|
| 103 |
+
|
| 104 |
+
// Defaults.
|
| 105 |
+
if ( empty( $colors['primary'] ) ) {
|
| 106 |
+
$colors['primary'] = '#a46497';
|
| 107 |
+
}
|
| 108 |
+
if ( empty( $colors['secondary'] ) ) {
|
| 109 |
+
$colors['secondary'] = '#ebe9eb';
|
| 110 |
+
}
|
| 111 |
+
if ( empty( $colors['highlight'] ) ) {
|
| 112 |
+
$colors['highlight'] = '#77a464';
|
| 113 |
+
}
|
| 114 |
+
if ( empty( $colors['content_bg'] ) ) {
|
| 115 |
+
$colors['content_bg'] = '#ffffff';
|
| 116 |
+
}
|
| 117 |
+
if ( empty( $colors['subtext'] ) ) {
|
| 118 |
+
$colors['subtext'] = '#777777';
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return $colors;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Install method.
|
| 126 |
+
*/
|
| 127 |
+
public static function install() {
|
| 128 |
+
// Get old frontend colors from WooCommerce core.
|
| 129 |
+
$colors = get_option( 'woocommerce_frontend_css_colors' );
|
| 130 |
+
|
| 131 |
+
if ( $colors ) {
|
| 132 |
+
$colors = self::get_options( $colors );
|
| 133 |
+
|
| 134 |
+
update_option( 'woocommerce_colors', $colors );
|
| 135 |
+
|
| 136 |
+
// Compile the css.
|
| 137 |
+
include_once 'includes/libs/class-scss.php';
|
| 138 |
+
|
| 139 |
+
ob_start();
|
| 140 |
+
include 'includes/views/scss.php';
|
| 141 |
+
$scss = ob_get_clean();
|
| 142 |
+
|
| 143 |
+
$compiler = new scssc;
|
| 144 |
+
$compiler->setFormatter( 'scss_formatter_compressed' );
|
| 145 |
+
$compiled_css = $compiler->compile( trim( $scss ) );
|
| 146 |
+
|
| 147 |
+
update_option( 'woocommerce_colors_css', $compiled_css );
|
| 148 |
+
|
| 149 |
+
// Delete the old option.
|
| 150 |
+
delete_option( 'woocommerce_frontend_css_colors' );
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/**
|
| 155 |
+
* WooCommerce fallback notice.
|
| 156 |
+
*
|
| 157 |
+
* @return string
|
| 158 |
+
*/
|
| 159 |
+
public function woocommerce_missing_notice() {
|
| 160 |
+
echo '<div class="error"><p>' . sprintf( __( 'WooCommerce Colors depends on the last version of %s or later to work!', 'woocommerce-colors' ), '<a href="http://www.woothemes.com/woocommerce/" target="_blank">' . __( 'WooCommerce 2.3', 'woocommerce-colors' ) . '</a>' ) . '</p></div>';
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
// Plugin install.
|
| 165 |
+
register_activation_hook( __FILE__, array( 'WC_Colors', 'install' ) );
|
| 166 |
+
|
| 167 |
+
add_action( 'plugins_loaded', array( 'WC_Colors', 'get_instance' ), 0 );
|
| 168 |
+
|
| 169 |
+
endif;
|
