8889841cPK-[Ddist/preview.jsnu[jQuery(document).ready((function(){wp.hooks.addFilter("kirkiPostMessageStylesOutput","kirki",(function(i,a,e,t){var n,r="";return a.variant&&(a["font-weight"]="regular"===a.variant||"italic"===a.variant?400:parseInt(a.variant,10),a["font-style"]=a.variant.includes("italic")?"italic":"normal"),"kirki-typography"===t&&(i+=e.element+"{",_.each(a,(function(a,t){e.choice&&t!==e.choice||"variant"!==t&&!1!==(n=window.kirkiPostMessage.util.processValue(e,a))&&(i+=t+":"+n+";")})),i+="}",!_.isUndefined(window.WebFont)&&a["font-family"]&&kirkiGoogleFontNames.includes(a["font-family"])&&(r=a["font-family"].replace(/\"/g,"""),a.variant&&("regular"===a.variant?r+=":400":"italic"===a.variant?r+=":400i":r+=":"+a.variant),r+=":cyrillic,cyrillic-ext,devanagari,greek,greek-ext,khmer,latin,latin-ext,vietnamese,hebrew,arabic,bengali,gujarati,tamil,telugu,thai",window.WebFont.load({google:{families:[r]}}))),i}))})); //# sourceMappingURL=preview.js.map PK-[dist/control.jsnu[!function(){function t(t,i){var n=wp.customize.control(t);if(void 0!==n){var o=(i=i||n.setting.get())["font-family"]&&kirkiGoogleFonts.items[i["font-family"]],a=i.variant?i.variant.toString():"regular",e=wp.customize.control(t+"[variant]"),r=[];if(o){var l=kirkiGoogleFonts.items[i["font-family"]].variants;l.sort((function(t,i){return ti?1:0})),kirkiFontVariants.complete.forEach((function(t){-1!==l.indexOf(t.value)&&r.push({value:t.value,label:t.label})}))}else{var c=t.replace(/]/g,"");c=c.replace(/\[/g,"_"),r=kirkiCustomVariants[c][i["font-family"]]?kirkiCustomVariants[c][i["font-family"]]:kirkiFontVariants.standard}-1!==a.indexOf("i")?i["font-style"]="italic":i["font-style"]="normal",i["font-weight"]="regular"===a||"italic"===a?400:parseInt(a,10),e&&(1 b) return 1;\n return 0;\n };\n\n let variants = [];\n\n if (isGoogle) {\n let gFontVariants = kirkiGoogleFonts.items[value[\"font-family\"]].variants;\n gFontVariants.sort(sortVariants);\n\n kirkiFontVariants.complete.forEach(function (variant) {\n if (-1 !== gFontVariants.indexOf(variant.value)) {\n variants.push({\n value: variant.value,\n label: variant.label,\n });\n }\n });\n } else {\n\t\tlet customVariantKey = id.replace(/]/g, '');\n\t\tcustomVariantKey = customVariantKey.replace(/\\[/g, '_');\n\n\t\tif (kirkiCustomVariants[customVariantKey][value[\"font-family\"]]) {\n variants = kirkiCustomVariants[customVariantKey][value[\"font-family\"]];\n } else {\n variants = kirkiFontVariants.standard;\n }\n }\n\n // Set the font-style value.\n if (-1 !== variantValue.indexOf(\"i\")) {\n value[\"font-style\"] = \"italic\";\n } else {\n value[\"font-style\"] = \"normal\";\n }\n\n // Set the font-weight value.\n value[\"font-weight\"] =\n \"regular\" === variantValue || \"italic\" === variantValue\n ? 400\n : parseInt(variantValue, 10);\n\n if (variantControl) {\n // Hide/show variant options depending on which are available for this font-family.\n if (1 < variants.length && control.active()) {\n variantControl.activate();\n } else {\n // If there's only 1 variant to choose from, we can hide the control.\n variantControl.deactivate();\n }\n\n variantControl.params.choices = variants;\n variantControl.formattedOptions = [];\n variantControl.destroy();\n\n if (!variants.includes(variantValue)) {\n // If the selected font-family doesn't support the currently selected variant, switch to \"regular\".\n variantControl.doSelectAction(\"selectOption\", \"regular\");\n } else {\n variantControl.doSelectAction(\"selectOption\", variantValue);\n }\n }\n\n wp.hooks.addAction(\n \"kirki.dynamicControl.initKirkiControl\",\n \"kirki\",\n function (controlInit) {\n if (variantControl && id + \"[variant]\" === controlInit.id) {\n }\n }\n );\n}\n\njQuery(document).ready(function () {\n _.each(kirkiTypographyControls, function (id) {\n kirkiTypographyCompositeControlFontProperties(id);\n\n wp.customize(id, function (value) {\n value.bind(function (newval) {\n kirkiTypographyCompositeControlFontProperties(id, newval);\n });\n });\n });\n});\n"],"names":["$1abc80d3e2df1201$var$kirkiTypographyCompositeControlFontProperties","id","value","control","wp","customize","isGoogle","setting","get","kirkiGoogleFonts","items","variantValue","toString","variantControl","variants","gFontVariants","sort","a","b","kirkiFontVariants","complete","forEach","variant","indexOf","push","label","customVariantKey","replace","kirkiCustomVariants","standard","parseInt","length","active","activate","deactivate","params","choices","formattedOptions","destroy","includes","doSelectAction","hooks","addAction","controlInit","jQuery","document","ready","_","each","kirkiTypographyControls","bind","newval"],"version":3,"file":"control.js.map"}PK-[㮜dist/control.css.mapnu[{"mappings":"AAAA,0EACE,kBCCF,CDCE,mGAGE,cAAA,CADA,eAAA,CADA,eCGJ,CDGA,yEACE,kBCAF,CDGA,sBAEE,iBAAA,CADA,cCCF,CDEE,yBAEE,eAAA,CADA,YCCJ","sources":["src/control.scss","%3Cinput%20css%20zBhG12%3E"],"sourcesContent":[".customize-control-kirki[data-kirki-parent-control-type=\"kirki-typography\"] {\n margin-bottom: 10px;\n\n .customize-control-title {\n margin-bottom: 0;\n font-weight: 500;\n font-size: 12px;\n }\n}\n\n.customize-control-kirki[data-kirki-typography-css-prop=\"text-decoration\"] {\n margin-bottom: 15px;\n}\n\n.kirki-typography-end {\n margin-top: 8px;\n margin-bottom: 8px;\n\n hr {\n margin-top: 0;\n margin-bottom: 0;\n }\n}\n",".customize-control-kirki[data-kirki-parent-control-type=kirki-typography] {\n margin-bottom: 10px;\n}\n.customize-control-kirki[data-kirki-parent-control-type=kirki-typography] .customize-control-title {\n margin-bottom: 0;\n font-weight: 500;\n font-size: 12px;\n}\n\n.customize-control-kirki[data-kirki-typography-css-prop=text-decoration] {\n margin-bottom: 15px;\n}\n\n.kirki-typography-end {\n margin-top: 8px;\n margin-bottom: 8px;\n}\n.kirki-typography-end hr {\n margin-top: 0;\n margin-bottom: 0;\n}\n/*# sourceMappingURL=control.css.map */\n"],"names":[],"version":3,"file":"control.css.map"}PK-[YMX  src/preview.jsnu[/** * Hook in the kirkiPostMessageStylesOutput filter. * * Handles postMessage styles for typography controls. */ jQuery(document).ready(function () { wp.hooks.addFilter( "kirkiPostMessageStylesOutput", "kirki", /** * Append styles for this control. * * @param {string} styles - The styles. * @param {Object} value - The control value. * @param {Object} output - The control's "output" argument. * @param {string} controlType - The control type. * @returns {string} - Returns the CSS as a string. */ function (styles, value, output, controlType) { var googleFont = "", processedValue; if (value.variant) { value["font-weight"] = "regular" === value.variant || "italic" === value.variant ? 400 : parseInt(value.variant, 10); value["font-style"] = value.variant.includes("italic") ? "italic" : "normal"; } if ("kirki-typography" === controlType) { styles += output.element + "{"; _.each(value, function (val, key) { if (output.choice && key !== output.choice) { return; } if ("variant" === key) { return; } processedValue = window.kirkiPostMessage.util.processValue( output, val ); if (false !== processedValue) { styles += key + ":" + processedValue + ";"; } }); styles += "}"; // Check if this is a googlefont so that we may load it. if ( !_.isUndefined(window.WebFont) && value["font-family"] && kirkiGoogleFontNames.includes(value["font-family"]) ) { // Calculate the googlefont params. googleFont = value["font-family"].replace(/\"/g, """); // eslint-disable-line no-useless-escape if (value.variant) { if ("regular" === value.variant) { googleFont += ":400"; } else if ("italic" === value.variant) { googleFont += ":400i"; } else { googleFont += ":" + value.variant; } } googleFont += ":cyrillic,cyrillic-ext,devanagari,greek,greek-ext,khmer,latin,latin-ext,vietnamese,hebrew,arabic,bengali,gujarati,tamil,telugu,thai"; window.WebFont.load({ google: { families: [googleFont], }, }); } } return styles; } ); }); PK-[rrsrc/Field/Typography.phpnu[ 'regular', 'label' => __( 'Regular', 'kirki' ), ], [ 'value' => 'italic', 'label' => __( 'Italic', 'kirki' ), ], [ 'value' => '700', 'label' => __( '700', 'kirki' ), ], [ 'value' => '700italic', 'label' => __( '700 Italic', 'kirki' ), ], ]; self::$complete_variants = [ [ 'value' => 'regular', 'label' => __( 'Regular', 'kirki' ), ], [ 'value' => 'italic', 'label' => __( 'Italic', 'kirki' ), ], [ 'value' => '100', 'label' => __( '100', 'kirki' ), ], [ 'value' => '100italic', 'label' => __( '100 Italic', 'kirki' ), ], [ 'value' => '200', 'label' => __( '200', 'kirki' ), ], [ 'value' => '200italic', 'label' => __( '200 Italic', 'kirki' ), ], [ 'value' => '300', 'label' => __( '300', 'kirki' ), ], [ 'value' => '300italic', 'label' => __( '300 Italic', 'kirki' ), ], [ 'value' => '500', 'label' => __( '500', 'kirki' ), ], [ 'value' => '500italic', 'label' => __( '500 Italic', 'kirki' ), ], [ 'value' => '600', 'label' => __( '600', 'kirki' ), ], [ 'value' => '600italic', 'label' => __( '600 Italic', 'kirki' ), ], [ 'value' => '700', 'label' => __( '700', 'kirki' ), ], [ 'value' => '700italic', 'label' => __( '700 Italic', 'kirki' ), ], [ 'value' => '800', 'label' => __( '800', 'kirki' ), ], [ 'value' => '800italic', 'label' => __( '800 Italic', 'kirki' ), ], [ 'value' => '900', 'label' => __( '900', 'kirki' ), ], [ 'value' => '900italic', 'label' => __( '900 Italic', 'kirki' ), ], ]; foreach ( self::$complete_variants as $variants ) { self::$complete_variant_labels[ $variants['value'] ] = $variants['label']; } $this->add_sub_fields( $args ); add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] ); add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] ); add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); } /** * Add sub-fields. * * @access private * @since 1.0 * @param array $args The field arguments. * @return void */ private function add_sub_fields( $args ) { $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global'; $defaults = isset( $args['default'] ) ? $args['default'] : []; /** * Add a hidden field, the label & description. */ new \Kirki\Field\Generic( wp_parse_args( [ 'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ], 'wrapper_opts' => [ 'gap' => 'small', ], 'input_attrs' => '', 'choices' => [ 'type' => 'hidden', 'parent_type' => 'kirki-typography', ], ], $args ) ); $args['parent_setting'] = $args['settings']; $args['output'] = []; $args['wrapper_attrs'] = [ 'data-kirki-parent-control-type' => 'kirki-typography', ]; if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) { $args['transport'] = 'postMessage'; } /** * Add font-family selection controls. * These include font-family and variant. * They are grouped here because all they are required. * in order to get the right googlefont variant. */ if ( isset( $args['default']['font-family'] ) ) { $args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family'; /** * Add font-family control. */ new \Kirki\Field\ReactSelect( wp_parse_args( [ 'label' => esc_html__( 'Font Family', 'kirki' ), 'description' => '', 'settings' => $args['settings'] . '[font-family]', 'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '', 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ), 'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file. 'css_vars' => [], 'output' => [], ], $args ) ); /** * Add font variant. */ $font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular'; if ( isset( $args['default']['font-weight'] ) ) { $font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight']; } $args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant'; new \Kirki\Field\ReactSelect( wp_parse_args( [ 'label' => esc_html__( 'Font Variant', 'kirki' ), 'description' => '', 'settings' => $args['settings'] . '[variant]', 'default' => $font_variant, 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ), 'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file. 'css_vars' => [], 'output' => [], ], $args ) ); } $font_size_field_specified = isset( $defaults['font-size'] ); $color_field_specified = isset( $defaults['color'] ); if ( $font_size_field_specified || $color_field_specified ) { $group = [ 'font-size' => [ 'type' => 'dimension', 'label' => esc_html__( 'Font Size', 'kirki' ), 'is_specified' => $font_size_field_specified, ], 'color' => [ 'type' => 'react-colorful', 'label' => esc_html__( 'Font Color', 'kirki' ), 'is_specified' => $color_field_specified, 'choices' => [ 'alpha' => true, 'label_style' => 'top', ], ], ]; $this->generate_controls_group( $group, $args ); } $text_align_field_specified = isset( $defaults['text-align'] ); $text_transform_field_specified = isset( $defaults['text-transform'] ); if ( $text_align_field_specified || $text_transform_field_specified ) { $group = [ 'text-align' => [ 'type' => 'react-select', 'label' => esc_html__( 'Text Align', 'kirki' ), 'is_specified' => $text_align_field_specified, 'choices' => [ 'initial' => esc_html__( 'Initial', 'kirki' ), 'left' => esc_html__( 'Left', 'kirki' ), 'center' => esc_html__( 'Center', 'kirki' ), 'right' => esc_html__( 'Right', 'kirki' ), 'justify' => esc_html__( 'Justify', 'kirki' ), ], ], 'text-transform' => [ 'type' => 'react-select', 'label' => esc_html__( 'Text Transform', 'kirki' ), 'is_specified' => $text_transform_field_specified, 'choices' => [ 'none' => esc_html__( 'None', 'kirki' ), 'capitalize' => esc_html__( 'Capitalize', 'kirki' ), 'uppercase' => esc_html__( 'Uppercase', 'kirki' ), 'lowercase' => esc_html__( 'Lowercase', 'kirki' ), ], ], ]; $this->generate_controls_group( $group, $args ); } $text_decoration_field_specified = isset( $defaults['text-decoration'] ); if ( $text_decoration_field_specified ) { $group = [ 'text-decoration' => [ 'type' => 'react-select', 'label' => esc_html__( 'Text Decoration', 'kirki' ), 'is_specified' => $text_decoration_field_specified, 'choices' => [ 'none' => esc_html__( 'None', 'kirki' ), 'underline' => esc_html__( 'Underline', 'kirki' ), 'line-through' => esc_html__( 'Line Through', 'kirki' ), 'overline' => esc_html__( 'Overline', 'kirki' ), 'solid' => esc_html__( 'Solid', 'kirki' ), 'wavy' => esc_html__( 'Wavy', 'kirki' ), ], ], ]; $this->generate_controls_group( $group, $args ); } $line_height_field_specified = isset( $defaults['line-height'] ); $letter_spacing_field_specified = isset( $defaults['letter-spacing'] ); if ( $line_height_field_specified || $letter_spacing_field_specified ) { $group = [ 'line-height' => [ 'type' => 'dimension', 'label' => esc_html__( 'Line Height', 'kirki' ), 'is_specified' => $line_height_field_specified, ], 'letter-spacing' => [ 'type' => 'dimension', 'label' => esc_html__( 'Letter Spacing', 'kirki' ), 'is_specified' => $letter_spacing_field_specified, ], ]; $this->generate_controls_group( $group, $args ); } $margin_top_field_specified = isset( $defaults['margin-top'] ); $margin_bottom_field_specified = isset( $defaults['margin-bottom'] ); if ( $margin_top_field_specified || $margin_bottom_field_specified ) { $group = [ 'margin-top' => [ 'type' => 'dimension', 'label' => esc_html__( 'Margin Top', 'kirki' ), 'is_specified' => $margin_top_field_specified, ], 'margin-bottom' => [ 'type' => 'dimension', 'label' => esc_html__( 'Margin Bottom', 'kirki' ), 'is_specified' => $margin_bottom_field_specified, ], ]; $this->generate_controls_group( $group, $args ); } } /** * Generate controls group. * * @param array $group The group data. * @param array $args The field args. */ public function generate_controls_group( $group, $args ) { $total_specified = 0; $field_width = 100; foreach ( $group as $css_prop => $control ) { if ( $control['is_specified'] ) { $total_specified++; } } if ( $total_specified > 1 ) { $field_width = floor( 100 / $total_specified ); } $group_count = 0; foreach ( $group as $css_prop => $control ) { if ( $control['is_specified'] ) { $group_count++; $group_classname = 'kirki-group-item'; $group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' ); $control_class = str_ireplace( '-', ' ', $control['type'] ); $control_class = ucwords( $control_class ); $control_class = str_replace( ' ', '', $control_class ); $control_class = '\\Kirki\\Field\\' . $control_class; new $control_class( wp_parse_args( [ 'label' => isset( $control['label'] ) ? $control['label'] : '', 'description' => isset( $control['description'] ) ? $control['description'] : '', 'settings' => $args['settings'] . '[' . $css_prop . ']', 'default' => $args['default'][ $css_prop ], 'wrapper_attrs' => wp_parse_args( [ 'data-kirki-typography-css-prop' => $css_prop, 'kirki-typography-subcontrol-type' => $css_prop, 'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width, ], $args['wrapper_attrs'] ), 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ), 'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ), 'css_vars' => [], 'output' => [], ], $args ) ); } } } /** * Sanitizes typography controls * * @static * @since 1.0 * @param array $value The value. * @return array */ public static function sanitize( $value ) { if ( ! is_array( $value ) ) { return []; } foreach ( $value as $key => $val ) { switch ( $key ) { case 'font-family': $value['font-family'] = sanitize_text_field( $val ); break; case 'variant': // Use 'regular' instead of 400 for font-variant. $value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val; // Get font-weight from variant. $value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); $value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] ); // Get font-style from variant. if ( ! isset( $value['font-style'] ) ) { $value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic'; } break; case 'text-align': if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) { $value['text-align'] = ''; } break; case 'text-transform': if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) { $value['text-transform'] = ''; } break; case 'text-decoration': if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) { $value['text-transform'] = ''; } break; case 'color': $value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] ); break; default: $value[ $key ] = sanitize_text_field( $value[ $key ] ); } } return $value; } /** * Enqueue scripts & styles. * * @access public * @since 1.0 * @return void */ public function enqueue_control_scripts() { wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' ); wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true ); wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls ); $args = $this->args; $variants = []; // Add custom variants (for custom fonts) to the $variants. if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) { // If $args['choices']['fonts']['families'] exists, then loop it. foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) { // Then loop the $font_family_value['children]. foreach ( $font_family_value['children'] as $font_family ) { // Then check if $font_family['id'] exists in variants argument. if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) { // Create new array if $variants[ $font_family['id'] ] doesn't exist. if ( ! isset( $variants[ $font_family['id'] ] ) ) { $variants[ $font_family['id'] ] = []; } // The $custom_variant here can be something like "400italic" or "italic". foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) { // Check if $custom_variant exists in self::$complete_variant_labels. if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) { // If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object. array_push( $variants[ $font_family['id'] ], [ 'value' => $custom_variant, 'label' => self::$complete_variant_labels[ $custom_variant ], ] ); } // End of isset(self::$complete_variant_labels[$font_family['id']]) if. } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach. } } // End of $font_family_value['children'] foreach. } // End of $args['choices']['fonts']['families'] foreach. } // End of $args['choices']['fonts']['families'] if. if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) { $standard_fonts = Fonts::get_standard_fonts(); foreach ( $standard_fonts as $font ) { if ( isset( $font['variants'] ) ) { // Create new array if $variants[ $font['stack'] ] doesn't exist. if ( ! isset( $variants[ $font['stack'] ] ) ) { $variants[ $font['stack'] ] = []; } // The $std_variant here can be something like "400italic" or "italic". foreach ( $font['variants'] as $std_variant ) { // Check if $std_variant exists in self::$complete_variant_labels. if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) { // If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object. array_push( $variants[ $font['stack'] ], [ 'value' => $std_variant, 'label' => self::$complete_variant_labels[ $std_variant ], ] ); } // End of isset(self::$complete_variant_labels[$font_family['id']]) if. } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach. } } } elseif ( is_array( $args['choices']['fonts']['standard'] ) ) { foreach ( $args['choices']['fonts']['standard'] as $key => $val ) { $key = ( is_int( $key ) ) ? $val : $key; if ( isset( $val['variants'] ) ) { // Create new array if $variants[ $font['stack'] ] doesn't exist. if ( ! isset( $variants[ $key ] ) ) { $variants[ $key ] = []; } // The $std_variant here can be something like "400italic" or "italic". foreach ( $val['variants'] as $std_variant ) { // Check if $std_variant exists in self::$complete_variant_labels. if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) { // If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object. array_push( $variants[ $key ], [ 'value' => $std_variant, 'label' => self::$complete_variant_labels[ $std_variant ], ] ); } // End of isset(self::$complete_variant_labels[$font_family['id']]) if. } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach. } } } // Scripts inside this block will only be executed once. if ( ! self::$fonts_var_added ) { wp_localize_script( 'kirki-control-typography', 'kirkiFontVariants', [ 'standard' => self::$std_variants, 'complete' => self::$complete_variants, ] ); $google = new GoogleFonts(); wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() ); wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' ); self::$fonts_var_added = true; } // This custom variants will be available for each typography control. $custom_variant_key = str_ireplace( ']', '', $args['settings'] ); $custom_variant_key = str_ireplace( '[', '_', $custom_variant_key ); $custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) ); wp_add_inline_script( 'kirki-control-typography', 'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';', $variants ); } /** * Enqueue scripts for customize_preview_init. * * @access public * @since 1.0 * @return void */ public function enqueue_preview_scripts() { wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true ); if ( ! self::$preview_var_added ) { $google = new GoogleFonts(); wp_localize_script( 'kirki-preview-typography', 'kirkiGoogleFontNames', $google->get_google_font_names() ); self::$preview_var_added = true; } } /** * Prefer control specific value over field value * * @access public * @since 4.0 * @param $setting * @param $choice * @param $args * * @return string */ public function filter_preferred_choice_setting( $setting, $choice, $args ) { // Fail early. if ( ! isset( $args[ $setting ] ) ) { return ''; } // If a specific field for the choice is set if ( isset( $args[ $setting ][ $choice ] ) ) { return $args[ $setting ][ $choice ]; } // Unset input_attrs of all other choices. foreach ( $args['choices'] as $id => $set ) { if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) { unset( $args[ $setting ][ $id ] ); } elseif ( ! isset( $args[ $setting ][ $id ] ) ) { $args[ $setting ] = ''; } } return $args[ $setting ]; } /** * Populate the font family choices. * * It's separated from the `add_sub_field` function to prevent a bug * when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field. * * When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work. * But if it's hooked after field registration, then the function won't be available. * * @access private * @since 1.0.1 * * @return array */ private function get_font_family_choices() { $args = $this->args; // Figure out how to sort the fonts. $sorting = 'alpha'; $max_fonts = 9999; $google = new GoogleFonts(); if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) { if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) { $sorting = $args['choices']['fonts']['google'][0]; if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) { $max_fonts = (int) $args['choices']['fonts']['google'][1]; } $g_fonts = $google->get_google_fonts_by_args( [ 'sort' => $sorting, 'count' => $max_fonts, ] ); } else { $g_fonts = $args['choices']['fonts']['google']; } } else { $g_fonts = $google->get_google_fonts_by_args( [ 'sort' => $sorting, 'count' => $max_fonts, ] ); } $std_fonts = []; if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) { $standard_fonts = Fonts::get_standard_fonts(); foreach ( $standard_fonts as $font ) { $std_fonts[ $font['stack'] ] = $font['label']; } } elseif ( is_array( $args['choices']['fonts']['standard'] ) ) { foreach ( $args['choices']['fonts']['standard'] as $key => $val ) { $key = ( \is_int( $key ) ) ? $val : $key; $std_fonts[ $key ] = $val; } } $choices = []; $choices['default'] = [ esc_html__( 'Defaults', 'kirki' ), [ '' => esc_html__( 'Default', 'kirki' ), ], ]; if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) { // Implementing the custom font families. foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) { if ( ! isset( $choices[ $font_family_key ] ) ) { $choices[ $font_family_key ] = []; } $family_opts = []; foreach ( $font_family_value['children'] as $font_family ) { $family_opts[ $font_family['id'] ] = $font_family['text']; } $choices[ $font_family_key ] = [ $font_family_value['text'], $family_opts, ]; } } $choices['standard'] = [ esc_html__( 'Standard Fonts', 'kirki' ), $std_fonts, ]; $choices['google'] = [ esc_html__( 'Google Fonts', 'kirki' ), array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ), ]; if ( empty( $choices['standard'][1] ) ) { $choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ); } elseif ( empty( $choices['google'][1] ) ) { $choices = $std_fonts; } return $choices; } /** * Get custom variant choices (for custom fonts). * * It's separated from the `add_sub_field` function to prevent a bug * when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field. * * When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work. * But if it's hooked after field registration, then the function won't be available. * * @access private * @since 1.0.2 * * @return array */ private function get_variant_choices() { $args = $this->args; $choices = self::$std_variants; // Implementing the custom variants for custom fonts. if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) { $choices = []; // If $args['choices']['fonts']['families'] exists, then loop it. foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) { // Then loop the $font_family_value['children]. foreach ( $font_family_value['children'] as $font_family ) { // Then check if $font_family['id'] exists in $args['choices']['fonts']['variants']. if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) { // The $custom_variant here can be something like "400italic" or "italic". foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) { // Check if $custom_variant exists in self::$complete_variant_labels. if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) { // If it exists, assign it to $choices. array_push( $choices, [ 'value' => $custom_variant, 'label' => self::$complete_variant_labels[ $custom_variant ], ] ); } // End of isset(self::$complete_variant_labels[$font_family['id']]) if. } // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach. } } // End of $font_family_value['children'] foreach. } // End of $args['choices']['fonts']['families'] foreach. } // End of $args['choices']['fonts']['families'] if. return $choices; } /** * Filter arguments before creating the control. * * @access public * @since 0.1 * @param array $args The field arguments. * @param WP_Customize_Manager $wp_customize The customizer instance. * @return array */ public function filter_control_args( $args, $wp_customize ) { if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) { $args = parent::filter_control_args( $args, $wp_customize ); $args['choices'] = $this->get_font_family_choices(); } if ( $args['settings'] === $this->args['settings'] . '[variant]' ) { $args = parent::filter_control_args( $args, $wp_customize ); $args['choices'] = $this->get_variant_choices(); } return $args; } /** * Adds a custom output class for typography fields. * * @access public * @since 1.0 * @param array $classnames The array of classnames. * @return array */ public function output_control_classnames( $classnames ) { $classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography'; return $classnames; } /** * Override parent method. No need to register any setting. * * @access public * @since 0.1 * @param WP_Customize_Manager $wp_customize The customizer instance. * @return void */ public function add_setting( $wp_customize ) {} /** * Override the parent method. No need for a control. * * @access public * @since 0.1 * @param WP_Customize_Manager $wp_customize The customizer instance. * @return void */ public function add_control( $wp_customize ) {} } PK-[\<  src/Field/CSS/Typography.phpnu[field['default'][ $property ] ) ) { continue; } // Early exit if the value is not saved in the values. if ( ! isset( $value[ $property ] ) || ! $value[ $property ] ) { continue; } // Early exit if we use "choice" but not for this property. if ( isset( $output['choice'] ) && $output['choice'] !== $property ) { continue; } // Take care of variants. if ( 'variant' === $property && isset( $value['variant'] ) && ! empty( $value['variant'] ) ) { // Get the font_weight. $font_weight = str_replace( 'italic', '', $value['variant'] ); $font_weight = ( in_array( $font_weight, [ '', 'regular' ], true ) ) ? '400' : $font_weight; // Is this italic? $is_italic = ( false !== strpos( $value['variant'], 'italic' ) ); $this->styles[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $font_weight; if ( $is_italic ) { $this->styles[ $output['media_query'] ][ $output['element'] ]['font-style'] = 'italic'; } continue; } $property_value = $this->process_property_value( $property, $value[ $property ] ); $property = ( isset( $output['choice'] ) && isset( $output['property'] ) ) ? $output['property'] : $property; $property_value = ( is_array( $property_value ) && isset( $property_value[0] ) ) ? $property_value[0] : $property_value; $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $property_value . $output['suffix']; } } } PK-[+ src/control.jsnu[import "./control.scss"; /* global kirkiTypographyControls, kirkiGoogleFonts, kirkiFontVariants */ function kirkiTypographyCompositeControlFontProperties(id, value) { const control = wp.customize.control(id); if ("undefined" === typeof control) { return; } value = value || control.setting.get(); const isGoogle = value["font-family"] && kirkiGoogleFonts.items[value["font-family"]]; const variantValue = value["variant"] ? value["variant"].toString() : "regular"; const variantControl = wp.customize.control(id + "[variant]"); const sortVariants = function (a, b) { if (a < b) return -1; if (a > b) return 1; return 0; }; let variants = []; if (isGoogle) { let gFontVariants = kirkiGoogleFonts.items[value["font-family"]].variants; gFontVariants.sort(sortVariants); kirkiFontVariants.complete.forEach(function (variant) { if (-1 !== gFontVariants.indexOf(variant.value)) { variants.push({ value: variant.value, label: variant.label, }); } }); } else { let customVariantKey = id.replace(/]/g, ''); customVariantKey = customVariantKey.replace(/\[/g, '_'); if (kirkiCustomVariants[customVariantKey][value["font-family"]]) { variants = kirkiCustomVariants[customVariantKey][value["font-family"]]; } else { variants = kirkiFontVariants.standard; } } // Set the font-style value. if (-1 !== variantValue.indexOf("i")) { value["font-style"] = "italic"; } else { value["font-style"] = "normal"; } // Set the font-weight value. value["font-weight"] = "regular" === variantValue || "italic" === variantValue ? 400 : parseInt(variantValue, 10); if (variantControl) { // Hide/show variant options depending on which are available for this font-family. if (1 < variants.length && control.active()) { variantControl.activate(); } else { // If there's only 1 variant to choose from, we can hide the control. variantControl.deactivate(); } variantControl.params.choices = variants; variantControl.formattedOptions = []; variantControl.destroy(); if (!variants.includes(variantValue)) { // If the selected font-family doesn't support the currently selected variant, switch to "regular". variantControl.doSelectAction("selectOption", "regular"); } else { variantControl.doSelectAction("selectOption", variantValue); } } wp.hooks.addAction( "kirki.dynamicControl.initKirkiControl", "kirki", function (controlInit) { if (variantControl && id + "[variant]" === controlInit.id) { } } ); } jQuery(document).ready(function () { _.each(kirkiTypographyControls, function (id) { kirkiTypographyCompositeControlFontProperties(id); wp.customize(id, function (value) { value.bind(function (newval) { kirkiTypographyCompositeControlFontProperties(id, newval); }); }); }); }); PK-[ln00LICENSEnu[MIT License Copyright (c) 2019 kirki-framework Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK-[Ddist/preview.jsnu[PK-[dist/control.jsnu[PK-[ dist/control.cssnu[PK-[6006 dist/preview.js.mapnu[PK-[´dist/control.js.mapnu[PK-[㮜.dist/control.css.mapnu[PK-[YMX  4src/preview.jsnu[PK-[rrk>src/Field/Typography.phpnu[PK-[\<  src/Field/CSS/Typography.phpnu[PK-[+ $src/control.jsnu[PK-[ln00LICENSEnu[PK x