-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from codeAdrian/feature/v2
Feature/v2
- Loading branch information
Showing
12 changed files
with
105 additions
and
231 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
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from "./AsyncFonts" | ||
export * from "./FontListener" | ||
export * from "./AsyncFonts"; |
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 |
---|---|---|
@@ -1,7 +1,2 @@ | ||
export const INTERVAL_DEFAULT = 300 | ||
|
||
export const TIMEOUT_DEFAULT = 30000 | ||
|
||
export const MODE_DEFAULT = "async" | ||
|
||
export const SCOPE_DEFAULT = "body" | ||
export const MODE_DEFAULT = "async"; | ||
export const SCOPE_DEFAULT = "body"; |
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 |
---|---|---|
@@ -1,48 +1,41 @@ | ||
import React from "react" | ||
import { AsyncFonts, FontListener } from "./components" | ||
import { | ||
INTERVAL_DEFAULT, | ||
MODE_DEFAULT, | ||
TIMEOUT_DEFAULT, | ||
SCOPE_DEFAULT, | ||
} from "./consts" | ||
import { getFontFiles, getFontNames } from "./utils" | ||
import React from "react"; | ||
import { AsyncFonts } from "./components"; | ||
import { MODE_DEFAULT, SCOPE_DEFAULT } from "./consts"; | ||
import { getFontFiles, getFontNames } from "./utils"; | ||
import { fontListener } from "./utils/fontListener"; | ||
|
||
export const onClientEntry = ( | ||
_, | ||
{ custom = [], web = [], enableListener = false, scope = SCOPE_DEFAULT } | ||
) => { | ||
if (!enableListener) { | ||
return; | ||
} | ||
|
||
const allFonts = [...custom, ...web]; | ||
const fontNames = getFontNames(allFonts); | ||
const listenerProps = { fontNames, scope }; | ||
|
||
fontListener(listenerProps); | ||
}; | ||
|
||
export const wrapRootElement = ( | ||
{ element }, | ||
{ | ||
custom = [], | ||
web = [], | ||
enableListener, | ||
interval = INTERVAL_DEFAULT, | ||
timeout = TIMEOUT_DEFAULT, | ||
scope = SCOPE_DEFAULT, | ||
mode = MODE_DEFAULT, | ||
} | ||
{ custom = [], web = [], mode = MODE_DEFAULT } | ||
) => { | ||
if (mode !== "async") { | ||
return element | ||
return element; | ||
} | ||
|
||
const allFonts = [...custom, ...web] | ||
const fontFiles = getFontFiles(allFonts) | ||
const fontNames = getFontNames(allFonts) | ||
const allFonts = [...custom, ...web]; | ||
const fontFiles = getFontFiles(allFonts); | ||
const fontNames = getFontNames(allFonts); | ||
const hasFontNames = Boolean(fontNames.length); | ||
|
||
const listenerProps = { fontNames, interval, timeout, scope } | ||
|
||
const hasFontFiles = Boolean(fontFiles.length) | ||
const hasFontNames = Boolean(fontNames.length) | ||
|
||
const children = ( | ||
return ( | ||
<> | ||
{hasFontNames && <AsyncFonts hrefs={fontFiles} />} | ||
{element} | ||
</> | ||
) | ||
|
||
if (!hasFontFiles || !enableListener) { | ||
return children | ||
} | ||
|
||
return <FontListener options={listenerProps}>{children}</FontListener> | ||
} | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,34 +1,21 @@ | ||
import { MODE_DEFAULT } from "./consts" | ||
import { getFontConfig, getTestFonts } from "./generators" | ||
import { getFontFiles, getFontNames } from "./utils" | ||
import { MODE_DEFAULT } from "./consts"; | ||
import { getFontConfig } from "./generators"; | ||
import { getFontFiles } from "./utils"; | ||
|
||
export const onRenderBody = ( | ||
{ setHeadComponents, setPostBodyComponents }, | ||
{ | ||
enableListener, | ||
preconnect = [], | ||
preload = [], | ||
web = [], | ||
custom = [], | ||
mode = MODE_DEFAULT, | ||
} | ||
{ setHeadComponents }, | ||
{ preconnect = [], preload = [], web = [], custom = [], mode = MODE_DEFAULT } | ||
) => { | ||
const allFonts = [...web, ...custom] | ||
const allPreloads = preload.concat(getFontFiles(allFonts)) | ||
const fontNames = getFontNames(allFonts) | ||
const allFonts = [...web, ...custom]; | ||
const allPreloads = preload.concat(getFontFiles(allFonts)); | ||
|
||
const preloadConfig = getFontConfig( | ||
preconnect, | ||
allPreloads, | ||
mode === "async" ? [] : allFonts | ||
) | ||
|
||
if (enableListener && Boolean(allFonts.length) && mode === "async") { | ||
const testFontConfig = getTestFonts(fontNames) | ||
setPostBodyComponents(testFontConfig) | ||
} | ||
); | ||
|
||
if (preloadConfig && Boolean(preloadConfig.length)) { | ||
setHeadComponents(preloadConfig) | ||
setHeadComponents(preloadConfig); | ||
} | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from "./getFontConfig" | ||
export * from "./getTestFonts" | ||
export * from "./getFontConfig"; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.