1. 序論
◎非規範的巨大な文書や~appは(あるいは小さなものですら)、 相当量の~CSSを包含し得る。 ~CSS~fileの中の値の多くは、 同じ~dataを複写することになる。 例えば、 色の~~体系を確立して,全体を通して数個の色を再利用している~siteがあったとする。 この~dataを改めることは、 ~CSS~fileの中に散らばっている(あるいは複数~fileにわたっている)がために,困難で誤り易い~~作業にもなりかねず、 また,検索置換も~~容易いとは限らない。 ◎ Large documents or applications (and even small ones) can contain quite a bit of CSS. Many of the values in the CSS file will be duplicate data; for example, a site may establish a color scheme and reuse three or four colors throughout the site. Altering this data can be difficult and error-prone, since it’s scattered throughout the CSS file (and possibly across multiple files), and may not be amenable to Find-and-Replace.
この~moduleは、 `~custom~prop$と~~総称される,作者~定義な~propの族を導入する。 それは、 ~stylesheet作者が[ 自身が選んだ名前を伴う~propに任意な値をアテガって、 その値を — `var$f 関数を通して — 文書~内の至る所にある他の~propに利用する ]ことを許容する。 これにより、[ 見かけからは~~意味を汲み取れない値にも,用途に見合った~~体系的な名前を付けられる ]ようになるので,巨大な~fileも読み易くなる。 また、[ `~custom~prop$の中で一箇所の値を変更するだけで,それが定義する変数を利用している箇所すべてに自動的に伝播する ]ことになるので, その種の~file編集も格段に容易かつ誤り難くなる。 ◎ This module introduces a family of custom author-defined properties known collectively as custom properties, which allow an author to assign arbitrary values to a property with an author-chosen name, and the var() function, which allow an author to then use those values in other properties elsewhere in the document. This makes it easier to read large files, as seemingly-arbitrary values now have informative names, and makes editing such files much easier and less error-prone, as one only has to change the value once, in the custom property, and the change will propagate to all uses of that variable automatically.
1.1. 値~定義
【 この節の内容は ~CSS日本語訳 共通~pageに移譲。 】
2. ~custom~propを定義する: ~propの族 `--*^p
この仕様は、 `~custom~prop$と呼ばれる,~~自由に~~拡張可能( `open-ended^en )な[ ~propの集合 ]を定義する。 それらは、 他の~propの値の中の `var$f 関数の代用~値 — `var$f を置換することになる値 — を定義するために利用される。 ◎ This specification defines an open-ended set of properties called custom properties, which, among other things, are used to define the substitution value of var() functions.
【 語 “~~代用( `substitute^en )” は、 一般に, “その場限り” の含みがある~~置換を意味する — “~~永続的な” 含みがある “~~置換( `replace^en )” に比して。 】
◎名 `--*@p 【注釈文を見よ】 ◎値 `declaration-value$t? ◎初 `無効が保証される値$ ◎ the guaranteed-invalid value ◎適 すべての要素, すべての疑似要素(一部の~propに制約されるものも含む) ◎ all elements and all pseudo-elements (including those with restricted property lists) ◎継 される ◎百 受容しない ◎算 指定d値の中の変数( `var$f )を`代用-$した結果/ `無効が保証される値$ ◎ specified value with variables substituted, or the guaranteed-invalid value ◎順 文法に従う ◎ア 離散的 ◎表終~UAには、 すべての媒体 — 視覚的でないものも含む — に対し,この~propを~supportすることが期待される。 ◎ User agents are expected to support this property on all media, including non-visual ones.
`~custom~prop@ は、 "`--^c" から開始される任意の名前の~propである — 例えば `--foo^p の様に。 `custom-property-name@t 生成規則がこれに対応する — それは、 `dashed-ident$t ( 2 個の~dashから開始される,任意の妥当な`~CSS識別子$)として定義される。 ただし, "`--^c" 自体は除く — それは、 ~CSSによる将来の利用~用に予約される。 `~custom~prop$は、 もっぱら[ 作者/利用者 ]から利用されるものである。 ~CSSが ここに示されるものを超える意味を与えることは、 決してない。 ◎ A custom property is any property whose name starts with two dashes (U+002D HYPHEN-MINUS), like --foo. The <custom-property-name> production corresponds to this: it’s defined as any <dashed-ident> (a valid identifier that starts with two dashes), except -- itself, which is reserved for future use by CSS. Custom properties are solely for use by authors and users; CSS will never give them a meaning beyond what is presented here.
【 この名前は、 ~vendor接頭辞~付きの~prop (例: `-webkit-foo^p ) から~vendor名を取り除いたもの (例: `--foo^p )と捉えることもできる (すなわち、作者~自身が “匿名な~vendor” である)。 そのような捉え方を意図して命名されたのかもしれない。 】
~custom~propは、 多目的に利用できる変数を定義し, `var$f 記法で参照される。 例えば,一群の色を一貫して~designに利用する~pageは、 それらの色を~custom~propに格納した上で,変数を通して利用できる: ◎ Custom properties define variables, referenced with the var() notation, which can be used for many purposes. For example, a page that consistently uses a small set of colors in its design can store the colors in custom properties and use them with variables:
`root$ps {
--main-color: #06c;
--accent-color: #006;
}
/*
~CSS~fileの残りの部分
◎
The rest of the CSS file
*/
#foo h1 {
`color$p: var(--main-color);
}
覚え易い色の命名により、 色~codeの中の見つけ難い誤記は防止される。 ~theme色が絶えず変更されようが、 ~web~page内のすべての~stylesheetに渡って多数の編集を行うことなく, 単純な一箇所(~custom~propの値)の変更に注力するだけで済むようになる。 ◎ The naming provides a mnemonic for the colors, prevents difficult-to-spot typos in the color codes, and if the theme colors are ever changed, focuses the change on one simple spot (the custom property value) rather than requiring many edits across all stylesheets in the webpage.
【 `var(--main-color)^v が参照するのは,[[ それを利用する~prop ]が適用される要素 ]の `--main-color^p ~propの値になる。 この例では, `--main-color^p が文書の~根~要素( `root$ps )に対し宣言されているので、 その値は, 普通の継承d~propと同様に — 別の `--main-color^p で上書きされない限り — 文書~内のどの要素(および疑似要素)にも継承され、 その結果,どの `var(--main-color)^v も値 `#06c^v で代用されることになる。 】
他の~CSS~propと違って、 ~custom~propの名前は`~ASCII大小無視$`ではない^em。 ~custom~propの名前は、 互いに`一致する$場合に限り,等しいとされる。 ◎ Unlike other CSS properties, custom property names are not ASCII case-insensitive. Instead, custom property names are only equal to each other if they are identical to each other.
`--foo^p と `--FOO^p は、 どちらも妥当であるが,別個な~propになる — `var(--foo)^v を利用すれば前者, `var(--FOO)^v を利用すれば後者を指すことになる。 ◎ While both --foo and --FOO are valid, they are distinct properties —using var(--foo) will refer to the first one, while using var(--FOO) will refer to the second.
たぶん,もっと驚くことに、 `--foó^p と `--foó^p は,別個な~propになる。 前者は[ `00F3^U `LATIN SMALL LETTER O WITH ACUTE^cn ]で綴られ, 後者は[ ~ASCII "o", `0301^U `COMBINING ACUTE ACCENT^cn ]並びとして綴られるが、 “`一致する$” 関係は — ~Unicode正規化と~localeに特有な照合cによる複階性と陥穽を避けるため — 2 個の文字列が等しいかどうか決定するときに,符号位置ごとに直に比較する。 ◎ Perhaps more surprisingly, --foó and --foó are distinct properties. The first is spelled with U+00F3 (LATIN SMALL LETTER O WITH ACUTE) while the second is spelled with an ASCII "o" followed by U+0301 (COMBINING ACUTE ACCENT), and the "identical to" relation uses direct codepoint-by-codepoint comparison to determine if two strings are equal, to avoid the complexities and pitfalls of unicode normalization and locale-specific collation.
各種[ ~OS/~keyboard/入力~method ]は,~textを[ 視覚的には一致するが,異なる符号位置を利用して符号化する ]こともあるので、 作者には、[ 混同の可能性を避けるよう,変数~名を選ぶ ]か[ 似て非なる並びが生じないことを確保するよう, 変数~名に~escapeその他の手段を利用する ]ことを勧める。 例えば, `CHARMOD-NORM$r の § 2.3 を見よ。 ◎ Operating systems, keyboards, or input methods sometimes encode visually-identical text using different codepoint sequences. Authors are advised to choose variable names that avoid potential confusion or to use escapes and other means to ensure that similar appearing sequences are identical. See Section 2.3 in [CHARMOD-NORM] for examples.
次の~CSSを保守している開発者は、 `.test^css がなぜ `red^v になるか困惑するかもしれない: ◎ Developers maintaining the following CSS might be confused why the test patch is red:
--fijord: red; --fijord: green; --fijord: blue; .test { background-color: var(--fijord); }
その理由は、 これらの~custom~propは,見かけは一致するが異なる文字~並びを利用していることにある ⇒# 1 個目は `LATIN SMALL LETTER F^cn + `LATIN SMALL LETTER I^cn + `LATIN SMALL LETTER J^cn / 2 個目は `LATIN SMALL LETTER F^cn + `LATIN SMALL LIGATURE IJ^cn / 3 個目は `LATIN SMALL LIGATURE FI^cn + `LATIN SMALL LETTER J^cn ◎ The reason is that the first custom property uses the character sequence LATIN SMALL LETTER F + LATIN SMALL LETTER I + LATIN SMALL LETTER J; the second, identical-looking one uses the character sequence LATIN SMALL LETTER F + LATIN SMALL LIGATURE IJ while the third uses the character sequence LATIN SMALL LIGATURE FI + LATIN SMALL LETTER J.
なので、 この~CSSは, 3 つの別個な~custom~propを包含する — うち 2 つは利用されない。 ◎ So the CSS contains three distinct custom properties, two of which are unused.
~custom~propは、 `all$p ~propにより設定し直されることはない。 将来には、 すべての変数を設定し直す~propも定義され得る。 ◎ Custom properties are not reset by the all property. We may define a property in the future that resets all variables.
他の任意の~propと同じ意味で、 ~custom~propにも`~CSS全域~keyword$を利用できる。 ◎ The CSS-wide keywords can be used in custom properties, with the same meaning as in any another property.
注記: すなわち それらは、 通常通り`~cascaded値$の時点で解釈され,~custom~propの値のように保全されることはない†。 したがって,対応する変数が解決される時点で代用されることもない。 ◎ Note: That is, they’re interpreted at cascaded-value time as normal, and are not preserved as the custom property’s value, and thus are not substituted in by the corresponding variable.
【† すなわち,~custom~propに対する全域~keyword値は、 `var$f 関数が解決される前 — 算出d値を得る前 — の段階で,`指定d値$(すなわち,初期~値または継承d値)にされる。 例えば,次の~stylesheet:
p { --foo: inherit; color: var(--foo); }
における `var(--foo)^v は、[ `inherit^v `ではなく^em, `--foo^p が継承する値 ]で代用されることになる。 したがって、 `p^e 要素の `color^p は,その先祖の[ `color^p `ではなく^em, `--foo^p ]~propの値をとることになる。 】
注記: この~moduleは, “変数” を作成するための[ `var$f による`~custom~prop$の利用 ]に注力しているが、 ~scriptから[ 構文解析される/作動される ]ような,実際の~custom~propとしても利用し得る。 `CSS-EXTENSIONS$r が、 これらの利用事例を拡げて,もっと利用し易くするものと期待されている。 ◎ Note: While this module focuses on the use of custom properties with the var() function to create “variables”, they can also be used as actual custom properties, parsed by and acted on by script. It’s expected that the CSS Extensions spec [CSS-EXTENSIONS] will expand on these use-cases and make them easier to do.
~custom~propは、 “普通の” ~propであり,どの要素に対しても宣言できる。 それらは、 通常の[ 継承と~cascade規則 ]で解決される。 それらは、[ `media$at その他の`条件付き~group規則$により条件付きにすることもできる/ ~HTMLの `style^a 属性の中でも利用できる/ ~CSSOMを利用して[読取る/設定する]こともできる ]等々…。 ◎ Custom properties are ordinary properties, so they can be declared on any element, are resolved with the normal inheritance and cascade rules, can be made conditional with @media and other conditional rules, can be used in HTML’s style attribute, can be read or set using the CSSOM, etc.
特に、 それらは,~animateすることすらできる — ただし、 ~UAには,それらの内容を解釈するすべがないので、 他の[ 補間が利かない値~pair ]に対するときと同じく, 常に, “50% の所で裏返す” 様なふるまいになる。 また、 `keyframes$at 規則の中で利用される【宣言される】どの`~custom~prop$も, `~animationに染まって@ いるとされ、 各種~animation~prop( `animation-*^p )の中で `var$f 関数を介して参照されたときの扱われ方に影響する。 ◎ Notably, they can even be animated, but since the UA has no way to interpret their contents, they always use the "flips at 50%" behavior that is used for any other pair of values that can’t be intelligently interpolated. However, any custom property used in a @keyframes rule becomes animation-tainted, which affects how it is treated when referred to via the var() function in an animation property.
注記: 離散的に~animateする他の~propと同様、 ~custom~propは,遷移し得ない。 しかしながら,`登録-済み~custom~prop$は、 それに与えた構文が離散的でない~animationの挙動を備える場合には,遷移し得る。 ◎ Note: Like any other property that animates discretely, custom properties can’t be transitioned. Registered custom properties can, however, if given a syntax that has non-discrete animation behavior.
~animationに染められるのは、 “伝染的” である: ~custom~propは、 `~animationに染まって$いる~propを参照するならば, 自身も`~animationに染まって$いることになる。 ◎ Animation-tainted is "infectious": custom properties which reference animation-tainted properties also become animation-tainted.
次の~style規則: ◎ This style rule:
:root { --header-color: #06c; }
は、 根~要素に対し名前 `--header-color^p の`~custom~prop$を宣言し, 値 "`#06c^v" をアテガう。 この~propは、 文書~内の他の要素に継承される。 その値は、 `var$f 関数を通して参照できるようになる: ◎ declares a custom property named --header-color on the root element, and assigns to it the value "#06c". This property is then inherited to the elements in the rest of the document. Its value can be referenced with the var() function:
h1 { `background-color$p: var(--header-color); }
この規則は,
`background-color^p: `#06c^v;
と記すことに等価になるが、
変数~名から色の用途が明瞭になることに加え、
根~要素の `--header-color^p ~propの値を変更するだけで,[
文書~内の他の要素に対し利用されている すべての `var(--header-color)^v
]が一括して更新される。
◎
The preceding rule is equivalent to writing background-color: #06c;, except that the variable name makes the origin of the color clearer, and if var(--header-color) is used on other elements in the document, all of the uses can be updated at once by changing the --header-color property on the root element.
同じ名前の`~custom~prop$が複数回 宣言されている場合、 標準な~cascade規則を利用して解決される。 変数は常に,同じ要素に結付けられた~custom~propの`算出d値$から値を取り出す: ◎ If a custom property is declared multiple times, the standard cascade rules help resolve it. Variables always draw from the computed value of the associated custom property on the same element:
:root { --color: blue; } div { --color: green; } #alert { --color: red; } * { color: var(--color); }
<p>僕は根~要素から `blue^v を継承しています。</p> <div>俺には `green^v が直に設定されている。</div> <div id='alert'> 私には `red^v が直に設定されているよ。 <p>自分も `red^v だけど、継承なんだな。</p> </div> ◎ <p>I inherited blue from the root element!</p> <div>I got green set directly on me!</div> <div id='alert'> While I got red set directly on me! <p>I’m red too, because of inheritance!</p> </div>
現実における`~custom~prop$の用例として、 文字列を その利用箇所から容易に外へ分離して,国際-化の保守を援助することが挙げられる: ◎ A real-world example of custom property usage is easily separating out strings from where they’re used, to aid in maintenance of internationalization:
:root, :root:lang(en) {--external-link: "external link";} :root:lang(el) {--external-link: "εξωτερικός σύνδεσμος";} :root:lang(ja) {--external-link: "~~外部~~リンク";} a[href^="http"]::after { content: " (" var(--external-link) ")" }
変数の宣言を別~fileに分けて,翻訳の保守をより単純にすることもできる。 ◎ The variable declarations can even be kept in a separate file, to make maintaining the translations simpler.
2.1. ~custom~propの値の構文
`~custom~prop$に許容される構文は極めて寛容にされている。 `declaration-value$t 生成規則は、[ 1 個~以上の~tokenからなり,次に挙げる~tokenは包含しない ]`任意の^em並びに合致する:
- `bad-string-token$P
- `bad-url-token$P
- 対を成さない括弧類: `)-token$P, `]-token$P, `}-token$P
- ~top-levelの `semicolon-token$P
- ~top-levelの `delim-token$P のうち,その.値に "`!^c" を伴うもの
加えて、 `~custom~prop$の値が `var$f 参照を包含している場合、 その `var$f 参照は,指定された `var$f 文法に則って妥当でなければナラナイ。 さもなければ、 `~custom~prop$は無効になり,無視するモノトスル。 ◎ In addition, if the value of a custom property contains a var() reference, the var() reference must be valid according to the specified var() grammar. If not, the custom property is invalid and must be ignored.
注記: この定義と一般~CSS構文~規則から、 ~custom~propの値は,対を成さない引用符や括弧類を決して含まず、 直列化し直すとき,より大きな構文~構成子 — それを囲っている~style規則など — に~~影響することはない。 ◎ Note: This definition, along with the general CSS syntax rules, implies that a custom property value never includes an unmatched quote or bracket, and so cannot have any effect on larger syntax constructs, like the enclosing style rule, when reserialized.
注記: ~custom~propは末尾に `!important^css を伴い得るが、 これは~CSS構文解析器により~propの値から自動的に除去された上で, 当の~custom~propを~CSS~cascadeにおいて`~importantな宣言$にする。 言い換えれば、 ~top-levelの文字 "`!^c" の禁則は, `!important^css の利用を妨げるものではない — `!important^css は、 構文を検査する前に除去されるので。 ◎ Note: Custom properties can contain a trailing !important, but this is automatically removed from the property’s value by the CSS parser, and makes the custom property "important" in the CSS cascade. In other words, the prohibition on top-level "!" characters does not prevent !important from being used, as the !important is removed before syntax checking happens.
例えば,次は、 妥当な~custom~propである: ◎ For example, the following is a valid custom property:
--foo: if(x > 5) this.width = 10;
この値は、 通常のどの~propの中でも無効になるので,`変数^emとしては明白に無用であるが、 ~JSにより[ 読取る/動作させる ]用途はあり得る。 ◎ While this value is obviously useless as a variable, as it would be invalid in any normal property, it might be read and acted on by JavaScript.
[ ~custom~propの値, および ~custom~propの値で代用される `var$f 関数の値 ]の文字大小は、 `区別され^em,作者が与えた元の文字大小を保全するモノトスル。 (多くの~CSS値は,[ `~ASCII大小無視$なので、 ~UAは,それらを大小いずれかに “正準-化” できる ]が、 ~custom~propには,それは許容されない。) ◎ The values of custom properties, and the values of var() functions substituted into custom properties, are case-sensitive, and must be preserved in their original author-given casing. (Many CSS values are ASCII case-insensitive, which user agents can take advantage of by "canonicalizing" them into a single casing, but that isn’t allowed for custom properties.)
注記: ~custom~propは,`何でも^emを包含し得るので、 その内側に何があるか解釈する方法を知る一般的な仕方は無い (既知な~propの中で,それを参照する `var$f が`代用-$されるまでは)。 それらの値は — `部分的に^em,一部の事例に限って解決されることはなく — 完全に,解決されずに残され、[ `var^f 関数が合間に挟まれた, ~CSS~token列 ]が成す裸の~streamになる。 ◎ Because custom properties can contain anything, there is no general way to know how to interpret what’s inside of them (until they’re substituted into a known property with var()). Rather than have them partially resolve in some cases but not others, they’re left completely unresolved; they’re a bare stream of CSS tokens interspersed with var() functions.
これには、
ある意外な含意がある。
例えば,~CSSにおける相対~URLは、
当の値が現れる~stylesheetの基底~URLを基準に解決される。
しかしながら,
`/a/style.css^l に在る~stylesheet内に
`--my-image^p: `url(foo.jpg)^v;
の様な~custom~propが~~現れる場合、
即時に絶対~URLに解決されることはない
— それを指す変数が後で
`/b/style.css^l に在る`異なる^em ~stylesheet内で
`background$p: `var(--my-image)^v;
の様に利用された場合、
`そこでは^em `/b/foo.jpg^l に解決されることになる。
◎
This has some knock-on implications. For example, relative URLs in CSS are resolved against the base URL of the stylesheet the value appears in. However, if a custom property like --my-image: url(foo.jpg); shows up in an "/a/style.css" stylesheet, it will not resolve into an absolute URL immediately; if that variable is later used in a different "/b/style.css" stylesheet like background: var(--my-image);, it will resolve at that point to "/b/foo.jpg".
2.2. 無効が保証される値
`~custom~prop$の初期~値は、 `無効が保証される値@ である。 § ~cascade変数の利用-法 に定義されるように、 `var$f を利用して,これを値にとる`~custom~prop$で代用すると、 それを参照している~propは,`算出d値の時点で無効$になる。 ◎ The initial value of a custom property is a guaranteed-invalid value. As defined in § 3 Using Cascading Variables: the var() notation, using var() to substitute a custom property with this as its value makes the property referencing it invalid at computed-value time.
この値が直列化されるときは,空~文字列になるが、 ~custom~propの中に — `--foo: ;^css の様に — 実際に空~値を書いても,妥当な(空)値になり、 `無効が保証される値$にはならない。 理由が何であれ,変数を`無効が保証される値$に手動で設定し直したいと求めるならば、 ~keyword `initial$v 利用して行える。 ◎ This value serializes as the empty string, but actually writing an empty value into a custom property, like --foo: ;, is a valid (empty) value, not the guaranteed-invalid value. If, for whatever reason, one wants to manually reset a variable to the guaranteed-invalid value, using the keyword initial will do this.
2.3. 循環依存の解決-法
`~custom~prop$は、 ほとんどの所では評価されないままにされるが, その値の中の `var$f 関数を評価することは許容されている。 そのため、 `~custom~prop$自身が自身を指す `var$f を利用していたり, 複数の`~custom~prop$が互いに他を指している場合、 循環依存が生じ得る。 ◎ Custom properties are left almost entirely unevaluated, except that they allow and evaluate the var() function in their value. This can create cyclic dependencies where a custom property uses a var() referring to itself, or two or more custom properties each attempt to refer to each other.
各~要素に対し、 各`~custom~prop$に対応する~nodeからなる有向~依存関係~graphを,次のように作成する ⇒ ある`~custom~prop$ %prop1 の値が,ある`~custom~prop$ %prop2 ( %prop1 と同じでもよい) を指している `var$f 関数を包含している( `var$f の~fallback引数も込みで)ならば、 %prop1 から %prop2 へ辺で結ぶ。 ◎ For each element, create a directed dependency graph, containing nodes for each custom property. If the value of a custom property prop contains a var() function referring to the property var (including in the fallback argument of var()), add an edge between prop and the var. Edges are possible from a custom property to itself.
この依存関係~graph内に循環がある場合、 その循環を成す どの`~custom~prop$も,`算出d値の時点で無効$になる。 ◎ If there is a cycle in the dependency graph, all the custom properties in the cycle are invalid at computed-value time.
注記: 定義-済み~propは、 ある[ 依存関係の循環 ]に関与する場合には,[ その値~内に無効な変数があることにより,`算出d値の時点で無効$になる ]か,循環~用に自前の取扱いを定義する( `em$u 値を利用している `font-size$p の様に)。 それらは、 ~custom~propの様に`無効が保証される値$には算出されない。 ◎ Note: Defined properties that participate in a dependency cycle either end up with invalid variables in their value (becoming invalid at computed-value time), or define their own cyclic handling (like font-size using em values). They do not compute to the guaranteed-invalid value like custom properties do.
変数を安全に利用する~custom~propの例を示す: ◎ This example shows a custom property safely using a variable:
:root { --main-color: #c06; --accent-background: linear-gradient( to top, var(--main-color), white ); }
`--accent-background^p ~propは (および、 `var(--main-color)^v を利用する他の~propも同様に)、 `--main-color^p ~propが変更されたときに自動的に更新されることになる。 ◎ The --accent-background property (along with any other properties that use var(--main-color)) will automatically update when the --main-color property is changed.
他方,次の例における 2 つの変数は、 互いに依存しているので,無効な~instanceになる: ◎ On the other hand, this example shows an invalid instance of variables depending on each other:
:root { --one: calc(var(--two) + 20px); --two: calc(var(--one) - 20px); }
`--one^p, `--two^p どちらも, 今や`算出d値の時点で無効$になり、 長さでなく`無効が保証される値$に算出される。 ◎ Both --one and --two are now invalid at computed-value time, and compute to the guaranteed-invalid value rather than lengths.
重要な点として、 `~custom~prop$の値の中のどの `var$f 関数も,`算出d値の時点$で解決される 【`代用-$される】 — したがって、 その値が継承されるときには,`すでに^em解決されている — ことを銘記しておく。 一般に,循環依存が生じるのは、 同じ要素~上の複数の~custom~propが互いを指すときに限られる。 要素~treeの中で,一方が他方の先祖である 2 つの要素~上に定義された~custom~propの間で参照が循環することは、 決してない。 ◎ It is important to note that custom properties resolve any var() functions in their values at computed-value time, which occurs before the value is inherited. In general, cyclic dependencies occur only when multiple custom properties on the same element refer to each other; custom properties defined on elements higher in the element tree can never cause a cyclic reference with properties defined on elements lower in the element tree.
【 `算出d値の時点@ — 明示的には定義されていないが、 `~cascaded値の処理$における,`算出d値$を得る段階を指すと見受けられる。 】
例えば,次の構造における、 3個の~custom~propが循環することはない。 すべて妥当な変数を定義する: ◎ For example, given the following structure, these custom properties are not cyclic, and all define valid variables:
<one><two><three /></two></one> <style> one { --foo: 10px; } two { --bar: calc(var(--foo) + 10px); } three { --foo: calc(var(--bar) + 10px); } </style>
`one^e 要素は、 `--foo^p 用の値を定義する。 `two^e 要素は、 この値を継承することに加え, `foo^css 変数を利用して自身の `--bar^p に値をアテガう。 最後に, `three^e 要素は、[ 変数が`代用された後の^em `--bar^p 値 ]を継承する (言い換えれば、 値 `calc(10px + 10px)^v を見る) — それから、 その値を通して自身の `--foo^p を定義し直す。 `three^e が継承する `--bar^p 値は, `one^e 上で定義される `--foo^p ~propへの参照をもはや包含していないので、 `var(--bar)^v 変数を利用して `--foo^p を定義することは循環的ではなく, (通常の~propの中で変数として参照されるときは) 実際に最終的に `30px^v に解決される値を定義する。 ◎ The <one> element defines a value for --foo. The <two> element inherits this value, and additionally assigns a value to --bar using the foo variable. Finally, the <three> element inherits the --bar value after variable substitution (in other words, it sees the value calc(10px + 10px)), and then redefines --foo in terms of that value. Since the value it inherited for --bar no longer contains a reference to the --foo property defined on <one>, defining --foo using the var(--bar) variable is not cyclic, and actually defines a value that will eventually (when referenced as a variable in a normal property) resolve to 30px.
3. ~cascade変数の利用-法: `var^f 記法
`~custom~prop$は、 別の~propの中で `var$f 関数を通して`代用-$され得る値を与える。 `var$f の構文は: ◎ The value of a custom property can be substituted into the value of another property with the var() function. The syntax of var() is:
`var@f = var( `custom-property-name$t, `declaration-value$t? )
通例的な[ 値どうしを分離していない~commaは省略するよう要求する規則 ]の例外として、 何も後続していない~commaが在る場合は,[ ~fallback値は空であることを指示している,妥当な `var$f ]として扱うモノトスル。 ◎ In an exception to the usual comma elision rules, which require commas to be omitted when they’re not separating values, a bare comma, with nothing following it, must be treated as valid in var(), indicating an empty fallback value.
注記: すなわち、 `var(--a,)^v は妥当な関数を指定している — ~custom~prop `--a^p が[ 妥当でない/欠落な ]場合、 `var$f は無に置換されるべきである。 ◎ Note: That is, var(--a,) is a valid function, specifying that if the --a custom property is invalid or missing, the var() should be replaced with nothing.
要素~上の どの~propにも、 その値を成す任意の部分に代えて, `var$f 関数を利用できる。 ~propの値~以外 — ~propの名前や選択子など — には、 `var$f 関数は利用できない (そのようにしても、 単に無効な構文になるか,変数とは繋がりの無い値になるだけである)。 ◎ The var() function can be used in place of any part of a value in any property on an element. The var() function can not be used as property names, selectors, or anything else besides property values. (Doing so usually produces invalid syntax, or else a value whose meaning has no connection to the variable.)
次の~codeは、 ~prop名として変数を利用しようと試みるので,不正な例になる: ◎ For example, the following code incorrectly attempts to use a variable as a property name:
.foo { --side: margin-top; var(--side): 20px; }
これは、
`margin-top^p: `20px^v;
を設定することに等価`でない^em。
2 個目の宣言は、
単に無効な~prop名として構文~errorにされ,棄てられる。
◎
This is not equivalent to setting margin-top: 20px;. Instead, the second declaration is simply thrown away as a syntax error for having an invalid property name.
関数の最初の引数が、 代用~値を~~供する`~custom~prop$†の,名前を与える。 関数に 2 個目の引数が供されている場合、 それが~fallback値になり,参照された`~custom~prop$が`無効が保証される値$をとるときの代用~値として利用される。 ◎ The first argument to the function is the name of the custom property to be substituted. The second argument to the function, if provided, is a fallback value, which is used as the substitution value when the value of the referenced custom property is the guaranteed-invalid value.
【† 代用~値を~~供する~custom~propは、[[ `var$f を値に利用する~prop ]が適用される要素 ]上のそれになる。 】
注記: ~fallbackの構文でも、 `~custom~prop$のそれと同様に,~commaが許容される。 例えば, `var(--foo, red, blue)^v は、 ~fallback値として `red, blue^v を定義する。 すなわち、 最初の~commaと関数の末尾までの間を成すすべてが,~fallback値と見なされる。 ◎ Note: The syntax of the fallback, like that of custom properties, allows commas. For example, var(--foo, red, blue) defines a fallback of red, blue; that is, anything between the first comma and the end of the function is considered a fallback value.
~fallback値により、 一種の安全弁付き~code( `defensive coding^en )を書けるようになる。 例えば,より大きな~appに組み込むための~componentを作成する場合、 変数をその~style付けに利用すれば, 当の~componentを~appの他の部分と調和させることも容易になる。 ◎ The fallback value allows for some types of defensive coding. For example, an author may create a component intended to be included in a larger application, and use variables to style it so that it’s easy for the author of the larger application to theme the component to match the rest of the app.
~fallbackが無ければ、 ~app作者は,当の~componentが利用するすべての変数に値を給さなければならなくなる。 ~fallbackがあれば、 ~component作者は,既定の値を給しておけるようになり、 ~app作者は,上書きしたい変数だけ値を給すれば済むようになる。 ◎ Without fallback, the app author must supply a value for every variable that your component uses. With fallback, the component author can supply defaults, so the app author only needs to supply values for the variables they wish to override.
/* ~componentの~style ◎ In the component’s style: */ .component .header { color: var(--header-color, blue); } .component .text { color: var(--text-color, black); } /* より大きな~appの~style: ◎ In the larger application’s style: */ .component { --text-color: #080; /* `--header-color^p は、 設定されないので,~fallback値( `blue^v )のまま。 ◎ header-color isn’t set, and so remains blue, the fallback value */ }
~propの値が `var$f 関数を包含していて,そのどれもが構文として妥当である場合、 その~propは,構文解析-時には妥当であると見做すモノトスル。 構文が検査されるのは、 `var$f 関数を`代用-$した後の,`算出d値の時点$である。 ◎ If a property contains one or more var() functions, and those functions are syntactically valid, the entire property’s grammar must be assumed to be valid at parse time. It is only syntax-checked at computed-value time, after var() functions have been substituted.
【所与の要素~上の】 ~prop %~prop の値の中の `var$f 関数 %関数 を `代用する@ ( `substitute^en する)ときは: ◎ To substitute a var() in a property’s value:
- %custom ~LET 要素~上の`~custom~prop$のうち, %関数 の 1 個目の引数を名前に持つもの
-
~IF[ ~NOT ~OR↓ ]…
- [ %custom は`~animationに染まって$いる ]~AND[ %~prop は`~animate不可$である ]
- %custom の値 ~EQ %custom の初期~値【すなわち,`無効が保証される値$】
…ならば ⇒ %関数 を %custom の値 に置換する
◎ If the custom property named by the first argument to the var() function is animation-tainted, and the var() function is being used in a property that is not animatable, treat the custom property as having its initial value for the rest of this algorithm. ◎ If the value of the custom property named by the first argument to the var() function is anything but the initial value, replace the var() function by the value of the corresponding custom property. -
~ELIF[ %関数 の 2 個目の引数として~fallback値 %~fallback が与えられている ]:
- %~fallback 内の各 `var$f 関数(もしあれば)を【同じ要素, %~prop の下で】`代用する$
- %関数 を %~fallback に置換する
-
~ELSE ⇒ %~prop は、 `算出d値の時点で無効$になる ◎ Otherwise, the property containing the var() function is invalid at computed-value time.
注記: %~prop を`算出d値の時点で無効$にするものは、 他にもあり得る。 ◎ Note: Other things can also make a property invalid at computed-value time.
注記: `var$f が`代用-$されるのは、 ~CSS~token `css-syntax-3$r の~levelであり,~textな~levelではない — 一部分だけ変数から供されるような単独の~tokenを築くことはできない: ◎ Note that var() substitution takes place at the level of CSS tokens [css-syntax-3], not at a textual level; you can’t build up a single token where part of it is provided by a variable:
.foo { --gap: 20; margin-top: var(--gap)px; }
これは
`margin-top^p: `20px^v;
(長さ)を設定することに等価`ではない^em。
`margin-top^p: `20 px^v;
と等価になり
(値は、~spaceを挟んだ実数と識別子の並びになる),
単に `margin-top$p ~propに対する無効な値になる。
このような場合、
`calc$f 式を利用すれば,同じものを妥当に得られる
— 次の様に:
◎
This is not equivalent to setting margin-top: 20px; (a length). Instead, it’s equivalent to margin-top: 20 px; (a number followed by an ident), which is simply an invalid value for the margin-top property. Note, though, that calc() can be used to validly achieve the same thing, like so:
.foo { --gap: 20; margin-top: calc(var(--gap) * 1px); }
このことは、 代用~後の値も,そのまま直に直列化-可能ではないかもしれないことを含意する。 上と類似な次の例において: ◎ This also implies that the post-substitution value might not be directly serializable as-is. Here’s a similar example to the preceding:
.foo { --gap: 20; --not-px-length: var(--gap)px; }
`--not-px-length^p の算出d値(代用~後の値)の直列化は、 `20px^l にはならない — そうすると、 それを構文解析して戻すとき,次元が結合された 1 個の~tokenとして~~扱われるので。 代わりに,構文解析し直すときも別々な~tokenであることを施行するため、 `20/**/px^l 【!px】の様に, 2 個の~tokenの合間に~commentを伴うよう直列化されることになる。 ◎ The serialization of the computed (post-substitution) value of --not-px-length is not 20px, because that would parse back as the single combined dimension; instead, it will serialize with a comment between the two tokens, like px, to enforce that they are separate tokens even when re-parsing.
`var$f 関数は、 `算出d値の時点$で`代用-$される。 宣言の中のすべての `var$f 関数が代用された時点で,宣言された文法に合致しないならば、 当の宣言は`算出d値の時点で無効$になる。 ◎ var() functions are substituted at computed-value time. If a declaration, once all var() functions are substituted in, does not match its declared grammar, the declaration is invalid at computed-value time.
所与の宣言が,[ すべての `var$f 関数を`代用-$した結果において,`~CSS全域~keyword$(および,場合によっては空白)のみを包含する ]場合、 その値【`算出d値$】は,[ その`指定d値$は、 初めから当の~keywordであった ]かのように決定される。 ◎ If a declaration, once all var() functions are substituted in, contains only a CSS-wide keyword (and possibly whitespace), its value is determined as if that keyword were its specified value all along.
例えば,次の用法は、 構文の観点からは~~問題ないが、 変数が代用された後は無意味な結果になる: ◎ For example, the following usage is fine from a syntax standpoint, but results in nonsense when the variable is substituted in:
:root { --looks-valid: 20px; } p { background-color: var(--looks-valid); }
`20px^v は, `background-color$p 用の値としては無効なので、 この~propの~instanceは, 代わりに `transparent^v ( `background-color$p 用の`初期~値$)に算出される。 ◎ Since 20px is an invalid value for background-color, this instance of the property computes to transparent (the initial value for background-color) instead.
~propが既定で継承されるもの( `color$p など)ならば、 `初期~値$ではなく`継承d値$に算出される。 ◎ If the property was one that’s inherited by default, such as color, it would compute to the inherited value rather than the initial value.
`var$f 関数は、 `~custom~prop$からは`~CSS全域~keyword$を取得し得ない — `--foo: initial;^css の様に指定しようと試行した場合、 単に,~custom~prop用に 明示的な~default法 を誘発することになる。 が、 その~fallbackは`~CSS全域~keyword$をとり得る: ◎ While a var() function can’t get a CSS-wide keyword from the custom property itself—if you tried to specify that, like --foo: initial;, it would just trigger explicit defaulting for the custom property—it can have a CSS-wide keyword in its fallback:
p { color: var(--does-not-exist, initial); }
上の~codeでは, `--does-not-exist^p ~propが[ 存在しない/`算出d値の時点で無効$になる ]場合、 `var$f は代わりに `initial$v ~keywordで代用され, `color$p ~propは元から `initial^v であったかのように挙動する。 その結果、 `color^p は,その初期~値をとることになる。 一方で,~fallbackが与えられなかった場合、 `color^p は既定で継承するので,それに従うことになる。 ◎ In the above code, if the --does-not-exist property didn’t exist or is invalid at computed-value time, the var() will instead substitute in the initial keyword, making the property behave as if it was originally color: initial. This will make it take on the document’s initial color value, rather than defaulting to inheritance, as it would if there were no fallback.
3.1. 可変~単位
`~custom~prop$は、 `var$f 関数で直に参照されることに加えて,~custom単位としても参照され得る。 それは、 文書~内の — たぶん,ある設計-~systemにより確立された — 有意な “基底~size” の倍数を容易に利用できるようにする。 ◎ In addition to being referenced directly with the var() function, custom properties can be referenced as custom units, making it easy to use multiples of significant "base sizes" in a document, perhaps established by a design system.
単位として `dashed-ident$t を伴う`次元$は、 `可変~単位~参照@ ( `variable unit reference^en )になる。 その効果, それに対する制約は、 `var$f を利用するときと一致する — `~custom~prop$は、 当の単位の名前で参照される。 ◎ A dimension whose unit is a <dashed-ident> is a variable unit reference. It has identical effects and restrictions to using var(); the unit name is the custom property being referenced.
唯一の相違は、
`可変~単位~参照$は
— `~custom~prop$の値で直に代用されるのではなく —
次で代用されることである
⇒
calc(%X * (var(%Y)))
— [
%X, %Y
]は,当の次元を成す[
数量-成分, 単位~成分
]
◎
The only difference is during substitution—rather than just substituting the custom property value directly, it substitutes as calc(X * (var(Y))), where X is numeric component of the dimension, and Y is the unit component of the dimension.
例えば, “流動的な( `fluid^en )~typography” は、 ~textを表示域の~sizeに則って~sizeする。 これのごく単純な~versionは、 次のように作成できる: ◎ For example, "fluid typography" sizes text according to the viewport size. A very simple version of this can be created as:
@property --fem { /* “流動的な `em^u” ◎ "fluid em" */ syntax: "<length>"; initial-value: 2vw; inherits: true; } .fluid-type { font-size: 1.2--fem; /* は、 次と等価になる ◎ equivalent to */ font-size: calc(1.2 * (var(--fem))); }
【 `initial-value$d 記述子は, 原文では `initial^d と記されているが(過去の名前と思われる)、 現在の仕様に基づくよう改めている。 】
もっと複階的な式も利用できる。 例えば,流動的な~typographyは、 ~screenがごく[ 大きい/小さい ]ときに退化する状況を避けるため,[ 表示域に応じて,~sizeが`どこまで^em応答するか ]に関して制限sを課すよう求まれることが多い: ◎ More complex expressions can be used as well. For example, fluid typography often wants to impose limits on how much the size responds to the viewport, to avoid degenerate situations on very large or very small screens:
@property --fem { /* “流動的な `em^u” ◎ "fluid em" */ syntax: "<length>"; initial-value: clamp(10px, 1vw + 1vh, 1rem); inherits: true; } .fluid-type { font-size: 1.2--fem; /* `12px^v 以上 `1.2rem^v 以下になる。 ◎ Won’t get smaller than 12px, or larger than 1.2rem. */ }
`可変~単位~参照$は,`~custom~prop$参照なので、 【子孫にて】`~custom~prop$を設定することで,通常に上書きできる。 これは、 ある~componentを汎用~的に~styleしつつ,~page上の位置に応じて特化するときに有用になり得る: ◎ As the variable unit reference is a custom property reference, it can be overridden by setting the custom property normally. This can be useful to specialize a component for a particular position on the page, while still styling it generically:
@property --bs { /* 塊~size ◎ block size */ syntax: "<length>"; initial-value: 8px; inherits: true; } .module { margin-block: 1.5--bs; border-block: .5--bs; /* 塊-軸[ ~margin, ~border ]を[ `12px^v, `4px^v ]にする ◎ gives a vertical margin of 12px, and vertical border of 4px */ } .sidebar .module { --bs: 6px; /* `.sidebar^css 内では~componentが少し密になるよう,塊-軸[ ~margin, ~border ]を[ `9px^v, `3px^v ]にする。 ◎ Makes the components slightly more compact in the sidebar, with a vertical margin of 9px and a vertical border of 3px. */ }
注記: `可変~単位~参照$は, ~fallback値をとり得ないので 【関数-記法ではないので,~fallback値を指定し得ない】、 参照-先の`~custom~prop$が存在しない場合や`無効が保証される値$【!無効な値】になる場合, 当の単位~参照も無効になる。 代わりに, `property$at を利用して`登録-済み~custom~prop$を作成すること — そうすれば、 `initial-value$d 記述子の値が既定として利用されるようになるので。 ◎ Note: Variable unit references can’t have fallback values, so if the referenced custom property doesn’t exist or is invalid, the unit reference will be invalid as well. Use @property to create a registered custom property, as the initial value will instead be used as the default.
注記:
`可変~単位~参照$は,明瞭に[
参照-先の`~custom~prop$が数量-値をとる
]ことを
( `calc$f で代用しても妥当になるよう)
期待するが、
これを施行するものは無い。
数量-値でない値を給して,
初期~値を上書きした場合、
代用した結果は,
単純に無効な~propになる
(例: 上の `--fem^u 単位の例が与えられた下で,
`--fem^p: `red^v;
を給したなら、
`font-size^p は `calc(1.2 * (red))^v になり,無効になる)。
◎
Note: While variable unit references clearly expect their referenced custom property to have a numeric value (so that it’s valid to substitute into a calc()), nothing enforces this. Supplying a non-numeric value, such as by using --fem: red; to override the initial value in the above examples, will simply result in an invalid property after substitution, like font-size: calc(1.2 * (red));.
3.2. 無効な変数
`~custom~prop$が`無効が保証される値$をとる場合、 `var$f 関数による代用に利用できなくなる。 そのような場合、 妥当な~fallbackが指定されていない限り,【当の関数を利用している】宣言は`算出d値の時点で無効$になる。 ◎ When a custom property’s value is the guaranteed-invalid value, var() functions cannot use it for substitution. Attempting to do so makes the declaration invalid at computed-value time, unless a valid fallback is specified.
上で説明したとおり、 宣言は,それが[ `無効が保証される値$をとる`~custom~prop$を参照する `var$f ]を包含する場合は `算出d値の時点で無効@ になる。 あるいは,それが妥当な`~custom~prop$を利用していても、[ 当の~propの値が,その中の `var$f 関数が代用された後に妥当でなくなる場合 ]にも無効になる。 これが起きた場合、 当の~prop %~prop の`算出d値$は,次に従って与えられる: ◎ A declaration can be invalid at computed-value time if it contains a var() that references a custom property with the guaranteed-invalid value, as explained above, or if it uses a valid custom property, but the property value, after substituting its var() functions, is invalid. When this happens, the computed value is one of the following depending on the property’s type:
- %~prop は登録-済みでない`~custom~prop$である場合 ◎ The property is a non-registered custom property
- %~prop は`全称~構文~定義$を伴う`登録-済み~custom~prop$である場合 ◎ The property is a registered custom property with universal syntax
- 算出d値は、 `無効が保証される値$になる。 ◎ The computed value is the guaranteed-invalid value.
- 他の場合 ◎ Otherwise
- 算出d値は、[ %~prop は`継承d~prop$であるならば,その`継承d値$/ ~ELSE_ %~prop の`初期~値$ ]になる — %~prop の値として `unset$v ~keywordが指定されていたかのように。 ◎ Either the property’s inherited value or its initial value depending on whether the property is inherited or not, respectively, as if the property’s value had been specified as the unset keyword.
例えば、 次の~codeでは: ◎ For example, in the following code:
:root { --not-a-color: 20px; } p { background-color: red; } p { background-color: var(--not-a-color); }
`p^e 要素の背景は、 `red^v ではなく, `background-color$p の`初期~値$ `transparent$v (透明)になる。 `~custom~prop$自身が `unset$v されたり,無効な `var$f 関数を包含している場合も同じことが生じる。 ◎ the <p> elements will have transparent backgrounds (the initial value for background-color), rather than red backgrounds. The same would happen if the custom property itself was unset, or contained an invalid var() function.
このことと[
作者が,単に~stylesheetに直に
`background-color^p: `20px^v;
と記した場合のふるまい
]との相違に注意されたし。
それは,通常の構文~errorなので、
その規則は
【~cascadeの最初の段階で】
破棄される結果,規則
`background-color^p: `red^v;
が代わりに利用されることになる。
◎
Note the difference between this and what happens if the author had just written background-color: 20px directly in their stylesheet - that would be a normal syntax error, which would cause the rule to be discarded, so the background-color: red rule would be used instead.
注記: `算出d値の時点で無効$の概念は、 `var$f 関数が他の構文~errorと異なり, “早期に失敗させ” 得ないがためにある。 ~prop値が~UAから無効なものと判明した時点では、 【より優先順位の低い】 他の`~cascaded値$は,すでに棄てられている。 ◎ Note: The invalid at computed-value time concept exists because variables can’t "fail early" like other syntax errors can, so by the time the user agent realizes a property value is invalid, it’s already thrown away the other cascaded values.
3.3. 略式~propにおける変数
`var$f 関数は、 次に挙げる所で,ある複雑化をもたらす ⇒# `略式~prop$を その各 非略式~成分に構文解析するとき/ それら各 非略式~成分から`略式~prop$を直列化するとき ◎ var() functions produce some complications when parsing shorthand properties into their component longhands, and when serializing shorthand properties from their component longhands.
所与の`略式~prop$の値が,その ある`非略式~prop$(下位~prop)用の成分として `var$f 関数を包含する場合、 当の`非略式~prop$には,代わりに `代用待ちの値@ をあてがうモノトスル — この値は: ◎ If a shorthand property contains a var() function in its value, the longhand properties it’s associated with must instead be filled in with\
- 作者からは観測-不能な特別な値であり,[ 略式~propは変数を包含するので、 非略式~propの値は,変数が`代用-$されるまで決定し得ない ]ことを指示する。 ◎ a special, unobservable-to-authors pending-substitution value that indicates the shorthand contains a variable, and thus the longhand’s value can’t be determined until variables are substituted.
- 通常通り~cascadeするモノトスル。 ◎ This value must then be cascaded as normal,\
- `var$f 関数が算出d値の時点で`代用-$され終えた後に、 略式~propの値を構文解析して,非略式~propに適切な値をあてがうモノトスル。 ◎ and at computed-value time, after var() functions are finally substituted in, the shorthand must be parsed and the longhands must be given their appropriate values at that point.
【 該当する非略式~propは、 1 個の `var$f 関数に対し複数個あり得る — 当の `var^f が成す略式~propの成分~値が,複数個の非略式~prop用の値を与えるものと定義されている場合や、 当の `var^f 関数~自体が複数個の非略式~prop用の値を まとめて与えている場合など。 】
注記: ある`略式~prop$が `var$f を伴わずに記された場合、 その値は,構文解析-時点で各 非略式~成分に分離されるよう構文解析される。 各`非略式~prop$は、 その後に`~cascade$に関与する — それに伴い,当の略式~propは およそ破棄される。 しかしながら,これは、 当の略式~propが `var$f を包含するときには行えない — `var$f は何にでも代用され得るので。 ◎ Note: When a shorthand is written without a var(), it is parsed and separated out into its component longhand properties at parse time; the longhands then participate in the cascade, with the shorthand property more or less discarded. When the shorthand contains a var(), however, this can’t be done, as the var() could be substituted with anything.
`代用待ちの値$は、 ~APIによる観測-が許容される所では,空~文字列に直列化するモノトスル。 ◎ Pending-substitution values must be serialized as the empty string, if an API allows them to be observed.
`略式~prop$は、 その各~非略式~成分の値を集めることにより直列化され, 同じ値~集合に構文解析されることになる値を合成することになる。 所与の`略式~prop$に対し: ◎ Shorthand properties are serialized by gathering the values of their component longhand properties, and synthesizing a value that will parse into the same set of values.
- すべての`非略式~prop$が`代用待ちの値$になる場合、 当の`略式~prop$は,その元の( `var$f を包含している)値に直列化するモノトスル。 ◎ If all of the component longhand properties for a given shorthand are pending-substitution values from the same original shorthand value, the shorthand property must serialize to that original (var()-containing) value.
- 他の場合,いずれかの`非略式~prop$が[ `代用待ちの値$になる場合 / まだ代用されていない自前の `var$f 関数を包含する場合 ]、 当の`略式~prop$は,空~文字列に直列化するモノトスル。 ◎ Otherwise, if any of the component longhand properties for a given shorthand are pending-substitution values, or contain var() functions of their own that have not yet been substituted, the shorthand property must serialize to the empty string.
3.4. 過度に長い変数の安全な取扱い
素朴に実装された `var$f 関数は、 “`billion laughs^en 攻撃” 【十億の笑い】の一種に利用され得る: ◎ Naively implemented, var() functions can be used in a variation of the "billion laughs attack":
.foo { --prop1: lol; /* 笑 */ --prop2: var(--prop1) var(--prop1); --prop3: var(--prop2) var(--prop2); --prop4: var(--prop3) var(--prop3); /* etc */ }
この短い例では、 `--prop4^p の算出d値は、 `lol lol lol lol lol lol lol lol^v になり,元の `lol^v の複製を 8 個 包含する。 追加される~levelごとに,識別子の個数は倍になり、 ほんの一手間,わずか 30 ~levelに拡張するだけで, `--prop30^p が包含する識別子は `およそ十億個^emになる。 ◎ In this short example, --prop4’s computed value is lol lol lol lol lol lol lol lol, containing 8 copies of the original lol. Every additional level added to this doubles the number of identifiers; extending it to a mere 30 levels, the work of a few minutes by hand, would make --prop30 contain nearly a billion instances of the identifier.
この類の攻撃を避けるため、 ~UAは,[ `var$f 関数を展開した結果の~token~streamに許容される長さ ]に自身が定義する上限を課すモノトスル。 `var^f がこの上限より長い~token~streamに展開される場合、 代わりに,~propは`算出d値の時点で無効$になるよう展開されるとする。 ◎ To avoid this sort of attack, UAs must impose a UA-defined limit on the allowed length of the token stream that a var() function expands into. If a var() would expand into a longer token stream than this limit, it instead makes the property it’s expanding into invalid at computed-value time.
この仕様は、 課すベキ上限~sizeは定義しない。 しかしながら, 1000 ~byte以上の~textを包含するような~custom~prop用の妥当な利用事例もあるので、 上限は多少高めに設定することが推奨される。 ◎ This specification does not define what size limit should be imposed. However, since there are valid use-cases for custom properties that contain a kilobyte or more of text, it’s recommended that the limit be set relatively high.
注記: [ ~UAには、 資源の拘束に因り標準に違反することが許容される ]とする一般~原則は、 ここにも一般に該当する。 ~UAは、 自身が~supportできる[ ~custom~propの~~長さ, 識別子の~~長さ ]に別々な上限を課すこともあろう。 この節が,この攻撃を特定的に引き合いに出すのは、 それには長い歴史があり,初回の検分では巨大~過ぎな~~片は`無さそうに見える^emものでも行える事実があることによる。 ◎ Note: The general principle that UAs are allowed to violate standards due to resource constraints is still generally true here; a UA might, separately, have limits on how long of a custom property they can support, or how large of an identifier they can support. This section calls out this attack specifically because of its long history, and the fact that it can be done without any of the pieces seeming to be too large on first inspection.
4. ~API
すべての`~custom~prop$`宣言$に対し、 その`文字大小区別か$は ~T に設定される。 ◎ All custom property declarations have the case-sensitive flag set.
注記: ~custom~propは,名前の文字大小が区別されるので、 `CSSStyleDeclaration$I ~objの中に CamelCase 形で現れることはない。 自動的に CamelCase 化する~text変形nの類いは,これと互換になれない。 それらは、 `getPropertyValue()$m, 等の~interfaceを介して,適正な名前で~accessできる。 ◎ Note: Custom properties do not appear on a CSSStyleDeclaration object in camel-cased form, because their names may have both upper and lower case letters which indicate distinct custom properties. The sort of text transformation that automatic camel-casing performs is incompatible with this. They can still be accessed by their proper name via getPropertyValue()/etc.
4.1. ~custom~propの直列化-法
~custom~propの名前を直列化した結果は、 作者から供されたものと正確に同じ符号位置~並びになるモノトスル — 文字大小を改めることなく。 ◎ Custom property names must be serialized as the exact code point sequence provided by the author, including not altering the case.
注記: ~customでない~propに対しては、 その名前は~ASCII範囲に制約され,`~ASCII大小無視$なので、 実装は,概して名前を小文字~化するよう直列化する。 ◎ Note: For non-custom properties, property names are restricted to the ASCII range and are ASCII case-insensitive, so implementations typically serialize the name lowercased.
`~custom~prop$の指定d値は、 `正確に作者が指定したとおり^emに直列化するモノトスル。 他の~propにて生じ得る単純~化 — 値を成す[ ~commentを落とす/ 空白を正規化する/ 数量-~tokenを直列化し直す ]等々 — は、 生じないモノトスル。 ◎ Specified values of custom properties must be serialized exactly as specified by the author. Simplifications that might occur in other properties, such as dropping comments, normalizing whitespace, reserializing numeric tokens from their value, etc., must not occur.
類似に,`~custom~prop$の算出d値も、 `正確に作者が指定したとおり^emに直列化して, `var$f 関数の置換~用に保存するモノトスル。 ◎ Computed values of custom properties must similarly be serialized exactly as specified by the author, save for the replacement of any var() functions.
例えば,次の~propが与えられられたとき: ◎ For example, given the following properties:
--y: /* baz */; --x: /* foo */ var(--y) /* bar */;
`--x^p の指定d値の直列化は `/* foo */ var(--y) /* bar */^l になり, `--x^p の算出d値の直列化は `/* foo */ /* baz */ /* bar */^l にならなければならない。 ◎ the serialization of the specified value of --x must be "/* foo */ var(--y) /* bar */", while the serialization of the computed value of --x must be "/* foo */ /* baz */ /* bar */".
(値の頭部を成す空白は、 ~CSS構文解析器により自動的に削られ,ここでは保全されないことに注意。) ◎ (Note that the leading whitespace on the value is automatically trimmed by the CSS parser; it’s not preserved here.)
注記: この要件が存在するわけは、 作者は,ときには~custom~prop内に非~CSSな情報を格納することもあり、 この情報を “正規化する” と,作者~codeを非互換化する仕方で値が変化し得るからである。 ◎ This requirement exists because authors sometimes store non-CSS information in custom properties, and "normalizing" this information can change it in ways that break author code.
例えば,~custom~prop内に
`--uuid^p: `12345678-12e3-8d9b-a456-426614174000^v
の様に~UUIDが格納され、
~scriptから~accessされたとき,当の~UUIDを記されたとおり復唱することが要求されることもある。
◎
For example, storing a UUID in a custom property, like --uuid: 12345678-12e3-8d9b-a456-426614174000, requires the UUID to be echoed back out as written when it’s accessed by script.
この値は、 形上では,~CSSにより一連の隣接な[ 実数/次元 ]として構文解析される。 特に,区分 `-12e3^l は、 −12000 に等しい実数として構文解析される。 それを,他の文脈において[ ~CSSOMにより要求されるとおり,その形で直列化し直す ]と、 作者による値の利用を致命的に非互換化することになろう。 ◎ This value is technically parsed by CSS as a series of adjacent numbers and dimensions. In particular, the segment "-12e3" parses as a number, equal to -12000. Reserializing it in that form, as required by CSSOM in other contexts, would fatally break the author’s use of the value.
変更点
- ~level 1 からの変更点 ◎ 5.1. Changes Since Variables 1
- `可変~単位~参照$を追加した。 ◎ Added variable unit references.
謝辞
何年にもわたり,~CSS変数の夢を生きたまま保ってこられた~CSS~WGの方々 — 特に, `Daniel Glazman^en, `David Hyatt^en 両氏 — に感謝する。 ~mailing~listにて,この仕様の開発に貢献するべく助力された人々 — 特に次に挙げる方々 — に感謝する: ◎ Many thanks to several people in the CSS Working Group for keeping the dream of variables alive over the years, particularly Daniel Glazman and David Hyatt. Thanks to multiple people on the mailing list for helping contribute to the development of this incarnation of variables, particularly\
~privacyの考慮点
この仕様が定義する仕組みは、 作者が制御する~pageの中で,作者~levelの~style付け情報を使い回す以上のことはしない。 そのようなわけで、 新たな~privacyの考慮点はない。 ◎ This specification defines a purely author-level mechanism for passing styling information around within a page they control. As such, there are no new privacy considerations.
~securityの考慮点
§ 過度に長い変数の安全な取扱いでは、 `var$f 関数などの “~macro展開” の様な仕組みに対し仕掛けれる,昔からある~DoS攻撃を引き合いに出し、 その攻撃に抗する防御を義務付ける。 ◎ § 3.4 Safely Handling Overly-Long Variables calls out a long-standing Denial-of-Service attack that can be mounted against "macro-expansion"-like mechanisms, such as the var() function, and mandates a defense against that attack.