* 仕様書

[REFS[
- [3] '''[CITE@en[DOM Standard]] ([TIME[2016-04-26 13:45:33 +09:00]] 版) <https://dom.spec.whatwg.org/#dom-element-attachshadow>'''
- [14] [CITE@en[DOM Standard]] ([TIME[2016-04-26 17:13:41 +09:00]] 版) <https://dom.spec.whatwg.org/#dictdef-shadowrootinit>
]REFS]

* 処理

@@
[4] [CODE(DOMi)@en[Element]] [[インターフェイス]]の
[DFN[[CODE(DOMm)@en[attachShadow]]]] [[メソッド]]は、
次のようにしなければ[MUST[なりません]] [SRC[>>3]]。
[FIG(steps)[
= [5] [VAR[状態]]を、第1引数を[[辞書]] [CODE(DOMi)@en[ShadowRootInit]] として解釈した結果に設定します。
= [6] [[文脈オブジェクト]]が、[[影ホスト]]となれる[[要素]]のいずれかでなければ、
== [7] [CODE(DOMe)@en[NotSupportedError]] [[例外]]を[[投げ]]、ここで停止します。
= [8] [[文脈オブジェクト]]が[[影ホスト]]なら、
== [9] [CODE(DOMe)@en[InvalidStateError]] [[例外]]を[[投げ]]、ここで停止します。
= [10] [VAR[影]]を、[[影根]]に設定します。
[FIG(list members)[
: [F[節点文書]] : [[文脈オブジェクト]]の[F[節点文書]]
: [F[ホスト][host (DOM)]] : [[文脈オブジェクト]]
: [F[モード][ShadowRootMode]] : [VAR[状態]]の [CODE[mode][ShadowRootMode]]
]FIG]
= [11] [[文脈オブジェクト]]の[F[影根]]を、[VAR[影]]に設定します。
= [12] [VAR[影]]を返します。
]FIG]

[15] [[辞書]] [DFN[[CODE(DOMi)@en[ShadowRootInit]]]] [SRC[>>14]] は、
次の[[メンバー]]を持ちます。
[FIG(list members)[
- [CODE(DOMa)@en[mode][ShadowRootMode]] ([CODE(DOMi)@en[ShadowRootMode]]、[[必須]])
]FIG]

[13] [[影ホスト]]となれる[[要素]]は、次のものです [SRC[>>3]]。
[FIG(list short)[
- [[妥当なカスタム要素]]
- [CODE(HTMLe)@en[article]]
- [CODE(HTMLe)@en[aside]]
- [CODE(HTMLe)@en[blockquote]]
- [CODE(HTMLe)@en[body]]
- [CODE(HTMLe)@en[div]]
- [CODE(HTMLe)@en[footer]]
- [CODE(HTMLe)@en[h1]]
- [CODE(HTMLe)@en[h2]]
- [CODE(HTMLe)@en[h3]]
- [CODE(HTMLe)@en[h4]]
- [CODE(HTMLe)@en[h5]]
- [CODE(HTMLe)@en[h6]]
- [CODE(HTMLe)@en[header]]
- [CODE(HTMLe)@en[nav]]
- [CODE(HTMLe)@en[p]]
- [CODE(HTMLe)@en[section]]
- [CODE(HTMLe)@en[span]]
]FIG]

* 歴史

[1] [CITE@en[Shadow: define .attachShadow() and .shadowRoot · whatwg/dom@1699495]]
([TIME[2016-03-16 14:27:36 +09:00]] 版)
<https://github.com/whatwg/dom/commit/169949553da85cfee6b03df361ed3e8142ddc54e>

[2] [CITE@en[Shadow: define attachShadow() for custom elements · whatwg/dom@b8d2854]]
([TIME[2016-04-17 14:01:34 +09:00]] 版)
<https://github.com/whatwg/dom/commit/b8d2854152aaabc412063c67bcb4177d8a2607a1>

[16] [CITE@en[Use "NotSupportedError" when trying to attachShadow() twice]]
([[domenic]]著, [TIME[2019-05-16 03:42:55 +09:00]])
<https://github.com/whatwg/dom/commit/bcdab96b3e72cebb168d02e2a566e845abbe0df4>

[17] [CITE@en[Add "disable shadow" flag check to Element.attachShadow() by tkent-google · Pull Request #760 · whatwg/dom]]
([TIME[2019-12-06 17:59:12 +09:00]])
<https://github.com/whatwg/dom/pull/760>

[18] [CITE@en[Use "NotSupportedError" when trying to attachShadow() twice by domenic · Pull Request #761 · whatwg/dom]]
([TIME[2019-12-06 17:59:31 +09:00]])
<https://github.com/whatwg/dom/pull/761>

[19] [CITE@en[Add "disable shadow" flag check to element.attachShadow()]]
([[tkent-google]]著, [TIME[2019-05-17 05:15:50 +09:00]])
<https://github.com/whatwg/dom/commit/daa525d4078a7991aa0d7698a3591a5e61f53dd3>

[20] [CITE@en[Custom elements: Add element.attachInternals() and ElementInternals interface by tkent-google · Pull Request #4324 · whatwg/html]]
([TIME[2019-12-06 18:09:52 +09:00]])
<https://github.com/whatwg/html/pull/4324>

[21] [CITE@en[Add "disable shadow" flag check to Element.attachShadow() by tkent-google · Pull Request #760 · whatwg/dom]]
([TIME[2019-12-06 18:10:43 +09:00]])
<https://github.com/whatwg/dom/pull/760>

[22] [CITE@en[Editorial: attachShadow() takes a required dictionary]]
([[annevk]]著, [TIME[2019-08-09 17:01:29 +09:00]])
<https://github.com/whatwg/dom/commit/a257369620a17b6af578591219a72b5c1d8f96a5>

[23] [CITE@en[Editorial: attachShadow() takes a required dictionary by annevk · Pull Request #775 · whatwg/dom]]
([TIME[2020-01-12 16:42:54 +09:00]])
<https://github.com/whatwg/dom/pull/775>