-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,400 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": ["eslint:recommended", "plugin:prettier/recommended"], | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module" | ||
}, | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"node": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"esversion": 6, | ||
"asi": true | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Neos: | ||
Fusion: | ||
defaultContext: | ||
Carbon.Webfonts: 'Carbon\Webfonts\EelHelper' | ||
Neos: | ||
userInterface: | ||
translation: | ||
autoInclude: | ||
Carbon.Webfonts: | ||
- 'Main' | ||
Ui: | ||
resources: | ||
javascript: | ||
Carbon.Webfonts: | ||
resource: resource://Carbon.Webfonts/Public/Editor/Main.js | ||
attributes: | ||
type: 'module' | ||
stylesheets: | ||
Carbon.Webfonts: | ||
resource: resource://Carbon.Webfonts/Public/Editor/Main.css | ||
|
||
frontendConfiguration: | ||
'Carbon.Webfonts.FontFamily': | ||
disabled: false | ||
readonly: false | ||
allowEmpty: true | ||
placeholder: '' | ||
placeholderFont: false | ||
# A path to a CSS file with @font-face declarations. Can be a resource:// or a http(s):// path | ||
cssFile: false | ||
|
||
# Sort the fonts by name | ||
sortFonts: true | ||
|
||
# Use the fonts from Carbon Webfonts | ||
useCarbonWebfonts: true | ||
|
||
# If set to false, only the font name is stored in the database | ||
enableFallback: true | ||
# Show icon if the font has a font file or a css file | ||
showIcon: true | ||
# List of available fonts | ||
# fonts: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
function getFilePath(file) { | ||
if (!file || typeof file !== "string") { | ||
return null; | ||
} | ||
if (file.startsWith("resource://")) { | ||
return file.replace("resource://", "/_Resources/Static/Packages/"); | ||
} | ||
return file; | ||
} | ||
|
||
export function injectStylesheet(file) { | ||
const href = getFilePath(file); | ||
if (!href || document.querySelector(`link[href="${href}"]`)) { | ||
return null; | ||
} | ||
const head = document.head; | ||
const link = document.createElement("link"); | ||
link.rel = "stylesheet"; | ||
link.href = href; | ||
head.appendChild(link); | ||
} | ||
|
||
function determineFontType(fallback, group) { | ||
if (group) { | ||
if (group === "Sans Serif") return "sans-serif"; | ||
return group.toLowerCase(); | ||
} | ||
if (fallback.includes("sans-serif")) return "sans-serif"; | ||
if (fallback.includes("serif")) return "serif"; | ||
if (fallback.includes("monospace")) return "monospace"; | ||
if (fallback.includes("cursive")) return "cursive"; | ||
if (fallback.includes("fantasy")) return "fantasy"; | ||
return "sans-serif"; | ||
} | ||
|
||
export function beautifyFontOutput(string) { | ||
if (!string || typeof string !== "string") { | ||
return ""; | ||
} | ||
return string.replaceAll("'", "").replaceAll('"', "").replaceAll(",", ", ").replaceAll(" ", " ").trim(); | ||
} | ||
|
||
function generateFontObject(key, item, enableFallback) { | ||
const label = beautifyFontOutput(item.label || key); | ||
const fallbackValue = item.fallback || ""; | ||
const fallback = beautifyFontOutput(fallbackValue); | ||
const type = determineFontType(fallback, item.group); | ||
const cssFile = item.cssFile === true ? true : getFilePath(item.cssFile); | ||
const value = `${key}${enableFallback && fallbackValue ? `,${fallbackValue}` : ""}`; | ||
const fontStyle = item?.display?.fontStyle || "normal"; | ||
const fontWeight = item?.display?.fontWeight || 400; | ||
|
||
if (typeof cssFile === "string") { | ||
injectStylesheet(cssFile); | ||
} | ||
|
||
return { label, fallback, fontStyle, fontWeight, cssFile, value, type }; | ||
} | ||
|
||
export function getFontCollection(fonts, enableFallback, placeholderFont, sortFonts) { | ||
const object = { | ||
fonts: {}, | ||
flat: {}, | ||
}; | ||
if (placeholderFont && placeholderFont.name) { | ||
generateFontObject(placeholderFont.name, placeholderFont, enableFallback); | ||
} | ||
for (const key in fonts) { | ||
const item = fonts[key]; | ||
if (!item) { | ||
continue; | ||
} | ||
const { type, ...result } = generateFontObject(key, item, enableFallback); | ||
|
||
if (!object.fonts[type]) { | ||
object.fonts[type] = {}; | ||
} | ||
object.flat[key] = result; | ||
object.fonts[type][key] = result; | ||
} | ||
if (sortFonts) { | ||
for (const type in object.fonts) { | ||
object.fonts[type] = Object.fromEntries( | ||
Object.entries(object.fonts[type]).sort(([, a], [, b]) => a.label.localeCompare(b.label)), | ||
); | ||
} | ||
} | ||
return object; | ||
} |
Oops, something went wrong.