@@ -12,97 +12,97 @@ discard block |
||
12 | 12 | global $customizer_colour_names; |
13 | 13 | global $customizer_colour_choices; |
14 | 14 | |
15 | -$customizer_colour_names = apply_filters( 'lsx_customizer_colour_names', array( |
|
16 | - 'button_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
17 | - 'button_background_hover_color' => esc_html__( 'Background (hover)', 'lsx-customizer' ), |
|
18 | - 'button_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
19 | - 'button_text_color_hover' => esc_html__( 'Text (hover)', 'lsx-customizer' ), |
|
20 | - 'button_shadow' => esc_html__( 'Shadow', 'lsx-customizer' ), |
|
21 | - |
|
22 | - 'button_cta_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
23 | - 'button_cta_background_hover_color' => esc_html__( 'Background (hover)', 'lsx-customizer' ), |
|
24 | - 'button_cta_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
25 | - 'button_cta_text_color_hover' => esc_html__( 'Text (hover)', 'lsx-customizer' ), |
|
26 | - 'button_cta_shadow' => esc_html__( 'Shadow', 'lsx-customizer' ), |
|
27 | - |
|
28 | - 'button_secondary_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
29 | - 'button_secondary_background_hover_color' => esc_html__( 'Background (hover)', 'lsx-customizer' ), |
|
30 | - 'button_secondary_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
31 | - 'button_secondary_text_color_hover' => esc_html__( 'Text (hover)', 'lsx-customizer' ), |
|
32 | - 'button_secondary_shadow' => esc_html__( 'Shadow', 'lsx-customizer' ), |
|
33 | - |
|
34 | - 'button_tertiary_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
35 | - 'button_tertiary_background_hover_color' => esc_html__( 'Background (hover)', 'lsx-customizer' ), |
|
36 | - 'button_tertiary_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
37 | - 'button_tertiary_text_color_hover' => esc_html__( 'Text (hover)', 'lsx-customizer' ), |
|
38 | - 'button_tertiary_shadow' => esc_html__( 'Shadow', 'lsx-customizer' ), |
|
39 | - |
|
40 | - 'top_menu_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
41 | - 'top_menu_link_color' => esc_html__( 'Link', 'lsx-customizer' ), |
|
42 | - 'top_menu_link_hover_color' => esc_html__( 'Link (hover)', 'lsx-customizer' ), |
|
43 | - 'top_menu_icon_color' => esc_html__( 'Icon', 'lsx-customizer' ), |
|
44 | - 'top_menu_icon_hover_color' => esc_html__( 'Icon (hover)', 'lsx-customizer' ), |
|
45 | - 'top_menu_dropdown_color' => esc_html__( 'Dropdown', 'lsx-customizer' ), |
|
46 | - 'top_menu_dropdown_hover_color' => esc_html__( 'Dropdown (hover)', 'lsx-customizer' ), |
|
47 | - 'top_menu_dropdown_link_color' => esc_html__( 'Dropdown link', 'lsx-customizer' ), |
|
48 | - 'top_menu_dropdown_link_hover_color' => esc_html__( 'Dropdown link (hover)', 'lsx-customizer' ), |
|
49 | - |
|
50 | - 'header_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
51 | - 'header_link_color' => esc_html__( 'Link', 'lsx-customizer' ), |
|
52 | - 'header_link_hover_color' => esc_html__( 'Link (hover)', 'lsx-customizer' ), |
|
53 | - 'header_description_color' => esc_html__( 'Description', 'lsx-customizer' ), |
|
54 | - |
|
55 | - 'main_menu_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
56 | - 'main_menu_link_color' => esc_html__( 'Link', 'lsx-customizer' ), |
|
57 | - 'main_menu_link_hover_color' => esc_html__( 'Link (hover)', 'lsx-customizer' ), |
|
58 | - 'main_menu_dropdown_background_color' => esc_html__( 'Dropdown', 'lsx-customizer' ), |
|
59 | - 'main_menu_dropdown_background_hover_color' => esc_html__( 'Dropdown (hover)', 'lsx-customizer' ), |
|
60 | - 'main_menu_dropdown_link_color' => esc_html__( 'Dropdown link', 'lsx-customizer' ), |
|
61 | - 'main_menu_dropdown_link_hover_color' => esc_html__( 'Dropdown link (hover)', 'lsx-customizer' ), |
|
62 | - |
|
63 | - 'banner_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
64 | - 'banner_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
65 | - 'banner_text_image_color' => esc_html__( 'Text (over image)', 'lsx-customizer' ), |
|
66 | - 'banner_breadcrumb_background_color' => esc_html__( 'Breadcrumb Background', 'lsx-customizer' ), |
|
67 | - 'banner_breadcrumb_text_color' => esc_html__( 'Breadcrumb Text', 'lsx-customizer' ), |
|
68 | - 'banner_breadcrumb_text_selected_color' => esc_html__( 'Breadcrumb Text (selected)', 'lsx-customizer' ), |
|
69 | - |
|
70 | - 'background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
71 | - 'body_line_color' => esc_html__( 'Line', 'lsx-customizer' ), |
|
72 | - 'body_text_heading_color' => esc_html__( 'Text (heading)', 'lsx-customizer' ), |
|
73 | - 'body_text_small_color' => esc_html__( 'Text (small)', 'lsx-customizer' ), |
|
74 | - 'body_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
75 | - 'body_link_color' => esc_html__( 'Link', 'lsx-customizer' ), |
|
76 | - 'body_link_hover_color' => esc_html__( 'Link (hover)', 'lsx-customizer' ), |
|
77 | - 'body_section_full_background_color' => esc_html__( 'Section full (background)', 'lsx-customizer' ), |
|
78 | - 'body_section_full_text_color' => esc_html__( 'Section full (text)', 'lsx-customizer' ), |
|
79 | - 'body_section_full_link_color' => esc_html__( 'Section full (link)', 'lsx-customizer' ), |
|
80 | - 'body_section_full_link_hover_color' => esc_html__( 'Section full (link hover)', 'lsx-customizer' ), |
|
81 | - 'body_section_full_cta_background_color' => esc_html__( 'Section full CTA (background)', 'lsx-customizer' ), |
|
82 | - 'body_section_full_cta_text_color' => esc_html__( 'Section full CTA (text)', 'lsx-customizer' ), |
|
83 | - 'body_section_full_cta_link_color' => esc_html__( 'Section full CTA (link)', 'lsx-customizer' ), |
|
84 | - 'body_section_full_cta_link_hover_color' => esc_html__( 'Section full CTA (link hover)', 'lsx-customizer' ), |
|
85 | - |
|
86 | - 'footer_cta_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
87 | - 'footer_cta_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
88 | - 'footer_cta_link_color' => esc_html__( 'Link', 'lsx-customizer' ), |
|
89 | - 'footer_cta_link_hover_color' => esc_html__( 'Link (hover)', 'lsx-customizer' ), |
|
90 | - |
|
91 | - 'footer_widgets_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
92 | - 'footer_widgets_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
93 | - 'footer_widgets_link_color' => esc_html__( 'Link', 'lsx-customizer' ), |
|
94 | - 'footer_widgets_link_hover_color' => esc_html__( 'Link (hover)', 'lsx-customizer' ), |
|
95 | - |
|
96 | - 'footer_background_color' => esc_html__( 'Background', 'lsx-customizer' ), |
|
97 | - 'footer_text_color' => esc_html__( 'Text', 'lsx-customizer' ), |
|
98 | - 'footer_link_color' => esc_html__( 'Link', 'lsx-customizer' ), |
|
99 | - 'footer_link_hover_color' => esc_html__( 'Link (hover)', 'lsx-customizer' ), |
|
100 | -) ); |
|
101 | - |
|
102 | -$customizer_colour_choices = apply_filters( 'lsx_customizer_colour_choices', array( |
|
15 | +$customizer_colour_names = apply_filters('lsx_customizer_colour_names', array( |
|
16 | + 'button_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
17 | + 'button_background_hover_color' => esc_html__('Background (hover)', 'lsx-customizer'), |
|
18 | + 'button_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
19 | + 'button_text_color_hover' => esc_html__('Text (hover)', 'lsx-customizer'), |
|
20 | + 'button_shadow' => esc_html__('Shadow', 'lsx-customizer'), |
|
21 | + |
|
22 | + 'button_cta_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
23 | + 'button_cta_background_hover_color' => esc_html__('Background (hover)', 'lsx-customizer'), |
|
24 | + 'button_cta_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
25 | + 'button_cta_text_color_hover' => esc_html__('Text (hover)', 'lsx-customizer'), |
|
26 | + 'button_cta_shadow' => esc_html__('Shadow', 'lsx-customizer'), |
|
27 | + |
|
28 | + 'button_secondary_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
29 | + 'button_secondary_background_hover_color' => esc_html__('Background (hover)', 'lsx-customizer'), |
|
30 | + 'button_secondary_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
31 | + 'button_secondary_text_color_hover' => esc_html__('Text (hover)', 'lsx-customizer'), |
|
32 | + 'button_secondary_shadow' => esc_html__('Shadow', 'lsx-customizer'), |
|
33 | + |
|
34 | + 'button_tertiary_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
35 | + 'button_tertiary_background_hover_color' => esc_html__('Background (hover)', 'lsx-customizer'), |
|
36 | + 'button_tertiary_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
37 | + 'button_tertiary_text_color_hover' => esc_html__('Text (hover)', 'lsx-customizer'), |
|
38 | + 'button_tertiary_shadow' => esc_html__('Shadow', 'lsx-customizer'), |
|
39 | + |
|
40 | + 'top_menu_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
41 | + 'top_menu_link_color' => esc_html__('Link', 'lsx-customizer'), |
|
42 | + 'top_menu_link_hover_color' => esc_html__('Link (hover)', 'lsx-customizer'), |
|
43 | + 'top_menu_icon_color' => esc_html__('Icon', 'lsx-customizer'), |
|
44 | + 'top_menu_icon_hover_color' => esc_html__('Icon (hover)', 'lsx-customizer'), |
|
45 | + 'top_menu_dropdown_color' => esc_html__('Dropdown', 'lsx-customizer'), |
|
46 | + 'top_menu_dropdown_hover_color' => esc_html__('Dropdown (hover)', 'lsx-customizer'), |
|
47 | + 'top_menu_dropdown_link_color' => esc_html__('Dropdown link', 'lsx-customizer'), |
|
48 | + 'top_menu_dropdown_link_hover_color' => esc_html__('Dropdown link (hover)', 'lsx-customizer'), |
|
49 | + |
|
50 | + 'header_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
51 | + 'header_link_color' => esc_html__('Link', 'lsx-customizer'), |
|
52 | + 'header_link_hover_color' => esc_html__('Link (hover)', 'lsx-customizer'), |
|
53 | + 'header_description_color' => esc_html__('Description', 'lsx-customizer'), |
|
54 | + |
|
55 | + 'main_menu_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
56 | + 'main_menu_link_color' => esc_html__('Link', 'lsx-customizer'), |
|
57 | + 'main_menu_link_hover_color' => esc_html__('Link (hover)', 'lsx-customizer'), |
|
58 | + 'main_menu_dropdown_background_color' => esc_html__('Dropdown', 'lsx-customizer'), |
|
59 | + 'main_menu_dropdown_background_hover_color' => esc_html__('Dropdown (hover)', 'lsx-customizer'), |
|
60 | + 'main_menu_dropdown_link_color' => esc_html__('Dropdown link', 'lsx-customizer'), |
|
61 | + 'main_menu_dropdown_link_hover_color' => esc_html__('Dropdown link (hover)', 'lsx-customizer'), |
|
62 | + |
|
63 | + 'banner_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
64 | + 'banner_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
65 | + 'banner_text_image_color' => esc_html__('Text (over image)', 'lsx-customizer'), |
|
66 | + 'banner_breadcrumb_background_color' => esc_html__('Breadcrumb Background', 'lsx-customizer'), |
|
67 | + 'banner_breadcrumb_text_color' => esc_html__('Breadcrumb Text', 'lsx-customizer'), |
|
68 | + 'banner_breadcrumb_text_selected_color' => esc_html__('Breadcrumb Text (selected)', 'lsx-customizer'), |
|
69 | + |
|
70 | + 'background_color' => esc_html__('Background', 'lsx-customizer'), |
|
71 | + 'body_line_color' => esc_html__('Line', 'lsx-customizer'), |
|
72 | + 'body_text_heading_color' => esc_html__('Text (heading)', 'lsx-customizer'), |
|
73 | + 'body_text_small_color' => esc_html__('Text (small)', 'lsx-customizer'), |
|
74 | + 'body_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
75 | + 'body_link_color' => esc_html__('Link', 'lsx-customizer'), |
|
76 | + 'body_link_hover_color' => esc_html__('Link (hover)', 'lsx-customizer'), |
|
77 | + 'body_section_full_background_color' => esc_html__('Section full (background)', 'lsx-customizer'), |
|
78 | + 'body_section_full_text_color' => esc_html__('Section full (text)', 'lsx-customizer'), |
|
79 | + 'body_section_full_link_color' => esc_html__('Section full (link)', 'lsx-customizer'), |
|
80 | + 'body_section_full_link_hover_color' => esc_html__('Section full (link hover)', 'lsx-customizer'), |
|
81 | + 'body_section_full_cta_background_color' => esc_html__('Section full CTA (background)', 'lsx-customizer'), |
|
82 | + 'body_section_full_cta_text_color' => esc_html__('Section full CTA (text)', 'lsx-customizer'), |
|
83 | + 'body_section_full_cta_link_color' => esc_html__('Section full CTA (link)', 'lsx-customizer'), |
|
84 | + 'body_section_full_cta_link_hover_color' => esc_html__('Section full CTA (link hover)', 'lsx-customizer'), |
|
85 | + |
|
86 | + 'footer_cta_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
87 | + 'footer_cta_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
88 | + 'footer_cta_link_color' => esc_html__('Link', 'lsx-customizer'), |
|
89 | + 'footer_cta_link_hover_color' => esc_html__('Link (hover)', 'lsx-customizer'), |
|
90 | + |
|
91 | + 'footer_widgets_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
92 | + 'footer_widgets_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
93 | + 'footer_widgets_link_color' => esc_html__('Link', 'lsx-customizer'), |
|
94 | + 'footer_widgets_link_hover_color' => esc_html__('Link (hover)', 'lsx-customizer'), |
|
95 | + |
|
96 | + 'footer_background_color' => esc_html__('Background', 'lsx-customizer'), |
|
97 | + 'footer_text_color' => esc_html__('Text', 'lsx-customizer'), |
|
98 | + 'footer_link_color' => esc_html__('Link', 'lsx-customizer'), |
|
99 | + 'footer_link_hover_color' => esc_html__('Link (hover)', 'lsx-customizer'), |
|
100 | +)); |
|
101 | + |
|
102 | +$customizer_colour_choices = apply_filters('lsx_customizer_colour_choices', array( |
|
103 | 103 | 'default' => array( |
104 | - 'label' => __( 'Default', 'lsx-customizer' ), |
|
105 | - 'colors' => apply_filters( 'lsx_customizer_colour_choices_default', array( |
|
104 | + 'label' => __('Default', 'lsx-customizer'), |
|
105 | + 'colors' => apply_filters('lsx_customizer_colour_choices_default', array( |
|
106 | 106 | 'button_background_color' => '#418AD0', |
107 | 107 | 'button_background_hover_color' => '#367DC0', |
108 | 108 | 'button_text_color' => '#FFFFFF', |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | 'footer_text_color' => '#ffffff', |
188 | 188 | 'footer_link_color' => '#F7AE00', |
189 | 189 | 'footer_link_hover_color' => '#CE9100', |
190 | - ) ), |
|
190 | + )), |
|
191 | 191 | ), |
192 | 192 | 'red' => array( |
193 | - 'label' => __( 'Red', 'lsx-customizer' ), |
|
194 | - 'colors' => apply_filters( 'lsx_customizer_colour_choices_red', array( |
|
193 | + 'label' => __('Red', 'lsx-customizer'), |
|
194 | + 'colors' => apply_filters('lsx_customizer_colour_choices_red', array( |
|
195 | 195 | 'button_background_color' => '#b64d3f', |
196 | 196 | 'button_background_hover_color' => '#87291c', |
197 | 197 | 'button_text_color' => '#ffffff', |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | 'footer_text_color' => '#ffffff', |
277 | 277 | 'footer_link_color' => '#b64d3f', |
278 | 278 | 'footer_link_hover_color' => '#969696', |
279 | - ) ), |
|
279 | + )), |
|
280 | 280 | ), |
281 | 281 | 'orange' => array( |
282 | - 'label' => __( 'Orange', 'lsx-customizer' ), |
|
283 | - 'colors' => apply_filters( 'lsx_customizer_colour_choices_orange', array( |
|
282 | + 'label' => __('Orange', 'lsx-customizer'), |
|
283 | + 'colors' => apply_filters('lsx_customizer_colour_choices_orange', array( |
|
284 | 284 | 'button_background_color' => '#fbaf3f', |
285 | 285 | 'button_background_hover_color' => '#e49435', |
286 | 286 | 'button_text_color' => '#260e03', |
@@ -365,11 +365,11 @@ discard block |
||
365 | 365 | 'footer_text_color' => '#ffffff', |
366 | 366 | 'footer_link_color' => '#e4701e', |
367 | 367 | 'footer_link_hover_color' => '#969696', |
368 | - ) ), |
|
368 | + )), |
|
369 | 369 | ), |
370 | 370 | 'green' => array( |
371 | - 'label' => __( 'Green', 'lsx-customizer' ), |
|
372 | - 'colors' => apply_filters( 'lsx_customizer_colour_choices_green', array( |
|
371 | + 'label' => __('Green', 'lsx-customizer'), |
|
372 | + 'colors' => apply_filters('lsx_customizer_colour_choices_green', array( |
|
373 | 373 | 'button_background_color' => '#596b46', |
374 | 374 | 'button_background_hover_color' => '#3d4a30', |
375 | 375 | 'button_text_color' => '#ffffff', |
@@ -454,11 +454,11 @@ discard block |
||
454 | 454 | 'footer_text_color' => '#ffffff', |
455 | 455 | 'footer_link_color' => '#596b46', |
456 | 456 | 'footer_link_hover_color' => '#969696', |
457 | - ) ), |
|
457 | + )), |
|
458 | 458 | ), |
459 | 459 | 'brown' => array( |
460 | - 'label' => __( 'Brown', 'lsx-customizer' ), |
|
461 | - 'colors' => apply_filters( 'lsx_customizer_colour_choices_brown', array( |
|
460 | + 'label' => __('Brown', 'lsx-customizer'), |
|
461 | + 'colors' => apply_filters('lsx_customizer_colour_choices_brown', array( |
|
462 | 462 | 'button_background_color' => '#8c6a45', |
463 | 463 | 'button_background_hover_color' => '#5b452e', |
464 | 464 | 'button_text_color' => '#ffffff', |
@@ -543,6 +543,6 @@ discard block |
||
543 | 543 | 'footer_text_color' => '#ffffff', |
544 | 544 | 'footer_link_color' => '#8c6a45', |
545 | 545 | 'footer_link_hover_color' => '#969696', |
546 | - ) ), |
|
546 | + )), |
|
547 | 547 | ), |
548 | -) ); |
|
548 | +)); |
@@ -5,72 +5,72 @@ discard block |
||
5 | 5 | * |
6 | 6 | * Add two new colors (test) in main array of colors |
7 | 7 | */ |
8 | -function test_lsx_customizer_colour_names( $array ) { |
|
9 | - $array['test_text_color'] = esc_html__( 'TEST: Text', 'lsx-customizer' ); |
|
10 | - $array['test_text_color_hover'] = esc_html__( 'TEST: Text (hover)', 'lsx-customizer' ); |
|
8 | +function test_lsx_customizer_colour_names($array) { |
|
9 | + $array['test_text_color'] = esc_html__('TEST: Text', 'lsx-customizer'); |
|
10 | + $array['test_text_color_hover'] = esc_html__('TEST: Text (hover)', 'lsx-customizer'); |
|
11 | 11 | return $array; |
12 | 12 | } |
13 | -add_filter( 'lsx_customizer_colour_names', 'test_lsx_customizer_colour_names' ); |
|
13 | +add_filter('lsx_customizer_colour_names', 'test_lsx_customizer_colour_names'); |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Filter: lsx_customizer_colour_choices_default |
17 | 17 | * |
18 | 18 | * Add the new colors (test) in default scheme |
19 | 19 | */ |
20 | -function test_lsx_customizer_colour_choices_default( $array ) { |
|
20 | +function test_lsx_customizer_colour_choices_default($array) { |
|
21 | 21 | $array['test_text_color'] = '#ddddd1'; |
22 | 22 | $array['test_text_color_hover'] = '#eeeee1'; |
23 | 23 | return $array; |
24 | 24 | } |
25 | -add_filter( 'lsx_customizer_colour_choices_default', 'test_lsx_customizer_colour_choices_default' ); |
|
25 | +add_filter('lsx_customizer_colour_choices_default', 'test_lsx_customizer_colour_choices_default'); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Filter: lsx_customizer_colour_choices_red |
29 | 29 | * |
30 | 30 | * Add the new colors (test) in red scheme |
31 | 31 | */ |
32 | -function test_lsx_customizer_colour_choices_red( $array ) { |
|
32 | +function test_lsx_customizer_colour_choices_red($array) { |
|
33 | 33 | $array['test_text_color'] = '#ddddd2'; |
34 | 34 | $array['test_text_color_hover'] = '#eeeee2'; |
35 | 35 | return $array; |
36 | 36 | } |
37 | -add_filter( 'lsx_customizer_colour_choices_red', 'test_lsx_customizer_colour_choices_red' ); |
|
37 | +add_filter('lsx_customizer_colour_choices_red', 'test_lsx_customizer_colour_choices_red'); |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Filter: lsx_customizer_colour_choices_orange |
41 | 41 | * |
42 | 42 | * Add the new colors (test) in orange scheme |
43 | 43 | */ |
44 | -function test_lsx_customizer_colour_choices_orange( $array ) { |
|
44 | +function test_lsx_customizer_colour_choices_orange($array) { |
|
45 | 45 | $array['test_text_color'] = '#ddddd3'; |
46 | 46 | $array['test_text_color_hover'] = '#eeeee3'; |
47 | 47 | return $array; |
48 | 48 | } |
49 | -add_filter( 'lsx_customizer_colour_choices_orange', 'test_lsx_customizer_colour_choices_orange' ); |
|
49 | +add_filter('lsx_customizer_colour_choices_orange', 'test_lsx_customizer_colour_choices_orange'); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Filter: lsx_customizer_colour_choices_green |
53 | 53 | * |
54 | 54 | * Add the new colors (test) in green scheme |
55 | 55 | */ |
56 | -function test_lsx_customizer_colour_choices_green( $array ) { |
|
56 | +function test_lsx_customizer_colour_choices_green($array) { |
|
57 | 57 | $array['test_text_color'] = '#ddddd4'; |
58 | 58 | $array['test_text_color_hover'] = '#eeeee4'; |
59 | 59 | return $array; |
60 | 60 | } |
61 | -add_filter( 'lsx_customizer_colour_choices_green', 'test_lsx_customizer_colour_choices_green' ); |
|
61 | +add_filter('lsx_customizer_colour_choices_green', 'test_lsx_customizer_colour_choices_green'); |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Filter: lsx_customizer_colour_choices_brown |
65 | 65 | * |
66 | 66 | * Add the new colors (test) in brown scheme |
67 | 67 | */ |
68 | -function test_lsx_customizer_colour_choices_brown( $array ) { |
|
68 | +function test_lsx_customizer_colour_choices_brown($array) { |
|
69 | 69 | $array['test_text_color'] = '#ddddd5'; |
70 | 70 | $array['test_text_color_hover'] = '#eeeee5'; |
71 | 71 | return $array; |
72 | 72 | } |
73 | -add_filter( 'lsx_customizer_colour_choices_brown', 'test_lsx_customizer_colour_choices_brown' ); |
|
73 | +add_filter('lsx_customizer_colour_choices_brown', 'test_lsx_customizer_colour_choices_brown'); |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * Filter: lsx_customizer_colour_choices |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * Add a new scheme |
79 | 79 | * Also add the new colors (test) in new scheme |
80 | 80 | */ |
81 | -function test_lsx_customizer_colour_choices( $array ) { |
|
81 | +function test_lsx_customizer_colour_choices($array) { |
|
82 | 82 | $array['test'] = array( |
83 | - 'label' => esc_html__( 'Test', 'lsx-customizer' ), |
|
83 | + 'label' => esc_html__('Test', 'lsx-customizer'), |
|
84 | 84 | 'colors' => array( |
85 | 85 | 'button_background_color' => '#428bca', |
86 | 86 | 'button_background_hover_color' => '#2a6496', |
@@ -162,14 +162,14 @@ discard block |
||
162 | 162 | |
163 | 163 | return $array; |
164 | 164 | } |
165 | -add_filter( 'lsx_customizer_colour_choices', 'test_lsx_customizer_colour_choices' ); |
|
165 | +add_filter('lsx_customizer_colour_choices', 'test_lsx_customizer_colour_choices'); |
|
166 | 166 | |
167 | 167 | /** |
168 | 168 | * Filter: lsx_customizer_colour_selectors_button |
169 | 169 | * |
170 | 170 | * Add new selectors in "button" group of colours |
171 | 171 | */ |
172 | -function test_lsx_customizer_colour_selectors_button( $css, $colors ) { |
|
172 | +function test_lsx_customizer_colour_selectors_button($css, $colors) { |
|
173 | 173 | $css .= <<<CSS |
174 | 174 | |
175 | 175 | /* Button TEST */ |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | |
186 | 186 | return $css; |
187 | 187 | } |
188 | -add_filter( 'lsx_customizer_colour_selectors_button', 'test_lsx_customizer_colour_selectors_button', 10, 2 ); |
|
188 | +add_filter('lsx_customizer_colour_selectors_button', 'test_lsx_customizer_colour_selectors_button', 10, 2); |
|
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Filter: lsx_customizer_colour_selectors_button_cta |
192 | 192 | * |
193 | 193 | * Add new selectors in "button cta" group of colours |
194 | 194 | */ |
195 | -function test_lsx_customizer_colour_selectors_button_cta( $css, $colors ) { |
|
195 | +function test_lsx_customizer_colour_selectors_button_cta($css, $colors) { |
|
196 | 196 | $css .= <<<CSS |
197 | 197 | |
198 | 198 | /* Button CTA TEST */ |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | |
209 | 209 | return $css; |
210 | 210 | } |
211 | -add_filter( 'lsx_customizer_colour_selectors_button_cta', 'test_lsx_customizer_colour_selectors_button_cta', 10, 2 ); |
|
211 | +add_filter('lsx_customizer_colour_selectors_button_cta', 'test_lsx_customizer_colour_selectors_button_cta', 10, 2); |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Filter: lsx_customizer_colour_selectors_top_menu |
215 | 215 | * |
216 | 216 | * Add new selectors in "top menu" group of colours |
217 | 217 | */ |
218 | -function test_lsx_customizer_colour_selectors_top_menu( $css, $colors ) { |
|
218 | +function test_lsx_customizer_colour_selectors_top_menu($css, $colors) { |
|
219 | 219 | $css .= <<<CSS |
220 | 220 | |
221 | 221 | /* Top Menu TEST */ |
@@ -235,14 +235,14 @@ discard block |
||
235 | 235 | |
236 | 236 | return $css; |
237 | 237 | } |
238 | -add_filter( 'lsx_customizer_colour_selectors_top_menu', 'test_lsx_customizer_colour_selectors_top_menu', 10, 2 ); |
|
238 | +add_filter('lsx_customizer_colour_selectors_top_menu', 'test_lsx_customizer_colour_selectors_top_menu', 10, 2); |
|
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Filter: lsx_customizer_colour_selectors_header |
242 | 242 | * |
243 | 243 | * Add new selectors in "header" group of colours |
244 | 244 | */ |
245 | -function test_lsx_customizer_colour_selectors_header( $css, $colors ) { |
|
245 | +function test_lsx_customizer_colour_selectors_header($css, $colors) { |
|
246 | 246 | $css .= <<<CSS |
247 | 247 | |
248 | 248 | /* Header TEST */ |
@@ -257,14 +257,14 @@ discard block |
||
257 | 257 | |
258 | 258 | return $css; |
259 | 259 | } |
260 | -add_filter( 'lsx_customizer_colour_selectors_header', 'test_lsx_customizer_colour_selectors_header', 10, 2 ); |
|
260 | +add_filter('lsx_customizer_colour_selectors_header', 'test_lsx_customizer_colour_selectors_header', 10, 2); |
|
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Filter: lsx_customizer_colour_selectors_main_menu |
264 | 264 | * |
265 | 265 | * Add new selectors in "main meun" group of colours |
266 | 266 | */ |
267 | -function test_lsx_customizer_colour_selectors_main_menu( $css, $colors ) { |
|
267 | +function test_lsx_customizer_colour_selectors_main_menu($css, $colors) { |
|
268 | 268 | $css .= <<<CSS |
269 | 269 | |
270 | 270 | /* Main Menu TEST */ |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | |
283 | 283 | return $css; |
284 | 284 | } |
285 | -add_filter( 'lsx_customizer_colour_selectors_main_menu', 'test_lsx_customizer_colour_selectors_main_menu', 10, 2 ); |
|
285 | +add_filter('lsx_customizer_colour_selectors_main_menu', 'test_lsx_customizer_colour_selectors_main_menu', 10, 2); |
|
286 | 286 | |
287 | 287 | /** |
288 | 288 | * Filter: lsx_customizer_colour_selectors_banner |
289 | 289 | * |
290 | 290 | * Add new selectors in "banner" group of colours |
291 | 291 | */ |
292 | -function test_lsx_customizer_colour_selectors_banner( $css, $colors ) { |
|
292 | +function test_lsx_customizer_colour_selectors_banner($css, $colors) { |
|
293 | 293 | $css .= <<<CSS |
294 | 294 | |
295 | 295 | /* Banner TEST */ |
@@ -306,14 +306,14 @@ discard block |
||
306 | 306 | |
307 | 307 | return $css; |
308 | 308 | } |
309 | -add_filter( 'lsx_customizer_colour_selectors_banner', 'test_lsx_customizer_colour_selectors_banner', 10, 2 ); |
|
309 | +add_filter('lsx_customizer_colour_selectors_banner', 'test_lsx_customizer_colour_selectors_banner', 10, 2); |
|
310 | 310 | |
311 | 311 | /** |
312 | 312 | * Filter: lsx_customizer_colour_selectors_body |
313 | 313 | * |
314 | 314 | * Add new selectors in "body" group of colours |
315 | 315 | */ |
316 | -function test_lsx_customizer_colour_selectors_body( $css, $colors ) { |
|
316 | +function test_lsx_customizer_colour_selectors_body($css, $colors) { |
|
317 | 317 | $css .= <<<CSS |
318 | 318 | |
319 | 319 | /* Body TEST */ |
@@ -340,14 +340,14 @@ discard block |
||
340 | 340 | |
341 | 341 | return $css; |
342 | 342 | } |
343 | -add_filter( 'lsx_customizer_colour_selectors_body', 'test_lsx_customizer_colour_selectors_body', 10, 2 ); |
|
343 | +add_filter('lsx_customizer_colour_selectors_body', 'test_lsx_customizer_colour_selectors_body', 10, 2); |
|
344 | 344 | |
345 | 345 | /** |
346 | 346 | * Filter: lsx_customizer_colour_selectors_footer_cta |
347 | 347 | * |
348 | 348 | * Add new selectors in "footer cta" group of colours |
349 | 349 | */ |
350 | -function test_lsx_customizer_colour_selectors_footer_cta( $css, $colors ) { |
|
350 | +function test_lsx_customizer_colour_selectors_footer_cta($css, $colors) { |
|
351 | 351 | $css .= <<<CSS |
352 | 352 | |
353 | 353 | /* Footer CTA TEST */ |
@@ -362,14 +362,14 @@ discard block |
||
362 | 362 | |
363 | 363 | return $css; |
364 | 364 | } |
365 | -add_filter( 'lsx_customizer_colour_selectors_footer_cta', 'test_lsx_customizer_colour_selectors_footer_cta', 10, 2 ); |
|
365 | +add_filter('lsx_customizer_colour_selectors_footer_cta', 'test_lsx_customizer_colour_selectors_footer_cta', 10, 2); |
|
366 | 366 | |
367 | 367 | /** |
368 | 368 | * Filter: lsx_customizer_colour_selectors_footer_widgets |
369 | 369 | * |
370 | 370 | * Add new selectors in "footer widgets" group of colours |
371 | 371 | */ |
372 | -function test_lsx_customizer_colour_selectors_footer_widgets( $css, $colors ) { |
|
372 | +function test_lsx_customizer_colour_selectors_footer_widgets($css, $colors) { |
|
373 | 373 | $css .= <<<CSS |
374 | 374 | |
375 | 375 | /* Footer Widgets TEST */ |
@@ -384,14 +384,14 @@ discard block |
||
384 | 384 | |
385 | 385 | return $css; |
386 | 386 | } |
387 | -add_filter( 'lsx_customizer_colour_selectors_footer_widgets', 'test_lsx_customizer_colour_selectors_footer_widgets', 10, 2 ); |
|
387 | +add_filter('lsx_customizer_colour_selectors_footer_widgets', 'test_lsx_customizer_colour_selectors_footer_widgets', 10, 2); |
|
388 | 388 | |
389 | 389 | /** |
390 | 390 | * Filter: lsx_customizer_colour_selectors_footer |
391 | 391 | * |
392 | 392 | * Add new selectors in "footer" group of colours |
393 | 393 | */ |
394 | -function test_lsx_customizer_colour_selectors_footer( $css, $colors ) { |
|
394 | +function test_lsx_customizer_colour_selectors_footer($css, $colors) { |
|
395 | 395 | $css .= <<<CSS |
396 | 396 | |
397 | 397 | /* Footer TEST */ |
@@ -406,4 +406,4 @@ discard block |
||
406 | 406 | |
407 | 407 | return $css; |
408 | 408 | } |
409 | -add_filter( 'lsx_customizer_colour_selectors_footer', 'test_lsx_customizer_colour_selectors_footer', 10, 2 ); |
|
409 | +add_filter('lsx_customizer_colour_selectors_footer', 'test_lsx_customizer_colour_selectors_footer', 10, 2); |
@@ -1,32 +1,32 @@ |
||
1 | 1 | <?php |
2 | 2 | if (version_compare(PHP_VERSION, '5.4') < 0) { |
3 | - throw new \Exception('scssphp requires PHP 5.4 or above'); |
|
3 | + throw new \Exception('scssphp requires PHP 5.4 or above'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | if (! class_exists('Leafo\ScssPhp\Version', false)) { |
7 | - include_once __DIR__ . '/src/Base/Range.php'; |
|
8 | - include_once __DIR__ . '/src/Block.php'; |
|
9 | - include_once __DIR__ . '/src/Colors.php'; |
|
10 | - include_once __DIR__ . '/src/Compiler.php'; |
|
11 | - include_once __DIR__ . '/src/Compiler/Environment.php'; |
|
12 | - include_once __DIR__ . '/src/Exception/CompilerException.php'; |
|
13 | - include_once __DIR__ . '/src/Exception/ParserException.php'; |
|
14 | - include_once __DIR__ . '/src/Exception/RangeException.php'; |
|
15 | - include_once __DIR__ . '/src/Exception/ServerException.php'; |
|
16 | - include_once __DIR__ . '/src/Formatter.php'; |
|
17 | - include_once __DIR__ . '/src/Formatter/Compact.php'; |
|
18 | - include_once __DIR__ . '/src/Formatter/Compressed.php'; |
|
19 | - include_once __DIR__ . '/src/Formatter/Crunched.php'; |
|
20 | - include_once __DIR__ . '/src/Formatter/Debug.php'; |
|
21 | - include_once __DIR__ . '/src/Formatter/Expanded.php'; |
|
22 | - include_once __DIR__ . '/src/Formatter/Nested.php'; |
|
23 | - include_once __DIR__ . '/src/Formatter/OutputBlock.php'; |
|
24 | - include_once __DIR__ . '/src/Node.php'; |
|
25 | - include_once __DIR__ . '/src/Node/Number.php'; |
|
26 | - include_once __DIR__ . '/src/Parser.php'; |
|
27 | - include_once __DIR__ . '/src/SourceMap/Base64VLQEncoder.php'; |
|
28 | - include_once __DIR__ . '/src/SourceMap/SourceMapGenerator.php'; |
|
29 | - include_once __DIR__ . '/src/Type.php'; |
|
30 | - include_once __DIR__ . '/src/Util.php'; |
|
31 | - include_once __DIR__ . '/src/Version.php'; |
|
7 | + include_once __DIR__ . '/src/Base/Range.php'; |
|
8 | + include_once __DIR__ . '/src/Block.php'; |
|
9 | + include_once __DIR__ . '/src/Colors.php'; |
|
10 | + include_once __DIR__ . '/src/Compiler.php'; |
|
11 | + include_once __DIR__ . '/src/Compiler/Environment.php'; |
|
12 | + include_once __DIR__ . '/src/Exception/CompilerException.php'; |
|
13 | + include_once __DIR__ . '/src/Exception/ParserException.php'; |
|
14 | + include_once __DIR__ . '/src/Exception/RangeException.php'; |
|
15 | + include_once __DIR__ . '/src/Exception/ServerException.php'; |
|
16 | + include_once __DIR__ . '/src/Formatter.php'; |
|
17 | + include_once __DIR__ . '/src/Formatter/Compact.php'; |
|
18 | + include_once __DIR__ . '/src/Formatter/Compressed.php'; |
|
19 | + include_once __DIR__ . '/src/Formatter/Crunched.php'; |
|
20 | + include_once __DIR__ . '/src/Formatter/Debug.php'; |
|
21 | + include_once __DIR__ . '/src/Formatter/Expanded.php'; |
|
22 | + include_once __DIR__ . '/src/Formatter/Nested.php'; |
|
23 | + include_once __DIR__ . '/src/Formatter/OutputBlock.php'; |
|
24 | + include_once __DIR__ . '/src/Node.php'; |
|
25 | + include_once __DIR__ . '/src/Node/Number.php'; |
|
26 | + include_once __DIR__ . '/src/Parser.php'; |
|
27 | + include_once __DIR__ . '/src/SourceMap/Base64VLQEncoder.php'; |
|
28 | + include_once __DIR__ . '/src/SourceMap/SourceMapGenerator.php'; |
|
29 | + include_once __DIR__ . '/src/Type.php'; |
|
30 | + include_once __DIR__ . '/src/Util.php'; |
|
31 | + include_once __DIR__ . '/src/Version.php'; |
|
32 | 32 | } |
@@ -3,7 +3,7 @@ |
||
3 | 3 | throw new \Exception('scssphp requires PHP 5.4 or above'); |
4 | 4 | } |
5 | 5 | |
6 | -if (! class_exists('Leafo\ScssPhp\Version', false)) { |
|
6 | +if ( ! class_exists('Leafo\ScssPhp\Version', false)) { |
|
7 | 7 | include_once __DIR__ . '/src/Base/Range.php'; |
8 | 8 | include_once __DIR__ . '/src/Block.php'; |
9 | 9 | include_once __DIR__ . '/src/Colors.php'; |
@@ -21,254 +21,254 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class Formatter |
23 | 23 | { |
24 | - /** |
|
25 | - * @var integer |
|
26 | - */ |
|
27 | - public $indentLevel; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - public $indentChar; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - public $break; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - public $open; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - public $close; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $tagSeparator; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $assignSeparator; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var boolean |
|
61 | - */ |
|
62 | - public $keepSemicolons; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var \Leafo\ScssPhp\Formatter\OutputBlock |
|
66 | - */ |
|
67 | - protected $currentBlock; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var integer |
|
71 | - */ |
|
72 | - protected $currentLine; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var integer |
|
76 | - */ |
|
77 | - protected $currentColumn; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var \Leafo\ScssPhp\SourceMap\SourceMapGenerator |
|
81 | - */ |
|
82 | - protected $sourceMapGenerator; |
|
83 | - |
|
84 | - /** |
|
85 | - * Initialize formatter |
|
86 | - * |
|
87 | - * @api |
|
88 | - */ |
|
89 | - abstract public function __construct(); |
|
90 | - |
|
91 | - /** |
|
92 | - * Return indentation (whitespace) |
|
93 | - * |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - protected function indentStr() |
|
97 | - { |
|
98 | - return ''; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Return property assignment |
|
103 | - * |
|
104 | - * @api |
|
105 | - * |
|
106 | - * @param string $name |
|
107 | - * @param mixed $value |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public function property($name, $value) |
|
112 | - { |
|
113 | - return rtrim($name) . $this->assignSeparator . $value . ';'; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Strip semi-colon appended by property(); it's a separator, not a terminator |
|
118 | - * |
|
119 | - * @api |
|
120 | - * |
|
121 | - * @param array $lines |
|
122 | - */ |
|
123 | - public function stripSemicolon(&$lines) |
|
124 | - { |
|
125 | - if ($this->keepSemicolons) { |
|
126 | - return; |
|
127 | - } |
|
128 | - |
|
129 | - if (($count = count($lines)) |
|
130 | - && substr($lines[$count - 1], -1) === ';' |
|
131 | - ) { |
|
132 | - $lines[$count - 1] = substr($lines[$count - 1], 0, -1); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Output lines inside a block |
|
138 | - * |
|
139 | - * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
140 | - */ |
|
141 | - protected function blockLines(OutputBlock $block) |
|
142 | - { |
|
143 | - $inner = $this->indentStr(); |
|
144 | - |
|
145 | - $glue = $this->break . $inner; |
|
146 | - |
|
147 | - $this->write($inner . implode($glue, $block->lines)); |
|
148 | - |
|
149 | - if (! empty($block->children)) { |
|
150 | - $this->write($this->break); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Output block selectors |
|
156 | - * |
|
157 | - * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
158 | - */ |
|
159 | - protected function blockSelectors(OutputBlock $block) |
|
160 | - { |
|
161 | - $inner = $this->indentStr(); |
|
162 | - |
|
163 | - $this->write($inner |
|
164 | - . implode($this->tagSeparator, $block->selectors) |
|
165 | - . $this->open . $this->break); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Output block children |
|
170 | - * |
|
171 | - * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
172 | - */ |
|
173 | - protected function blockChildren(OutputBlock $block) |
|
174 | - { |
|
175 | - foreach ($block->children as $child) { |
|
176 | - $this->block($child); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Output non-empty block |
|
182 | - * |
|
183 | - * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
184 | - */ |
|
185 | - protected function block(OutputBlock $block) |
|
186 | - { |
|
187 | - if (empty($block->lines) && empty($block->children)) { |
|
188 | - return; |
|
189 | - } |
|
190 | - |
|
191 | - $this->currentBlock = $block; |
|
192 | - |
|
193 | - $pre = $this->indentStr(); |
|
194 | - |
|
195 | - if (! empty($block->selectors)) { |
|
196 | - $this->blockSelectors($block); |
|
197 | - |
|
198 | - $this->indentLevel++; |
|
199 | - } |
|
200 | - |
|
201 | - if (! empty($block->lines)) { |
|
202 | - $this->blockLines($block); |
|
203 | - } |
|
204 | - |
|
205 | - if (! empty($block->children)) { |
|
206 | - $this->blockChildren($block); |
|
207 | - } |
|
208 | - |
|
209 | - if (! empty($block->selectors)) { |
|
210 | - $this->indentLevel--; |
|
211 | - |
|
212 | - if (empty($block->children)) { |
|
213 | - $this->write($this->break); |
|
214 | - } |
|
215 | - |
|
216 | - $this->write($pre . $this->close . $this->break); |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Entry point to formatting a block |
|
222 | - * |
|
223 | - * @api |
|
224 | - * |
|
225 | - * @param \Leafo\ScssPhp\Formatter\OutputBlock $block An abstract syntax tree |
|
226 | - * @param \Leafo\ScssPhp\SourceMap\SourceMapGenerator|null $sourceMapGenerator Optional source map generator |
|
227 | - * |
|
228 | - * @return string |
|
229 | - */ |
|
230 | - public function format(OutputBlock $block, SourceMapGenerator $sourceMapGenerator = null) |
|
231 | - { |
|
232 | - $this->sourceMapGenerator = null; |
|
233 | - |
|
234 | - if ($sourceMapGenerator) { |
|
235 | - $this->currentLine = 1; |
|
236 | - $this->currentColumn = 0; |
|
237 | - $this->sourceMapGenerator = $sourceMapGenerator; |
|
238 | - } |
|
239 | - |
|
240 | - ob_start(); |
|
241 | - |
|
242 | - $this->block($block); |
|
243 | - |
|
244 | - $out = ob_get_clean(); |
|
245 | - |
|
246 | - return $out; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @param string $str |
|
251 | - */ |
|
252 | - protected function write($str) |
|
253 | - { |
|
254 | - if ($this->sourceMapGenerator) { |
|
255 | - $this->sourceMapGenerator->addMapping( |
|
256 | - $this->currentLine, |
|
257 | - $this->currentColumn, |
|
258 | - $this->currentBlock->sourceLine, |
|
259 | - $this->currentBlock->sourceColumn - 1, //columns from parser are off by one |
|
260 | - $this->currentBlock->sourceName |
|
261 | - ); |
|
262 | - |
|
263 | - $lines = explode("\n", $str); |
|
264 | - $lineCount = count($lines); |
|
265 | - $this->currentLine += $lineCount-1; |
|
266 | - |
|
267 | - $lastLine = array_pop($lines); |
|
268 | - |
|
269 | - $this->currentColumn = ($lineCount === 1 ? $this->currentColumn : 0) + strlen($lastLine); |
|
270 | - } |
|
271 | - |
|
272 | - echo $str; |
|
273 | - } |
|
24 | + /** |
|
25 | + * @var integer |
|
26 | + */ |
|
27 | + public $indentLevel; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + public $indentChar; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + public $break; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + public $open; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + public $close; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $tagSeparator; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $assignSeparator; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var boolean |
|
61 | + */ |
|
62 | + public $keepSemicolons; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var \Leafo\ScssPhp\Formatter\OutputBlock |
|
66 | + */ |
|
67 | + protected $currentBlock; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var integer |
|
71 | + */ |
|
72 | + protected $currentLine; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var integer |
|
76 | + */ |
|
77 | + protected $currentColumn; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var \Leafo\ScssPhp\SourceMap\SourceMapGenerator |
|
81 | + */ |
|
82 | + protected $sourceMapGenerator; |
|
83 | + |
|
84 | + /** |
|
85 | + * Initialize formatter |
|
86 | + * |
|
87 | + * @api |
|
88 | + */ |
|
89 | + abstract public function __construct(); |
|
90 | + |
|
91 | + /** |
|
92 | + * Return indentation (whitespace) |
|
93 | + * |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + protected function indentStr() |
|
97 | + { |
|
98 | + return ''; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Return property assignment |
|
103 | + * |
|
104 | + * @api |
|
105 | + * |
|
106 | + * @param string $name |
|
107 | + * @param mixed $value |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public function property($name, $value) |
|
112 | + { |
|
113 | + return rtrim($name) . $this->assignSeparator . $value . ';'; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Strip semi-colon appended by property(); it's a separator, not a terminator |
|
118 | + * |
|
119 | + * @api |
|
120 | + * |
|
121 | + * @param array $lines |
|
122 | + */ |
|
123 | + public function stripSemicolon(&$lines) |
|
124 | + { |
|
125 | + if ($this->keepSemicolons) { |
|
126 | + return; |
|
127 | + } |
|
128 | + |
|
129 | + if (($count = count($lines)) |
|
130 | + && substr($lines[$count - 1], -1) === ';' |
|
131 | + ) { |
|
132 | + $lines[$count - 1] = substr($lines[$count - 1], 0, -1); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Output lines inside a block |
|
138 | + * |
|
139 | + * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
140 | + */ |
|
141 | + protected function blockLines(OutputBlock $block) |
|
142 | + { |
|
143 | + $inner = $this->indentStr(); |
|
144 | + |
|
145 | + $glue = $this->break . $inner; |
|
146 | + |
|
147 | + $this->write($inner . implode($glue, $block->lines)); |
|
148 | + |
|
149 | + if (! empty($block->children)) { |
|
150 | + $this->write($this->break); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Output block selectors |
|
156 | + * |
|
157 | + * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
158 | + */ |
|
159 | + protected function blockSelectors(OutputBlock $block) |
|
160 | + { |
|
161 | + $inner = $this->indentStr(); |
|
162 | + |
|
163 | + $this->write($inner |
|
164 | + . implode($this->tagSeparator, $block->selectors) |
|
165 | + . $this->open . $this->break); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Output block children |
|
170 | + * |
|
171 | + * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
172 | + */ |
|
173 | + protected function blockChildren(OutputBlock $block) |
|
174 | + { |
|
175 | + foreach ($block->children as $child) { |
|
176 | + $this->block($child); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Output non-empty block |
|
182 | + * |
|
183 | + * @param \Leafo\ScssPhp\Formatter\OutputBlock $block |
|
184 | + */ |
|
185 | + protected function block(OutputBlock $block) |
|
186 | + { |
|
187 | + if (empty($block->lines) && empty($block->children)) { |
|
188 | + return; |
|
189 | + } |
|
190 | + |
|
191 | + $this->currentBlock = $block; |
|
192 | + |
|
193 | + $pre = $this->indentStr(); |
|
194 | + |
|
195 | + if (! empty($block->selectors)) { |
|
196 | + $this->blockSelectors($block); |
|
197 | + |
|
198 | + $this->indentLevel++; |
|
199 | + } |
|
200 | + |
|
201 | + if (! empty($block->lines)) { |
|
202 | + $this->blockLines($block); |
|
203 | + } |
|
204 | + |
|
205 | + if (! empty($block->children)) { |
|
206 | + $this->blockChildren($block); |
|
207 | + } |
|
208 | + |
|
209 | + if (! empty($block->selectors)) { |
|
210 | + $this->indentLevel--; |
|
211 | + |
|
212 | + if (empty($block->children)) { |
|
213 | + $this->write($this->break); |
|
214 | + } |
|
215 | + |
|
216 | + $this->write($pre . $this->close . $this->break); |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Entry point to formatting a block |
|
222 | + * |
|
223 | + * @api |
|
224 | + * |
|
225 | + * @param \Leafo\ScssPhp\Formatter\OutputBlock $block An abstract syntax tree |
|
226 | + * @param \Leafo\ScssPhp\SourceMap\SourceMapGenerator|null $sourceMapGenerator Optional source map generator |
|
227 | + * |
|
228 | + * @return string |
|
229 | + */ |
|
230 | + public function format(OutputBlock $block, SourceMapGenerator $sourceMapGenerator = null) |
|
231 | + { |
|
232 | + $this->sourceMapGenerator = null; |
|
233 | + |
|
234 | + if ($sourceMapGenerator) { |
|
235 | + $this->currentLine = 1; |
|
236 | + $this->currentColumn = 0; |
|
237 | + $this->sourceMapGenerator = $sourceMapGenerator; |
|
238 | + } |
|
239 | + |
|
240 | + ob_start(); |
|
241 | + |
|
242 | + $this->block($block); |
|
243 | + |
|
244 | + $out = ob_get_clean(); |
|
245 | + |
|
246 | + return $out; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @param string $str |
|
251 | + */ |
|
252 | + protected function write($str) |
|
253 | + { |
|
254 | + if ($this->sourceMapGenerator) { |
|
255 | + $this->sourceMapGenerator->addMapping( |
|
256 | + $this->currentLine, |
|
257 | + $this->currentColumn, |
|
258 | + $this->currentBlock->sourceLine, |
|
259 | + $this->currentBlock->sourceColumn - 1, //columns from parser are off by one |
|
260 | + $this->currentBlock->sourceName |
|
261 | + ); |
|
262 | + |
|
263 | + $lines = explode("\n", $str); |
|
264 | + $lineCount = count($lines); |
|
265 | + $this->currentLine += $lineCount-1; |
|
266 | + |
|
267 | + $lastLine = array_pop($lines); |
|
268 | + |
|
269 | + $this->currentColumn = ($lineCount === 1 ? $this->currentColumn : 0) + strlen($lastLine); |
|
270 | + } |
|
271 | + |
|
272 | + echo $str; |
|
273 | + } |
|
274 | 274 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | $this->write($inner . implode($glue, $block->lines)); |
148 | 148 | |
149 | - if (! empty($block->children)) { |
|
149 | + if ( ! empty($block->children)) { |
|
150 | 150 | $this->write($this->break); |
151 | 151 | } |
152 | 152 | } |
@@ -192,21 +192,21 @@ discard block |
||
192 | 192 | |
193 | 193 | $pre = $this->indentStr(); |
194 | 194 | |
195 | - if (! empty($block->selectors)) { |
|
195 | + if ( ! empty($block->selectors)) { |
|
196 | 196 | $this->blockSelectors($block); |
197 | 197 | |
198 | 198 | $this->indentLevel++; |
199 | 199 | } |
200 | 200 | |
201 | - if (! empty($block->lines)) { |
|
201 | + if ( ! empty($block->lines)) { |
|
202 | 202 | $this->blockLines($block); |
203 | 203 | } |
204 | 204 | |
205 | - if (! empty($block->children)) { |
|
205 | + if ( ! empty($block->children)) { |
|
206 | 206 | $this->blockChildren($block); |
207 | 207 | } |
208 | 208 | |
209 | - if (! empty($block->selectors)) { |
|
209 | + if ( ! empty($block->selectors)) { |
|
210 | 210 | $this->indentLevel--; |
211 | 211 | |
212 | 212 | if (empty($block->children)) { |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | $lines = explode("\n", $str); |
264 | 264 | $lineCount = count($lines); |
265 | - $this->currentLine += $lineCount-1; |
|
265 | + $this->currentLine += $lineCount - 1; |
|
266 | 266 | |
267 | 267 | $lastLine = array_pop($lines); |
268 | 268 |
@@ -18,30 +18,30 @@ |
||
18 | 18 | */ |
19 | 19 | class Range |
20 | 20 | { |
21 | - public $first; |
|
22 | - public $last; |
|
21 | + public $first; |
|
22 | + public $last; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Initialize range |
|
26 | - * |
|
27 | - * @param integer|float $first |
|
28 | - * @param integer|float $last |
|
29 | - */ |
|
30 | - public function __construct($first, $last) |
|
31 | - { |
|
32 | - $this->first = $first; |
|
33 | - $this->last = $last; |
|
34 | - } |
|
24 | + /** |
|
25 | + * Initialize range |
|
26 | + * |
|
27 | + * @param integer|float $first |
|
28 | + * @param integer|float $last |
|
29 | + */ |
|
30 | + public function __construct($first, $last) |
|
31 | + { |
|
32 | + $this->first = $first; |
|
33 | + $this->last = $last; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Test for inclusion in range |
|
38 | - * |
|
39 | - * @param integer|float $value |
|
40 | - * |
|
41 | - * @return boolean |
|
42 | - */ |
|
43 | - public function includes($value) |
|
44 | - { |
|
45 | - return $value >= $this->first && $value <= $this->last; |
|
46 | - } |
|
36 | + /** |
|
37 | + * Test for inclusion in range |
|
38 | + * |
|
39 | + * @param integer|float $value |
|
40 | + * |
|
41 | + * @return boolean |
|
42 | + */ |
|
43 | + public function includes($value) |
|
44 | + { |
|
45 | + return $value >= $this->first && $value <= $this->last; |
|
46 | + } |
|
47 | 47 | } |
@@ -21,197 +21,197 @@ |
||
21 | 21 | */ |
22 | 22 | class Base64VLQEncoder |
23 | 23 | { |
24 | - /** |
|
25 | - * Shift |
|
26 | - * |
|
27 | - * @var integer |
|
28 | - */ |
|
29 | - private $shift = 5; |
|
30 | - |
|
31 | - /** |
|
32 | - * Mask |
|
33 | - * |
|
34 | - * @var integer |
|
35 | - */ |
|
36 | - private $mask = 0x1F; // == (1 << shift) == 0b00011111 |
|
37 | - |
|
38 | - /** |
|
39 | - * Continuation bit |
|
40 | - * |
|
41 | - * @var integer |
|
42 | - */ |
|
43 | - private $continuationBit = 0x20; // == (mask - 1 ) == 0b00100000 |
|
44 | - |
|
45 | - /** |
|
46 | - * Char to integer map |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - private $charToIntMap = array( |
|
51 | - 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, |
|
52 | - 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, |
|
53 | - 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, |
|
54 | - 'Y' => 24, 'Z' => 25, 'a' => 26, 'b' => 27, 'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31, |
|
55 | - 'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 'k' => 36, 'l' => 37, 'm' => 38, 'n' => 39, |
|
56 | - 'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, |
|
57 | - 'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55, |
|
58 | - 4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63, |
|
59 | - ); |
|
60 | - |
|
61 | - /** |
|
62 | - * Integer to char map |
|
63 | - * |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - private $intToCharMap = array( |
|
67 | - 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', |
|
68 | - 8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', |
|
69 | - 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', 21 => 'V', 22 => 'W', 23 => 'X', |
|
70 | - 24 => 'Y', 25 => 'Z', 26 => 'a', 27 => 'b', 28 => 'c', 29 => 'd', 30 => 'e', 31 => 'f', |
|
71 | - 32 => 'g', 33 => 'h', 34 => 'i', 35 => 'j', 36 => 'k', 37 => 'l', 38 => 'm', 39 => 'n', |
|
72 | - 40 => 'o', 41 => 'p', 42 => 'q', 43 => 'r', 44 => 's', 45 => 't', 46 => 'u', 47 => 'v', |
|
73 | - 48 => 'w', 49 => 'x', 50 => 'y', 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3', |
|
74 | - 56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', 61 => '9', 62 => '+', 63 => '/', |
|
75 | - ); |
|
76 | - |
|
77 | - /** |
|
78 | - * Constructor |
|
79 | - */ |
|
80 | - public function __construct() |
|
81 | - { |
|
82 | - // I leave it here for future reference |
|
83 | - // foreach (str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') as $i => $char) |
|
84 | - // { |
|
85 | - // $this->charToIntMap[$char] = $i; |
|
86 | - // $this->intToCharMap[$i] = $char; |
|
87 | - // } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Convert from a two-complement value to a value where the sign bit is |
|
92 | - * is placed in the least significant bit. For example, as decimals: |
|
93 | - * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) |
|
94 | - * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) |
|
95 | - * We generate the value for 32 bit machines, hence -2147483648 becomes 1, not 4294967297, |
|
96 | - * even on a 64 bit machine. |
|
97 | - * |
|
98 | - * @param string $aValue |
|
99 | - */ |
|
100 | - public function toVLQSigned($aValue) |
|
101 | - { |
|
102 | - return 0xffffffff & ($aValue < 0 ? ((-$aValue) << 1) + 1 : ($aValue << 1) + 0); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Convert to a two-complement value from a value where the sign bit is |
|
107 | - * is placed in the least significant bit. For example, as decimals: |
|
108 | - * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 |
|
109 | - * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 |
|
110 | - * We assume that the value was generated with a 32 bit machine in mind. |
|
111 | - * Hence |
|
112 | - * 1 becomes -2147483648 |
|
113 | - * even on a 64 bit machine. |
|
114 | - * |
|
115 | - * @param integer $aValue |
|
116 | - */ |
|
117 | - public function fromVLQSigned($aValue) |
|
118 | - { |
|
119 | - return $aValue & 1 ? $this->zeroFill(~$aValue + 2, 1) | (-1 - 0x7fffffff) : $this->zeroFill($aValue, 1); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Return the base 64 VLQ encoded value. |
|
124 | - * |
|
125 | - * @param string $aValue The value to encode |
|
126 | - * |
|
127 | - * @return string The encoded value |
|
128 | - */ |
|
129 | - public function encode($aValue) |
|
130 | - { |
|
131 | - $encoded = ''; |
|
132 | - $vlq = $this->toVLQSigned($aValue); |
|
133 | - |
|
134 | - do { |
|
135 | - $digit = $vlq & $this->mask; |
|
136 | - $vlq = $this->zeroFill($vlq, $this->shift); |
|
137 | - |
|
138 | - if ($vlq > 0) { |
|
139 | - $digit |= $this->continuationBit; |
|
140 | - } |
|
141 | - |
|
142 | - $encoded .= $this->base64Encode($digit); |
|
143 | - } while ($vlq > 0); |
|
144 | - |
|
145 | - return $encoded; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Return the value decoded from base 64 VLQ. |
|
150 | - * |
|
151 | - * @param string $encoded The encoded value to decode |
|
152 | - * |
|
153 | - * @return integer The decoded value |
|
154 | - */ |
|
155 | - public function decode($encoded) |
|
156 | - { |
|
157 | - $vlq = 0; |
|
158 | - $i = 0; |
|
159 | - |
|
160 | - do { |
|
161 | - $digit = $this->base64Decode($encoded[$i]); |
|
162 | - $vlq |= ($digit & $this->mask) << ($i * $this->shift); |
|
163 | - $i++; |
|
164 | - } while ($digit & $this->continuationBit); |
|
165 | - |
|
166 | - return $this->fromVLQSigned($vlq); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Right shift with zero fill. |
|
171 | - * |
|
172 | - * @param integer $a number to shift |
|
173 | - * @param integer $b number of bits to shift |
|
174 | - * |
|
175 | - * @return integer |
|
176 | - */ |
|
177 | - public function zeroFill($a, $b) |
|
178 | - { |
|
179 | - return ($a >= 0) ? ($a >> $b) : ($a >> $b) & (PHP_INT_MAX >> ($b - 1)); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Encode single 6-bit digit as base64. |
|
184 | - * |
|
185 | - * @param integer $number |
|
186 | - * |
|
187 | - * @return string |
|
188 | - * |
|
189 | - * @throws \Exception If the number is invalid |
|
190 | - */ |
|
191 | - public function base64Encode($number) |
|
192 | - { |
|
193 | - if ($number < 0 || $number > 63) { |
|
194 | - throw new \Exception(sprintf('Invalid number "%s" given. Must be between 0 and 63.', $number)); |
|
195 | - } |
|
196 | - |
|
197 | - return $this->intToCharMap[$number]; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Decode single 6-bit digit from base64 |
|
202 | - * |
|
203 | - * @param string $char |
|
204 | - * |
|
205 | - * @return integer |
|
206 | - * |
|
207 | - * @throws \Exception If the number is invalid |
|
208 | - */ |
|
209 | - public function base64Decode($char) |
|
210 | - { |
|
211 | - if (! array_key_exists($char, $this->charToIntMap)) { |
|
212 | - throw new \Exception(sprintf('Invalid base 64 digit "%s" given.', $char)); |
|
213 | - } |
|
214 | - |
|
215 | - return $this->charToIntMap[$char]; |
|
216 | - } |
|
24 | + /** |
|
25 | + * Shift |
|
26 | + * |
|
27 | + * @var integer |
|
28 | + */ |
|
29 | + private $shift = 5; |
|
30 | + |
|
31 | + /** |
|
32 | + * Mask |
|
33 | + * |
|
34 | + * @var integer |
|
35 | + */ |
|
36 | + private $mask = 0x1F; // == (1 << shift) == 0b00011111 |
|
37 | + |
|
38 | + /** |
|
39 | + * Continuation bit |
|
40 | + * |
|
41 | + * @var integer |
|
42 | + */ |
|
43 | + private $continuationBit = 0x20; // == (mask - 1 ) == 0b00100000 |
|
44 | + |
|
45 | + /** |
|
46 | + * Char to integer map |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + private $charToIntMap = array( |
|
51 | + 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, |
|
52 | + 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, |
|
53 | + 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, |
|
54 | + 'Y' => 24, 'Z' => 25, 'a' => 26, 'b' => 27, 'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31, |
|
55 | + 'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 'k' => 36, 'l' => 37, 'm' => 38, 'n' => 39, |
|
56 | + 'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, |
|
57 | + 'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55, |
|
58 | + 4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63, |
|
59 | + ); |
|
60 | + |
|
61 | + /** |
|
62 | + * Integer to char map |
|
63 | + * |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + private $intToCharMap = array( |
|
67 | + 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', |
|
68 | + 8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', |
|
69 | + 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', 21 => 'V', 22 => 'W', 23 => 'X', |
|
70 | + 24 => 'Y', 25 => 'Z', 26 => 'a', 27 => 'b', 28 => 'c', 29 => 'd', 30 => 'e', 31 => 'f', |
|
71 | + 32 => 'g', 33 => 'h', 34 => 'i', 35 => 'j', 36 => 'k', 37 => 'l', 38 => 'm', 39 => 'n', |
|
72 | + 40 => 'o', 41 => 'p', 42 => 'q', 43 => 'r', 44 => 's', 45 => 't', 46 => 'u', 47 => 'v', |
|
73 | + 48 => 'w', 49 => 'x', 50 => 'y', 51 => 'z', 52 => '0', 53 => '1', 54 => '2', 55 => '3', |
|
74 | + 56 => '4', 57 => '5', 58 => '6', 59 => '7', 60 => '8', 61 => '9', 62 => '+', 63 => '/', |
|
75 | + ); |
|
76 | + |
|
77 | + /** |
|
78 | + * Constructor |
|
79 | + */ |
|
80 | + public function __construct() |
|
81 | + { |
|
82 | + // I leave it here for future reference |
|
83 | + // foreach (str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') as $i => $char) |
|
84 | + // { |
|
85 | + // $this->charToIntMap[$char] = $i; |
|
86 | + // $this->intToCharMap[$i] = $char; |
|
87 | + // } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Convert from a two-complement value to a value where the sign bit is |
|
92 | + * is placed in the least significant bit. For example, as decimals: |
|
93 | + * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) |
|
94 | + * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) |
|
95 | + * We generate the value for 32 bit machines, hence -2147483648 becomes 1, not 4294967297, |
|
96 | + * even on a 64 bit machine. |
|
97 | + * |
|
98 | + * @param string $aValue |
|
99 | + */ |
|
100 | + public function toVLQSigned($aValue) |
|
101 | + { |
|
102 | + return 0xffffffff & ($aValue < 0 ? ((-$aValue) << 1) + 1 : ($aValue << 1) + 0); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Convert to a two-complement value from a value where the sign bit is |
|
107 | + * is placed in the least significant bit. For example, as decimals: |
|
108 | + * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 |
|
109 | + * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 |
|
110 | + * We assume that the value was generated with a 32 bit machine in mind. |
|
111 | + * Hence |
|
112 | + * 1 becomes -2147483648 |
|
113 | + * even on a 64 bit machine. |
|
114 | + * |
|
115 | + * @param integer $aValue |
|
116 | + */ |
|
117 | + public function fromVLQSigned($aValue) |
|
118 | + { |
|
119 | + return $aValue & 1 ? $this->zeroFill(~$aValue + 2, 1) | (-1 - 0x7fffffff) : $this->zeroFill($aValue, 1); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Return the base 64 VLQ encoded value. |
|
124 | + * |
|
125 | + * @param string $aValue The value to encode |
|
126 | + * |
|
127 | + * @return string The encoded value |
|
128 | + */ |
|
129 | + public function encode($aValue) |
|
130 | + { |
|
131 | + $encoded = ''; |
|
132 | + $vlq = $this->toVLQSigned($aValue); |
|
133 | + |
|
134 | + do { |
|
135 | + $digit = $vlq & $this->mask; |
|
136 | + $vlq = $this->zeroFill($vlq, $this->shift); |
|
137 | + |
|
138 | + if ($vlq > 0) { |
|
139 | + $digit |= $this->continuationBit; |
|
140 | + } |
|
141 | + |
|
142 | + $encoded .= $this->base64Encode($digit); |
|
143 | + } while ($vlq > 0); |
|
144 | + |
|
145 | + return $encoded; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Return the value decoded from base 64 VLQ. |
|
150 | + * |
|
151 | + * @param string $encoded The encoded value to decode |
|
152 | + * |
|
153 | + * @return integer The decoded value |
|
154 | + */ |
|
155 | + public function decode($encoded) |
|
156 | + { |
|
157 | + $vlq = 0; |
|
158 | + $i = 0; |
|
159 | + |
|
160 | + do { |
|
161 | + $digit = $this->base64Decode($encoded[$i]); |
|
162 | + $vlq |= ($digit & $this->mask) << ($i * $this->shift); |
|
163 | + $i++; |
|
164 | + } while ($digit & $this->continuationBit); |
|
165 | + |
|
166 | + return $this->fromVLQSigned($vlq); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Right shift with zero fill. |
|
171 | + * |
|
172 | + * @param integer $a number to shift |
|
173 | + * @param integer $b number of bits to shift |
|
174 | + * |
|
175 | + * @return integer |
|
176 | + */ |
|
177 | + public function zeroFill($a, $b) |
|
178 | + { |
|
179 | + return ($a >= 0) ? ($a >> $b) : ($a >> $b) & (PHP_INT_MAX >> ($b - 1)); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Encode single 6-bit digit as base64. |
|
184 | + * |
|
185 | + * @param integer $number |
|
186 | + * |
|
187 | + * @return string |
|
188 | + * |
|
189 | + * @throws \Exception If the number is invalid |
|
190 | + */ |
|
191 | + public function base64Encode($number) |
|
192 | + { |
|
193 | + if ($number < 0 || $number > 63) { |
|
194 | + throw new \Exception(sprintf('Invalid number "%s" given. Must be between 0 and 63.', $number)); |
|
195 | + } |
|
196 | + |
|
197 | + return $this->intToCharMap[$number]; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Decode single 6-bit digit from base64 |
|
202 | + * |
|
203 | + * @param string $char |
|
204 | + * |
|
205 | + * @return integer |
|
206 | + * |
|
207 | + * @throws \Exception If the number is invalid |
|
208 | + */ |
|
209 | + public function base64Decode($char) |
|
210 | + { |
|
211 | + if (! array_key_exists($char, $this->charToIntMap)) { |
|
212 | + throw new \Exception(sprintf('Invalid base 64 digit "%s" given.', $char)); |
|
213 | + } |
|
214 | + |
|
215 | + return $this->charToIntMap[$char]; |
|
216 | + } |
|
217 | 217 | } |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | * @var array |
49 | 49 | */ |
50 | 50 | private $charToIntMap = array( |
51 | - 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, |
|
52 | - 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, |
|
51 | + 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, |
|
52 | + 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, |
|
53 | 53 | 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, |
54 | 54 | 'Y' => 24, 'Z' => 25, 'a' => 26, 'b' => 27, 'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31, |
55 | 55 | 'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 'k' => 36, 'l' => 37, 'm' => 38, 'n' => 39, |
56 | 56 | 'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, |
57 | - 'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55, |
|
58 | - 4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63, |
|
57 | + 'w' => 48, 'x' => 49, 'y' => 50, 'z' => 51, 0 => 52, 1 => 53, 2 => 54, 3 => 55, |
|
58 | + 4 => 56, 5 => 57, 6 => 58, 7 => 59, 8 => 60, 9 => 61, '+' => 62, '/' => 63, |
|
59 | 59 | ); |
60 | 60 | |
61 | 61 | /** |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * @var array |
65 | 65 | */ |
66 | 66 | private $intToCharMap = array( |
67 | - 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', |
|
68 | - 8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', |
|
67 | + 0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D', 4 => 'E', 5 => 'F', 6 => 'G', 7 => 'H', |
|
68 | + 8 => 'I', 9 => 'J', 10 => 'K', 11 => 'L', 12 => 'M', 13 => 'N', 14 => 'O', 15 => 'P', |
|
69 | 69 | 16 => 'Q', 17 => 'R', 18 => 'S', 19 => 'T', 20 => 'U', 21 => 'V', 22 => 'W', 23 => 'X', |
70 | 70 | 24 => 'Y', 25 => 'Z', 26 => 'a', 27 => 'b', 28 => 'c', 29 => 'd', 30 => 'e', 31 => 'f', |
71 | 71 | 32 => 'g', 33 => 'h', 34 => 'i', 35 => 'j', 36 => 'k', 37 => 'l', 38 => 'm', 39 => 'n', |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function base64Decode($char) |
210 | 210 | { |
211 | - if (! array_key_exists($char, $this->charToIntMap)) { |
|
211 | + if ( ! array_key_exists($char, $this->charToIntMap)) { |
|
212 | 212 | throw new \Exception(sprintf('Invalid base 64 digit "%s" given.', $char)); |
213 | 213 | } |
214 | 214 |
@@ -23,315 +23,315 @@ |
||
23 | 23 | */ |
24 | 24 | class SourceMapGenerator |
25 | 25 | { |
26 | - /** |
|
27 | - * What version of source map does the generator generate? |
|
28 | - */ |
|
29 | - const VERSION = 3; |
|
30 | - |
|
31 | - /** |
|
32 | - * Array of default options |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $defaultOptions = array( |
|
37 | - // an optional source root, useful for relocating source files |
|
38 | - // on a server or removing repeated values in the 'sources' entry. |
|
39 | - // This value is prepended to the individual entries in the 'source' field. |
|
40 | - 'sourceRoot' => '', |
|
41 | - |
|
42 | - // an optional name of the generated code that this source map is associated with. |
|
43 | - 'sourceMapFilename' => null, |
|
44 | - |
|
45 | - // url of the map |
|
46 | - 'sourceMapURL' => null, |
|
47 | - |
|
48 | - // absolute path to a file to write the map to |
|
49 | - 'sourceMapWriteTo' => null, |
|
50 | - |
|
51 | - // output source contents? |
|
52 | - 'outputSourceFiles' => false, |
|
53 | - |
|
54 | - // base path for filename normalization |
|
55 | - 'sourceMapRootpath' => '', |
|
56 | - |
|
57 | - // base path for filename normalization |
|
58 | - 'sourceMapBasepath' => '' |
|
59 | - ); |
|
60 | - |
|
61 | - /** |
|
62 | - * The base64 VLQ encoder |
|
63 | - * |
|
64 | - * @var \Leafo\ScssPhp\SourceMap\Base64VLQEncoder |
|
65 | - */ |
|
66 | - protected $encoder; |
|
67 | - |
|
68 | - /** |
|
69 | - * Array of mappings |
|
70 | - * |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - protected $mappings = array(); |
|
74 | - |
|
75 | - /** |
|
76 | - * Array of contents map |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - protected $contentsMap = array(); |
|
81 | - |
|
82 | - /** |
|
83 | - * File to content map |
|
84 | - * |
|
85 | - * @var array |
|
86 | - */ |
|
87 | - protected $sources = array(); |
|
88 | - protected $source_keys = array(); |
|
89 | - |
|
90 | - /** |
|
91 | - * @var array |
|
92 | - */ |
|
93 | - private $options; |
|
94 | - |
|
95 | - public function __construct(array $options = []) |
|
96 | - { |
|
97 | - $this->options = array_merge($this->defaultOptions, $options); |
|
98 | - $this->encoder = new Base64VLQEncoder(); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Adds a mapping |
|
103 | - * |
|
104 | - * @param integer $generatedLine The line number in generated file |
|
105 | - * @param integer $generatedColumn The column number in generated file |
|
106 | - * @param integer $originalLine The line number in original file |
|
107 | - * @param integer $originalColumn The column number in original file |
|
108 | - * @param string $sourceFile The original source file |
|
109 | - */ |
|
110 | - public function addMapping($generatedLine, $generatedColumn, $originalLine, $originalColumn, $sourceFile) |
|
111 | - { |
|
112 | - $this->mappings[] = array( |
|
113 | - 'generated_line' => $generatedLine, |
|
114 | - 'generated_column' => $generatedColumn, |
|
115 | - 'original_line' => $originalLine, |
|
116 | - 'original_column' => $originalColumn, |
|
117 | - 'source_file' => $sourceFile |
|
118 | - ); |
|
119 | - |
|
120 | - $this->sources[$sourceFile] = $sourceFile; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Saves the source map to a file |
|
125 | - * |
|
126 | - * @param string $file The absolute path to a file |
|
127 | - * @param string $content The content to write |
|
128 | - * |
|
129 | - * @throws \Leafo\ScssPhp\Exception\CompilerException If the file could not be saved |
|
130 | - */ |
|
131 | - public function saveMap($content) |
|
132 | - { |
|
133 | - $file = $this->options['sourceMapWriteTo']; |
|
134 | - $dir = dirname($file); |
|
135 | - |
|
136 | - // directory does not exist |
|
137 | - if (! is_dir($dir)) { |
|
138 | - // FIXME: create the dir automatically? |
|
139 | - throw new CompilerException(sprintf('The directory "%s" does not exist. Cannot save the source map.', $dir)); |
|
140 | - } |
|
141 | - |
|
142 | - // FIXME: proper saving, with dir write check! |
|
143 | - if (file_put_contents($file, $content) === false) { |
|
144 | - throw new CompilerException(sprintf('Cannot save the source map to "%s"', $file)); |
|
145 | - } |
|
146 | - |
|
147 | - return $this->options['sourceMapURL']; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Generates the JSON source map |
|
152 | - * |
|
153 | - * @return string |
|
154 | - * |
|
155 | - * @see https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit# |
|
156 | - */ |
|
157 | - public function generateJson() |
|
158 | - { |
|
159 | - $sourceMap = array(); |
|
160 | - $mappings = $this->generateMappings(); |
|
161 | - |
|
162 | - // File version (always the first entry in the object) and must be a positive integer. |
|
163 | - $sourceMap['version'] = self::VERSION; |
|
164 | - |
|
165 | - // An optional name of the generated code that this source map is associated with. |
|
166 | - $file = $this->options['sourceMapFilename']; |
|
167 | - |
|
168 | - if ($file) { |
|
169 | - $sourceMap['file'] = $file; |
|
170 | - } |
|
171 | - |
|
172 | - // An optional source root, useful for relocating source files on a server or removing repeated values in the |
|
173 | - // 'sources' entry. This value is prepended to the individual entries in the 'source' field. |
|
174 | - $root = $this->options['sourceRoot']; |
|
175 | - |
|
176 | - if ($root) { |
|
177 | - $sourceMap['sourceRoot'] = $root; |
|
178 | - } |
|
179 | - |
|
180 | - // A list of original sources used by the 'mappings' entry. |
|
181 | - $sourceMap['sources'] = array(); |
|
182 | - |
|
183 | - foreach ($this->sources as $source_uri => $source_filename) { |
|
184 | - $sourceMap['sources'][] = $this->normalizeFilename($source_filename); |
|
185 | - } |
|
186 | - |
|
187 | - // A list of symbol names used by the 'mappings' entry. |
|
188 | - $sourceMap['names'] = array(); |
|
189 | - |
|
190 | - // A string with the encoded mapping data. |
|
191 | - $sourceMap['mappings'] = $mappings; |
|
192 | - |
|
193 | - if ($this->options['outputSourceFiles']) { |
|
194 | - // An optional list of source content, useful when the 'source' can't be hosted. |
|
195 | - // The contents are listed in the same order as the sources above. |
|
196 | - // 'null' may be used if some original sources should be retrieved by name. |
|
197 | - $sourceMap['sourcesContent'] = $this->getSourcesContent(); |
|
198 | - } |
|
199 | - |
|
200 | - // less.js compat fixes |
|
201 | - if (count($sourceMap['sources']) && empty($sourceMap['sourceRoot'])) { |
|
202 | - unset($sourceMap['sourceRoot']); |
|
203 | - } |
|
204 | - |
|
205 | - return json_encode($sourceMap); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Returns the sources contents |
|
210 | - * |
|
211 | - * @return array|null |
|
212 | - */ |
|
213 | - protected function getSourcesContent() |
|
214 | - { |
|
215 | - if (empty($this->sources)) { |
|
216 | - return null; |
|
217 | - } |
|
218 | - |
|
219 | - $content = array(); |
|
220 | - |
|
221 | - foreach ($this->sources as $sourceFile) { |
|
222 | - $content[] = file_get_contents($sourceFile); |
|
223 | - } |
|
224 | - |
|
225 | - return $content; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Generates the mappings string |
|
230 | - * |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function generateMappings() |
|
234 | - { |
|
235 | - if (! count($this->mappings)) { |
|
236 | - return ''; |
|
237 | - } |
|
238 | - |
|
239 | - $this->source_keys = array_flip(array_keys($this->sources)); |
|
240 | - |
|
241 | - // group mappings by generated line number. |
|
242 | - $groupedMap = $groupedMapEncoded = array(); |
|
243 | - |
|
244 | - foreach ($this->mappings as $m) { |
|
245 | - $groupedMap[$m['generated_line']][] = $m; |
|
246 | - } |
|
247 | - |
|
248 | - ksort($groupedMap); |
|
249 | - $lastGeneratedLine = $lastOriginalIndex = $lastOriginalLine = $lastOriginalColumn = 0; |
|
250 | - |
|
251 | - foreach ($groupedMap as $lineNumber => $line_map) { |
|
252 | - while (++$lastGeneratedLine < $lineNumber) { |
|
253 | - $groupedMapEncoded[] = ';'; |
|
254 | - } |
|
255 | - |
|
256 | - $lineMapEncoded = array(); |
|
257 | - $lastGeneratedColumn = 0; |
|
258 | - |
|
259 | - foreach ($line_map as $m) { |
|
260 | - $mapEncoded = $this->encoder->encode($m['generated_column'] - $lastGeneratedColumn); |
|
261 | - $lastGeneratedColumn = $m['generated_column']; |
|
262 | - |
|
263 | - // find the index |
|
264 | - if ($m['source_file']) { |
|
265 | - $index = $this->findFileIndex($m['source_file']); |
|
266 | - |
|
267 | - if ($index !== false) { |
|
268 | - $mapEncoded .= $this->encoder->encode($index - $lastOriginalIndex); |
|
269 | - $lastOriginalIndex = $index; |
|
270 | - // lines are stored 0-based in SourceMap spec version 3 |
|
271 | - $mapEncoded .= $this->encoder->encode($m['original_line'] - 1 - $lastOriginalLine); |
|
272 | - $lastOriginalLine = $m['original_line'] - 1; |
|
273 | - $mapEncoded .= $this->encoder->encode($m['original_column'] - $lastOriginalColumn); |
|
274 | - $lastOriginalColumn = $m['original_column']; |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - $lineMapEncoded[] = $mapEncoded; |
|
279 | - } |
|
280 | - |
|
281 | - $groupedMapEncoded[] = implode(',', $lineMapEncoded) . ';'; |
|
282 | - } |
|
283 | - |
|
284 | - return rtrim(implode($groupedMapEncoded), ';'); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Finds the index for the filename |
|
289 | - * |
|
290 | - * @param string $filename |
|
291 | - * |
|
292 | - * @return integer|false |
|
293 | - */ |
|
294 | - protected function findFileIndex($filename) |
|
295 | - { |
|
296 | - return $this->source_keys[$filename]; |
|
297 | - } |
|
298 | - |
|
299 | - protected function normalizeFilename($filename) |
|
300 | - { |
|
301 | - $filename = $this->fixWindowsPath($filename); |
|
302 | - $rootpath = $this->options['sourceMapRootpath']; |
|
303 | - $basePath = $this->options['sourceMapBasepath']; |
|
304 | - |
|
305 | - // "Trim" the 'sourceMapBasepath' from the output filename. |
|
306 | - if (strpos($filename, $basePath) === 0) { |
|
307 | - $filename = substr($filename, strlen($basePath)); |
|
308 | - } |
|
309 | - |
|
310 | - // Remove extra leading path separators. |
|
311 | - if (strpos($filename, '\\') === 0 || strpos($filename, '/') === 0) { |
|
312 | - $filename = substr($filename, 1); |
|
313 | - } |
|
314 | - |
|
315 | - return $rootpath . $filename; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Fix windows paths |
|
320 | - * |
|
321 | - * @param string $path |
|
322 | - * @param boolean $addEndSlash |
|
323 | - * |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function fixWindowsPath($path, $addEndSlash = false) |
|
327 | - { |
|
328 | - $slash = ($addEndSlash) ? '/' : ''; |
|
329 | - |
|
330 | - if (! empty($path)) { |
|
331 | - $path = str_replace('\\', '/', $path); |
|
332 | - $path = rtrim($path, '/') . $slash; |
|
333 | - } |
|
334 | - |
|
335 | - return $path; |
|
336 | - } |
|
26 | + /** |
|
27 | + * What version of source map does the generator generate? |
|
28 | + */ |
|
29 | + const VERSION = 3; |
|
30 | + |
|
31 | + /** |
|
32 | + * Array of default options |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $defaultOptions = array( |
|
37 | + // an optional source root, useful for relocating source files |
|
38 | + // on a server or removing repeated values in the 'sources' entry. |
|
39 | + // This value is prepended to the individual entries in the 'source' field. |
|
40 | + 'sourceRoot' => '', |
|
41 | + |
|
42 | + // an optional name of the generated code that this source map is associated with. |
|
43 | + 'sourceMapFilename' => null, |
|
44 | + |
|
45 | + // url of the map |
|
46 | + 'sourceMapURL' => null, |
|
47 | + |
|
48 | + // absolute path to a file to write the map to |
|
49 | + 'sourceMapWriteTo' => null, |
|
50 | + |
|
51 | + // output source contents? |
|
52 | + 'outputSourceFiles' => false, |
|
53 | + |
|
54 | + // base path for filename normalization |
|
55 | + 'sourceMapRootpath' => '', |
|
56 | + |
|
57 | + // base path for filename normalization |
|
58 | + 'sourceMapBasepath' => '' |
|
59 | + ); |
|
60 | + |
|
61 | + /** |
|
62 | + * The base64 VLQ encoder |
|
63 | + * |
|
64 | + * @var \Leafo\ScssPhp\SourceMap\Base64VLQEncoder |
|
65 | + */ |
|
66 | + protected $encoder; |
|
67 | + |
|
68 | + /** |
|
69 | + * Array of mappings |
|
70 | + * |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + protected $mappings = array(); |
|
74 | + |
|
75 | + /** |
|
76 | + * Array of contents map |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $contentsMap = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * File to content map |
|
84 | + * |
|
85 | + * @var array |
|
86 | + */ |
|
87 | + protected $sources = array(); |
|
88 | + protected $source_keys = array(); |
|
89 | + |
|
90 | + /** |
|
91 | + * @var array |
|
92 | + */ |
|
93 | + private $options; |
|
94 | + |
|
95 | + public function __construct(array $options = []) |
|
96 | + { |
|
97 | + $this->options = array_merge($this->defaultOptions, $options); |
|
98 | + $this->encoder = new Base64VLQEncoder(); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Adds a mapping |
|
103 | + * |
|
104 | + * @param integer $generatedLine The line number in generated file |
|
105 | + * @param integer $generatedColumn The column number in generated file |
|
106 | + * @param integer $originalLine The line number in original file |
|
107 | + * @param integer $originalColumn The column number in original file |
|
108 | + * @param string $sourceFile The original source file |
|
109 | + */ |
|
110 | + public function addMapping($generatedLine, $generatedColumn, $originalLine, $originalColumn, $sourceFile) |
|
111 | + { |
|
112 | + $this->mappings[] = array( |
|
113 | + 'generated_line' => $generatedLine, |
|
114 | + 'generated_column' => $generatedColumn, |
|
115 | + 'original_line' => $originalLine, |
|
116 | + 'original_column' => $originalColumn, |
|
117 | + 'source_file' => $sourceFile |
|
118 | + ); |
|
119 | + |
|
120 | + $this->sources[$sourceFile] = $sourceFile; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Saves the source map to a file |
|
125 | + * |
|
126 | + * @param string $file The absolute path to a file |
|
127 | + * @param string $content The content to write |
|
128 | + * |
|
129 | + * @throws \Leafo\ScssPhp\Exception\CompilerException If the file could not be saved |
|
130 | + */ |
|
131 | + public function saveMap($content) |
|
132 | + { |
|
133 | + $file = $this->options['sourceMapWriteTo']; |
|
134 | + $dir = dirname($file); |
|
135 | + |
|
136 | + // directory does not exist |
|
137 | + if (! is_dir($dir)) { |
|
138 | + // FIXME: create the dir automatically? |
|
139 | + throw new CompilerException(sprintf('The directory "%s" does not exist. Cannot save the source map.', $dir)); |
|
140 | + } |
|
141 | + |
|
142 | + // FIXME: proper saving, with dir write check! |
|
143 | + if (file_put_contents($file, $content) === false) { |
|
144 | + throw new CompilerException(sprintf('Cannot save the source map to "%s"', $file)); |
|
145 | + } |
|
146 | + |
|
147 | + return $this->options['sourceMapURL']; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Generates the JSON source map |
|
152 | + * |
|
153 | + * @return string |
|
154 | + * |
|
155 | + * @see https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit# |
|
156 | + */ |
|
157 | + public function generateJson() |
|
158 | + { |
|
159 | + $sourceMap = array(); |
|
160 | + $mappings = $this->generateMappings(); |
|
161 | + |
|
162 | + // File version (always the first entry in the object) and must be a positive integer. |
|
163 | + $sourceMap['version'] = self::VERSION; |
|
164 | + |
|
165 | + // An optional name of the generated code that this source map is associated with. |
|
166 | + $file = $this->options['sourceMapFilename']; |
|
167 | + |
|
168 | + if ($file) { |
|
169 | + $sourceMap['file'] = $file; |
|
170 | + } |
|
171 | + |
|
172 | + // An optional source root, useful for relocating source files on a server or removing repeated values in the |
|
173 | + // 'sources' entry. This value is prepended to the individual entries in the 'source' field. |
|
174 | + $root = $this->options['sourceRoot']; |
|
175 | + |
|
176 | + if ($root) { |
|
177 | + $sourceMap['sourceRoot'] = $root; |
|
178 | + } |
|
179 | + |
|
180 | + // A list of original sources used by the 'mappings' entry. |
|
181 | + $sourceMap['sources'] = array(); |
|
182 | + |
|
183 | + foreach ($this->sources as $source_uri => $source_filename) { |
|
184 | + $sourceMap['sources'][] = $this->normalizeFilename($source_filename); |
|
185 | + } |
|
186 | + |
|
187 | + // A list of symbol names used by the 'mappings' entry. |
|
188 | + $sourceMap['names'] = array(); |
|
189 | + |
|
190 | + // A string with the encoded mapping data. |
|
191 | + $sourceMap['mappings'] = $mappings; |
|
192 | + |
|
193 | + if ($this->options['outputSourceFiles']) { |
|
194 | + // An optional list of source content, useful when the 'source' can't be hosted. |
|
195 | + // The contents are listed in the same order as the sources above. |
|
196 | + // 'null' may be used if some original sources should be retrieved by name. |
|
197 | + $sourceMap['sourcesContent'] = $this->getSourcesContent(); |
|
198 | + } |
|
199 | + |
|
200 | + // less.js compat fixes |
|
201 | + if (count($sourceMap['sources']) && empty($sourceMap['sourceRoot'])) { |
|
202 | + unset($sourceMap['sourceRoot']); |
|
203 | + } |
|
204 | + |
|
205 | + return json_encode($sourceMap); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Returns the sources contents |
|
210 | + * |
|
211 | + * @return array|null |
|
212 | + */ |
|
213 | + protected function getSourcesContent() |
|
214 | + { |
|
215 | + if (empty($this->sources)) { |
|
216 | + return null; |
|
217 | + } |
|
218 | + |
|
219 | + $content = array(); |
|
220 | + |
|
221 | + foreach ($this->sources as $sourceFile) { |
|
222 | + $content[] = file_get_contents($sourceFile); |
|
223 | + } |
|
224 | + |
|
225 | + return $content; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Generates the mappings string |
|
230 | + * |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function generateMappings() |
|
234 | + { |
|
235 | + if (! count($this->mappings)) { |
|
236 | + return ''; |
|
237 | + } |
|
238 | + |
|
239 | + $this->source_keys = array_flip(array_keys($this->sources)); |
|
240 | + |
|
241 | + // group mappings by generated line number. |
|
242 | + $groupedMap = $groupedMapEncoded = array(); |
|
243 | + |
|
244 | + foreach ($this->mappings as $m) { |
|
245 | + $groupedMap[$m['generated_line']][] = $m; |
|
246 | + } |
|
247 | + |
|
248 | + ksort($groupedMap); |
|
249 | + $lastGeneratedLine = $lastOriginalIndex = $lastOriginalLine = $lastOriginalColumn = 0; |
|
250 | + |
|
251 | + foreach ($groupedMap as $lineNumber => $line_map) { |
|
252 | + while (++$lastGeneratedLine < $lineNumber) { |
|
253 | + $groupedMapEncoded[] = ';'; |
|
254 | + } |
|
255 | + |
|
256 | + $lineMapEncoded = array(); |
|
257 | + $lastGeneratedColumn = 0; |
|
258 | + |
|
259 | + foreach ($line_map as $m) { |
|
260 | + $mapEncoded = $this->encoder->encode($m['generated_column'] - $lastGeneratedColumn); |
|
261 | + $lastGeneratedColumn = $m['generated_column']; |
|
262 | + |
|
263 | + // find the index |
|
264 | + if ($m['source_file']) { |
|
265 | + $index = $this->findFileIndex($m['source_file']); |
|
266 | + |
|
267 | + if ($index !== false) { |
|
268 | + $mapEncoded .= $this->encoder->encode($index - $lastOriginalIndex); |
|
269 | + $lastOriginalIndex = $index; |
|
270 | + // lines are stored 0-based in SourceMap spec version 3 |
|
271 | + $mapEncoded .= $this->encoder->encode($m['original_line'] - 1 - $lastOriginalLine); |
|
272 | + $lastOriginalLine = $m['original_line'] - 1; |
|
273 | + $mapEncoded .= $this->encoder->encode($m['original_column'] - $lastOriginalColumn); |
|
274 | + $lastOriginalColumn = $m['original_column']; |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + $lineMapEncoded[] = $mapEncoded; |
|
279 | + } |
|
280 | + |
|
281 | + $groupedMapEncoded[] = implode(',', $lineMapEncoded) . ';'; |
|
282 | + } |
|
283 | + |
|
284 | + return rtrim(implode($groupedMapEncoded), ';'); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Finds the index for the filename |
|
289 | + * |
|
290 | + * @param string $filename |
|
291 | + * |
|
292 | + * @return integer|false |
|
293 | + */ |
|
294 | + protected function findFileIndex($filename) |
|
295 | + { |
|
296 | + return $this->source_keys[$filename]; |
|
297 | + } |
|
298 | + |
|
299 | + protected function normalizeFilename($filename) |
|
300 | + { |
|
301 | + $filename = $this->fixWindowsPath($filename); |
|
302 | + $rootpath = $this->options['sourceMapRootpath']; |
|
303 | + $basePath = $this->options['sourceMapBasepath']; |
|
304 | + |
|
305 | + // "Trim" the 'sourceMapBasepath' from the output filename. |
|
306 | + if (strpos($filename, $basePath) === 0) { |
|
307 | + $filename = substr($filename, strlen($basePath)); |
|
308 | + } |
|
309 | + |
|
310 | + // Remove extra leading path separators. |
|
311 | + if (strpos($filename, '\\') === 0 || strpos($filename, '/') === 0) { |
|
312 | + $filename = substr($filename, 1); |
|
313 | + } |
|
314 | + |
|
315 | + return $rootpath . $filename; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Fix windows paths |
|
320 | + * |
|
321 | + * @param string $path |
|
322 | + * @param boolean $addEndSlash |
|
323 | + * |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function fixWindowsPath($path, $addEndSlash = false) |
|
327 | + { |
|
328 | + $slash = ($addEndSlash) ? '/' : ''; |
|
329 | + |
|
330 | + if (! empty($path)) { |
|
331 | + $path = str_replace('\\', '/', $path); |
|
332 | + $path = rtrim($path, '/') . $slash; |
|
333 | + } |
|
334 | + |
|
335 | + return $path; |
|
336 | + } |
|
337 | 337 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $dir = dirname($file); |
135 | 135 | |
136 | 136 | // directory does not exist |
137 | - if (! is_dir($dir)) { |
|
137 | + if ( ! is_dir($dir)) { |
|
138 | 138 | // FIXME: create the dir automatically? |
139 | 139 | throw new CompilerException(sprintf('The directory "%s" does not exist. Cannot save the source map.', $dir)); |
140 | 140 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function generateMappings() |
234 | 234 | { |
235 | - if (! count($this->mappings)) { |
|
235 | + if ( ! count($this->mappings)) { |
|
236 | 236 | return ''; |
237 | 237 | } |
238 | 238 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | { |
328 | 328 | $slash = ($addEndSlash) ? '/' : ''; |
329 | 329 | |
330 | - if (! empty($path)) { |
|
330 | + if ( ! empty($path)) { |
|
331 | 331 | $path = str_replace('\\', '/', $path); |
332 | 332 | $path = rtrim($path, '/') . $slash; |
333 | 333 | } |
@@ -18,52 +18,52 @@ |
||
18 | 18 | */ |
19 | 19 | class Type |
20 | 20 | { |
21 | - const T_ASSIGN = 'assign'; |
|
22 | - const T_AT_ROOT = 'at-root'; |
|
23 | - const T_BLOCK = 'block'; |
|
24 | - const T_BREAK = 'break'; |
|
25 | - const T_CHARSET = 'charset'; |
|
26 | - const T_COLOR = 'color'; |
|
27 | - const T_COMMENT = 'comment'; |
|
28 | - const T_CONTINUE = 'continue'; |
|
29 | - const T_CONTROL = 'control'; |
|
30 | - const T_DEBUG = 'debug'; |
|
31 | - const T_DIRECTIVE = 'directive'; |
|
32 | - const T_EACH = 'each'; |
|
33 | - const T_ELSE = 'else'; |
|
34 | - const T_ELSEIF = 'elseif'; |
|
35 | - const T_ERROR = 'error'; |
|
36 | - const T_EXPRESSION = 'exp'; |
|
37 | - const T_EXTEND = 'extend'; |
|
38 | - const T_FOR = 'for'; |
|
39 | - const T_FUNCTION = 'function'; |
|
40 | - const T_FUNCTION_CALL = 'fncall'; |
|
41 | - const T_HSL = 'hsl'; |
|
42 | - const T_IF = 'if'; |
|
43 | - const T_IMPORT = 'import'; |
|
44 | - const T_INCLUDE = 'include'; |
|
45 | - const T_INTERPOLATE = 'interpolate'; |
|
46 | - const T_INTERPOLATED = 'interpolated'; |
|
47 | - const T_KEYWORD = 'keyword'; |
|
48 | - const T_LIST = 'list'; |
|
49 | - const T_MAP = 'map'; |
|
50 | - const T_MEDIA = 'media'; |
|
51 | - const T_MEDIA_EXPRESSION = 'mediaExp'; |
|
52 | - const T_MEDIA_TYPE = 'mediaType'; |
|
53 | - const T_MEDIA_VALUE = 'mediaValue'; |
|
54 | - const T_MIXIN = 'mixin'; |
|
55 | - const T_MIXIN_CONTENT = 'mixin_content'; |
|
56 | - const T_NESTED_PROPERTY = 'nestedprop'; |
|
57 | - const T_NOT = 'not'; |
|
58 | - const T_NULL = 'null'; |
|
59 | - const T_NUMBER = 'number'; |
|
60 | - const T_RETURN = 'return'; |
|
61 | - const T_ROOT = 'root'; |
|
62 | - const T_SCSSPHP_IMPORT_ONCE = 'scssphp-import-once'; |
|
63 | - const T_SELF = 'self'; |
|
64 | - const T_STRING = 'string'; |
|
65 | - const T_UNARY = 'unary'; |
|
66 | - const T_VARIABLE = 'var'; |
|
67 | - const T_WARN = 'warn'; |
|
68 | - const T_WHILE = 'while'; |
|
21 | + const T_ASSIGN = 'assign'; |
|
22 | + const T_AT_ROOT = 'at-root'; |
|
23 | + const T_BLOCK = 'block'; |
|
24 | + const T_BREAK = 'break'; |
|
25 | + const T_CHARSET = 'charset'; |
|
26 | + const T_COLOR = 'color'; |
|
27 | + const T_COMMENT = 'comment'; |
|
28 | + const T_CONTINUE = 'continue'; |
|
29 | + const T_CONTROL = 'control'; |
|
30 | + const T_DEBUG = 'debug'; |
|
31 | + const T_DIRECTIVE = 'directive'; |
|
32 | + const T_EACH = 'each'; |
|
33 | + const T_ELSE = 'else'; |
|
34 | + const T_ELSEIF = 'elseif'; |
|
35 | + const T_ERROR = 'error'; |
|
36 | + const T_EXPRESSION = 'exp'; |
|
37 | + const T_EXTEND = 'extend'; |
|
38 | + const T_FOR = 'for'; |
|
39 | + const T_FUNCTION = 'function'; |
|
40 | + const T_FUNCTION_CALL = 'fncall'; |
|
41 | + const T_HSL = 'hsl'; |
|
42 | + const T_IF = 'if'; |
|
43 | + const T_IMPORT = 'import'; |
|
44 | + const T_INCLUDE = 'include'; |
|
45 | + const T_INTERPOLATE = 'interpolate'; |
|
46 | + const T_INTERPOLATED = 'interpolated'; |
|
47 | + const T_KEYWORD = 'keyword'; |
|
48 | + const T_LIST = 'list'; |
|
49 | + const T_MAP = 'map'; |
|
50 | + const T_MEDIA = 'media'; |
|
51 | + const T_MEDIA_EXPRESSION = 'mediaExp'; |
|
52 | + const T_MEDIA_TYPE = 'mediaType'; |
|
53 | + const T_MEDIA_VALUE = 'mediaValue'; |
|
54 | + const T_MIXIN = 'mixin'; |
|
55 | + const T_MIXIN_CONTENT = 'mixin_content'; |
|
56 | + const T_NESTED_PROPERTY = 'nestedprop'; |
|
57 | + const T_NOT = 'not'; |
|
58 | + const T_NULL = 'null'; |
|
59 | + const T_NUMBER = 'number'; |
|
60 | + const T_RETURN = 'return'; |
|
61 | + const T_ROOT = 'root'; |
|
62 | + const T_SCSSPHP_IMPORT_ONCE = 'scssphp-import-once'; |
|
63 | + const T_SELF = 'self'; |
|
64 | + const T_STRING = 'string'; |
|
65 | + const T_UNARY = 'unary'; |
|
66 | + const T_VARIABLE = 'var'; |
|
67 | + const T_WARN = 'warn'; |
|
68 | + const T_WHILE = 'while'; |
|
69 | 69 | } |
@@ -18,5 +18,5 @@ |
||
18 | 18 | */ |
19 | 19 | class Version |
20 | 20 | { |
21 | - const VERSION = 'v0.7.5'; |
|
21 | + const VERSION = 'v0.7.5'; |
|
22 | 22 | } |