{
  "version": 3,
  "sources": ["../../../src/font-library/utils/toggleFont.ts"],
  "sourcesContent": ["/**\n * Toggles the activation of a given font or font variant within a list of custom fonts.\n *\n * - If only the font is provided (without face), the entire font family's activation is toggled.\n * - If both font and face are provided, the activation of the specific font variant is toggled.\n *\n * @param {Object} font            - The font to be toggled.\n * @param {string} font.slug       - The unique identifier for the font.\n * @param {Array}  [font.fontFace] - The list of font variants (faces) associated with the font.\n *\n * @param {Object} [face]          - The specific font variant to be toggled.\n * @param {string} face.fontWeight - The weight of the font variant.\n * @param {string} face.fontStyle  - The style of the font variant.\n *\n * @param {Array}  initialfonts    - The initial list of custom fonts.\n *\n * @return {Array} - The updated list of custom fonts with the font/font variant toggled.\n *\n * @example\n * const customFonts = [\n *     { slug: 'roboto', fontFace: [{ fontWeight: '400', fontStyle: 'normal' }] }\n * ];\n *\n * toggleFont({ slug: 'roboto' }, null, customFonts);\n * // This will remove 'roboto' from customFonts\n *\n * toggleFont({ slug: 'roboto' }, { fontWeight: '400', fontStyle: 'normal' }, customFonts);\n * // This will remove the specified face from 'roboto' in customFonts\n *\n * toggleFont({ slug: 'roboto' }, { fontWeight: '500', fontStyle: 'normal' }, customFonts);\n * // This will add the specified face to 'roboto' in customFonts\n */\n/**\n * WordPress dependencies\n */\nimport type { FontFamily, FontFace } from '@wordpress/core-data';\n\nexport function toggleFont(\n\tfont: FontFamily,\n\tface?: FontFace,\n\tinitialfonts: FontFamily[] = []\n): FontFamily[] {\n\t// Helper to check if a font is activated based on its slug\n\tconst isFontActivated = ( f: FontFamily ): boolean => f.slug === font.slug;\n\n\t// Helper to get the activated font from a list of fonts\n\tconst getActivatedFont = ( fonts: FontFamily[] ): FontFamily | undefined =>\n\t\tfonts.find( isFontActivated );\n\n\t// Toggle the activation status of an entire font family\n\tconst toggleEntireFontFamily = (\n\t\tactivatedFont: FontFamily | undefined\n\t): FontFamily[] => {\n\t\tif ( ! activatedFont ) {\n\t\t\t// If the font is not active, activate the entire font family\n\t\t\treturn [ ...initialfonts, font ];\n\t\t}\n\t\t// If the font is already active, deactivate the entire font family\n\t\treturn initialfonts.filter(\n\t\t\t( f: FontFamily ) => ! isFontActivated( f )\n\t\t);\n\t};\n\n\t// Toggle the activation status of a specific font variant\n\tconst toggleFontVariant = (\n\t\tactivatedFont: FontFamily | undefined\n\t): FontFamily[] => {\n\t\tconst isFaceActivated = ( f: FontFace ): boolean =>\n\t\t\tf.fontWeight === face!.fontWeight &&\n\t\t\tf.fontStyle === face!.fontStyle;\n\n\t\tif ( ! activatedFont ) {\n\t\t\t// If the font family is not active, activate the font family with the font variant\n\t\t\treturn [ ...initialfonts, { ...font, fontFace: [ face! ] } ];\n\t\t}\n\n\t\tlet newFontFaces = activatedFont.fontFace || [];\n\n\t\tif ( newFontFaces.find( isFaceActivated ) ) {\n\t\t\t// If the font variant is active, deactivate it\n\t\t\tnewFontFaces = newFontFaces.filter(\n\t\t\t\t( f: FontFace ) => ! isFaceActivated( f )\n\t\t\t);\n\t\t} else {\n\t\t\t// If the font variant is not active, activate it\n\t\t\tnewFontFaces = [ ...newFontFaces, face! ];\n\t\t}\n\n\t\t// If there are no more font faces, deactivate the font family\n\t\tif ( newFontFaces.length === 0 ) {\n\t\t\treturn initialfonts.filter(\n\t\t\t\t( f: FontFamily ) => ! isFontActivated( f )\n\t\t\t);\n\t\t}\n\n\t\t// Return updated fonts list with toggled font variant\n\t\treturn initialfonts.map( ( f: FontFamily ) =>\n\t\t\tisFontActivated( f ) ? { ...f, fontFace: newFontFaces } : f\n\t\t);\n\t};\n\n\tconst activatedFont = getActivatedFont( initialfonts );\n\n\tif ( ! face ) {\n\t\treturn toggleEntireFontFamily( activatedFont );\n\t}\n\n\treturn toggleFontVariant( activatedFont );\n}\n"],
  "mappings": ";AAqCO,SAAS,WACf,MACA,MACA,eAA6B,CAAC,GACf;AAEf,QAAM,kBAAkB,CAAE,MAA4B,EAAE,SAAS,KAAK;AAGtE,QAAM,mBAAmB,CAAE,UAC1B,MAAM,KAAM,e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