-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
tools: fix CJS/ESM toggle on small screens #43506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dbd9385
tools: fix CJS/ESM toggle on small screens
aduh95 ba014dd
fixup! tools: fix CJS/ESM toggle on small screens
aduh95 e6adc23
fixup! tools: fix CJS/ESM toggle on small screens
aduh95 40906b8
fixup! tools: fix CJS/ESM toggle on small screens
aduh95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,53 @@ | ||
const CHAR_THRESHOLD = 68; // Around 68 characters, we have to take into | ||
// account the left column that appears on screen | ||
// wider than 1024px. | ||
|
||
const ESTIMATED_CHAR_WIDTH = 8; // If the root element font-size is 16px (default value), 1ch is 7.8025px. | ||
const TOGGLE_WIDTH = 142; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L954 | ||
|
||
const PRE_MARGIN_LEFT = 16; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L516 | ||
const PRE_MARGIN_RIGHT = 16; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L516 | ||
const PRE_PADDING_LEFT = 16; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L513 | ||
const PRE_PADDING_RIGHT = 16; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L513 | ||
|
||
|
||
const COLUMN_RIGHT_MARGIN_LEFT_LARGE_SCREEN = 234; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L653 | ||
const COLUMN_RIGHT_MARGIN_LEFT_SMALL_SCREEN = 0; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L906 | ||
const COLUMN_RIGHT_MARGIN_RIGHT_LARGE_SCREEN = 0; | ||
const COLUMN_RIGHT_MARGIN_RIGHT_SMALL_SCREEN = 0; | ||
const COLUMN_RIGHT_PADDING_LEFT_LARGE_SCREEN = 24; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L655 | ||
const COLUMN_RIGHT_PADDING_LEFT_SMALL_SCREEN = 8; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L907 | ||
const COLUMN_RIGHT_PADDING_RIGHT_LARGE_SCREEN = 32; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L654 | ||
const COLUMN_RIGHT_PADDING_RIGHT_SMALL_SCREEN = 8; // https://github.com/nodejs/node/blob/dbd938549b16718f2e4cc2809746b8c44a191b1d/doc/api_assets/style.css#L908 | ||
|
||
const getMarginLeft = (charCount) => | ||
(charCount > CHAR_THRESHOLD ? | ||
COLUMN_RIGHT_MARGIN_LEFT_LARGE_SCREEN : | ||
COLUMN_RIGHT_MARGIN_LEFT_SMALL_SCREEN) + PRE_MARGIN_LEFT; | ||
const getPaddingLeft = (charCount) => | ||
(charCount > CHAR_THRESHOLD ? | ||
COLUMN_RIGHT_PADDING_LEFT_LARGE_SCREEN : | ||
COLUMN_RIGHT_PADDING_LEFT_SMALL_SCREEN) + PRE_PADDING_LEFT; | ||
const getPaddingRight = (charCount) => | ||
(charCount > CHAR_THRESHOLD ? | ||
COLUMN_RIGHT_PADDING_RIGHT_LARGE_SCREEN : | ||
COLUMN_RIGHT_PADDING_RIGHT_SMALL_SCREEN) + PRE_PADDING_RIGHT; | ||
const getMarginRight = (charCount) => | ||
(charCount > CHAR_THRESHOLD ? | ||
COLUMN_RIGHT_MARGIN_RIGHT_LARGE_SCREEN : | ||
COLUMN_RIGHT_MARGIN_RIGHT_SMALL_SCREEN) + PRE_MARGIN_RIGHT; | ||
|
||
|
||
export default function buildCSSForFlavoredJS(dynamicSizes) { | ||
if (dynamicSizes == null || dynamicSizes.length === 0) return ''; | ||
|
||
return `<style>${Array.from(dynamicSizes, (charCount) => | ||
`@media(max-width:${getMarginLeft(charCount) + getPaddingLeft(charCount) + | ||
charCount * ESTIMATED_CHAR_WIDTH + TOGGLE_WIDTH + | ||
getPaddingRight(charCount) + getMarginRight(charCount)}px){` + | ||
`.with-${charCount}-chars>.js-flavor-selector{` + | ||
'float:none;' + | ||
'margin:0 0 1em auto;' + | ||
aduh95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'}' + | ||
'}').join('')}</style>`; | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.