| 1 |
import { DecorationLineThrough, DecorationUnderline, ItalicIcon } from "./svgIcon"; |
| 2 |
|
| 3 |
export const fontWeightMap = { |
| 4 |
100: "Thin 100", |
| 5 |
200: "Extra Light 200", |
| 6 |
300: "Light 300", |
| 7 |
400: "Regular 400", |
| 8 |
500: "Medium 500", |
| 9 |
600: "Semi Bold 600", |
| 10 |
700: "Bold 700", |
| 11 |
800: "Extra Bold 800", |
| 12 |
900: "Black 900", |
| 13 |
"100italic": "italic 100", |
| 14 |
"200italic": "italic 200", |
| 15 |
"300italic": "italic 300", |
| 16 |
italic: "italic 400", |
| 17 |
"400italic": "italic 400", |
| 18 |
"500italic": "italic 500", |
| 19 |
"600italic": "italic 600", |
| 20 |
"700italic": "italic 700", |
| 21 |
"800italic": "italic 800", |
| 22 |
"900italic": "italic 900", |
| 23 |
}; |
| 24 |
|
| 25 |
export const textDecorationOptions = [ |
| 26 |
{ |
| 27 |
label: <ItalicIcon />, |
| 28 |
key: "style", |
| 29 |
value: "italic", |
| 30 |
}, |
| 31 |
{ |
| 32 |
label: <DecorationUnderline />, |
| 33 |
key: "decoration", |
| 34 |
value: "underline", |
| 35 |
}, |
| 36 |
{ |
| 37 |
label: <DecorationLineThrough />, |
| 38 |
key: "decoration", |
| 39 |
value: "line-through", |
| 40 |
}, |
| 41 |
]; |
| 42 |
|
| 43 |
export const textCaseOptions = [ |
| 44 |
{ |
| 45 |
label: "AB", |
| 46 |
key: "transform", |
| 47 |
value: "uppercase", |
| 48 |
}, |
| 49 |
{ |
| 50 |
label: "ab", |
| 51 |
key: "transform", |
| 52 |
value: "lowercase", |
| 53 |
}, |
| 54 |
{ |
| 55 |
label: "Ab", |
| 56 |
key: "transform", |
| 57 |
value: "capitalize", |
| 58 |
}, |
| 59 |
]; |
| 60 |
export const getFontWeightList = (activeFontFamily) => { |
| 61 |
const weightLists = activeFontFamily?.font?.variants |
| 62 |
?.map((variant) => { |
| 63 |
const value = variant === "regular" ? "400" : variant; |
| 64 |
if (fontWeightMap[value]) { |
| 65 |
return { label: fontWeightMap[value], value }; |
| 66 |
} |
| 67 |
return null; |
| 68 |
}) |
| 69 |
.filter(Boolean); |
| 70 |
const updatedWeightLists = [{ label: "Select Font Style", value: "", disabled: true }, ...weightLists]; |
| 71 |
return updatedWeightLists || [{ label: "Regular", value: "regular" }]; |
| 72 |
}; |
| 73 |
|
| 74 |
const bodyFontSizePresets = [ |
| 75 |
{ value: 12, label: 12 }, |
| 76 |
{ value: 14, label: 14 }, |
| 77 |
{ value: 16, label: 16 }, |
| 78 |
{ value: 18, label: 18 }, |
| 79 |
{ value: 20, label: 20 }, |
| 80 |
]; |
| 81 |
const titleFontSizePresets = [ |
| 82 |
{ value: 18, label: 18 }, |
| 83 |
{ value: 20, label: 20 }, |
| 84 |
{ value: 24, label: 24 }, |
| 85 |
{ value: 32, label: 32 }, |
| 86 |
{ value: 44, label: 44 }, |
| 87 |
]; |
| 88 |
|
| 89 |
export const getFontSizePresets = (type) => { |
| 90 |
return type === "body" ? bodyFontSizePresets : titleFontSizePresets; |
| 91 |
}; |
| 92 |
|
| 93 |
export const getGlobalTypoPresets = () => { |
| 94 |
const globalTypo = window.SmartPostSettings.getTypography(); |
| 95 |
const globalTypoSizes = globalTypo?.typographySizes ?? {}; |
| 96 |
|
| 97 |
const result = []; |
| 98 |
|
| 99 |
Object.keys(globalTypoSizes).forEach((typoKey) => { |
| 100 |
globalTypoSizes[typoKey].forEach((item) => { |
| 101 |
// Handle "sizes" group (heading, body, button) |
| 102 |
if (item.sizes) { |
| 103 |
item.sizes.forEach((size, index) => { |
| 104 |
result.push({ |
| 105 |
class: `sp-smart-${item.slug}`, |
| 106 |
fontSize: `var(--sp-smart-font-size-${item.slug}-${index + 1}, initial)`, |
| 107 |
lineHeight: `var(--sp-smart-line-height-${item.slug}-${index + 1}, initial)`, |
| 108 |
value: `${item.slug}-${index + 1}`, |
| 109 |
label: `${item.title} ${index + 1}`, |
| 110 |
}); |
| 111 |
}); |
| 112 |
} |
| 113 |
// Handle "custom" group |
| 114 |
if (item.fontSize) { |
| 115 |
result.push({ |
| 116 |
class: `sp-smart-${item.slug}`, |
| 117 |
value: `sp-smart-${item.slug}`, |
| 118 |
label: item.title, |
| 119 |
fontSize: "", |
| 120 |
lineHeight: "", |
| 121 |
}); |
| 122 |
} |
| 123 |
}); |
| 124 |
}); |
| 125 |
return result; |
| 126 |
}; |
| 127 |
|