{"id":459710,"date":"2025-05-14T15:01:57","date_gmt":"2025-05-14T15:01:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=459710"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=459710","title":{"rendered":"<span>\u0412\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u0430 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u043e\u043c HTML, CSS \u0438 JavaScript<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/companies\/ruvds\/articles\/909390\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p><\/a><br \/> \u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u0445. \u041d\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043b\u0438\u0448\u044c HTML, CSS \u0438 JavaScript.<\/p>\n<p> \u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u043c\u043e\u0449\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0441\u0442\u043e\u044f\u0442 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u0430 \u044d\u0442\u0443 \u0431\u043e\u0433\u0430\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u0430 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430.<\/p>\n<p> \u0412\u044b\u0431\u0440\u0430\u0432 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043c\u044b \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0435\u043c \u043a\u0440\u0430\u0442\u043a\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u0434\u043e\u043b\u0433\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430, \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0443\u043b\u0435\u0432\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0443\u0440\u043e\u0432\u043d\u044e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0432\u0435\u0431-\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432.<a name=\"habracut\"><\/a><\/p>\n<h2><font color=\"#3AC1EF\">\u0427\u0430\u0441\u0442\u044c 1. \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b<\/font><\/h2>\n<p> <\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435?<\/font><\/h3>\n<p> <strong><font color=\"#3AC1EF\">\u0412\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b (Web Components)<\/font><\/strong> \u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e HTML-\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/a> \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438.<\/p>\n<p> \u0415\u0441\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438:<\/p>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_components\/Using_custom_elements\">\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b (Custom elements)<\/a> \u2014 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c HTML, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0443 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 <code>&lt;div&gt;<\/code>, <code>&lt;input&gt;<\/code>, <code>&lt;span&gt;<\/code> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435, \u043d\u043e \u0438 \u0438\u0437 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432.<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_components\/Using_shadow_DOM\">Shadow DOM<\/a> \u2014 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0438\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e DOM; \u0438\u0437\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_components\/Using_templates_and_slots\">\u0428\u0430\u0431\u043b\u043e\u043d\u044b HTML<\/a> \u2014 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438 \u0431\u043b\u043e\u043a\u0430\u043c\u0438 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438 \u0441 \u0442\u0435\u0433\u0430\u043c\u0438 <code>&lt;template&gt;<\/code> \u0438 <code>&lt;slot&gt;<\/code> \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440.<\/li>\n<\/ul>\n<p> \u042d\u0442\u0438 \u0442\u0440\u0438 \u043f\u0443\u043d\u043a\u0442\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043d\u0430\u043c \u043e\u0431\u043e \u0432\u0441\u0451\u043c \u0438 \u043d\u0438 \u043e \u0447\u0451\u043c. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u044d\u0442\u043e \u043d\u0435 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0448 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b \u043f\u043e Web Components, \u0438 \u0432\u0430\u043c \u043c\u043e\u0433\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u0430.<\/p>\n<p> \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e, \u0432\u0441\u0451 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u043e\u2026<\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/font><\/h3>\n<p> \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0433\u043e \u2014 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <em>&#8216;hello world!&#8217;<\/em>:<\/p>\n<p> <code>hello-world.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class HelloWorldComponent extends HTMLElement {     connectedCallback() {         this.textContent = 'hello world!';     } } customElements.define('x-hello-world', HelloWorldComponent);<\/code><\/pre>\n<p> \u041d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p> <code>index.html<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;!doctype html&gt; &lt;html lang=\"en\"&gt; &lt;body&gt;     &lt;script src=\"hello-world.js\"&gt;&lt;\/script&gt;     &lt;p&gt;I just want to say...&lt;\/p&gt;     &lt;x-hello-world&gt;&lt;\/x-hello-world&gt; &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p> \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u0438\u043c: <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/sg\/xm\/ge\/sgxmgektbhiycbsp697dwklx6u0.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/sg\/xm\/ge\/sgxmgektbhiycbsp697dwklx6u0.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/sg\/xm\/ge\/sgxmgektbhiycbsp697dwklx6u0.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p> \u0427\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442?<\/p>\n<p> \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 HTML-\u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0432 \u0435\u0433\u043e \u043a\u0430\u043a \u0442\u0435\u0433 <code>x-hello-world<\/code>, \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u0435\u0433\u043e \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435. \u0421\u0434\u0435\u043b\u0430\u0432 \u044d\u0442\u043e, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 DOM:<\/p>\n<ul>\n<li>body (\u0443\u0437\u0435\u043b)<br \/> \n<ul>\n<li>x-hello-world (\u0443\u0437\u0435\u043b)<br \/> \n<ul>\n<li>&#8216;hello world!&#8217; (textContent)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p> \u041f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<p> <code>class HelloWorldComponent extends HTMLElement {<\/code> \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u0439 <code>HTMLElement<\/code>. \u0422\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>HTMLButtonElement<\/code>, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c <code>&lt;button&gt;<\/code>, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 <a href=\"https:\/\/caniuse.com\/mdn-api_customelementregistry_builtin_element_support\">\u044d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 Safari<\/a>.<\/p>\n<p> <code>connectedCallback() {<\/code> \u2014 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 DOM; \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0433\u043e\u0442\u043e\u0432 \u0432\u043d\u043e\u0441\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 DOM. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u043b\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043a\u043e\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u043e DOM.<\/p>\n<p> <code>this.textContent = 'hello world!';<\/code> \u2014 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <code>this<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0448 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u043d\u044b\u0439 API <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/HTMLElement\">HTMLElement<\/a>, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043a\u043e\u0432 <code>Element<\/code> \u0438 <code>Node<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>textContent<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0435 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 <code>'hello world!'<\/code> \u0432 DOM.<\/p>\n<p> <code>customElements.define('x-hello-world', HelloWorldComponent);<\/code> \u2014 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>window.customElements.define<\/code>, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u0442\u0435\u0433\u043e\u043c. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 HTML-\u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435, \u0430 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u0441\u0432\u043e\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b.<\/p>\n<blockquote><p><b><font color=\"#3AC1EF\">\u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f x-hello-world, \u0430 \u043d\u0435 hello-world?<\/font><\/b><\/p>\n<p> \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/custom-elements.html#valid-custom-element-name\">\u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u0433\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/a>; \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0438\u043c\u044f \u0434\u043e\u043b\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\u0441\u044f \u0441 \u0431\u0443\u043a\u0432\u044b \u0432 \u043d\u0438\u0436\u043d\u0435\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0435\u0444\u0438\u0441. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432\u0441\u0435 \u0442\u0435\u0433\u0438 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u0451\u043d, \u0433\u0434\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0438\u0441\u043a \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0430 \u0438\u043c\u0451\u043d. \u0425\u043e\u0442\u044f <code>hello-world<\/code> \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435\u043c, \u043e\u0431\u044b\u0447\u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u043c\u0435\u043d\u0430 \u0442\u0435\u0433\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u043c. \u041c\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u043f\u0440\u0435\u0444\u0438\u043a\u0441 <code>x-<\/code>.<\/p>\n<p> \u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0435\u0433\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u0430\u043c\u043e\u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u043c\u0438\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 <code>&lt;x-hello-world&gt;&lt;\/x-hello-world&gt;<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043c\u043e\u0436\u043d\u043e, \u0430 <code>&lt;x-hello-world \/&gt;<\/code> \u2014 \u043d\u0435\u043b\u044c\u0437\u044f.<\/p><\/blockquote>\n<p> <\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u0421\u043b\u043e\u0436\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/font><\/h3>\n<p> \u041f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u0430\u044f \u0432\u044b\u0448\u0435 \u0432\u0435\u0440\u0441\u0438\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0434\u0435\u043c\u043e, \u043d\u043e \u0432\u0430\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0435:<\/p>\n<ul>\n<li>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 DOM \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430.<\/li>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 DOM \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u044d\u0442\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u0445.<\/li>\n<li>\u0421\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0438 \u0443\u0434\u043e\u0431\u043d\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c.<\/li>\n<li>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043a\u0438\u0434\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0433\u043e\u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438.<\/li>\n<\/ul>\n<p> \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>&lt;x-avatar&gt;<\/code>, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e <a href=\"https:\/\/nextui.org\/docs\/components\/avatar\">\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 NextUI Avatar<\/a> (React):<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/nq\/lw\/kk\/nqlwkkldb3b48jdiwudlakkg8wu.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/nq\/lw\/kk\/nqlwkkldb3b48jdiwudlakkg8wu.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/nq\/lw\/kk\/nqlwkkldb3b48jdiwudlakkg8wu.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p> <code>components\/avatar.js<\/code>:<\/p>\n<pre><code class=\"javascript\">\/**  * \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:  * &lt;x-avatar src=\"https:\/\/...\/avatar.png\"&gt;&lt;\/x-avatar&gt;  * &lt;x-avatar src=\"https:\/\/...\/avatar-large.png\" size=\"lg\"&gt;&lt;\/x-avatar&gt;  *\/ class AvatarComponent extends HTMLElement {     connectedCallback() {         if (!this.querySelector('img')) {             this.append(document.createElement('img'));         }         this.update();     }      static get observedAttributes() {         return ['src', 'alt'];     }      attributeChangedCallback() {         this.update();     }      update() {         const img = this.querySelector('img');         if (img) {             img.src = this.getAttribute('src');             img.alt = this.getAttribute('alt') || 'avatar';             }     } }  export const registerAvatarComponent = () =&gt; {     customElements.define('x-avatar', AvatarComponent); }<\/code><\/pre>\n<p> \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\u0413\u0435\u0442\u0442\u0435\u0440 <code>observedAttributes<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0432\u044b\u0437\u043e\u0432\u0443 <code>attributeChangedCallback()<\/code> \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c UI.<\/li>\n<li>\u041c\u0435\u0442\u043e\u0434 <code>connectedCallback<\/code> \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441 \u0434\u043e\u043f\u0443\u0449\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f DOM, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f.<\/li>\n<li>\u041c\u0435\u0442\u043e\u0434 <code>update()<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f, \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u0443\u044f \u043b\u043e\u0433\u0438\u043a\u0443 UI. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>if<\/code>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u043d \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 <code>attributeChangedCallback()<\/code> \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a <code>connectedCallback()<\/code> \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>&lt;img&gt;<\/code>.<\/li>\n<li>\u042d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>registerAvatarComponent<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e \u0432\u0441\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/li>\n<\/ul>\n<p> \u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u044d\u0442\u043e\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0430\u0432\u0430\u0442\u0430\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 DOM:<\/p>\n<ul>\n<li>body (\u0443\u0437\u0435\u043b)<br \/> \n<ul>\n<li>x-avatar (\u0443\u0437\u0435\u043b)<br \/> \n<ul>\n<li>img (\u0443\u0437\u0435\u043b)<br \/> \n<ul>\n<li>src (\u0430\u0442\u0440\u0438\u0431\u0443\u0442)<\/li>\n<li>alt (\u0430\u0442\u0440\u0438\u0431\u0443\u0442)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p> \u0414\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b CSS:<\/p>\n<p> <code>components\/avatar.css<\/code>:<\/p>\n<pre><code class=\"css\">x-avatar {     display: flex;     align-items: center;     justify-content: center;     width: 2.5rem;     height: 2.5rem; }  x-avatar[size=lg] {     width: 3.5rem;     height: 3.5rem; }  x-avatar img {     border-radius: 9999px;     width: 100%;     height: 100%;     vertical-align: middle;     object-fit: cover; }<\/code><\/pre>\n<p> \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u0442\u0435\u0433 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u0442\u0438\u043b\u0435\u0439, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u043a \u043d\u0438\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 <code>x-avatar<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043d\u0435 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432\u0430\u043b\u0438 \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/li>\n<li>\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e HTML, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c CSS, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>size<\/code>, \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0449\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0431\u0435\u0437 JavaScript.<\/li>\n<\/ul>\n<p> \u041f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/iq\/0n\/a7\/iq0na7cq2i7ecu89xfsujztjbxu.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/iq\/0n\/a7\/iq0na7cq2i7ecu89xfsujztjbxu.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/iq\/0n\/a7\/iq0na7cq2i7ecu89xfsujztjbxu.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p> HTML \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 JavaScript \u0438 CSS \u043f\u043e \u0434\u0432\u0443\u043c \u0444\u0430\u0439\u043b\u0430\u043c index, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u0422\u0430\u043a\u043e\u0439 \u0438\u043b\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0438\u043b\u0438 \u0441\u043e\u0442\u0435\u043d \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p> <code>index.html<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;!doctype html&gt; &lt;html lang=\"en\"&gt; &lt;head&gt;     &lt;link rel=\"stylesheet\" href=\"index.css\"&gt; &lt;\/head&gt; &lt;body&gt;     &lt;script type=\"module\" src=\"index.js\"&gt;&lt;\/script&gt;     &lt;p&gt;A basic avatar component in two sizes:&lt;\/p&gt;     &lt;x-avatar src=\"https:\/\/i.pravatar.cc\/150?u=a042581f4e29026024d\"&gt;&lt;\/x-avatar&gt;     &lt;x-avatar src=\"https:\/\/i.pravatar.cc\/150?u=a04258114e29026302d\" size=\"lg\"&gt;&lt;\/x-avatar&gt; &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p> <code>index.js<\/code>:<\/p>\n<pre><code class=\"javascript\">import { registerAvatarComponent } from '.\/components\/avatar.js'; const app = () =&gt; {     registerAvatarComponent(); } document.addEventListener('DOMContentLoaded', app);<\/code><\/pre>\n<p> <code>index.css<\/code>:<\/p>\n<pre><code class=\"css\">@import url(\".\/components\/avatar.css\"); body { font-family: monospace; }<\/code><\/pre>\n<p> \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 CSS <code>@import<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0447\u0430\u0441\u0442\u043e \u043e\u043f\u0430\u0441\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 \u0441 HTTP\/2 \u0438 \u0432 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0441 HTTP\/3 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043d\u0435 \u0442\u0430\u043a\u043e\u0435 \u0443\u0436 \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e\u0435.<\/p>\n<blockquote><p><b><font color=\"#3AC1EF\">\u0420\u0430\u0437\u0432\u0435 \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0431\u0430\u043d\u0434\u043b\u0435\u0440?<\/font><\/b><\/p>\n<p> \u0415\u0441\u043b\u0438 \u0432\u044b \u0447\u0438\u0442\u0430\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0442\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Guide\/Modules\">\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 ES<\/a> \u0434\u043b\u044f <code>import<\/code> \u0438 <code>export<\/code>, \u043d\u043e \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0431\u0430\u043d\u0434\u043b\u0435\u0440\u0430 JavaScript \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430. \u041c\u0430\u0433\u0438\u044f, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 <code>index.html<\/code>, \u0433\u0434\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0442\u0438\u043f\u0430 \u0442\u0435\u0433\u0430 <code>&lt;script type=\"module\" src=\"index.js\"&gt;<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u0436\u0438\u043c \u043c\u043e\u0434\u0443\u043b\u044f ES \u0434\u043b\u044f \u0432\u0441\u0435\u0433\u043e JavaScript. \u041e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445.<\/p><\/blockquote>\n<p> <\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b<\/font><\/h3>\n<p> \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u0430\u043a \u0441\u043b\u043e\u0436\u043d\u043e. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u044d\u0442\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0430\u0432\u0430\u0442\u0430\u0440\u043e\u043c, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u0435\u0433\u043e \u0432 \u0437\u043d\u0430\u0447\u043e\u043a:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/7i\/ws\/y0\/7iwsy0-9mp0gwyazowcanwhvm6a.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/7i\/ws\/y0\/7iwsy0-9mp0gwyazowcanwhvm6a.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/7i\/ws\/y0\/7iwsy0-9mp0gwyazowcanwhvm6a.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p> <code>index.html<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;!doctype html&gt; &lt;html lang=\"en\"&gt; &lt;head&gt;     &lt;link rel=\"stylesheet\" href=\"index.css\"&gt; &lt;\/head&gt; &lt;body&gt;     &lt;script type=\"module\" src=\"index.js\"&gt;&lt;\/script&gt;     &lt;p&gt;Avatar and badge, when their powers combine...&lt;\/p&gt;     &lt;div&gt;         &lt;x-badge content=\"5\" id=\"live-badge\"&gt;             &lt;x-avatar src=\"https:\/\/i.pravatar.cc\/150?u=a042581f4e29026704d\"&gt;&lt;\/x-avatar&gt;         &lt;\/x-badge&gt;         \u2190         &lt;input type=\"number\" value=\"5\" title=\"badge value\"                oninput=\"document.getElementById('live-badge').content = this.value\" \/&gt;         &lt;\/div&gt; &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p> <code>index.js<\/code>:<\/p>\n<pre><code class=\"javascript\">import { registerAvatarComponent } from '.\/components\/avatar.js'; import { registerBadgeComponent } from '.\/components\/badge.js'; const app = () =&gt; {     registerAvatarComponent();     registerBadgeComponent(); } document.addEventListener('DOMContentLoaded', app);<\/code><\/pre>\n<p> <code>index.css<\/code>:<\/p>\n<pre><code class=\"css\">@import url(\".\/components\/avatar.css\"); @import url(\".\/components\/badge.css\");  p, div { margin: 1em; font-family: sans-serif; } x-badge { vertical-align: middle; }<\/code><\/pre>\n<p> \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 DOM:<\/p>\n<ul>\n<li>div (\u0443\u0437\u0435\u043b)<br \/> \n<ul>\n<li>x-badge (\u0443\u0437\u0435\u043b)<br \/> \n<ul>\n<li>content (\u0430\u0442\u0440\u0438\u0431\u0443\u0442)<\/li>\n<li>span (\u0443\u0437\u0435\u043b, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442)<\/li>\n<li>x-avatar (\u0443\u0437\u0435\u043b)<\/li>\n<\/ul>\n<\/li>\n<li>input (\u0443\u0437\u0435\u043b)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p> \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>x-avatar<\/code> \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u0435\u043d \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u043d\u043e \u043a\u0430\u043a \u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 <code>x-badge<\/code>?<\/p>\n<p> <code>components\/badge.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class BadgeComponent extends HTMLElement {     #span;      connectedCallback() {         if (!this.#span) {             this.#span = document.createElement('span');             this.#span.className = 'x-badge-label';                         }         this.insertBefore(this.#span, this.firstChild);         this.update();     }      update() {         if (this.#span) this.#span.textContent = this.getAttribute('content');     }      static get observedAttributes() {         return ['content'];     }      attributeChangedCallback() {         this.update();     }      set content(value) {         if (this.getAttribute('content') !== value) {             this.setAttribute('content', value);         }     }      get content() {         return this.getAttribute('content');     } }  export const registerBadgeComponent = () =&gt; customElements.define('x-badge', BadgeComponent);<\/code><\/pre>\n<p> <code>components\/badge.css<\/code>:<\/p>\n<pre><code class=\"css\">x-badge {     position: relative;     display: inline-flex;     flex-shrink: 0;     box-sizing: border-box; }  x-badge &gt; span.x-badge-label {     \/* \u0440\u0430\u0437\u043c\u0435\u0440 \u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u044f *\/     box-sizing: inherit;     position: absolute;     top: 0.2rem;     right: 0.2rem;     width: 1.25rem;     height: 1.25rem;     transform: translate(50%, -50%);     z-index: 10;     \/* \u0446\u0432\u0435\u0442\u0430 \u0438 \u0448\u0440\u0438\u0444\u0442\u044b *\/     color: white;     background-color: rgb(0, 111, 238);     border-style: solid;     border-color: #333333;     border-width: 2px;     border-radius: 9999px;     font-size: 0.875rem;     line-height: 1.2;     \/* \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 *\/     display: flex;     place-content: center;     user-select: none; }<\/code><\/pre>\n<p> \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u044f \u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u0437\u0434\u0435\u0441\u044c:<\/p>\n<p> <code>this.insertBefore<\/code> \u2014 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 <code>innerHTML<\/code>. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 span, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u0439 badge, \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438. \u0422\u0430\u043a\u0436\u0435 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0432\u044b\u0437\u0432\u0430\u0432 <code>this.innerHTML = ''<\/code> \u0438\u0437 <code>connectedCallback()<\/code>.<\/p>\n<p> <code>set content(value) {<\/code> \u2014 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 JavaScript \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0442\u043e\u0434\u044b <code>setAttribute()<\/code> \u0438 <code>getAttribute()<\/code>. \u0427\u0442\u043e\u0431\u044b JavaScript API \u0431\u044b\u043b \u0447\u0438\u0449\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0442\u0442\u0435\u0440 \u0438 \u0433\u0435\u0442\u0442\u0435\u0440 \u0434\u043b\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430, \u043e\u0431\u0451\u0440\u0442\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>content<\/code> \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430. \u0421\u043c. \u043f\u0440\u0438\u043c\u0435\u0440 \u0432 <code>index.html<\/code> \u0432\u044b\u0448\u0435.<\/p>\n<blockquote><p><b><font color=\"#3AC1EF\">\u0412\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/font><\/b><\/p>\n<p> \u0423\u0437\u043d\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043a \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/MutationObserver\">MutationObserver<\/a>, \u0432\u044b\u0437\u0432\u0430\u0432 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434 observe \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>observer.observe(this, { childList: true })<\/code>. \u0415\u0441\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0437\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0442\u0438\u043f\u0430 <code>childList<\/code> \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f.<\/p><\/blockquote>\n<p> <\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u0423\u043a\u0440\u0430\u0448\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430<\/font><\/h3>\n<p> \u0420\u0430\u0437\u043e\u0431\u0440\u0430\u0432\u0448\u0438\u0441\u044c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0438\u0445 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0444\u0438\u0447\u0438: Shadow DOM \u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u044b HTML.<\/p>\n<p> \u0412\u0441\u0451 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0449\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>&lt;x-header&gt;<\/code>:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p> <code>index.html<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;!doctype html&gt; &lt;html lang=\"en\"&gt; &lt;head&gt;     &lt;link rel=\"stylesheet\" href=\"index.css\"&gt; &lt;\/head&gt; &lt;body&gt;     &lt;x-header title=\"Welcome\"&gt;         &lt;x-badge content=\"2\"&gt;             &lt;x-avatar src=\"https:\/\/i.pravatar.cc\/150?u=a042581f4e29026704d\"&gt;&lt;\/x-avatar&gt;         &lt;\/x-badge&gt;     &lt;\/x-header&gt;     &lt;main&gt;         &lt;p&gt;Hello, shadow DOM!&lt;\/p&gt;     &lt;\/main&gt;     &lt;script type=\"module\" src=\"index.js\"&gt;&lt;\/script&gt; &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p> \u0412\u043e\u0442 \u043a\u043e\u0434 \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<code>&lt;x-header&gt;<\/code>:<\/p>\n<p> <code>components\/header.js<\/code>:<\/p>\n<pre><code class=\"javascript\">const template = document.createElement('template'); template.innerHTML = `     &lt;link rel=\"stylesheet\" href=\"${import.meta.resolve('.\/header.css')}\"&gt;     &lt;header&gt;         &lt;h1&gt;&lt;\/h1&gt;         &lt;slot&gt;&lt;\/slot&gt;     &lt;\/header&gt; `;  class HeaderComponent extends HTMLElement {     constructor() {         super();         if (!this.shadowRoot) {             this.attachShadow({ mode: 'open' });             this.shadowRoot.append(template.content.cloneNode(true));         }         this.update();     }      update() {         this.shadowRoot.querySelector('h1').textContent = this.getAttribute('title');     }      static get observedAttributes() {         return ['title'];     }      attributeChangedCallback() {         this.update();     } }  export const registerHeaderComponent = () =&gt; customElements.define('x-header', HeaderComponent);<\/code><\/pre>\n<p> \u0412 <code>header.js<\/code> \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p> <code>const template = document.createElement('template');<\/code> \u2014 \u043a\u043e\u0434 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043e\u0447\u0438\u0441\u0442\u043a\u0438 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Web_components\/Using_templates_and_slots\">\u0448\u0430\u0431\u043b\u043e\u043d\u0430 HTML<\/a>. \u0428\u0430\u0431\u043b\u043e\u043d\u044b \u2014 \u044d\u0442\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b HTML, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 DOM. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438, \u0447\u0430\u0441\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432. \u0415\u0441\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432\u043d\u0435 \u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0442\u043e \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>&lt;x-header&gt;<\/code>.<\/p>\n<p> <code>&lt;link rel=\"stylesheet\" href=\"${import.meta.resolve('.\/header.css')}\"&gt;<\/code> \u2014 \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 shadow DOM, \u043e\u043d \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0435\u0433\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438. <code>header.css<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 shadow DOM \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0435\u0433\u0430 <code>&lt;link&gt;<\/code>. \u0422\u0440\u044e\u043a \u0441 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/import.meta\/resolve\">import.meta.resolve<\/a> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u0444\u0430\u0439\u043b CSS \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0443\u0442\u0438, \u0447\u0442\u043e \u0438 \u0443 \u0444\u0430\u0439\u043b\u0430 <code>header.js<\/code>.<\/p>\n<p> <code>&lt;slot&gt;&lt;\/slot&gt;<\/code> \u2014 \u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>&lt;slot&gt;<\/code> \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 <code>&lt;x-badge&gt;<\/code> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 <code>&lt;x-header&gt;<\/code>). \u0420\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0441\u043b\u043e\u0442\u0435 \u0441\u0445\u043e\u0436\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u043f\u0441\u0430 <code>children<\/code> \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 React. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0442\u043e\u0432 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438\u043c\u0435\u044e\u0442 shadow DOM.<\/p>\n<p> <code>constructor() {<\/code> \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043d\u043e \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d \u0433\u043e\u0442\u043e\u0432 \u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e \u0441 DOM. \u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 <code>super()<\/code> \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0422\u043e \u0435\u0441\u0442\u044c \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 HTMLElement \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p> \u0417\u0434\u0435\u0441\u044c \u043e\u043d \u0443\u043a\u0430\u0437\u0430\u043d \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0442\u043e \u044d\u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f shadow DOM.<\/p>\n<p> <code>if (!this.shadowRoot) { this.attachShadow({ mode: 'open' });<\/code><\/p>\n<p> <code>attachShadow<\/code> \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u0442 shadow DOM \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443, \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b DOM \u0441 CSS, \u043e\u0442\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0435\u0433\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0441 \u0442\u0435\u043d\u0435\u0432\u044b\u043c \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c, \u0441\u043f\u0440\u044f\u0442\u0430\u043d\u043d\u044b\u043c \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 JavaScript \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b (\u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u043d\u043e <code>mode: 'closed'<\/code>). \u0415\u0441\u043b\u0438 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u0435, \u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 open, \u043a\u0430\u043a \u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0437\u0434\u0435\u0441\u044c.<\/p>\n<p> <code>if (!this.shadowRoot) {<\/code> \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d, \u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 HTML \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/developer.chrome.com\/docs\/css-ui\/declarative-shadow-dom\">\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e shadow DOM<\/a>.<\/p>\n<p> <code>this.shadowRoot.append(template.content.cloneNode(true));<\/code> \u2014 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>shadowRoot<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0451\u043d\u043d\u043e\u0433\u043e shadow DOM, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043a\u0430\u043a \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 <code>&lt;x-header&gt;<\/code>. \u0428\u0430\u0431\u043b\u043e\u043d HTML \u043a\u043b\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u043d\u0435\u043c\u0443.<\/p>\n<p> Shadow DOM \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <code>attachShadow<\/code>, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0443, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434 <code>update()<\/code>. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0431\u0435\u0437 shadow DOM \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d \u0434\u043e <code>connectedCallback()<\/code>.<\/p>\n<p> \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430:<\/p>\n<p> <code>index.html<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;!doctype html&gt; &lt;html lang=\"en\"&gt; &lt;head&gt;     &lt;link rel=\"stylesheet\" href=\"index.css\"&gt; &lt;\/head&gt; &lt;body&gt;     &lt;x-header title=\"Welcome\"&gt;         &lt;x-badge content=\"2\"&gt;             &lt;x-avatar src=\"https:\/\/i.pravatar.cc\/150?u=a042581f4e29026704d\"&gt;&lt;\/x-avatar&gt;         &lt;\/x-badge&gt;     &lt;\/x-header&gt;     &lt;main&gt;         &lt;p&gt;Hello, shadow DOM!&lt;\/p&gt;     &lt;\/main&gt;     &lt;script type=\"module\" src=\"index.js\"&gt;&lt;\/script&gt; &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p> <code>index.css<\/code>:<\/p>\n<pre><code class=\"css\">@import url(\".\/reset.css\"); @import url(\".\/components\/avatar.css\"); @import url(\".\/components\/badge.css\");  body {      font-family: system-ui, sans-serif; }  x-header, main {      margin: 1em;      padding: 1em;     border: 1px dashed black; }<\/code><\/pre>\n<p> <code>reset.css<\/code>:<\/p>\n<pre><code class=\"css\">\/* \u041e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0431\u0440\u043e\u0441 CSS    \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u044f: https:\/\/www.digitalocean.com\/community\/tutorials\/css-minimal-css-reset *\/  :root {     box-sizing: border-box;     line-height: 1.4;     \/* https:\/\/kilianvalkhof.com\/2022\/css-html\/your-css-reset-needs-text-size-adjust-probably\/ *\/     -moz-text-size-adjust: none;     -webkit-text-size-adjust: none;     text-size-adjust: none; }  *, *:before, *:after {     box-sizing: inherit; }  body, h1, h2, h3, h4, h5, h6, p {     margin: 0;     padding: 0;     font-weight: normal; }  img {     max-width:100%;     height:auto; }<\/code><\/pre>\n<p> <code>index.js<\/code>:<\/p>\n<pre><code class=\"javascript\">import { registerAvatarComponent } from '.\/components\/avatar.js'; import { registerBadgeComponent } from '.\/components\/badge.js'; import { registerHeaderComponent } from '.\/components\/header.js'; const app = () =&gt; {     registerAvatarComponent();     registerBadgeComponent();     registerHeaderComponent(); } document.addEventListener('DOMContentLoaded', app);<\/code><\/pre>\n<p> <code>components\/header.js<\/code>:<\/p>\n<pre><code class=\"javascript\">const template = document.createElement('template'); template.innerHTML = `     &lt;link rel=\"stylesheet\" href=\"${import.meta.resolve('.\/header.css')}\"&gt;     &lt;header&gt;         &lt;h1&gt;&lt;\/h1&gt;         &lt;slot&gt;&lt;\/slot&gt;     &lt;\/header&gt; `;  class HeaderComponent extends HTMLElement {     constructor() {         super();         if (!this.shadowRoot) {             this.attachShadow({ mode: 'open' });             this.shadowRoot.append(template.content.cloneNode(true));         }         this.update();     }      update() {         this.shadowRoot.querySelector('h1').textContent = this.getAttribute('title');     }      static get observedAttributes() {         return ['title'];     }      attributeChangedCallback() {         this.update();     } }  export const registerHeaderComponent = () =&gt; customElements.define('x-header', HeaderComponent);<\/code><\/pre>\n<p> <code>components\/header.css<\/code>:<\/p>\n<pre><code class=\"css\">@import url(\"..\/reset.css\");  :host {     display: block; }  header {     display: flex;     flex-flow: row wrap;     justify-content: right;     align-items: center; }  h1 {     font-family: system-ui, sans-serif;     margin: 0;     display: flex;     flex: 1 1 auto; }  ::slotted(*) {     display: flex;     flex: 0 1 auto; }<\/code><\/pre>\n<p> \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 <code>header.css<\/code>, \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 shadow DOM \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\u041f\u0441\u0435\u0432\u0434\u043e\u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 <code>:host<\/code> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0442\u0438\u043b\u0438 \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0438\u0437 \u00ab\u0441\u0432\u0435\u0442\u043b\u043e\u0439\u00bb DOM, \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u0439 shadow DOM (\u0438\u043b\u0438, \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443).<\/li>\n<li>\u0414\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0438\u043b\u0438 (\u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>h1<\/code>) \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432\u043d\u0443\u0442\u0440\u0438 shadow DOM.<\/li>\n<li>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e shadow DOM \u043d\u0435 \u0441\u0442\u0438\u043b\u0438\u0437\u043e\u0432\u0430\u043d, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <code>reset.css<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e.<\/li>\n<\/ul>\n<p> <\/p>\n<blockquote><p><b><font color=\"#3AC1EF\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c shadow?<\/font><\/b><\/p>\n<p> \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 shadow DOM \u0438 \u0431\u0435\u0437 \u043d\u0435\u0451, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p> Shadow DOM \u0438\u043c\u0435\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432:<\/p>\n<ul>\n<li>\u041e\u043d\u0430 <a href=\"https:\/\/plainvanillaweb.com\/blog\/articles\/2024-09-06-how-fast-are-web-components\/\">\u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/a>, \u0447\u0442\u043e \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441\u043e\u0442\u0435\u043d shadow DOM.<\/li>\n<li>\u041e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c <a href=\"https:\/\/nolanlawson.com\/2022\/11\/28\/shadow-dom-and-accessibility-the-trouble-with-aria\/\">\u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 accessibility<\/a>.<\/li>\n<li>\u0425\u043e\u0442\u044f Google \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u0440\u0430\u0443\u043b\u0438\u043d\u0433 \u0432 shadow DOM, <a href=\"https:\/\/help.siteimprove.com\/support\/solutions\/articles\/80001132321-shadow-dom-support\">\u0443 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u0440\u0430\u0443\u043b\u0435\u0440\u043e\u0432, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/a>.<\/li>\n<li>\u041f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0442\u0438\u043b\u044f \u0438\u0437 \u0442\u0435\u0433\u0430 <code>&lt;link&gt;<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u00ab\u0432\u0441\u043f\u044b\u0448\u043a\u0430 \u043d\u0435\u0441\u0442\u0438\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430\u00bb (Flash Of Unstyled Content, FOUC). \u042d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/web.dev\/articles\/constructable-stylesheets\">constructable stylesheet<\/a>, \u043d\u043e \u043e\u043d\u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u044e\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c.<\/li>\n<\/ul>\n<p> \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043a\u043e\u0433\u043e-\u0442\u043e \u0435\u0449\u0451, \u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0449\u0435 \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 shadow DOM.<\/p>\n<p> \u041e\u0434\u043d\u0430\u043a\u043e Shadow DOM \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445:<\/p>\n<ul>\n<li>\u041f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u043c\u0438\u0441\u044f \u0432 \u043d\u0451\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438, \u043a\u0430\u043a \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 <code>&lt;header&gt;<\/code>. \u042d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u043b\u043e\u0442\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 shadow DOM.<\/li>\n<li>\u041a\u043e\u0433\u0434\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u042d\u0442\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0442\u0430\u043c\u0438. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b.<\/li>\n<li>\u0421\u0442\u0438\u043b\u0438 \u0438 DOM \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0438\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u0427\u0430\u0441\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u0432 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438 \u0438\u043b\u0438 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0441\u0430\u0439\u0442\u044b.<\/li>\n<\/ul>\n<\/blockquote>\n<p> <\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/font><\/h3>\n<p> \u0412\u044b\u0448\u0435 \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u0438, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b, \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0432\u043d\u0438\u0437 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0438 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043c\u0435\u0436\u0434\u0443 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c \u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u044b.<\/p>\n<p> \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ne\/o0\/bp\/neo0bp9e2vva7c0elb5u6n0axcc.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ne\/o0\/bp\/neo0bp9e2vva7c0elb5u6n0axcc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ne\/o0\/bp\/neo0bp9e2vva7c0elb5u6n0axcc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p> <\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u0421\u043e\u0431\u044b\u0442\u0438\u044f<\/font><\/h3>\n<p> \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043a \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443. \u042d\u0442\u043e \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0444\u043e\u0440\u043c\u043e\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430.<\/p>\n<p> <code>components\/form.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasForm extends HTMLElement {     connectedCallback() {         if (this.querySelector('form')) return;         this.innerHTML = `             &lt;form&gt;                 &lt;label for=\"name\"&gt;Name&lt;\/label&gt;                 &lt;input type=\"text\" id=\"name\" name=\"name\" required \/&gt;                 &lt;input type=\"checkbox\" id=\"nice\" name=\"nice\" value=\"1\" \/&gt;                 &lt;label for=\"nice\"&gt;Nice?&lt;\/label&gt;                 &lt;button type=\"submit\"&gt;Add&lt;\/button&gt;             &lt;\/form&gt;         `;         this.querySelector('form').onsubmit = (e) =&gt; {             e.preventDefault();             const data = new FormData(e.target);             this.dispatchEvent(new CustomEvent('add', {                 detail: { form: Object.fromEntries(data.entries()) }             }));             e.target.reset();         }     } }  export const registerSantasForm =      () =&gt; customElements.define('santas-form', SantasForm);<\/code><\/pre>\n<p> \u041f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 <strong><font color=\"#3AC1EF\">Add<\/font><\/strong> \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>dispatchEvent<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>CustomEvent<\/code> \u0442\u0438\u043f\u0430 <code>add<\/code>. \u0412 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 <code>detail<\/code> \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0444\u043e\u0440\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p> \u042d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0432\u044b\u0448\u0435:<\/p>\n<p> <code>components\/app.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasApp extends HTMLElement {     #theList = [\/* { name, nice } *\/];      connectedCallback() {         if (this.querySelector('h1')) return;         this.innerHTML = `             &lt;h1&gt;Santa's List&lt;\/h1&gt;             &lt;santas-form&gt;&lt;\/santas-form&gt;             &lt;santas-list&gt;&lt;\/santas-list&gt;             &lt;santas-summary&gt;&lt;\/santas-summary&gt;         `;         this.querySelector('santas-form')             .addEventListener('add', (e) =&gt; {                 this.#theList.push(e.detail.form);                 this.update();             });         this.update();     }      update() {         this.querySelector('santas-list').list = this.#theList.slice();         this.querySelector('santas-summary').update(this.#theList.slice());     } }  export const registerApp =      () =&gt; customElements.define('santas-app', SantasApp);<\/code><\/pre>\n<p> \u041c\u0435\u0442\u043e\u0434 <code>update()<\/code> \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043d\u0438\u0437, \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c <code>&lt;santas-list&gt;<\/code> \u0438 <code>&lt;santas-summary&gt;<\/code>, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0434\u0432\u0443\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/font><\/h3>\n<p> \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>&lt;santas-list&gt;<\/code>:<\/p>\n<p> <code>components\/list.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasList extends HTMLElement {     #currentList = [\/* { name, nice } *\/];     set list(newList) {         this.#currentList = newList;         this.update();     }     update() {         this.innerHTML =              '&lt;ul&gt;' +             this.#currentList.map(person =&gt;                  `&lt;li&gt;${person.name} is ${person.nice ? 'nice' : 'naughty'}&lt;\/li&gt;`             ).join('\\n') +             '&lt;\/ul&gt;';     } }  export const registerSantasList =     () =&gt; customElements.define('santas-list', SantasList);<\/code><\/pre>\n<p> \u0421\u0435\u0442\u0442\u0435\u0440 <code>list<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>update()<\/code> \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0441\u043f\u0438\u0441\u043a\u0430.<\/p>\n<p> \u042d\u0442\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c.<\/p>\n<blockquote><p><b><font color=\"#3AC1EF\">\u041e\u043f\u0430\u0441\u0430\u0439\u0442\u0435\u0441\u044c XSS<\/font><\/b><\/p>\n<p> \u041d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0435\u0441\u0442\u044c \u0431\u0430\u0433 cross-site scripting. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>person.name<\/code>. \u041e \u0442\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f, \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432 \u0433\u043b\u0430\u0432\u0435 \u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 (\u00ab\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u00bb).<\/p><\/blockquote>\n<p> \u041a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0431\u0435\u0441\u0441\u043f\u043e\u0440\u043d\u043e\u0433\u043e \u0438 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432, \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0435\u0442. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435, \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u043e\u0439 <a href=\"https:\/\/blog.ltgt.net\/web-component-properties\/\">\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/a>, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432\u0435\u043b\u0438 \u0441\u0435\u0431\u044f \u0441\u0445\u043e\u0436\u0435 \u0441\u043e \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438; \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0442\u044c \u0435\u0451 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0435 \u0441\u0430\u0439\u0442\u044b.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u041c\u0435\u0442\u043e\u0434\u044b<\/font><\/h3>\n<p> \u0422\u0440\u0435\u0442\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u044d\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430; \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <code>&lt;santas-summary&gt;<\/code>:<\/p>\n<p> <code>components\/summary.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasSummary extends HTMLElement {     update(list) {         const nice = list.filter((item) =&gt; item.nice).length;         const naughty = list.length - nice;         this.innerHTML = list.length ? `             &lt;p&gt;${nice} nice, ${naughty} naughty&lt;\/p&gt;         ` : \"&lt;p&gt;Nobody's on the list yet.&lt;\/p&gt;\";     } }  export const registerSantasSummary =      () =&gt; customElements.define('santas-summary', SantasSummary);<\/code><\/pre>\n<p> \u042d\u0442\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c \u0431\u0435\u0437 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<h3><font color=\"#3AC1EF\">\u258d \u041f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/font><\/h3>\n<p> \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f Santa&#8217;s List:<\/p>\n<p> <code>index.html<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;!doctype html&gt; &lt;html lang=\"en\"&gt; &lt;head&gt;     &lt;link rel=\"stylesheet\" href=\"index.css\"&gt; &lt;\/head&gt; &lt;body&gt;     &lt;script type=\"module\" src=\"index.js\"&gt;&lt;\/script&gt;     &lt;santas-app&gt;&lt;\/santas-app&gt; &lt;\/body&gt; &lt;\/html&gt;<\/code><\/pre>\n<p> <code>index.js<\/code>:<\/p>\n<pre><code class=\"javascript\">import { registerSantasForm } from '.\/components\/form.js'; import { registerSantasList } from '.\/components\/list.js'; import { registerSantasSummary } from '.\/components\/summary.js'; import { registerApp } from '.\/components\/app.js';  const app = () =&gt; {     registerSantasForm();     registerSantasList();     registerSantasSummary();     registerApp(); }  document.addEventListener('DOMContentLoaded', app);<\/code><\/pre>\n<p> <code>index.css<\/code>: <\/p>\n<pre><code class=\"css\">body {      font-family: 'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif;     margin: 1em; }  button { font-family: inherit; font-size: 100%; }  santas-form { display: block } santas-form * { vertical-align: middle; }  santas-app h1 { color: darkred; }<\/code><\/pre>\n<p> <code>components\/app.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasApp extends HTMLElement {     #theList = [\/* { name, nice } *\/];      connectedCallback() {         if (this.querySelector('h1')) return;         this.innerHTML = `             &lt;h1&gt;Santa's List&lt;\/h1&gt;             &lt;santas-form&gt;&lt;\/santas-form&gt;             &lt;santas-list&gt;&lt;\/santas-list&gt;             &lt;santas-summary&gt;&lt;\/santas-summary&gt;         `;         this.querySelector('santas-form')             .addEventListener('add', (e) =&gt; {                 this.#theList.push(e.detail.form);                 this.update();             });         this.update();     }      update() {         this.querySelector('santas-list').list = this.#theList.slice();         this.querySelector('santas-summary').update(this.#theList.slice());     } }  export const registerApp =      () =&gt; customElements.define('santas-app', SantasApp);<\/code><\/pre>\n<p> <code>components\/form.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasForm extends HTMLElement {     connectedCallback() {         if (this.querySelector('form')) return;         this.innerHTML = `             &lt;form&gt;                 &lt;label for=\"name\"&gt;Name&lt;\/label&gt;                 &lt;input type=\"text\" id=\"name\" name=\"name\" required \/&gt;                 &lt;input type=\"checkbox\" id=\"nice\" name=\"nice\" value=\"1\" \/&gt;                 &lt;label for=\"nice\"&gt;Nice?&lt;\/label&gt;                 &lt;button type=\"submit\"&gt;Add&lt;\/button&gt;             &lt;\/form&gt;         `;         this.querySelector('form').onsubmit = (e) =&gt; {             e.preventDefault();             const data = new FormData(e.target);             this.dispatchEvent(new CustomEvent('add', {                 detail: { form: Object.fromEntries(data.entries()) }             }));             e.target.reset();         }     } }  export const registerSantasForm =      () =&gt; customElements.define('santas-form', SantasForm);<\/code><\/pre>\n<p> <code>components\/list.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasList extends HTMLElement {     #currentList = [\/* { name, nice } *\/];     set list(newList) {         this.#currentList = newList;         this.update();     }     update() {         this.innerHTML =              '&lt;ul&gt;' +             this.#currentList.map(person =&gt;                  `&lt;li&gt;${person.name} is ${person.nice ? 'nice' : 'naughty'}&lt;\/li&gt;`             ).join('\\n') +             '&lt;\/ul&gt;';     } }  export const registerSantasList =     () =&gt; customElements.define('santas-list', SantasList);<\/code><\/pre>\n<p> <code>components\/summary.js<\/code>:<\/p>\n<pre><code class=\"javascript\">class SantasSummary extends HTMLElement {     update(list) {         const nice = list.filter((item) =&gt; item.nice).length;         const naughty = list.length - nice;         this.innerHTML = list.length ? `             &lt;p&gt;${nice} nice, ${naughty} naughty&lt;\/p&gt;         ` : \"&lt;p&gt;Nobody's on the list yet.&lt;\/p&gt;\";     } }  export const registerSantasSummary =      () =&gt; customElements.define('santas-summary', SantasSummary);<\/code><\/pre>\n<p> <\/p>\n<blockquote><p><b><font color=\"#3AC1EF\">\u0421\u0438\u043b\u0430 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430<\/font><\/b><\/p>\n<p> \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e \u0432\u0435\u0441\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0439. \u0412 \u043d\u0451\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u0438 \u043e\u0434\u0438\u043d \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0441\u0431\u043e\u0440\u043a\u0438, \u0438 \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445. \u0415\u043c\u0443 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 \u043d\u043e\u0432\u044b\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u0410 \u0441\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c \u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435.<\/p>\n<p> \u041e \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u0449\u0451 \u043c\u043d\u043e\u0433\u043e\u0435. \u0427\u0442\u043e\u0431\u044b \u0433\u043b\u0443\u0431\u0436\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u0445 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435, \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043d\u0430\u0448\u0443 <a href=\"https:\/\/plainvanillaweb.com\/blog\/articles\/2024-09-16-life-and-times-of-a-custom-element\/\">\u0441\u0442\u0430\u0442\u044c\u044e<\/a>.<\/p><\/blockquote>\n<p> \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u0431-\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0438\u0445 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u0438 \u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<blockquote><p><b><font color=\"#3AC1EF\"><a href=\"https:\/\/t.me\/ruvds_community\">Telegram-\u043a\u0430\u043d\u0430\u043b \u0441\u043e \u0441\u043a\u0438\u0434\u043a\u0430\u043c\u0438, \u0440\u043e\u0437\u044b\u0433\u0440\u044b\u0448\u0430\u043c\u0438 \u043f\u0440\u0438\u0437\u043e\u0432 \u0438 \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u043c\u0438 IT \ud83d\udcbb<\/a><\/font><\/b><\/p><\/blockquote>\n<p><a href=\"https:\/\/ruvds.com\/ru-rub?utm_source=habr&amp;utm_medium=article&amp;utm_campaign=perevod&amp;utm_content=veb_razrabotka_na_vanilnom_html_css_i_javascript\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/yo\/se\/km\/yosekm4h_f7y7oia-ghbbpc0phi.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/yo\/se\/km\/yosekm4h_f7y7oia-ghbbpc0phi.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/yo\/se\/km\/yosekm4h_f7y7oia-ghbbpc0phi.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/a><\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/909390\/\"> https:\/\/habr.com\/ru\/articles\/909390\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><a href=\"https:\/\/habr.com\/ru\/companies\/ruvds\/articles\/909390\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/vi\/rd\/h_\/virdh_fo4fv76yzlbtrv1nzdk9o.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/div>\n<p><\/a><br \/> \u0412 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u0445. \u041d\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u043b\u0438\u0448\u044c HTML, CSS \u0438 JavaScript.<\/p>\n<p> \u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u043c\u043e\u0449\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d\u0438 \u0441\u0442\u043e\u044f\u0442 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u0430 \u044d\u0442\u0443 \u0431\u043e\u0433\u0430\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u0430 \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430.<\/p>\n<p> \u0412\u044b\u0431\u0440\u0430\u0432 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043c\u044b \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0435\u043c \u043a\u0440\u0430\u0442\u043a\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u0434\u043e\u043b\u0433\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430, \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0443\u043b\u0435\u0432\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c\u0443 \u0443\u0440\u043e\u0432\u043d\u044e \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0432\u0435\u0431-\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u0432.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-459710","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/459710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=459710"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/459710\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=459710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=459710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=459710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}