Skip to content
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

Is it possible to split by lines and by characters? #34

Open
Rigo-m opened this issue Jan 16, 2019 · 7 comments
Open

Is it possible to split by lines and by characters? #34

Rigo-m opened this issue Jan 16, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@Rigo-m
Copy link

Rigo-m commented Jan 16, 2019

If it's possible, it should be documented.

Also, in my use-case I would like to be able to have splitting by lines, words and characters working together with whitespace:true OR i would like to have whitespace:true on words plugin (counting whitespace as a word).

Should this be a feature or am I missing something?

Thanks in advance

@Rigo-m
Copy link
Author

Rigo-m commented Jan 16, 2019

Also, shouldn't the lines plugin divide the words inside .line div's?

@ThomasRutzer
Copy link

Seems like adding it to depends-List of linePlugin could do that job:

var linePlugin = createPlugin(
    /*by: */ 'lines',
    /*depends: */ [WORDS, CHARS],
    /*key: */ 'line',
    /*split: */ function(el, options, ctx) {
      return detectGrid(el, { matching: ctx[WORDS] }, 'offsetTop')
   }
);

Still, this could / should be an option...

@shshaw
Copy link
Owner

shshaw commented Feb 4, 2019

Currently, it is possible in this way, though it does end up wrapping the words twice:

Splitting({ by: 'lines' }).forEach( s => {
  Splitting({ target: s.el, by: 'chars', force: true })
});

https://codepen.io/shshaw/pen/04873953a73e6d6dc60ad539a35a26ae

Agreed that this should be better supported. Resplitting should also be a little cleaner overall. Making some notes for the next release. Thanks!

@shshaw shshaw added the enhancement New feature or request label Feb 4, 2019
@Rigo-m
Copy link
Author

Rigo-m commented Feb 5, 2019

using forEach on the output is actually quite clean, I feel stupid for not thinking about that solution. I'm glad I gave you a use case to think about.

Thanks for the answers!

@notoriousb1t
Copy link
Collaborator

notoriousb1t commented Feb 5, 2019

I believe this might also work and avoid the double wrapping:

Splitting({ by: 'lines' }).forEach(s => { 
  // Use s.words as the target instead of s.el
  Splitting({ target: s.words, by: 'chars', force: true }) 
});

but I don't have time to validate it right at this moment.

@chrisjwaddell
Copy link

I'd also love to do animations by line like letting the line float up but the last part of each line float up later than the first part of the line according to it's index within the line.
It would be great to have extra variables for line animation.
charline-index or linechar-index
wordline-index or lineword-index

word-index is 50 but it's 4th on that line.

So you can do something like:
transition-delay: calc(var(--linechar-index) * 0.5s)
or
transition-delay: calc(calc(var(--linechar-index) * 0.1s) + calc(var(--line-index) * 0.8s))

If these line variables were optionally available, that would be great.

By doing it this way, you probably wouldn't need '.word' within a new '.line' class as suggested above. I'm not sure if you would need to do that or not. But --linechar-index and --lineword-index would be easy for users.

@powerbuoy
Copy link

powerbuoy commented Feb 16, 2021

Currently, it is possible in this way, though it does end up wrapping the words twice:

Splitting({ by: 'lines' }).forEach( s => {
  Splitting({ target: s.el, by: 'chars', force: true })
});

https://codepen.io/shshaw/pen/04873953a73e6d6dc60ad539a35a26ae

Agreed that this should be better supported. Resplitting should also be a little cleaner overall. Making some notes for the next release. Thanks!

This also seems to strip the space from inside the span.whitespace elements for some reason. You can try tour pen with this HTML instead: <div data-splitting>Hello World World World World World!</div> (I wasn't allowed to fork it).

I believe this might also work and avoid the double wrapping:

Splitting({ by: 'lines' }).forEach(s => { 
  // Use s.words as the target instead of s.el
  Splitting({ target: s.words, by: 'chars', force: true }) 
});

but I don't have time to validate it right at this moment.

This does not remove whitespace, however the (inner) --word-index is always 0 with this approach.

Both do wrap words twice.

For me the ideal solution would be to simply be able to run by: ['lines', 'chars'] and not have any double wrapping or other strange behaviour. Just the same markup as with chars only but with the added lines-variables.

Also, having a span.line around each line would actually be ideal. At least for what I'm trying to accomplish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants