-
Notifications
You must be signed in to change notification settings - Fork 64
curr(pretext): Review for the Pretext library PT #219
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
Open
Goku-kun
wants to merge
4
commits into
main
Choose a base branch
from
curr/pretext-review
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+15
−15
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
814d2ef
curr(pretext): canvas pretext link fix
Goku-kun ec89d2b
curr(pretext-pt): link fix
Goku-kun 51fb3f6
fix(pretext-pt): ARTICLE doesn't exist in the code; add the sample file
Goku-kun 23538ca
fix(pretext-pt): rendering offset logic for text
Goku-kun 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ The traditional way to find out is to literally render the text to the screen (e | |
| Pretext solves the problem of calculating the height of a paragraph of line-wrapped text without touching the DOM at all. | ||
|
|
||
|
|
||
| View demos of pretext here: https://chenglou.me/pretext/ | ||
| View demos of pretext here: [Pretext](https://www.pretext.cool/) | ||
|
|
||
| ## Introduction | ||
|
|
||
|
|
@@ -201,7 +201,7 @@ const TEXT_WIDTH = CANVAS_WIDTH - PADDING * 2; | |
| const IMAGE_GAP = 20; | ||
| ``` | ||
|
|
||
| After the setup, create a `const` variable called `ARTICLE`, and in quotes, paste your article or text. If you want some sample text you can use text from this repo [here](). | ||
| After the setup, create a `const` variable called `ARTICLE`, and in quotes, paste your article or text. If you want some sample text you can use text from this repo [here](https://raw.githubusercontent.com/codedex-io/projects/main/projects/build-a-canvas-typography-layout-with-pretext/sample-article.txt). | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to add a sample-article.txt file with the content you want to add! @exrlla |
||
|
|
||
| Now, let's connect the JavaScript to the HTML elements we have: | ||
|
|
||
|
|
@@ -258,11 +258,11 @@ let y = PADDING; | |
| const lines = []; | ||
|
|
||
| while (true) { | ||
| let lineWidth = TEXT_WIDTH; | ||
| let xOffset = PADDING; | ||
| let leftCut = PADDING; | ||
| let rightCut = CANVAS_WIDTH - PADDING; | ||
| ``` | ||
|
|
||
| We'll then check if each line overlaps an image. | ||
| We track the left and right edges of the available text band separately so multiple images on the same line can each tighten one side without overwriting each other. We'll then check if each line overlaps an image. | ||
|
|
||
| ```js | ||
| for (const obs of obstacles) { | ||
|
|
@@ -274,21 +274,21 @@ We'll then check if each line overlaps an image. | |
| const canvasCenter = CANVAS_WIDTH / 2; | ||
| ``` | ||
|
|
||
| For the following lines of code, we're asking to detect if the image is on the right to then shrink line width, and If image is on the left to push text to the right. Depending on your desired layout or behaviour you want to execute, this could change. | ||
| For the following lines of code, we're asking to detect if the image is on the right to then tighten the right edge, and if the image is on the left to push the left edge inward. Depending on your desired layout or behaviour you want to execute, this could change. | ||
|
|
||
| ```js | ||
| if (obsCenter > canvasCenter) { | ||
| // Image on right → shrink width | ||
| const availableRight = obs.left - IMAGE_GAP; | ||
| lineWidth = Math.max(50, availableRight - PADDING); | ||
| // Image on right → tighten the right edge | ||
| rightCut = Math.min(rightCut, obs.left - IMAGE_GAP); | ||
| } else { | ||
| // Image on left → push text right | ||
| const imgRight = obs.right + IMAGE_GAP; | ||
| xOffset = Math.max(PADDING, imgRight); | ||
| lineWidth = Math.max(50, CANVAS_WIDTH - PADDING - xOffset); | ||
| // Image on left → push the left edge inward | ||
| leftCut = Math.max(leftCut, obs.right + IMAGE_GAP); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const xOffset = leftCut; | ||
| const lineWidth = Math.max(50, rightCut - leftCut); | ||
| ``` | ||
|
|
||
| Now, we'll ask pretext for the next line that fits using `layoutNextLineRange()` and `materializeLineRange()` to then store it. | ||
|
|
@@ -369,8 +369,8 @@ Huge shoutout to [Cheng Lou](https://chenglou.me/) for pioneering this engineeri | |
|
|
||
| Feel free to take a look at these resources and some ideas to expand on this current pretext project! | ||
|
|
||
| - [pretext GitHub](https://github.com/chenglou/pretext#js-repo-pjax-container) from @_chenglou | ||
| - [pretext demos](https://chenglou.me/pretext/) | ||
| - [pretext GitHub](https://github.com/chenglou/pretext) from @_chenglou | ||
| - [pretext demos](https://www.pretext.cool/) | ||
| - [more! pretext demos](https://somnai-dreams.github.io/pretext-demos/) | ||
| - [this](https://github.com/exrlla/pretext-scrollabe-project) project demo repo on GitHub | ||
| - [x thread on pretext projects](https://x.com/_chenglou/status/2038497396033012131) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@exrlla This is the new demo link.