Update to Kirki 4.2.0

This commit is contained in:
AlxMedia 2023-08-04 15:41:48 +02:00
parent cbfd4f27e4
commit 77ecd4ca69
440 changed files with 6230 additions and 5211 deletions

View file

@ -0,0 +1,21 @@
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.

View file

@ -0,0 +1,2 @@
.customize-control-kirki[data-kirki-parent-control-type=kirki-typography]{margin-bottom:10px}.customize-control-kirki[data-kirki-parent-control-type=kirki-typography] .customize-control-title{font-size:12px;font-weight:500;margin-bottom:0}.customize-control-kirki[data-kirki-typography-css-prop=text-decoration]{margin-bottom:15px}.kirki-typography-end{margin-bottom:8px;margin-top:8px}.kirki-typography-end hr{margin-bottom:0;margin-top:0}
/*# sourceMappingURL=control.css.map */

View file

@ -0,0 +1 @@
{"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"}

View file

@ -0,0 +1,2 @@
!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 t<i?-1:t>i?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<r.length&&n.active()?e.activate():e.deactivate(),e.params.choices=r,e.formattedOptions=[],e.destroy(),r.includes(a)?e.doSelectAction("selectOption",a):e.doSelectAction("selectOption","regular")),wp.hooks.addAction("kirki.dynamicControl.initKirkiControl","kirki",(function(t){e&&t.id}))}}jQuery(document).ready((function(){_.each(kirkiTypographyControls,(function(i){t(i),wp.customize(i,(function(n){n.bind((function(n){t(i,n)}))}))}))}))}();
//# sourceMappingURL=control.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,2 @@
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,"&quot;"),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

View file

@ -0,0 +1 @@
{"mappings":"AAKAA,OAAOC,UAAUC,OAAM,WACrBC,GAAGC,MAAMC,UACP,+BACA,SAWA,SAAUC,EAAQC,EAAOC,EAAQC,GAC/B,IACEC,EADEC,EAAa,GAoEjB,OAjEIJ,EAAMK,UACRL,EAAM,eACJ,YAAcA,EAAMK,SAAW,WAAaL,EAAMK,QAC9C,IACAC,SAASN,EAAMK,QAAS,IAE9BL,EAAM,cAAgBA,EAAMK,QAAQE,SAAS,UACzC,SACA,UAGF,qBAAuBL,IACzBH,GAAUE,EAAOO,QAAU,IAE3BC,EAAEC,KAAKV,GAAO,SAAUW,EAAKC,GACvBX,EAAOY,QAAUD,IAAQX,EAAOY,QAIhC,YAAcD,IASd,KALJT,EAAiBW,OAAOC,iBAAiBC,KAAKC,aAC5ChB,EACAU,MAIAZ,GAAUa,EAAM,IAAMT,EAAiB,QAI3CJ,GAAU,KAIPU,EAAES,YAAYJ,OAAOK,UACtBnB,EAAM,gBACNoB,qBAAqBb,SAASP,EAAM,kBAGpCI,EAAaJ,EAAM,eAAeqB,QAAO,MAAQ,UAE7CrB,EAAMK,UACJ,YAAcL,EAAMK,QACtBD,GAAc,OACL,WAAaJ,EAAMK,QAC5BD,GAAc,QAEdA,GAAc,IAAMJ,EAAMK,SAI9BD,GACE,sIAEFU,OAAOK,QAAQG,KAAK,CAClBC,OAAQ,CACNC,SAAU,CAACpB,QAMZL","sources":["src/preview.js"],"sourcesContent":["/**\n * Hook in the kirkiPostMessageStylesOutput filter.\n *\n * Handles postMessage styles for typography controls.\n */\njQuery(document).ready(function () {\n wp.hooks.addFilter(\n \"kirkiPostMessageStylesOutput\",\n \"kirki\",\n\n /**\n * Append styles for this control.\n *\n * @param {string} styles - The styles.\n * @param {Object} value - The control value.\n * @param {Object} output - The control's \"output\" argument.\n * @param {string} controlType - The control type.\n * @returns {string} - Returns the CSS as a string.\n */\n function (styles, value, output, controlType) {\n var googleFont = \"\",\n processedValue;\n\n if (value.variant) {\n value[\"font-weight\"] =\n \"regular\" === value.variant || \"italic\" === value.variant\n ? 400\n : parseInt(value.variant, 10);\n\n value[\"font-style\"] = value.variant.includes(\"italic\")\n ? \"italic\"\n : \"normal\";\n }\n\n if (\"kirki-typography\" === controlType) {\n styles += output.element + \"{\";\n\n _.each(value, function (val, key) {\n if (output.choice && key !== output.choice) {\n return;\n }\n\n if (\"variant\" === key) {\n return;\n }\n\n processedValue = window.kirkiPostMessage.util.processValue(\n output,\n val\n );\n\n if (false !== processedValue) {\n styles += key + \":\" + processedValue + \";\";\n }\n });\n\n styles += \"}\";\n\n // Check if this is a googlefont so that we may load it.\n if (\n !_.isUndefined(window.WebFont) &&\n value[\"font-family\"] &&\n kirkiGoogleFontNames.includes(value[\"font-family\"])\n ) {\n // Calculate the googlefont params.\n googleFont = value[\"font-family\"].replace(/\\\"/g, \"&quot;\"); // eslint-disable-line no-useless-escape\n\n if (value.variant) {\n if (\"regular\" === value.variant) {\n googleFont += \":400\";\n } else if (\"italic\" === value.variant) {\n googleFont += \":400i\";\n } else {\n googleFont += \":\" + value.variant;\n }\n }\n\n googleFont +=\n \":cyrillic,cyrillic-ext,devanagari,greek,greek-ext,khmer,latin,latin-ext,vietnamese,hebrew,arabic,bengali,gujarati,tamil,telugu,thai\";\n\n window.WebFont.load({\n google: {\n families: [googleFont],\n },\n });\n }\n }\n\n return styles;\n }\n );\n});\n"],"names":["jQuery","document","ready","wp","hooks","addFilter","styles","value","output","controlType","processedValue","googleFont","variant","parseInt","includes","element","_","each","val","key","choice","window","kirkiPostMessage","util","processValue","isUndefined","WebFont","kirkiGoogleFontNames","replace","load","google","families"],"version":3,"file":"preview.js.map"}

View file

@ -0,0 +1,95 @@
<?php
/**
* Handles CSS output for typography fields.
*
* @package Kirki
* @subpackage Controls
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 2.2.0
*/
namespace Kirki\Field\CSS;
use Kirki\Module\CSS\Output;
/**
* Output overrides.
*/
class Typography extends Output {
/**
* Processes a single item from the `output` array.
*
* @access protected
* @param array $output The `output` item.
* @param array $value The field's value.
*/
protected function process_output( $output, $value ) {
$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
$output['element'] = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
$output['prefix'] = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
$output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
$properties = [
'font-family',
'font-size',
'variant',
'font-weight',
'font-style',
'letter-spacing',
'word-spacing',
'line-height',
'text-align',
'text-transform',
'text-decoration',
'color',
'margin-top',
'margin-bottom',
];
foreach ( $properties as $property ) {
// Early exit if the value is not in the defaults.
if ( ! isset( $this->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'];
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,105 @@
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);
});
});
});
});

View file

@ -0,0 +1,23 @@
.customize-control-kirki[data-kirki-parent-control-type="kirki-typography"] {
margin-bottom: 10px;
.customize-control-title {
margin-bottom: 0;
font-weight: 500;
font-size: 12px;
}
}
.customize-control-kirki[data-kirki-typography-css-prop="text-decoration"] {
margin-bottom: 15px;
}
.kirki-typography-end {
margin-top: 8px;
margin-bottom: 8px;
hr {
margin-top: 0;
margin-bottom: 0;
}
}

View file

@ -0,0 +1,92 @@
/**
* 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, "&quot;"); // 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;
}
);
});