-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
feat: adds text splitting functionality #11496
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c7bf3bf:
|
This is a very cool idea and well documented! Excellent bar of quality as usual @Zyie. Would you mind creating a quick demo (maybe with animation) to showcase this? I have one general concern which is about destroying lifecycle. Since the split result is a generic object, I don't see an easy way to destroy the extra text elements and containers. Our contract generally is: if Pixi instantiates it, Pixi destroys it. How would a user do that here? Also Another API approach might be to introduce a new display class to manage the element more directly (maybe that extends Container). Something like const myText = new Text({
text: 'Hello World',
style: {},
});
const seg = new TextSegmenter({
element: myText,
replace: true,
});
seg.chars.forEach((char, i) => {
char.alpha = 0;
// Fade in each character sequentially
gsap.to(char, {
alpha: 1,
delay: i * 0.1
});
});
seg.destroy(); |
Here is a demo link:
So the result from interface Result {
container: Container;
lines: Container[];
words: Container[];
chars: Text[];
} So to destroy the new text you would use
That is correct. It doesn't destroy the original text. My thinking was that you might want to split the text up for an animation, then swap it back for the original.
I'm not against this approach either. It aligns with what i had in mind originally before going down the current path. Also just as a note that this is all inspired by the gsap plugin that does this for html text: https://gsap.com/docs/v3/Plugins/SplitText/ |
Me and Mat had a quick chat about this today and agree that we should go down the |
Cool. The benefit of an explicit class destroy is that it will also handle all the dereferencing for lines, words, chars arrays. |
Adds an 'origin' property to the container, providing a way to specify the point around which the container rotates and scales without affecting its position. This allows for more flexible and intuitive control over container transformations, particularly when rotating or scaling around a specific point.
@bigtimebuddy ready for another review |
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.
This is great. I love the naming choices here. This experimental feature is enough functionality to get some feedback from developers.
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.
looks good!
Co-authored-by: Mat Groves <mat@goodboydigital.com>
Adds the ability to split Text and BitmapText objects into characters, words, and lines.
This provides a more granular control over text elements, allowing for advanced animations and effects.
We now have two new classes
SplitText
andSplitBitmapText
. I decided to split these up to allow for as much tree shaking to be preserved as possible. If we went with the one class approach you would always be bundlingText
andBitmapText
.These classes also support dynamic updates to styles and text. Changing text does mean we destroy all the children and make them again. Changes to style are safe as we just update the position/style without needing to create a new instance.
examples
Split Existing Text
New Instance
Working with Results
demo: https://codesandbox.io/p/sandbox/pixi-js-sandbox-forked-chgp88
demo2: https://codesandbox.io/p/devbox/pixi-js-sandbox-forked-yly7k3
demo3: https://codesandbox.io/p/devbox/pixi-js-sandbox-forked-j4swyl
demo4: https://codesandbox.io/p/devbox/pixi-js-sandbox-forked-sfny96
demo5: https://codesandbox.io/p/devbox/pixi-js-sandbox-forked-cctmf8