Re: [csswg-drafts] [css-values] Proposal: add sibling-count() and sibling-index() (#4559)

So I agree with the proposed set of four functions: `sibling-index()`, `sibling-count()`, `child-count()`, and `tree-depth()`.

> concern about "sibling" naming

I get the concern on precision, but I don't know of another word covering the concept, and "sibling" can be used in this sense (like "I'm one of three siblings"). I think it's the most reasonable name. I do *not* like being less specific with something like `count()` or `index()`.

> node vs element

Node count is just so, so un-useful. ^_^ But also, having these functions disagree with the :nth-child() selectors would be a *terrible* idea imo.

> function vs keyword

Hm, yeah, could go either way. I don't plan on extending the functions to more stuff, so I guess keywords could work. I'm slightly wary of adding "keywords that can be used anywhere" because of the potential syntax conflicts (such as animation-name in the 'animation' property); functions avoid that. (We *should* have ensured that author-defined names were syntactically distinguishable in all cases earlier, but that's a legacy mistake.) If these were usable *only* in calculations (that is, you have to wrap it in a calc() or other math function), my concern would be alleviated.

Tho the suggestion to later extend this to allow a selector, a la the `:nth-child(... of <selector>)`, is a reasonable future extension point, and thus a decent argument for function over keyword.

> 1-index vs 0-index

Definitely 1-indexed, just like :nth-child(). Diverging from :nth-child() would be a terrible mistake.

> count of siblings vs count of "siblings other than me"

I think the concept is a lot cleaner to express and understand if it's just "how many children there are"; both "sibling count" and "child count" should agree. Some cases definitely want "siblings other than me", but that's trivial to do in a calc(), and you're probably already using a calc() anyway. (The given example is, to do a division as well.)

> count/index across the entire document

Not planning on doing this; it would be *super* expensive. Use-cases are small enough, as far as I'm aware, that I'm happy to leave that to JS for decorating the element with a value.

> using var() with predefined (not --prefixed) keywords

This would be a misuse of the var() syntax, and have unfortunate implications regarding parsing; we wouldn't be able to reject a `color: children-count()` even tho the function can only ever return integers.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4559#issuecomment-562374563 using your GitHub account

Received on Friday, 6 December 2019 00:09:21 UTC