1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var _a, _b;
|
7 |
|
8 |
|
9 | var styledScopes = new Set();
|
10 |
|
11 |
|
12 | var scopeCssStore = new Map();
|
13 | var ENABLE_SHADYDOM_NOPATCH = true;
|
14 |
|
15 |
|
16 |
|
17 | var DEV_MODE = true;
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var polyfillSupport = function (Template, ChildPart) {
|
24 | var _a, _b;
|
25 |
|
26 |
|
27 |
|
28 | if (window.ShadyCSS === undefined ||
|
29 | (window.ShadyCSS.nativeShadow && !window.ShadyCSS.ApplyShim)) {
|
30 | return;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | var wrap = ENABLE_SHADYDOM_NOPATCH &&
|
37 | ((_a = window.ShadyDOM) === null || _a === void 0 ? void 0 : _a.inUse) &&
|
38 | ((_b = window.ShadyDOM) === null || _b === void 0 ? void 0 : _b.noPatch) === true
|
39 | ? window.ShadyDOM.wrap
|
40 | : function (node) { return node; };
|
41 | var needsPrepareStyles = function (name) {
|
42 | return name !== undefined && !styledScopes.has(name);
|
43 | };
|
44 | var cssForScope = function (name) {
|
45 | var scopeCss = scopeCssStore.get(name);
|
46 | if (scopeCss === undefined) {
|
47 | scopeCssStore.set(name, (scopeCss = []));
|
48 | }
|
49 | return scopeCss;
|
50 | };
|
51 | var prepareStyles = function (name, template) {
|
52 |
|
53 | var scopeCss = cssForScope(name);
|
54 | var hasScopeCss = scopeCss.length !== 0;
|
55 | if (hasScopeCss) {
|
56 | var style = document.createElement('style');
|
57 | style.textContent = scopeCss.join('\n');
|
58 |
|
59 |
|
60 | template.content.appendChild(style);
|
61 | }
|
62 |
|
63 | styledScopes.add(name);
|
64 |
|
65 | scopeCssStore.delete(name);
|
66 |
|
67 |
|
68 | window.ShadyCSS.prepareTemplateStyles(template, name);
|
69 |
|
70 |
|
71 |
|
72 | if (hasScopeCss && window.ShadyCSS.nativeShadow) {
|
73 |
|
74 |
|
75 | var style = template.content.querySelector('style');
|
76 | if (style !== null) {
|
77 | template.content.appendChild(style);
|
78 | }
|
79 | }
|
80 | };
|
81 | var scopedTemplateCache = new Map();
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 | var originalCreateElement = Template.createElement;
|
88 | Template.createElement = function (html, options) {
|
89 | var element = originalCreateElement.call(Template, html, options);
|
90 | var scope = options === null || options === void 0 ? void 0 : options.scope;
|
91 | if (scope !== undefined) {
|
92 | if (!window.ShadyCSS.nativeShadow) {
|
93 | window.ShadyCSS.prepareTemplateDom(element, scope);
|
94 | }
|
95 |
|
96 |
|
97 | if (needsPrepareStyles(scope)) {
|
98 | var scopeCss = cssForScope(scope);
|
99 |
|
100 | var styles = element.content.querySelectorAll('style');
|
101 |
|
102 |
|
103 | scopeCss.push.apply(scopeCss, Array.from(styles).map(function (style) {
|
104 | var _a;
|
105 | (_a = style.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(style);
|
106 | return style.textContent;
|
107 | }));
|
108 | }
|
109 | }
|
110 | return element;
|
111 | };
|
112 | var renderContainer = document.createDocumentFragment();
|
113 | var renderContainerMarker = document.createComment('');
|
114 | var childPartProto = ChildPart.prototype;
|
115 | |
116 |
|
117 |
|
118 | var setValue = childPartProto._$setValue;
|
119 | childPartProto._$setValue = function (value, directiveParent) {
|
120 | var _a, _b;
|
121 | if (directiveParent === void 0) { directiveParent = this; }
|
122 | var container = wrap(this._$startNode).parentNode;
|
123 | var scope = (_a = this.options) === null || _a === void 0 ? void 0 : _a.scope;
|
124 | if (container instanceof ShadowRoot && needsPrepareStyles(scope)) {
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | var startNode = this._$startNode;
|
134 | var endNode = this._$endNode;
|
135 |
|
136 | renderContainer.appendChild(renderContainerMarker);
|
137 | this._$startNode = renderContainerMarker;
|
138 | this._$endNode = null;
|
139 |
|
140 |
|
141 | setValue.call(this, value, directiveParent);
|
142 |
|
143 |
|
144 |
|
145 | var template = (value === null || value === void 0 ? void 0 : value['_$litType$'])
|
146 | ? this._$committedValue._$template.el
|
147 | : document.createElement('template');
|
148 | prepareStyles(scope, template);
|
149 |
|
150 | renderContainer.removeChild(renderContainerMarker);
|
151 |
|
152 | if ((_b = window.ShadyCSS) === null || _b === void 0 ? void 0 : _b.nativeShadow) {
|
153 | var style = template.content.querySelector('style');
|
154 | if (style !== null) {
|
155 | renderContainer.appendChild(style.cloneNode(true));
|
156 | }
|
157 | }
|
158 | container.insertBefore(renderContainer, endNode);
|
159 |
|
160 | this._$startNode = startNode;
|
161 | this._$endNode = endNode;
|
162 | }
|
163 | else {
|
164 | setValue.call(this, value, directiveParent);
|
165 | }
|
166 | };
|
167 | |
168 |
|
169 |
|
170 |
|
171 | childPartProto._$getTemplate = function (result) {
|
172 | var _a;
|
173 | var scope = (_a = this.options) === null || _a === void 0 ? void 0 : _a.scope;
|
174 | var templateCache = scopedTemplateCache.get(scope);
|
175 | if (templateCache === undefined) {
|
176 | scopedTemplateCache.set(scope, (templateCache = new Map()));
|
177 | }
|
178 | var template = templateCache.get(result.strings);
|
179 | if (template === undefined) {
|
180 | templateCache.set(result.strings, (template = new Template(result, this.options)));
|
181 | }
|
182 | return template;
|
183 | };
|
184 | };
|
185 | if (ENABLE_SHADYDOM_NOPATCH) {
|
186 | polyfillSupport.noPatchSupported = ENABLE_SHADYDOM_NOPATCH;
|
187 | }
|
188 | if (DEV_MODE) {
|
189 | (_a = globalThis.litHtmlPolyfillSupportDevMode) !== null && _a !== void 0 ? _a : (globalThis.litHtmlPolyfillSupportDevMode = polyfillSupport);
|
190 | }
|
191 | else {
|
192 | (_b = globalThis.litHtmlPolyfillSupport) !== null && _b !== void 0 ? _b : (globalThis.litHtmlPolyfillSupport = polyfillSupport);
|
193 | }
|
194 | export {};
|
195 |
|
\ | No newline at end of file |