@govtechsg/sgds-web-component 2.0.0-rc.1 → 2.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Accordion/accordion.cjs.js +1 -1
- package/components/Accordion/accordion.js +1 -1
- package/components/Accordion/index.umd.js +1 -1
- package/components/ActionCard/index.umd.js +1938 -1836
- package/components/ActionCard/index.umd.js.map +1 -1
- package/components/ActionCard/sgds-action-card.cjs.js +2 -2
- package/components/ActionCard/sgds-action-card.cjs.js.map +1 -1
- package/components/ActionCard/sgds-action-card.d.ts +1 -1
- package/components/ActionCard/sgds-action-card.js +1 -1
- package/components/ActionCard/sgds-action-card.js.map +1 -1
- package/components/Alert/index.umd.js +200 -98
- package/components/Alert/index.umd.js.map +1 -1
- package/components/Alert/sgds-alert.cjs.js +2 -2
- package/components/Alert/sgds-alert.cjs.js.map +1 -1
- package/components/Alert/sgds-alert.d.ts +1 -1
- package/components/Alert/sgds-alert.js +1 -1
- package/components/Alert/sgds-alert.js.map +1 -1
- package/components/Button/button.cjs.js +1 -1
- package/components/Button/button.js +1 -1
- package/components/Button/index.umd.js +1 -1
- package/components/ComboBox/index.umd.js +229 -127
- package/components/ComboBox/index.umd.js.map +1 -1
- package/components/ComboBox/sgds-combo-box.cjs.js +2 -2
- package/components/ComboBox/sgds-combo-box.cjs.js.map +1 -1
- package/components/ComboBox/sgds-combo-box.d.ts +1 -1
- package/components/ComboBox/sgds-combo-box.js +1 -1
- package/components/ComboBox/sgds-combo-box.js.map +1 -1
- package/components/Datepicker/index.umd.js +7837 -7735
- package/components/Datepicker/index.umd.js.map +1 -1
- package/components/Datepicker/sgds-datepicker.cjs.js +2 -2
- package/components/Datepicker/sgds-datepicker.cjs.js.map +1 -1
- package/components/Datepicker/sgds-datepicker.d.ts +1 -1
- package/components/Datepicker/sgds-datepicker.js +1 -1
- package/components/Datepicker/sgds-datepicker.js.map +1 -1
- package/components/Drawer/index.umd.js +200 -98
- package/components/Drawer/index.umd.js.map +1 -1
- package/components/Drawer/sgds-drawer.cjs.js +2 -2
- package/components/Drawer/sgds-drawer.cjs.js.map +1 -1
- package/components/Drawer/sgds-drawer.d.ts +1 -1
- package/components/Drawer/sgds-drawer.js +1 -1
- package/components/Drawer/sgds-drawer.js.map +1 -1
- package/components/Dropdown/index.umd.js +230 -128
- package/components/Dropdown/index.umd.js.map +1 -1
- package/components/Dropdown/sgds-dropdown.cjs.js +2 -2
- package/components/Dropdown/sgds-dropdown.cjs.js.map +1 -1
- package/components/Dropdown/sgds-dropdown.d.ts +1 -1
- package/components/Dropdown/sgds-dropdown.js +1 -1
- package/components/Dropdown/sgds-dropdown.js.map +1 -1
- package/components/FileUpload/index.umd.js +230 -128
- package/components/FileUpload/index.umd.js.map +1 -1
- package/components/FileUpload/sgds-file-upload.cjs.js +2 -2
- package/components/FileUpload/sgds-file-upload.cjs.js.map +1 -1
- package/components/FileUpload/sgds-file-upload.d.ts +1 -1
- package/components/FileUpload/sgds-file-upload.js +1 -1
- package/components/FileUpload/sgds-file-upload.js.map +1 -1
- package/components/Modal/index.umd.js +200 -98
- package/components/Modal/index.umd.js.map +1 -1
- package/components/Modal/sgds-modal.cjs.js +2 -2
- package/components/Modal/sgds-modal.cjs.js.map +1 -1
- package/components/Modal/sgds-modal.d.ts +1 -1
- package/components/Modal/sgds-modal.js +1 -1
- package/components/Modal/sgds-modal.js.map +1 -1
- package/components/QuantityToggle/index.umd.js +201 -99
- package/components/QuantityToggle/index.umd.js.map +1 -1
- package/components/QuantityToggle/sgds-quantity-toggle.cjs.js +2 -2
- package/components/QuantityToggle/sgds-quantity-toggle.cjs.js.map +1 -1
- package/components/QuantityToggle/sgds-quantity-toggle.d.ts +1 -1
- package/components/QuantityToggle/sgds-quantity-toggle.js +1 -1
- package/components/QuantityToggle/sgds-quantity-toggle.js.map +1 -1
- package/components/Toast/index.umd.js +1938 -1836
- package/components/Toast/index.umd.js.map +1 -1
- package/components/Toast/sgds-toast.cjs.js +2 -2
- package/components/Toast/sgds-toast.cjs.js.map +1 -1
- package/components/Toast/sgds-toast.d.ts +1 -1
- package/components/Toast/sgds-toast.js +1 -1
- package/components/Toast/sgds-toast.js.map +1 -1
- package/components/index.umd.js +202 -100
- package/components/index.umd.js.map +1 -1
- package/index.umd.js +202 -100
- package/index.umd.js.map +1 -1
- package/package.json +2 -2
|
@@ -65,6 +65,235 @@
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @license
|
|
70
|
+
* Copyright 2019 Google LLC
|
|
71
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
72
|
+
*/
|
|
73
|
+
const global$3 = window;
|
|
74
|
+
/**
|
|
75
|
+
* Whether the current browser supports `adoptedStyleSheets`.
|
|
76
|
+
*/
|
|
77
|
+
const supportsAdoptingStyleSheets$1 = global$3.ShadowRoot &&
|
|
78
|
+
(global$3.ShadyCSS === undefined || global$3.ShadyCSS.nativeShadow) &&
|
|
79
|
+
'adoptedStyleSheets' in Document.prototype &&
|
|
80
|
+
'replace' in CSSStyleSheet.prototype;
|
|
81
|
+
/**
|
|
82
|
+
* Applies the given styles to a `shadowRoot`. When Shadow DOM is
|
|
83
|
+
* available but `adoptedStyleSheets` is not, styles are appended to the
|
|
84
|
+
* `shadowRoot` to [mimic spec behavior](https://wicg.github.io/construct-stylesheets/#using-constructed-stylesheets).
|
|
85
|
+
* Note, when shimming is used, any styles that are subsequently placed into
|
|
86
|
+
* the shadowRoot should be placed *before* any shimmed adopted styles. This
|
|
87
|
+
* will match spec behavior that gives adopted sheets precedence over styles in
|
|
88
|
+
* shadowRoot.
|
|
89
|
+
*/
|
|
90
|
+
const adoptStyles$1 = (renderRoot, styles) => {
|
|
91
|
+
if (supportsAdoptingStyleSheets$1) {
|
|
92
|
+
renderRoot.adoptedStyleSheets = styles.map((s) => s instanceof CSSStyleSheet ? s : s.styleSheet);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
styles.forEach((s) => {
|
|
96
|
+
const style = document.createElement('style');
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
const nonce = global$3['litNonce'];
|
|
99
|
+
if (nonce !== undefined) {
|
|
100
|
+
style.setAttribute('nonce', nonce);
|
|
101
|
+
}
|
|
102
|
+
style.textContent = s.cssText;
|
|
103
|
+
renderRoot.appendChild(style);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @typedef {import('./types').RenderOptions} RenderOptions
|
|
110
|
+
* @typedef {import('./types').ScopedElementsMixin} ScopedElementsMixin
|
|
111
|
+
* @typedef {import('./types').ScopedElementsHost} ScopedElementsHost
|
|
112
|
+
* @typedef {import('./types').ScopedElementsMap} ScopedElementsMap
|
|
113
|
+
* @typedef {import('@lit/reactive-element').CSSResultOrNative} CSSResultOrNative
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
const supportsScopedRegistry = !!ShadowRoot.prototype.createElement;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @template {import('./types').Constructor<HTMLElement>} T
|
|
121
|
+
* @param {T} superclass
|
|
122
|
+
* @return {T & import('./types').Constructor<ScopedElementsHost>}
|
|
123
|
+
*/
|
|
124
|
+
const ScopedElementsMixinImplementation = superclass =>
|
|
125
|
+
/** @type {ScopedElementsHost} */
|
|
126
|
+
class ScopedElementsHost extends superclass {
|
|
127
|
+
/**
|
|
128
|
+
* Obtains the scoped elements definitions map if specified.
|
|
129
|
+
*
|
|
130
|
+
* @returns {ScopedElementsMap}
|
|
131
|
+
*/
|
|
132
|
+
static get scopedElements() {
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Obtains the ShadowRoot options.
|
|
138
|
+
*
|
|
139
|
+
* @type {ShadowRootInit}
|
|
140
|
+
*/
|
|
141
|
+
static get shadowRootOptions() {
|
|
142
|
+
return this.__shadowRootOptions;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Set the shadowRoot options.
|
|
147
|
+
*
|
|
148
|
+
* @param {ShadowRootInit} value
|
|
149
|
+
*/
|
|
150
|
+
static set shadowRootOptions(value) {
|
|
151
|
+
this.__shadowRootOptions = value;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Obtains the element styles.
|
|
156
|
+
*
|
|
157
|
+
* @returns {CSSResultOrNative[]}
|
|
158
|
+
*/
|
|
159
|
+
static get elementStyles() {
|
|
160
|
+
return this.__elementStyles;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static set elementStyles(styles) {
|
|
164
|
+
this.__elementStyles = styles;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// either TS or ESLint will complain here
|
|
168
|
+
// eslint-disable-next-line no-unused-vars
|
|
169
|
+
constructor(..._args) {
|
|
170
|
+
super();
|
|
171
|
+
/** @type {RenderOptions} */
|
|
172
|
+
this.renderOptions = this.renderOptions || undefined;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Obtains the CustomElementRegistry associated to the ShadowRoot.
|
|
177
|
+
*
|
|
178
|
+
* @returns {CustomElementRegistry}
|
|
179
|
+
*/
|
|
180
|
+
get registry() {
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
return this.constructor.__registry;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Set the CustomElementRegistry associated to the ShadowRoot
|
|
187
|
+
*
|
|
188
|
+
* @param {CustomElementRegistry} registry
|
|
189
|
+
*/
|
|
190
|
+
set registry(registry) {
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
this.constructor.__registry = registry;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
createRenderRoot() {
|
|
196
|
+
const { scopedElements, shadowRootOptions, elementStyles } =
|
|
197
|
+
/** @type {typeof ScopedElementsHost} */ (this.constructor);
|
|
198
|
+
|
|
199
|
+
const shouldCreateRegistry =
|
|
200
|
+
!this.registry ||
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
(this.registry === this.constructor.__registry &&
|
|
203
|
+
!Object.prototype.hasOwnProperty.call(this.constructor, '__registry'));
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Create a new registry if:
|
|
207
|
+
* - the registry is not defined
|
|
208
|
+
* - this class doesn't have its own registry *AND* has no shared registry
|
|
209
|
+
*/
|
|
210
|
+
if (shouldCreateRegistry) {
|
|
211
|
+
this.registry = supportsScopedRegistry ? new CustomElementRegistry() : customElements;
|
|
212
|
+
for (const [tagName, klass] of Object.entries(scopedElements)) {
|
|
213
|
+
this.defineScopedElement(tagName, klass);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @type {ShadowRootInit} */
|
|
218
|
+
const options = {
|
|
219
|
+
mode: 'open',
|
|
220
|
+
...shadowRootOptions,
|
|
221
|
+
customElements: this.registry,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const createdRoot = this.attachShadow(options);
|
|
225
|
+
if (supportsScopedRegistry) {
|
|
226
|
+
this.renderOptions.creationScope = createdRoot;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (createdRoot instanceof ShadowRoot) {
|
|
230
|
+
adoptStyles$1(createdRoot, elementStyles);
|
|
231
|
+
this.renderOptions.renderBefore = this.renderOptions.renderBefore || createdRoot.firstChild;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return createdRoot;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
createScopedElement(tagName) {
|
|
238
|
+
const root = supportsScopedRegistry ? this.shadowRoot : document;
|
|
239
|
+
// @ts-ignore polyfill to support createElement on shadowRoot is loaded
|
|
240
|
+
return root.createElement(tagName);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Defines a scoped element.
|
|
245
|
+
*
|
|
246
|
+
* @param {string} tagName
|
|
247
|
+
* @param {typeof HTMLElement} klass
|
|
248
|
+
*/
|
|
249
|
+
defineScopedElement(tagName, klass) {
|
|
250
|
+
const registeredClass = this.registry.get(tagName);
|
|
251
|
+
if (registeredClass && supportsScopedRegistry === false && registeredClass !== klass) {
|
|
252
|
+
// eslint-disable-next-line no-console
|
|
253
|
+
console.error(
|
|
254
|
+
[
|
|
255
|
+
`You are trying to re-register the "${tagName}" custom element with a different class via ScopedElementsMixin.`,
|
|
256
|
+
'This is only possible with a CustomElementRegistry.',
|
|
257
|
+
'Your browser does not support this feature so you will need to load a polyfill for it.',
|
|
258
|
+
'Load "@webcomponents/scoped-custom-element-registry" before you register ANY web component to the global customElements registry.',
|
|
259
|
+
'e.g. add "<script src="/node_modules/@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min.js"></script>" as your first script tag.',
|
|
260
|
+
'For more details you can visit https://open-wc.org/docs/development/scoped-elements/',
|
|
261
|
+
].join('\n'),
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (!registeredClass) {
|
|
265
|
+
return this.registry.define(tagName, klass);
|
|
266
|
+
}
|
|
267
|
+
return this.registry.get(tagName);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @deprecated use the native el.tagName instead
|
|
272
|
+
*
|
|
273
|
+
* @param {string} tagName
|
|
274
|
+
* @returns {string} the tag name
|
|
275
|
+
*/
|
|
276
|
+
// eslint-disable-next-line class-methods-use-this
|
|
277
|
+
getScopedTagName(tagName) {
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
return this.constructor.getScopedTagName(tagName);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @deprecated use the native el.tagName instead
|
|
284
|
+
*
|
|
285
|
+
* @param {string} tagName
|
|
286
|
+
* @returns {string} the tag name
|
|
287
|
+
*/
|
|
288
|
+
// eslint-disable-next-line class-methods-use-this
|
|
289
|
+
static getScopedTagName(tagName) {
|
|
290
|
+
// @ts-ignore
|
|
291
|
+
return this.__registry.get(tagName) ? tagName : undefined;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const ScopedElementsMixin = dedupeMixin(ScopedElementsMixinImplementation);
|
|
296
|
+
|
|
68
297
|
/**
|
|
69
298
|
* @license
|
|
70
299
|
* Copyright 2019 Google LLC
|
|
@@ -1260,1949 +1489,1664 @@
|
|
|
1260
1489
|
* Copyright 2017 Google LLC
|
|
1261
1490
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
1262
1491
|
*/
|
|
1263
|
-
// Allows minifiers to rename references to globalThis
|
|
1264
|
-
const global = globalThis;
|
|
1265
|
-
/**
|
|
1266
|
-
* Useful for visualizing and logging insights into what the Lit template system is doing.
|
|
1267
|
-
*
|
|
1268
|
-
* Compiled out of prod mode builds.
|
|
1269
|
-
*/
|
|
1270
|
-
const debugLogEvent = (event) => {
|
|
1271
|
-
const shouldEmit = global
|
|
1272
|
-
.emitLitDebugLogEvents;
|
|
1273
|
-
if (!shouldEmit) {
|
|
1274
|
-
return;
|
|
1275
|
-
}
|
|
1276
|
-
global.dispatchEvent(new CustomEvent('lit-debug', {
|
|
1277
|
-
detail: event,
|
|
1278
|
-
}));
|
|
1279
|
-
}
|
|
1280
|
-
;
|
|
1281
|
-
// Used for connecting beginRender and endRender events when there are nested
|
|
1282
|
-
// renders when errors are thrown preventing an endRender event from being
|
|
1283
|
-
// called.
|
|
1284
|
-
let debugLogRenderId = 0;
|
|
1285
1492
|
let issueWarning$3;
|
|
1286
1493
|
{
|
|
1287
|
-
|
|
1494
|
+
// Ensure warnings are issued only 1x, even if multiple versions of Lit
|
|
1495
|
+
// are loaded.
|
|
1496
|
+
const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
|
|
1288
1497
|
// Issue a warning, if we haven't already.
|
|
1289
1498
|
issueWarning$3 = (code, warning) => {
|
|
1290
|
-
warning += code
|
|
1291
|
-
|
|
1292
|
-
: '';
|
|
1293
|
-
if (!global.litIssuedWarnings.has(warning)) {
|
|
1499
|
+
warning += ` See https://lit.dev/msg/${code} for more information.`;
|
|
1500
|
+
if (!issuedWarnings.has(warning)) {
|
|
1294
1501
|
console.warn(warning);
|
|
1295
|
-
|
|
1502
|
+
issuedWarnings.add(warning);
|
|
1296
1503
|
}
|
|
1297
1504
|
};
|
|
1298
|
-
issueWarning$3('dev-mode', `Lit is in dev mode. Not recommended for production!`);
|
|
1299
1505
|
}
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
?
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
:
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
const setSanitizer = (newSanitizer) => {
|
|
1322
|
-
if (sanitizerFactoryInternal !== noopSanitizer) {
|
|
1323
|
-
throw new Error(`Attempted to overwrite existing lit-html security policy.` +
|
|
1324
|
-
` setSanitizeDOMValueFactory should be called at most once.`);
|
|
1325
|
-
}
|
|
1326
|
-
sanitizerFactoryInternal = newSanitizer;
|
|
1506
|
+
const legacyProperty = (options, proto, name) => {
|
|
1507
|
+
const hasOwnProperty = proto.hasOwnProperty(name);
|
|
1508
|
+
proto.constructor.createProperty(name, hasOwnProperty ? { ...options, wrapped: true } : options);
|
|
1509
|
+
// For accessors (which have a descriptor on the prototype) we need to
|
|
1510
|
+
// return a descriptor, otherwise TypeScript overwrites the descriptor we
|
|
1511
|
+
// define in createProperty() with the original descriptor. We don't do this
|
|
1512
|
+
// for fields, which don't have a descriptor, because this could overwrite
|
|
1513
|
+
// descriptor defined by other decorators.
|
|
1514
|
+
return hasOwnProperty
|
|
1515
|
+
? Object.getOwnPropertyDescriptor(proto, name)
|
|
1516
|
+
: undefined;
|
|
1517
|
+
};
|
|
1518
|
+
// This is duplicated from a similar variable in reactive-element.ts, but
|
|
1519
|
+
// actually makes sense to have this default defined with the decorator, so
|
|
1520
|
+
// that different decorators could have different defaults.
|
|
1521
|
+
const defaultPropertyDeclaration = {
|
|
1522
|
+
attribute: true,
|
|
1523
|
+
type: String,
|
|
1524
|
+
converter: defaultConverter,
|
|
1525
|
+
reflect: false,
|
|
1526
|
+
hasChanged: notEqual,
|
|
1327
1527
|
};
|
|
1328
1528
|
/**
|
|
1329
|
-
*
|
|
1529
|
+
* Wraps a class accessor or setter so that `requestUpdate()` is called with the
|
|
1530
|
+
* property name and old value when the accessor is set.
|
|
1330
1531
|
*/
|
|
1331
|
-
const
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
const textEndRegex = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;
|
|
1375
|
-
const COMMENT_START = 1;
|
|
1376
|
-
const TAG_NAME = 2;
|
|
1377
|
-
const DYNAMIC_TAG_NAME = 3;
|
|
1378
|
-
const commentEndRegex = /-->/g;
|
|
1379
|
-
/**
|
|
1380
|
-
* Comments not started with <!--, like </{, can be ended by a single `>`
|
|
1381
|
-
*/
|
|
1382
|
-
const comment2EndRegex = />/g;
|
|
1532
|
+
const standardProperty = (options = defaultPropertyDeclaration, target, context) => {
|
|
1533
|
+
const { kind, metadata } = context;
|
|
1534
|
+
if (metadata == null) {
|
|
1535
|
+
issueWarning$3('missing-class-metadata', `The class ${target} is missing decorator metadata. This ` +
|
|
1536
|
+
`could mean that you're using a compiler that supports decorators ` +
|
|
1537
|
+
`but doesn't support decorator metadata, such as TypeScript 5.1. ` +
|
|
1538
|
+
`Please update your compiler.`);
|
|
1539
|
+
}
|
|
1540
|
+
// Store the property options
|
|
1541
|
+
let properties = globalThis.litPropertyMetadata.get(metadata);
|
|
1542
|
+
if (properties === undefined) {
|
|
1543
|
+
globalThis.litPropertyMetadata.set(metadata, (properties = new Map()));
|
|
1544
|
+
}
|
|
1545
|
+
properties.set(context.name, options);
|
|
1546
|
+
if (kind === 'accessor') {
|
|
1547
|
+
// Standard decorators cannot dynamically modify the class, so we can't
|
|
1548
|
+
// replace a field with accessors. The user must use the new `accessor`
|
|
1549
|
+
// keyword instead.
|
|
1550
|
+
const { name } = context;
|
|
1551
|
+
return {
|
|
1552
|
+
set(v) {
|
|
1553
|
+
const oldValue = target.get.call(this);
|
|
1554
|
+
target.set.call(this, v);
|
|
1555
|
+
this.requestUpdate(name, oldValue, options);
|
|
1556
|
+
},
|
|
1557
|
+
init(v) {
|
|
1558
|
+
if (v !== undefined) {
|
|
1559
|
+
this._$changeProperty(name, undefined, options);
|
|
1560
|
+
}
|
|
1561
|
+
return v;
|
|
1562
|
+
},
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
else if (kind === 'setter') {
|
|
1566
|
+
const { name } = context;
|
|
1567
|
+
return function (value) {
|
|
1568
|
+
const oldValue = this[name];
|
|
1569
|
+
target.call(this, value);
|
|
1570
|
+
this.requestUpdate(name, oldValue, options);
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
throw new Error(`Unsupported decorator location: ${kind}`);
|
|
1574
|
+
};
|
|
1383
1575
|
/**
|
|
1384
|
-
*
|
|
1385
|
-
*
|
|
1386
|
-
*
|
|
1576
|
+
* A class field or accessor decorator which creates a reactive property that
|
|
1577
|
+
* reflects a corresponding attribute value. When a decorated property is set
|
|
1578
|
+
* the element will update and render. A {@linkcode PropertyDeclaration} may
|
|
1579
|
+
* optionally be supplied to configure property features.
|
|
1387
1580
|
*
|
|
1388
|
-
*
|
|
1389
|
-
*
|
|
1581
|
+
* This decorator should only be used for public fields. As public fields,
|
|
1582
|
+
* properties should be considered as primarily settable by element users,
|
|
1583
|
+
* either via attribute or the property itself.
|
|
1390
1584
|
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1585
|
+
* Generally, properties that are changed by the element should be private or
|
|
1586
|
+
* protected fields and should use the {@linkcode state} decorator.
|
|
1393
1587
|
*
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1396
|
-
*
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1399
|
-
*
|
|
1400
|
-
*
|
|
1401
|
-
*
|
|
1402
|
-
*
|
|
1403
|
-
* * (') then any non-(')
|
|
1404
|
-
*/
|
|
1405
|
-
const tagEndRegex = new RegExp(`>|${SPACE_CHAR}(?:(${NAME_CHAR}+)(${SPACE_CHAR}*=${SPACE_CHAR}*(?:${ATTR_VALUE_CHAR}|("|')|))|$)`, 'g');
|
|
1406
|
-
const ENTIRE_MATCH = 0;
|
|
1407
|
-
const ATTRIBUTE_NAME = 1;
|
|
1408
|
-
const SPACES_AND_EQUALS = 2;
|
|
1409
|
-
const QUOTE_CHAR = 3;
|
|
1410
|
-
const singleQuoteAttrEndRegex = /'/g;
|
|
1411
|
-
const doubleQuoteAttrEndRegex = /"/g;
|
|
1412
|
-
/**
|
|
1413
|
-
* Matches the raw text elements.
|
|
1588
|
+
* However, sometimes element code does need to set a public property. This
|
|
1589
|
+
* should typically only be done in response to user interaction, and an event
|
|
1590
|
+
* should be fired informing the user; for example, a checkbox sets its
|
|
1591
|
+
* `checked` property when clicked and fires a `changed` event. Mutating public
|
|
1592
|
+
* properties should typically not be done for non-primitive (object or array)
|
|
1593
|
+
* properties. In other cases when an element needs to manage state, a private
|
|
1594
|
+
* property decorated via the {@linkcode state} decorator should be used. When
|
|
1595
|
+
* needed, state properties can be initialized via public properties to
|
|
1596
|
+
* facilitate complex interactions.
|
|
1414
1597
|
*
|
|
1415
|
-
*
|
|
1416
|
-
*
|
|
1598
|
+
* ```ts
|
|
1599
|
+
* class MyElement {
|
|
1600
|
+
* @property({ type: Boolean })
|
|
1601
|
+
* clicked = false;
|
|
1602
|
+
* }
|
|
1603
|
+
* ```
|
|
1604
|
+
* @category Decorator
|
|
1605
|
+
* @ExportDecoratedItems
|
|
1417
1606
|
*/
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
const EVENT_PART = 5;
|
|
1429
|
-
const ELEMENT_PART = 6;
|
|
1430
|
-
const COMMENT_PART = 7;
|
|
1607
|
+
function property(options) {
|
|
1608
|
+
return (protoOrTarget, nameOrContext
|
|
1609
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1610
|
+
) => {
|
|
1611
|
+
return (typeof nameOrContext === 'object'
|
|
1612
|
+
? standardProperty(options, protoOrTarget, nameOrContext)
|
|
1613
|
+
: legacyProperty(options, protoOrTarget, nameOrContext));
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1431
1617
|
/**
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
1618
|
+
* @license
|
|
1619
|
+
* Copyright 2017 Google LLC
|
|
1620
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
1434
1621
|
*/
|
|
1435
|
-
const tag = (type) => (strings, ...values) => {
|
|
1436
|
-
// Warn against templates octal escape sequences
|
|
1437
|
-
// We do this here rather than in render so that the warning is closer to the
|
|
1438
|
-
// template definition.
|
|
1439
|
-
if (strings.some((s) => s === undefined)) {
|
|
1440
|
-
console.warn('Some template strings are undefined.\n' +
|
|
1441
|
-
'This is probably caused by illegal octal escape sequences.');
|
|
1442
|
-
}
|
|
1443
|
-
{
|
|
1444
|
-
// Import static-html.js results in a circular dependency which g3 doesn't
|
|
1445
|
-
// handle. Instead we know that static values must have the field
|
|
1446
|
-
// `_$litStatic$`.
|
|
1447
|
-
if (values.some((val) => val?.['_$litStatic$'])) {
|
|
1448
|
-
issueWarning$3('', `Static values 'literal' or 'unsafeStatic' cannot be used as values to non-static templates.\n` +
|
|
1449
|
-
`Please use the static 'html' tag function. See https://lit.dev/docs/templates/expressions/#static-expressions`);
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
return {
|
|
1453
|
-
// This property needs to remain unminified.
|
|
1454
|
-
['_$litType$']: type,
|
|
1455
|
-
strings,
|
|
1456
|
-
values,
|
|
1457
|
-
};
|
|
1458
|
-
};
|
|
1459
1622
|
/**
|
|
1460
|
-
*
|
|
1461
|
-
*
|
|
1623
|
+
* Wraps up a few best practices when returning a property descriptor from a
|
|
1624
|
+
* decorator.
|
|
1462
1625
|
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1626
|
+
* Marks the defined property as configurable, and enumerable, and handles
|
|
1627
|
+
* the case where we have a busted Reflect.decorate zombiefill (e.g. in Angular
|
|
1628
|
+
* apps).
|
|
1466
1629
|
*
|
|
1467
|
-
*
|
|
1468
|
-
* lazy, meaning no work is done until the template is rendered. When rendering,
|
|
1469
|
-
* if a template comes from the same expression as a previously rendered result,
|
|
1470
|
-
* it's efficiently updated instead of replaced.
|
|
1630
|
+
* @internal
|
|
1471
1631
|
*/
|
|
1472
|
-
const
|
|
1632
|
+
const desc = (obj, name, descriptor) => {
|
|
1633
|
+
// For backwards compatibility, we keep them configurable and enumerable.
|
|
1634
|
+
descriptor.configurable = true;
|
|
1635
|
+
descriptor.enumerable = true;
|
|
1636
|
+
if (
|
|
1637
|
+
// We check for Reflect.decorate each time, in case the zombiefill
|
|
1638
|
+
// is applied via lazy loading some Angular code.
|
|
1639
|
+
Reflect.decorate &&
|
|
1640
|
+
typeof name !== 'object') {
|
|
1641
|
+
// If we're called as a legacy decorator, and Reflect.decorate is present
|
|
1642
|
+
// then we have no guarantees that the returned descriptor will be
|
|
1643
|
+
// defined on the class, so we must apply it directly ourselves.
|
|
1644
|
+
Object.defineProperty(obj, name, descriptor);
|
|
1645
|
+
}
|
|
1646
|
+
return descriptor;
|
|
1647
|
+
};
|
|
1648
|
+
|
|
1473
1649
|
/**
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1650
|
+
* @license
|
|
1651
|
+
* Copyright 2017 Google LLC
|
|
1652
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
1476
1653
|
*/
|
|
1477
|
-
|
|
1654
|
+
let issueWarning$2;
|
|
1655
|
+
{
|
|
1656
|
+
// Ensure warnings are issued only 1x, even if multiple versions of Lit
|
|
1657
|
+
// are loaded.
|
|
1658
|
+
const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
|
|
1659
|
+
// Issue a warning, if we haven't already.
|
|
1660
|
+
issueWarning$2 = (code, warning) => {
|
|
1661
|
+
warning += code
|
|
1662
|
+
? ` See https://lit.dev/msg/${code} for more information.`
|
|
1663
|
+
: '';
|
|
1664
|
+
if (!issuedWarnings.has(warning)) {
|
|
1665
|
+
console.warn(warning);
|
|
1666
|
+
issuedWarnings.add(warning);
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1478
1670
|
/**
|
|
1479
|
-
* A
|
|
1671
|
+
* A property decorator that converts a class property into a getter that
|
|
1672
|
+
* executes a querySelector on the element's renderRoot.
|
|
1480
1673
|
*
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1483
|
-
*
|
|
1484
|
-
* ? html`<button>DELETE</button>`
|
|
1485
|
-
* : nothing
|
|
1486
|
-
* }`;
|
|
1487
|
-
* ```
|
|
1674
|
+
* @param selector A DOMString containing one or more selectors to match.
|
|
1675
|
+
* @param cache An optional boolean which when true performs the DOM query only
|
|
1676
|
+
* once and caches the result.
|
|
1488
1677
|
*
|
|
1489
|
-
*
|
|
1490
|
-
* behavior between various expression binding contexts.
|
|
1678
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
|
|
1491
1679
|
*
|
|
1492
|
-
*
|
|
1493
|
-
*
|
|
1494
|
-
*
|
|
1495
|
-
*
|
|
1680
|
+
* ```ts
|
|
1681
|
+
* class MyElement {
|
|
1682
|
+
* @query('#first')
|
|
1683
|
+
* first: HTMLDivElement;
|
|
1684
|
+
*
|
|
1685
|
+
* render() {
|
|
1686
|
+
* return html`
|
|
1687
|
+
* <div id="first"></div>
|
|
1688
|
+
* <div id="second"></div>
|
|
1689
|
+
* `;
|
|
1690
|
+
* }
|
|
1691
|
+
* }
|
|
1692
|
+
* ```
|
|
1693
|
+
* @category Decorator
|
|
1496
1694
|
*/
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
{
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1695
|
+
function query(selector, cache) {
|
|
1696
|
+
return ((protoOrTarget, nameOrContext, descriptor) => {
|
|
1697
|
+
const doQuery = (el) => {
|
|
1698
|
+
const result = (el.renderRoot?.querySelector(selector) ?? null);
|
|
1699
|
+
if (result === null && cache && !el.hasUpdated) {
|
|
1700
|
+
const name = typeof nameOrContext === 'object'
|
|
1701
|
+
? nameOrContext.name
|
|
1702
|
+
: nameOrContext;
|
|
1703
|
+
issueWarning$2('', `@query'd field ${JSON.stringify(String(name))} with the 'cache' ` +
|
|
1704
|
+
`flag set for selector '${selector}' has been accessed before ` +
|
|
1705
|
+
`the first update and returned null. This is expected if the ` +
|
|
1706
|
+
`renderRoot tree has not been provided beforehand (e.g. via ` +
|
|
1707
|
+
`Declarative Shadow DOM). Therefore the value hasn't been cached.`);
|
|
1708
|
+
}
|
|
1709
|
+
// TODO: if we want to allow users to assert that the query will never
|
|
1710
|
+
// return null, we need a new option and to throw here if the result
|
|
1711
|
+
// is null.
|
|
1712
|
+
return result;
|
|
1713
|
+
};
|
|
1714
|
+
if (cache) {
|
|
1715
|
+
// Accessors to wrap from either:
|
|
1716
|
+
// 1. The decorator target, in the case of standard decorators
|
|
1717
|
+
// 2. The property descriptor, in the case of experimental decorators
|
|
1718
|
+
// on auto-accessors.
|
|
1719
|
+
// 3. Functions that access our own cache-key property on the instance,
|
|
1720
|
+
// in the case of experimental decorators on fields.
|
|
1721
|
+
const { get, set } = typeof nameOrContext === 'object'
|
|
1722
|
+
? protoOrTarget
|
|
1723
|
+
: descriptor ??
|
|
1724
|
+
(() => {
|
|
1725
|
+
const key = Symbol(`${String(nameOrContext)} (@query() cache)`)
|
|
1726
|
+
;
|
|
1727
|
+
return {
|
|
1728
|
+
get() {
|
|
1729
|
+
return this[key];
|
|
1730
|
+
},
|
|
1731
|
+
set(v) {
|
|
1732
|
+
this[key] = v;
|
|
1733
|
+
},
|
|
1734
|
+
};
|
|
1735
|
+
})();
|
|
1736
|
+
return desc(protoOrTarget, nameOrContext, {
|
|
1737
|
+
get() {
|
|
1738
|
+
let result = get.call(this);
|
|
1739
|
+
if (result === undefined) {
|
|
1740
|
+
result = doQuery(this);
|
|
1741
|
+
if (result !== null || this.hasUpdated) {
|
|
1742
|
+
set.call(this, result);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return result;
|
|
1746
|
+
},
|
|
1747
|
+
});
|
|
1530
1748
|
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1749
|
+
else {
|
|
1750
|
+
// This object works as the return type for both standard and
|
|
1751
|
+
// experimental decorators.
|
|
1752
|
+
return desc(protoOrTarget, nameOrContext, {
|
|
1753
|
+
get() {
|
|
1754
|
+
return doQuery(this);
|
|
1755
|
+
},
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
});
|
|
1536
1759
|
}
|
|
1760
|
+
|
|
1537
1761
|
/**
|
|
1538
|
-
*
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
1541
|
-
|
|
1762
|
+
* @license
|
|
1763
|
+
* Copyright 2017 Google LLC
|
|
1764
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
1765
|
+
*/
|
|
1766
|
+
// Allows minifiers to rename references to globalThis
|
|
1767
|
+
const global = globalThis;
|
|
1768
|
+
/**
|
|
1769
|
+
* Useful for visualizing and logging insights into what the Lit template system is doing.
|
|
1542
1770
|
*
|
|
1543
|
-
*
|
|
1544
|
-
* @param type HTML or SVG
|
|
1545
|
-
* @return Array containing `[html, attrNames]` (array returned for terseness,
|
|
1546
|
-
* to avoid object fields since this code is shared with non-minified SSR
|
|
1547
|
-
* code)
|
|
1771
|
+
* Compiled out of prod mode builds.
|
|
1548
1772
|
*/
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
// sentinel string and re-write the attribute name, or inside a tag where
|
|
1555
|
-
// we insert the sentinel string.
|
|
1556
|
-
const l = strings.length - 1;
|
|
1557
|
-
// Stores the case-sensitive bound attribute names in the order of their
|
|
1558
|
-
// parts. ElementParts are also reflected in this array as undefined
|
|
1559
|
-
// rather than a string, to disambiguate from attribute bindings.
|
|
1560
|
-
const attrNames = [];
|
|
1561
|
-
let html = type === SVG_RESULT ? '<svg>' : '';
|
|
1562
|
-
// When we're inside a raw text tag (not it's text content), the regex
|
|
1563
|
-
// will still be tagRegex so we can find attributes, but will switch to
|
|
1564
|
-
// this regex when the tag ends.
|
|
1565
|
-
let rawTextEndRegex;
|
|
1566
|
-
// The current parsing state, represented as a reference to one of the
|
|
1567
|
-
// regexes
|
|
1568
|
-
let regex = textEndRegex;
|
|
1569
|
-
for (let i = 0; i < l; i++) {
|
|
1570
|
-
const s = strings[i];
|
|
1571
|
-
// The index of the end of the last attribute name. When this is
|
|
1572
|
-
// positive at end of a string, it means we're in an attribute value
|
|
1573
|
-
// position and need to rewrite the attribute name.
|
|
1574
|
-
// We also use a special value of -2 to indicate that we encountered
|
|
1575
|
-
// the end of a string in attribute name position.
|
|
1576
|
-
let attrNameEndIndex = -1;
|
|
1577
|
-
let attrName;
|
|
1578
|
-
let lastIndex = 0;
|
|
1579
|
-
let match;
|
|
1580
|
-
// The conditions in this loop handle the current parse state, and the
|
|
1581
|
-
// assignments to the `regex` variable are the state transitions.
|
|
1582
|
-
while (lastIndex < s.length) {
|
|
1583
|
-
// Make sure we start searching from where we previously left off
|
|
1584
|
-
regex.lastIndex = lastIndex;
|
|
1585
|
-
match = regex.exec(s);
|
|
1586
|
-
if (match === null) {
|
|
1587
|
-
break;
|
|
1588
|
-
}
|
|
1589
|
-
lastIndex = regex.lastIndex;
|
|
1590
|
-
if (regex === textEndRegex) {
|
|
1591
|
-
if (match[COMMENT_START] === '!--') {
|
|
1592
|
-
regex = commentEndRegex;
|
|
1593
|
-
}
|
|
1594
|
-
else if (match[COMMENT_START] !== undefined) {
|
|
1595
|
-
// We started a weird comment, like </{
|
|
1596
|
-
regex = comment2EndRegex;
|
|
1597
|
-
}
|
|
1598
|
-
else if (match[TAG_NAME] !== undefined) {
|
|
1599
|
-
if (rawTextElement.test(match[TAG_NAME])) {
|
|
1600
|
-
// Record if we encounter a raw-text element. We'll switch to
|
|
1601
|
-
// this regex at the end of the tag.
|
|
1602
|
-
rawTextEndRegex = new RegExp(`</${match[TAG_NAME]}`, 'g');
|
|
1603
|
-
}
|
|
1604
|
-
regex = tagEndRegex;
|
|
1605
|
-
}
|
|
1606
|
-
else if (match[DYNAMIC_TAG_NAME] !== undefined) {
|
|
1607
|
-
{
|
|
1608
|
-
throw new Error('Bindings in tag names are not supported. Please use static templates instead. ' +
|
|
1609
|
-
'See https://lit.dev/docs/templates/expressions/#static-expressions');
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
else if (regex === tagEndRegex) {
|
|
1614
|
-
if (match[ENTIRE_MATCH] === '>') {
|
|
1615
|
-
// End of a tag. If we had started a raw-text element, use that
|
|
1616
|
-
// regex
|
|
1617
|
-
regex = rawTextEndRegex ?? textEndRegex;
|
|
1618
|
-
// We may be ending an unquoted attribute value, so make sure we
|
|
1619
|
-
// clear any pending attrNameEndIndex
|
|
1620
|
-
attrNameEndIndex = -1;
|
|
1621
|
-
}
|
|
1622
|
-
else if (match[ATTRIBUTE_NAME] === undefined) {
|
|
1623
|
-
// Attribute name position
|
|
1624
|
-
attrNameEndIndex = -2;
|
|
1625
|
-
}
|
|
1626
|
-
else {
|
|
1627
|
-
attrNameEndIndex = regex.lastIndex - match[SPACES_AND_EQUALS].length;
|
|
1628
|
-
attrName = match[ATTRIBUTE_NAME];
|
|
1629
|
-
regex =
|
|
1630
|
-
match[QUOTE_CHAR] === undefined
|
|
1631
|
-
? tagEndRegex
|
|
1632
|
-
: match[QUOTE_CHAR] === '"'
|
|
1633
|
-
? doubleQuoteAttrEndRegex
|
|
1634
|
-
: singleQuoteAttrEndRegex;
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
else if (regex === doubleQuoteAttrEndRegex ||
|
|
1638
|
-
regex === singleQuoteAttrEndRegex) {
|
|
1639
|
-
regex = tagEndRegex;
|
|
1640
|
-
}
|
|
1641
|
-
else if (regex === commentEndRegex || regex === comment2EndRegex) {
|
|
1642
|
-
regex = textEndRegex;
|
|
1643
|
-
}
|
|
1644
|
-
else {
|
|
1645
|
-
// Not one of the five state regexes, so it must be the dynamically
|
|
1646
|
-
// created raw text regex and we're at the close of that element.
|
|
1647
|
-
regex = tagEndRegex;
|
|
1648
|
-
rawTextEndRegex = undefined;
|
|
1649
|
-
}
|
|
1773
|
+
const debugLogEvent = (event) => {
|
|
1774
|
+
const shouldEmit = global
|
|
1775
|
+
.emitLitDebugLogEvents;
|
|
1776
|
+
if (!shouldEmit) {
|
|
1777
|
+
return;
|
|
1650
1778
|
}
|
|
1651
|
-
{
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1779
|
+
global.dispatchEvent(new CustomEvent('lit-debug', {
|
|
1780
|
+
detail: event,
|
|
1781
|
+
}));
|
|
1782
|
+
}
|
|
1783
|
+
;
|
|
1784
|
+
// Used for connecting beginRender and endRender events when there are nested
|
|
1785
|
+
// renders when errors are thrown preventing an endRender event from being
|
|
1786
|
+
// called.
|
|
1787
|
+
let debugLogRenderId = 0;
|
|
1788
|
+
let issueWarning$1;
|
|
1789
|
+
{
|
|
1790
|
+
global.litIssuedWarnings ??= new Set();
|
|
1791
|
+
// Issue a warning, if we haven't already.
|
|
1792
|
+
issueWarning$1 = (code, warning) => {
|
|
1793
|
+
warning += code
|
|
1794
|
+
? ` See https://lit.dev/msg/${code} for more information.`
|
|
1795
|
+
: '';
|
|
1796
|
+
if (!global.litIssuedWarnings.has(warning)) {
|
|
1797
|
+
console.warn(warning);
|
|
1798
|
+
global.litIssuedWarnings.add(warning);
|
|
1659
1799
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
// (regex === textEndRegex): insert a comment marker.
|
|
1663
|
-
// 2. We have a non-negative attrNameEndIndex which means we need to
|
|
1664
|
-
// rewrite the attribute name to add a bound attribute suffix.
|
|
1665
|
-
// 3. We're at the non-first binding in a multi-binding attribute, use a
|
|
1666
|
-
// plain marker.
|
|
1667
|
-
// 4. We're somewhere else inside the tag. If we're in attribute name
|
|
1668
|
-
// position (attrNameEndIndex === -2), add a sequential suffix to
|
|
1669
|
-
// generate a unique attribute name.
|
|
1670
|
-
// Detect a binding next to self-closing tag end and insert a space to
|
|
1671
|
-
// separate the marker from the tag end:
|
|
1672
|
-
const end = regex === tagEndRegex && strings[i + 1].startsWith('/>') ? ' ' : '';
|
|
1673
|
-
html +=
|
|
1674
|
-
regex === textEndRegex
|
|
1675
|
-
? s + nodeMarker
|
|
1676
|
-
: attrNameEndIndex >= 0
|
|
1677
|
-
? (attrNames.push(attrName),
|
|
1678
|
-
s.slice(0, attrNameEndIndex) +
|
|
1679
|
-
boundAttributeSuffix +
|
|
1680
|
-
s.slice(attrNameEndIndex)) +
|
|
1681
|
-
marker +
|
|
1682
|
-
end
|
|
1683
|
-
: s + marker + (attrNameEndIndex === -2 ? i : end);
|
|
1684
|
-
}
|
|
1685
|
-
const htmlResult = html + (strings[l] || '<?>') + (type === SVG_RESULT ? '</svg>' : '');
|
|
1686
|
-
// Returned as an array for terseness
|
|
1687
|
-
return [trustFromTemplateString(strings, htmlResult), attrNames];
|
|
1688
|
-
};
|
|
1689
|
-
class Template {
|
|
1690
|
-
constructor(
|
|
1691
|
-
// This property needs to remain unminified.
|
|
1692
|
-
{ strings, ['_$litType$']: type }, options) {
|
|
1693
|
-
this.parts = [];
|
|
1694
|
-
let node;
|
|
1695
|
-
let nodeIndex = 0;
|
|
1696
|
-
let attrNameIndex = 0;
|
|
1697
|
-
const partCount = strings.length - 1;
|
|
1698
|
-
const parts = this.parts;
|
|
1699
|
-
// Create template element
|
|
1700
|
-
const [html, attrNames] = getTemplateHtml(strings, type);
|
|
1701
|
-
this.el = Template.createElement(html, options);
|
|
1702
|
-
walker.currentNode = this.el.content;
|
|
1703
|
-
// Re-parent SVG nodes into template root
|
|
1704
|
-
if (type === SVG_RESULT) {
|
|
1705
|
-
const svgElement = this.el.content.firstChild;
|
|
1706
|
-
svgElement.replaceWith(...svgElement.childNodes);
|
|
1707
|
-
}
|
|
1708
|
-
// Walk the template to find binding markers and create TemplateParts
|
|
1709
|
-
while ((node = walker.nextNode()) !== null && parts.length < partCount) {
|
|
1710
|
-
if (node.nodeType === 1) {
|
|
1711
|
-
{
|
|
1712
|
-
const tag = node.localName;
|
|
1713
|
-
// Warn if `textarea` includes an expression and throw if `template`
|
|
1714
|
-
// does since these are not supported. We do this by checking
|
|
1715
|
-
// innerHTML for anything that looks like a marker. This catches
|
|
1716
|
-
// cases like bindings in textarea there markers turn into text nodes.
|
|
1717
|
-
if (/^(?:textarea|template)$/i.test(tag) &&
|
|
1718
|
-
node.innerHTML.includes(marker)) {
|
|
1719
|
-
const m = `Expressions are not supported inside \`${tag}\` ` +
|
|
1720
|
-
`elements. See https://lit.dev/msg/expression-in-${tag} for more ` +
|
|
1721
|
-
`information.`;
|
|
1722
|
-
if (tag === 'template') {
|
|
1723
|
-
throw new Error(m);
|
|
1724
|
-
}
|
|
1725
|
-
else
|
|
1726
|
-
issueWarning$3('', m);
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
// TODO (justinfagnani): for attempted dynamic tag names, we don't
|
|
1730
|
-
// increment the bindingIndex, and it'll be off by 1 in the element
|
|
1731
|
-
// and off by two after it.
|
|
1732
|
-
if (node.hasAttributes()) {
|
|
1733
|
-
for (const name of node.getAttributeNames()) {
|
|
1734
|
-
if (name.endsWith(boundAttributeSuffix)) {
|
|
1735
|
-
const realName = attrNames[attrNameIndex++];
|
|
1736
|
-
const value = node.getAttribute(name);
|
|
1737
|
-
const statics = value.split(marker);
|
|
1738
|
-
const m = /([.?@])?(.*)/.exec(realName);
|
|
1739
|
-
parts.push({
|
|
1740
|
-
type: ATTRIBUTE_PART,
|
|
1741
|
-
index: nodeIndex,
|
|
1742
|
-
name: m[2],
|
|
1743
|
-
strings: statics,
|
|
1744
|
-
ctor: m[1] === '.'
|
|
1745
|
-
? PropertyPart
|
|
1746
|
-
: m[1] === '?'
|
|
1747
|
-
? BooleanAttributePart
|
|
1748
|
-
: m[1] === '@'
|
|
1749
|
-
? EventPart
|
|
1750
|
-
: AttributePart,
|
|
1751
|
-
});
|
|
1752
|
-
node.removeAttribute(name);
|
|
1753
|
-
}
|
|
1754
|
-
else if (name.startsWith(marker)) {
|
|
1755
|
-
parts.push({
|
|
1756
|
-
type: ELEMENT_PART,
|
|
1757
|
-
index: nodeIndex,
|
|
1758
|
-
});
|
|
1759
|
-
node.removeAttribute(name);
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
// TODO (justinfagnani): benchmark the regex against testing for each
|
|
1764
|
-
// of the 3 raw text element names.
|
|
1765
|
-
if (rawTextElement.test(node.tagName)) {
|
|
1766
|
-
// For raw text elements we need to split the text content on
|
|
1767
|
-
// markers, create a Text node for each segment, and create
|
|
1768
|
-
// a TemplatePart for each marker.
|
|
1769
|
-
const strings = node.textContent.split(marker);
|
|
1770
|
-
const lastIndex = strings.length - 1;
|
|
1771
|
-
if (lastIndex > 0) {
|
|
1772
|
-
node.textContent = trustedTypes
|
|
1773
|
-
? trustedTypes.emptyScript
|
|
1774
|
-
: '';
|
|
1775
|
-
// Generate a new text node for each literal section
|
|
1776
|
-
// These nodes are also used as the markers for node parts
|
|
1777
|
-
// We can't use empty text nodes as markers because they're
|
|
1778
|
-
// normalized when cloning in IE (could simplify when
|
|
1779
|
-
// IE is no longer supported)
|
|
1780
|
-
for (let i = 0; i < lastIndex; i++) {
|
|
1781
|
-
node.append(strings[i], createMarker());
|
|
1782
|
-
// Walk past the marker node we just added
|
|
1783
|
-
walker.nextNode();
|
|
1784
|
-
parts.push({ type: CHILD_PART, index: ++nodeIndex });
|
|
1785
|
-
}
|
|
1786
|
-
// Note because this marker is added after the walker's current
|
|
1787
|
-
// node, it will be walked to in the outer loop (and ignored), so
|
|
1788
|
-
// we don't need to adjust nodeIndex here
|
|
1789
|
-
node.append(strings[lastIndex], createMarker());
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
else if (node.nodeType === 8) {
|
|
1794
|
-
const data = node.data;
|
|
1795
|
-
if (data === markerMatch) {
|
|
1796
|
-
parts.push({ type: CHILD_PART, index: nodeIndex });
|
|
1797
|
-
}
|
|
1798
|
-
else {
|
|
1799
|
-
let i = -1;
|
|
1800
|
-
while ((i = node.data.indexOf(marker, i + 1)) !== -1) {
|
|
1801
|
-
// Comment node has a binding marker inside, make an inactive part
|
|
1802
|
-
// The binding won't work, but subsequent bindings will
|
|
1803
|
-
parts.push({ type: COMMENT_PART, index: nodeIndex });
|
|
1804
|
-
// Move to the end of the match
|
|
1805
|
-
i += marker.length - 1;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
nodeIndex++;
|
|
1810
|
-
}
|
|
1811
|
-
{
|
|
1812
|
-
// If there was a duplicate attribute on a tag, then when the tag is
|
|
1813
|
-
// parsed into an element the attribute gets de-duplicated. We can detect
|
|
1814
|
-
// this mismatch if we haven't precisely consumed every attribute name
|
|
1815
|
-
// when preparing the template. This works because `attrNames` is built
|
|
1816
|
-
// from the template string and `attrNameIndex` comes from processing the
|
|
1817
|
-
// resulting DOM.
|
|
1818
|
-
if (attrNames.length !== attrNameIndex) {
|
|
1819
|
-
throw new Error(`Detected duplicate attribute bindings. This occurs if your template ` +
|
|
1820
|
-
`has duplicate attributes on an element tag. For example ` +
|
|
1821
|
-
`"<input ?disabled=\${true} ?disabled=\${false}>" contains a ` +
|
|
1822
|
-
`duplicate "disabled" attribute. The error was detected in ` +
|
|
1823
|
-
`the following template: \n` +
|
|
1824
|
-
'`' +
|
|
1825
|
-
strings.join('${...}') +
|
|
1826
|
-
'`');
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
// We could set walker.currentNode to another node here to prevent a memory
|
|
1830
|
-
// leak, but every time we prepare a template, we immediately render it
|
|
1831
|
-
// and re-use the walker in new TemplateInstance._clone().
|
|
1832
|
-
debugLogEvent &&
|
|
1833
|
-
debugLogEvent({
|
|
1834
|
-
kind: 'template prep',
|
|
1835
|
-
template: this,
|
|
1836
|
-
clonableTemplate: this.el,
|
|
1837
|
-
parts: this.parts,
|
|
1838
|
-
strings,
|
|
1839
|
-
});
|
|
1840
|
-
}
|
|
1841
|
-
// Overridden via `litHtmlPolyfillSupport` to provide platform support.
|
|
1842
|
-
/** @nocollapse */
|
|
1843
|
-
static createElement(html, _options) {
|
|
1844
|
-
const el = d.createElement('template');
|
|
1845
|
-
el.innerHTML = html;
|
|
1846
|
-
return el;
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
function resolveDirective(part, value, parent = part, attributeIndex) {
|
|
1850
|
-
// Bail early if the value is explicitly noChange. Note, this means any
|
|
1851
|
-
// nested directive is still attached and is not run.
|
|
1852
|
-
if (value === noChange) {
|
|
1853
|
-
return value;
|
|
1854
|
-
}
|
|
1855
|
-
let currentDirective = attributeIndex !== undefined
|
|
1856
|
-
? parent.__directives?.[attributeIndex]
|
|
1857
|
-
: parent.__directive;
|
|
1858
|
-
const nextDirectiveConstructor = isPrimitive(value)
|
|
1859
|
-
? undefined
|
|
1860
|
-
: // This property needs to remain unminified.
|
|
1861
|
-
value['_$litDirective$'];
|
|
1862
|
-
if (currentDirective?.constructor !== nextDirectiveConstructor) {
|
|
1863
|
-
// This property needs to remain unminified.
|
|
1864
|
-
currentDirective?.['_$notifyDirectiveConnectionChanged']?.(false);
|
|
1865
|
-
if (nextDirectiveConstructor === undefined) {
|
|
1866
|
-
currentDirective = undefined;
|
|
1867
|
-
}
|
|
1868
|
-
else {
|
|
1869
|
-
currentDirective = new nextDirectiveConstructor(part);
|
|
1870
|
-
currentDirective._$initialize(part, parent, attributeIndex);
|
|
1871
|
-
}
|
|
1872
|
-
if (attributeIndex !== undefined) {
|
|
1873
|
-
(parent.__directives ??= [])[attributeIndex] =
|
|
1874
|
-
currentDirective;
|
|
1875
|
-
}
|
|
1876
|
-
else {
|
|
1877
|
-
parent.__directive = currentDirective;
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
if (currentDirective !== undefined) {
|
|
1881
|
-
value = resolveDirective(part, currentDirective._$resolve(part, value.values), currentDirective, attributeIndex);
|
|
1882
|
-
}
|
|
1883
|
-
return value;
|
|
1800
|
+
};
|
|
1801
|
+
issueWarning$1('dev-mode', `Lit is in dev mode. Not recommended for production!`);
|
|
1884
1802
|
}
|
|
1803
|
+
const wrap = global.ShadyDOM?.inUse &&
|
|
1804
|
+
global.ShadyDOM?.noPatch === true
|
|
1805
|
+
? global.ShadyDOM.wrap
|
|
1806
|
+
: (node) => node;
|
|
1807
|
+
const trustedTypes = global.trustedTypes;
|
|
1885
1808
|
/**
|
|
1886
|
-
*
|
|
1887
|
-
*
|
|
1809
|
+
* Our TrustedTypePolicy for HTML which is declared using the html template
|
|
1810
|
+
* tag function.
|
|
1811
|
+
*
|
|
1812
|
+
* That HTML is a developer-authored constant, and is parsed with innerHTML
|
|
1813
|
+
* before any untrusted expressions have been mixed in. Therefor it is
|
|
1814
|
+
* considered safe by construction.
|
|
1888
1815
|
*/
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1816
|
+
const policy = trustedTypes
|
|
1817
|
+
? trustedTypes.createPolicy('lit-html', {
|
|
1818
|
+
createHTML: (s) => s,
|
|
1819
|
+
})
|
|
1820
|
+
: undefined;
|
|
1821
|
+
const identityFunction = (value) => value;
|
|
1822
|
+
const noopSanitizer = (_node, _name, _type) => identityFunction;
|
|
1823
|
+
/** Sets the global sanitizer factory. */
|
|
1824
|
+
const setSanitizer = (newSanitizer) => {
|
|
1825
|
+
if (sanitizerFactoryInternal !== noopSanitizer) {
|
|
1826
|
+
throw new Error(`Attempted to overwrite existing lit-html security policy.` +
|
|
1827
|
+
` setSanitizeDOMValueFactory should be called at most once.`);
|
|
1900
1828
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
return parentNode;
|
|
2026
|
-
}
|
|
2027
|
-
/**
|
|
2028
|
-
* The part's leading marker node, if any. See `.parentNode` for more
|
|
2029
|
-
* information.
|
|
2030
|
-
*/
|
|
2031
|
-
get startNode() {
|
|
2032
|
-
return this._$startNode;
|
|
2033
|
-
}
|
|
2034
|
-
/**
|
|
2035
|
-
* The part's trailing marker node, if any. See `.parentNode` for more
|
|
2036
|
-
* information.
|
|
2037
|
-
*/
|
|
2038
|
-
get endNode() {
|
|
2039
|
-
return this._$endNode;
|
|
2040
|
-
}
|
|
2041
|
-
_$setValue(value, directiveParent = this) {
|
|
2042
|
-
if (this.parentNode === null) {
|
|
2043
|
-
throw new Error(`This \`ChildPart\` has no \`parentNode\` and therefore cannot accept a value. This likely means the element containing the part was manipulated in an unsupported way outside of Lit's control such that the part's marker nodes were ejected from DOM. For example, setting the element's \`innerHTML\` or \`textContent\` can do this.`);
|
|
2044
|
-
}
|
|
2045
|
-
value = resolveDirective(this, value, directiveParent);
|
|
2046
|
-
if (isPrimitive(value)) {
|
|
2047
|
-
// Non-rendering child values. It's important that these do not render
|
|
2048
|
-
// empty text nodes to avoid issues with preventing default <slot>
|
|
2049
|
-
// fallback content.
|
|
2050
|
-
if (value === nothing || value == null || value === '') {
|
|
2051
|
-
if (this._$committedValue !== nothing) {
|
|
2052
|
-
debugLogEvent &&
|
|
2053
|
-
debugLogEvent({
|
|
2054
|
-
kind: 'commit nothing to child',
|
|
2055
|
-
start: this._$startNode,
|
|
2056
|
-
end: this._$endNode,
|
|
2057
|
-
parent: this._$parent,
|
|
2058
|
-
options: this.options,
|
|
2059
|
-
});
|
|
2060
|
-
this._$clear();
|
|
2061
|
-
}
|
|
2062
|
-
this._$committedValue = nothing;
|
|
2063
|
-
}
|
|
2064
|
-
else if (value !== this._$committedValue && value !== noChange) {
|
|
2065
|
-
this._commitText(value);
|
|
2066
|
-
}
|
|
2067
|
-
// This property needs to remain unminified.
|
|
2068
|
-
}
|
|
2069
|
-
else if (value['_$litType$'] !== undefined) {
|
|
2070
|
-
this._commitTemplateResult(value);
|
|
2071
|
-
}
|
|
2072
|
-
else if (value.nodeType !== undefined) {
|
|
2073
|
-
if (this.options?.host === value) {
|
|
2074
|
-
this._commitText(`[probable mistake: rendered a template's host in itself ` +
|
|
2075
|
-
`(commonly caused by writing \${this} in a template]`);
|
|
2076
|
-
console.warn(`Attempted to render the template host`, value, `inside itself. This is almost always a mistake, and in dev mode `, `we render some warning text. In production however, we'll `, `render it, which will usually result in an error, and sometimes `, `in the element disappearing from the DOM.`);
|
|
2077
|
-
return;
|
|
2078
|
-
}
|
|
2079
|
-
this._commitNode(value);
|
|
2080
|
-
}
|
|
2081
|
-
else if (isIterable(value)) {
|
|
2082
|
-
this._commitIterable(value);
|
|
2083
|
-
}
|
|
2084
|
-
else {
|
|
2085
|
-
// Fallback, will render the string representation
|
|
2086
|
-
this._commitText(value);
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
_insert(node) {
|
|
2090
|
-
return wrap(wrap(this._$startNode).parentNode).insertBefore(node, this._$endNode);
|
|
2091
|
-
}
|
|
2092
|
-
_commitNode(value) {
|
|
2093
|
-
if (this._$committedValue !== value) {
|
|
2094
|
-
this._$clear();
|
|
2095
|
-
if (sanitizerFactoryInternal !== noopSanitizer) {
|
|
2096
|
-
const parentNodeName = this._$startNode.parentNode?.nodeName;
|
|
2097
|
-
if (parentNodeName === 'STYLE' || parentNodeName === 'SCRIPT') {
|
|
2098
|
-
let message = 'Forbidden';
|
|
2099
|
-
{
|
|
2100
|
-
if (parentNodeName === 'STYLE') {
|
|
2101
|
-
message =
|
|
2102
|
-
`Lit does not support binding inside style nodes. ` +
|
|
2103
|
-
`This is a security risk, as style injection attacks can ` +
|
|
2104
|
-
`exfiltrate data and spoof UIs. ` +
|
|
2105
|
-
`Consider instead using css\`...\` literals ` +
|
|
2106
|
-
`to compose styles, and make do dynamic styling with ` +
|
|
2107
|
-
`css custom properties, ::parts, <slot>s, ` +
|
|
2108
|
-
`and by mutating the DOM rather than stylesheets.`;
|
|
2109
|
-
}
|
|
2110
|
-
else {
|
|
2111
|
-
message =
|
|
2112
|
-
`Lit does not support binding inside script nodes. ` +
|
|
2113
|
-
`This is a security risk, as it could allow arbitrary ` +
|
|
2114
|
-
`code execution.`;
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
throw new Error(message);
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
debugLogEvent &&
|
|
2121
|
-
debugLogEvent({
|
|
2122
|
-
kind: 'commit node',
|
|
2123
|
-
start: this._$startNode,
|
|
2124
|
-
parent: this._$parent,
|
|
2125
|
-
value: value,
|
|
2126
|
-
options: this.options,
|
|
2127
|
-
});
|
|
2128
|
-
this._$committedValue = this._insert(value);
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
_commitText(value) {
|
|
2132
|
-
// If the committed value is a primitive it means we called _commitText on
|
|
2133
|
-
// the previous render, and we know that this._$startNode.nextSibling is a
|
|
2134
|
-
// Text node. We can now just replace the text content (.data) of the node.
|
|
2135
|
-
if (this._$committedValue !== nothing &&
|
|
2136
|
-
isPrimitive(this._$committedValue)) {
|
|
2137
|
-
const node = wrap(this._$startNode).nextSibling;
|
|
2138
|
-
{
|
|
2139
|
-
if (this._textSanitizer === undefined) {
|
|
2140
|
-
this._textSanitizer = createSanitizer(node, 'data', 'property');
|
|
2141
|
-
}
|
|
2142
|
-
value = this._textSanitizer(value);
|
|
2143
|
-
}
|
|
2144
|
-
debugLogEvent &&
|
|
2145
|
-
debugLogEvent({
|
|
2146
|
-
kind: 'commit text',
|
|
2147
|
-
node,
|
|
2148
|
-
value,
|
|
2149
|
-
options: this.options,
|
|
2150
|
-
});
|
|
2151
|
-
node.data = value;
|
|
2152
|
-
}
|
|
2153
|
-
else {
|
|
2154
|
-
{
|
|
2155
|
-
const textNode = d.createTextNode('');
|
|
2156
|
-
this._commitNode(textNode);
|
|
2157
|
-
// When setting text content, for security purposes it matters a lot
|
|
2158
|
-
// what the parent is. For example, <style> and <script> need to be
|
|
2159
|
-
// handled with care, while <span> does not. So first we need to put a
|
|
2160
|
-
// text node into the document, then we can sanitize its content.
|
|
2161
|
-
if (this._textSanitizer === undefined) {
|
|
2162
|
-
this._textSanitizer = createSanitizer(textNode, 'data', 'property');
|
|
2163
|
-
}
|
|
2164
|
-
value = this._textSanitizer(value);
|
|
2165
|
-
debugLogEvent &&
|
|
2166
|
-
debugLogEvent({
|
|
2167
|
-
kind: 'commit text',
|
|
2168
|
-
node: textNode,
|
|
2169
|
-
value,
|
|
2170
|
-
options: this.options,
|
|
2171
|
-
});
|
|
2172
|
-
textNode.data = value;
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
this._$committedValue = value;
|
|
2176
|
-
}
|
|
2177
|
-
_commitTemplateResult(result) {
|
|
2178
|
-
// This property needs to remain unminified.
|
|
2179
|
-
const { values, ['_$litType$']: type } = result;
|
|
2180
|
-
// If $litType$ is a number, result is a plain TemplateResult and we get
|
|
2181
|
-
// the template from the template cache. If not, result is a
|
|
2182
|
-
// CompiledTemplateResult and _$litType$ is a CompiledTemplate and we need
|
|
2183
|
-
// to create the <template> element the first time we see it.
|
|
2184
|
-
const template = typeof type === 'number'
|
|
2185
|
-
? this._$getTemplate(result)
|
|
2186
|
-
: (type.el === undefined &&
|
|
2187
|
-
(type.el = Template.createElement(trustFromTemplateString(type.h, type.h[0]), this.options)),
|
|
2188
|
-
type);
|
|
2189
|
-
if (this._$committedValue?._$template === template) {
|
|
2190
|
-
debugLogEvent &&
|
|
2191
|
-
debugLogEvent({
|
|
2192
|
-
kind: 'template updating',
|
|
2193
|
-
template,
|
|
2194
|
-
instance: this._$committedValue,
|
|
2195
|
-
parts: this._$committedValue._$parts,
|
|
2196
|
-
options: this.options,
|
|
2197
|
-
values,
|
|
2198
|
-
});
|
|
2199
|
-
this._$committedValue._update(values);
|
|
2200
|
-
}
|
|
2201
|
-
else {
|
|
2202
|
-
const instance = new TemplateInstance(template, this);
|
|
2203
|
-
const fragment = instance._clone(this.options);
|
|
2204
|
-
debugLogEvent &&
|
|
2205
|
-
debugLogEvent({
|
|
2206
|
-
kind: 'template instantiated',
|
|
2207
|
-
template,
|
|
2208
|
-
instance,
|
|
2209
|
-
parts: instance._$parts,
|
|
2210
|
-
options: this.options,
|
|
2211
|
-
fragment,
|
|
2212
|
-
values,
|
|
2213
|
-
});
|
|
2214
|
-
instance._update(values);
|
|
2215
|
-
debugLogEvent &&
|
|
2216
|
-
debugLogEvent({
|
|
2217
|
-
kind: 'template instantiated and updated',
|
|
2218
|
-
template,
|
|
2219
|
-
instance,
|
|
2220
|
-
parts: instance._$parts,
|
|
2221
|
-
options: this.options,
|
|
2222
|
-
fragment,
|
|
2223
|
-
values,
|
|
2224
|
-
});
|
|
2225
|
-
this._commitNode(fragment);
|
|
2226
|
-
this._$committedValue = instance;
|
|
2227
|
-
}
|
|
2228
|
-
}
|
|
2229
|
-
// Overridden via `litHtmlPolyfillSupport` to provide platform support.
|
|
2230
|
-
/** @internal */
|
|
2231
|
-
_$getTemplate(result) {
|
|
2232
|
-
let template = templateCache.get(result.strings);
|
|
2233
|
-
if (template === undefined) {
|
|
2234
|
-
templateCache.set(result.strings, (template = new Template(result)));
|
|
2235
|
-
}
|
|
2236
|
-
return template;
|
|
2237
|
-
}
|
|
2238
|
-
_commitIterable(value) {
|
|
2239
|
-
// For an Iterable, we create a new InstancePart per item, then set its
|
|
2240
|
-
// value to the item. This is a little bit of overhead for every item in
|
|
2241
|
-
// an Iterable, but it lets us recurse easily and efficiently update Arrays
|
|
2242
|
-
// of TemplateResults that will be commonly returned from expressions like:
|
|
2243
|
-
// array.map((i) => html`${i}`), by reusing existing TemplateInstances.
|
|
2244
|
-
// If value is an array, then the previous render was of an
|
|
2245
|
-
// iterable and value will contain the ChildParts from the previous
|
|
2246
|
-
// render. If value is not an array, clear this part and make a new
|
|
2247
|
-
// array for ChildParts.
|
|
2248
|
-
if (!isArray(this._$committedValue)) {
|
|
2249
|
-
this._$committedValue = [];
|
|
2250
|
-
this._$clear();
|
|
2251
|
-
}
|
|
2252
|
-
// Lets us keep track of how many items we stamped so we can clear leftover
|
|
2253
|
-
// items from a previous render
|
|
2254
|
-
const itemParts = this._$committedValue;
|
|
2255
|
-
let partIndex = 0;
|
|
2256
|
-
let itemPart;
|
|
2257
|
-
for (const item of value) {
|
|
2258
|
-
if (partIndex === itemParts.length) {
|
|
2259
|
-
// If no existing part, create a new one
|
|
2260
|
-
// TODO (justinfagnani): test perf impact of always creating two parts
|
|
2261
|
-
// instead of sharing parts between nodes
|
|
2262
|
-
// https://github.com/lit/lit/issues/1266
|
|
2263
|
-
itemParts.push((itemPart = new ChildPart(this._insert(createMarker()), this._insert(createMarker()), this, this.options)));
|
|
2264
|
-
}
|
|
2265
|
-
else {
|
|
2266
|
-
// Reuse an existing part
|
|
2267
|
-
itemPart = itemParts[partIndex];
|
|
2268
|
-
}
|
|
2269
|
-
itemPart._$setValue(item);
|
|
2270
|
-
partIndex++;
|
|
2271
|
-
}
|
|
2272
|
-
if (partIndex < itemParts.length) {
|
|
2273
|
-
// itemParts always have end nodes
|
|
2274
|
-
this._$clear(itemPart && wrap(itemPart._$endNode).nextSibling, partIndex);
|
|
2275
|
-
// Truncate the parts array so _value reflects the current state
|
|
2276
|
-
itemParts.length = partIndex;
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
/**
|
|
2280
|
-
* Removes the nodes contained within this Part from the DOM.
|
|
2281
|
-
*
|
|
2282
|
-
* @param start Start node to clear from, for clearing a subset of the part's
|
|
2283
|
-
* DOM (used when truncating iterables)
|
|
2284
|
-
* @param from When `start` is specified, the index within the iterable from
|
|
2285
|
-
* which ChildParts are being removed, used for disconnecting directives in
|
|
2286
|
-
* those Parts.
|
|
2287
|
-
*
|
|
2288
|
-
* @internal
|
|
2289
|
-
*/
|
|
2290
|
-
_$clear(start = wrap(this._$startNode).nextSibling, from) {
|
|
2291
|
-
this._$notifyConnectionChanged?.(false, true, from);
|
|
2292
|
-
while (start && start !== this._$endNode) {
|
|
2293
|
-
const n = wrap(start).nextSibling;
|
|
2294
|
-
wrap(start).remove();
|
|
2295
|
-
start = n;
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
/**
|
|
2299
|
-
* Implementation of RootPart's `isConnected`. Note that this metod
|
|
2300
|
-
* should only be called on `RootPart`s (the `ChildPart` returned from a
|
|
2301
|
-
* top-level `render()` call). It has no effect on non-root ChildParts.
|
|
2302
|
-
* @param isConnected Whether to set
|
|
2303
|
-
* @internal
|
|
2304
|
-
*/
|
|
2305
|
-
setConnected(isConnected) {
|
|
2306
|
-
if (this._$parent === undefined) {
|
|
2307
|
-
this.__isConnected = isConnected;
|
|
2308
|
-
this._$notifyConnectionChanged?.(isConnected);
|
|
2309
|
-
}
|
|
2310
|
-
else {
|
|
2311
|
-
throw new Error('part.setConnected() may only be called on a ' +
|
|
2312
|
-
'RootPart returned from render().');
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
}
|
|
2316
|
-
class AttributePart {
|
|
2317
|
-
get tagName() {
|
|
2318
|
-
return this.element.tagName;
|
|
2319
|
-
}
|
|
2320
|
-
// See comment in Disconnectable interface for why this is a getter
|
|
2321
|
-
get _$isConnected() {
|
|
2322
|
-
return this._$parent._$isConnected;
|
|
2323
|
-
}
|
|
2324
|
-
constructor(element, name, strings, parent, options) {
|
|
2325
|
-
this.type = ATTRIBUTE_PART;
|
|
2326
|
-
/** @internal */
|
|
2327
|
-
this._$committedValue = nothing;
|
|
2328
|
-
/** @internal */
|
|
2329
|
-
this._$disconnectableChildren = undefined;
|
|
2330
|
-
this.element = element;
|
|
2331
|
-
this.name = name;
|
|
2332
|
-
this._$parent = parent;
|
|
2333
|
-
this.options = options;
|
|
2334
|
-
if (strings.length > 2 || strings[0] !== '' || strings[1] !== '') {
|
|
2335
|
-
this._$committedValue = new Array(strings.length - 1).fill(new String());
|
|
2336
|
-
this.strings = strings;
|
|
2337
|
-
}
|
|
2338
|
-
else {
|
|
2339
|
-
this._$committedValue = nothing;
|
|
1829
|
+
sanitizerFactoryInternal = newSanitizer;
|
|
1830
|
+
};
|
|
1831
|
+
/**
|
|
1832
|
+
* Only used in internal tests, not a part of the public API.
|
|
1833
|
+
*/
|
|
1834
|
+
const _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {
|
|
1835
|
+
sanitizerFactoryInternal = noopSanitizer;
|
|
1836
|
+
};
|
|
1837
|
+
const createSanitizer = (node, name, type) => {
|
|
1838
|
+
return sanitizerFactoryInternal(node, name, type);
|
|
1839
|
+
};
|
|
1840
|
+
// Added to an attribute name to mark the attribute as bound so we can find
|
|
1841
|
+
// it easily.
|
|
1842
|
+
const boundAttributeSuffix = '$lit$';
|
|
1843
|
+
// This marker is used in many syntactic positions in HTML, so it must be
|
|
1844
|
+
// a valid element name and attribute name. We don't support dynamic names (yet)
|
|
1845
|
+
// but this at least ensures that the parse tree is closer to the template
|
|
1846
|
+
// intention.
|
|
1847
|
+
const marker = `lit$${Math.random().toFixed(9).slice(2)}$`;
|
|
1848
|
+
// String used to tell if a comment is a marker comment
|
|
1849
|
+
const markerMatch = '?' + marker;
|
|
1850
|
+
// Text used to insert a comment marker node. We use processing instruction
|
|
1851
|
+
// syntax because it's slightly smaller, but parses as a comment node.
|
|
1852
|
+
const nodeMarker = `<${markerMatch}>`;
|
|
1853
|
+
const d = document;
|
|
1854
|
+
// Creates a dynamic marker. We never have to search for these in the DOM.
|
|
1855
|
+
const createMarker = () => d.createComment('');
|
|
1856
|
+
const isPrimitive = (value) => value === null || (typeof value != 'object' && typeof value != 'function');
|
|
1857
|
+
const isArray = Array.isArray;
|
|
1858
|
+
const isIterable = (value) => isArray(value) ||
|
|
1859
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1860
|
+
typeof value?.[Symbol.iterator] === 'function';
|
|
1861
|
+
const SPACE_CHAR = `[ \t\n\f\r]`;
|
|
1862
|
+
const ATTR_VALUE_CHAR = `[^ \t\n\f\r"'\`<>=]`;
|
|
1863
|
+
const NAME_CHAR = `[^\\s"'>=/]`;
|
|
1864
|
+
// These regexes represent the five parsing states that we care about in the
|
|
1865
|
+
// Template's HTML scanner. They match the *end* of the state they're named
|
|
1866
|
+
// after.
|
|
1867
|
+
// Depending on the match, we transition to a new state. If there's no match,
|
|
1868
|
+
// we stay in the same state.
|
|
1869
|
+
// Note that the regexes are stateful. We utilize lastIndex and sync it
|
|
1870
|
+
// across the multiple regexes used. In addition to the five regexes below
|
|
1871
|
+
// we also dynamically create a regex to find the matching end tags for raw
|
|
1872
|
+
// text elements.
|
|
1873
|
+
/**
|
|
1874
|
+
* End of text is: `<` followed by:
|
|
1875
|
+
* (comment start) or (tag) or (dynamic tag binding)
|
|
1876
|
+
*/
|
|
1877
|
+
const textEndRegex = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;
|
|
1878
|
+
const COMMENT_START = 1;
|
|
1879
|
+
const TAG_NAME = 2;
|
|
1880
|
+
const DYNAMIC_TAG_NAME = 3;
|
|
1881
|
+
const commentEndRegex = /-->/g;
|
|
1882
|
+
/**
|
|
1883
|
+
* Comments not started with <!--, like </{, can be ended by a single `>`
|
|
1884
|
+
*/
|
|
1885
|
+
const comment2EndRegex = />/g;
|
|
1886
|
+
/**
|
|
1887
|
+
* The tagEnd regex matches the end of the "inside an opening" tag syntax
|
|
1888
|
+
* position. It either matches a `>`, an attribute-like sequence, or the end
|
|
1889
|
+
* of the string after a space (attribute-name position ending).
|
|
1890
|
+
*
|
|
1891
|
+
* See attributes in the HTML spec:
|
|
1892
|
+
* https://www.w3.org/TR/html5/syntax.html#elements-attributes
|
|
1893
|
+
*
|
|
1894
|
+
* " \t\n\f\r" are HTML space characters:
|
|
1895
|
+
* https://infra.spec.whatwg.org/#ascii-whitespace
|
|
1896
|
+
*
|
|
1897
|
+
* So an attribute is:
|
|
1898
|
+
* * The name: any character except a whitespace character, ("), ('), ">",
|
|
1899
|
+
* "=", or "/". Note: this is different from the HTML spec which also excludes control characters.
|
|
1900
|
+
* * Followed by zero or more space characters
|
|
1901
|
+
* * Followed by "="
|
|
1902
|
+
* * Followed by zero or more space characters
|
|
1903
|
+
* * Followed by:
|
|
1904
|
+
* * Any character except space, ('), ("), "<", ">", "=", (`), or
|
|
1905
|
+
* * (") then any non-("), or
|
|
1906
|
+
* * (') then any non-(')
|
|
1907
|
+
*/
|
|
1908
|
+
const tagEndRegex = new RegExp(`>|${SPACE_CHAR}(?:(${NAME_CHAR}+)(${SPACE_CHAR}*=${SPACE_CHAR}*(?:${ATTR_VALUE_CHAR}|("|')|))|$)`, 'g');
|
|
1909
|
+
const ENTIRE_MATCH = 0;
|
|
1910
|
+
const ATTRIBUTE_NAME = 1;
|
|
1911
|
+
const SPACES_AND_EQUALS = 2;
|
|
1912
|
+
const QUOTE_CHAR = 3;
|
|
1913
|
+
const singleQuoteAttrEndRegex = /'/g;
|
|
1914
|
+
const doubleQuoteAttrEndRegex = /"/g;
|
|
1915
|
+
/**
|
|
1916
|
+
* Matches the raw text elements.
|
|
1917
|
+
*
|
|
1918
|
+
* Comments are not parsed within raw text elements, so we need to search their
|
|
1919
|
+
* text content for marker strings.
|
|
1920
|
+
*/
|
|
1921
|
+
const rawTextElement = /^(?:script|style|textarea|title)$/i;
|
|
1922
|
+
/** TemplateResult types */
|
|
1923
|
+
const HTML_RESULT = 1;
|
|
1924
|
+
const SVG_RESULT = 2;
|
|
1925
|
+
// TemplatePart types
|
|
1926
|
+
// IMPORTANT: these must match the values in PartType
|
|
1927
|
+
const ATTRIBUTE_PART = 1;
|
|
1928
|
+
const CHILD_PART = 2;
|
|
1929
|
+
const PROPERTY_PART = 3;
|
|
1930
|
+
const BOOLEAN_ATTRIBUTE_PART = 4;
|
|
1931
|
+
const EVENT_PART = 5;
|
|
1932
|
+
const ELEMENT_PART = 6;
|
|
1933
|
+
const COMMENT_PART = 7;
|
|
1934
|
+
/**
|
|
1935
|
+
* Generates a template literal tag function that returns a TemplateResult with
|
|
1936
|
+
* the given result type.
|
|
1937
|
+
*/
|
|
1938
|
+
const tag = (type) => (strings, ...values) => {
|
|
1939
|
+
// Warn against templates octal escape sequences
|
|
1940
|
+
// We do this here rather than in render so that the warning is closer to the
|
|
1941
|
+
// template definition.
|
|
1942
|
+
if (strings.some((s) => s === undefined)) {
|
|
1943
|
+
console.warn('Some template strings are undefined.\n' +
|
|
1944
|
+
'This is probably caused by illegal octal escape sequences.');
|
|
1945
|
+
}
|
|
1946
|
+
{
|
|
1947
|
+
// Import static-html.js results in a circular dependency which g3 doesn't
|
|
1948
|
+
// handle. Instead we know that static values must have the field
|
|
1949
|
+
// `_$litStatic$`.
|
|
1950
|
+
if (values.some((val) => val?.['_$litStatic$'])) {
|
|
1951
|
+
issueWarning$1('', `Static values 'literal' or 'unsafeStatic' cannot be used as values to non-static templates.\n` +
|
|
1952
|
+
`Please use the static 'html' tag function. See https://lit.dev/docs/templates/expressions/#static-expressions`);
|
|
2340
1953
|
}
|
|
1954
|
+
}
|
|
1955
|
+
return {
|
|
1956
|
+
// This property needs to remain unminified.
|
|
1957
|
+
['_$litType$']: type,
|
|
1958
|
+
strings,
|
|
1959
|
+
values,
|
|
1960
|
+
};
|
|
1961
|
+
};
|
|
1962
|
+
/**
|
|
1963
|
+
* Interprets a template literal as an HTML template that can efficiently
|
|
1964
|
+
* render to and update a container.
|
|
1965
|
+
*
|
|
1966
|
+
* ```ts
|
|
1967
|
+
* const header = (title: string) => html`<h1>${title}</h1>`;
|
|
1968
|
+
* ```
|
|
1969
|
+
*
|
|
1970
|
+
* The `html` tag returns a description of the DOM to render as a value. It is
|
|
1971
|
+
* lazy, meaning no work is done until the template is rendered. When rendering,
|
|
1972
|
+
* if a template comes from the same expression as a previously rendered result,
|
|
1973
|
+
* it's efficiently updated instead of replaced.
|
|
1974
|
+
*/
|
|
1975
|
+
const html$1 = tag(HTML_RESULT);
|
|
1976
|
+
/**
|
|
1977
|
+
* A sentinel value that signals that a value was handled by a directive and
|
|
1978
|
+
* should not be written to the DOM.
|
|
1979
|
+
*/
|
|
1980
|
+
const noChange = Symbol.for('lit-noChange');
|
|
1981
|
+
/**
|
|
1982
|
+
* A sentinel value that signals a ChildPart to fully clear its content.
|
|
1983
|
+
*
|
|
1984
|
+
* ```ts
|
|
1985
|
+
* const button = html`${
|
|
1986
|
+
* user.isAdmin
|
|
1987
|
+
* ? html`<button>DELETE</button>`
|
|
1988
|
+
* : nothing
|
|
1989
|
+
* }`;
|
|
1990
|
+
* ```
|
|
1991
|
+
*
|
|
1992
|
+
* Prefer using `nothing` over other falsy values as it provides a consistent
|
|
1993
|
+
* behavior between various expression binding contexts.
|
|
1994
|
+
*
|
|
1995
|
+
* In child expressions, `undefined`, `null`, `''`, and `nothing` all behave the
|
|
1996
|
+
* same and render no nodes. In attribute expressions, `nothing` _removes_ the
|
|
1997
|
+
* attribute, while `undefined` and `null` will render an empty string. In
|
|
1998
|
+
* property expressions `nothing` becomes `undefined`.
|
|
1999
|
+
*/
|
|
2000
|
+
const nothing = Symbol.for('lit-nothing');
|
|
2001
|
+
/**
|
|
2002
|
+
* The cache of prepared templates, keyed by the tagged TemplateStringsArray
|
|
2003
|
+
* and _not_ accounting for the specific template tag used. This means that
|
|
2004
|
+
* template tags cannot be dynamic - the must statically be one of html, svg,
|
|
2005
|
+
* or attr. This restriction simplifies the cache lookup, which is on the hot
|
|
2006
|
+
* path for rendering.
|
|
2007
|
+
*/
|
|
2008
|
+
const templateCache = new WeakMap();
|
|
2009
|
+
const walker = d.createTreeWalker(d, 129 /* NodeFilter.SHOW_{ELEMENT|COMMENT} */);
|
|
2010
|
+
let sanitizerFactoryInternal = noopSanitizer;
|
|
2011
|
+
function trustFromTemplateString(tsa, stringFromTSA) {
|
|
2012
|
+
// A security check to prevent spoofing of Lit template results.
|
|
2013
|
+
// In the future, we may be able to replace this with Array.isTemplateObject,
|
|
2014
|
+
// though we might need to make that check inside of the html and svg
|
|
2015
|
+
// functions, because precompiled templates don't come in as
|
|
2016
|
+
// TemplateStringArray objects.
|
|
2017
|
+
if (!Array.isArray(tsa) || !tsa.hasOwnProperty('raw')) {
|
|
2018
|
+
let message = 'invalid template strings array';
|
|
2341
2019
|
{
|
|
2342
|
-
|
|
2020
|
+
message = `
|
|
2021
|
+
Internal Error: expected template strings to be an array
|
|
2022
|
+
with a 'raw' field. Faking a template strings array by
|
|
2023
|
+
calling html or svg like an ordinary function is effectively
|
|
2024
|
+
the same as calling unsafeHtml and can lead to major security
|
|
2025
|
+
issues, e.g. opening your code up to XSS attacks.
|
|
2026
|
+
If you're using the html or svg tagged template functions normally
|
|
2027
|
+
and still seeing this error, please file a bug at
|
|
2028
|
+
https://github.com/lit/lit/issues/new?template=bug_report.md
|
|
2029
|
+
and include information about your build tooling, if any.
|
|
2030
|
+
`
|
|
2031
|
+
.trim()
|
|
2032
|
+
.replace(/\n */g, '\n');
|
|
2343
2033
|
}
|
|
2034
|
+
throw new Error(message);
|
|
2344
2035
|
}
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2036
|
+
return policy !== undefined
|
|
2037
|
+
? policy.createHTML(stringFromTSA)
|
|
2038
|
+
: stringFromTSA;
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* Returns an HTML string for the given TemplateStringsArray and result type
|
|
2042
|
+
* (HTML or SVG), along with the case-sensitive bound attribute names in
|
|
2043
|
+
* template order. The HTML contains comment markers denoting the `ChildPart`s
|
|
2044
|
+
* and suffixes on bound attributes denoting the `AttributeParts`.
|
|
2045
|
+
*
|
|
2046
|
+
* @param strings template strings array
|
|
2047
|
+
* @param type HTML or SVG
|
|
2048
|
+
* @return Array containing `[html, attrNames]` (array returned for terseness,
|
|
2049
|
+
* to avoid object fields since this code is shared with non-minified SSR
|
|
2050
|
+
* code)
|
|
2051
|
+
*/
|
|
2052
|
+
const getTemplateHtml = (strings, type) => {
|
|
2053
|
+
// Insert makers into the template HTML to represent the position of
|
|
2054
|
+
// bindings. The following code scans the template strings to determine the
|
|
2055
|
+
// syntactic position of the bindings. They can be in text position, where
|
|
2056
|
+
// we insert an HTML comment, attribute value position, where we insert a
|
|
2057
|
+
// sentinel string and re-write the attribute name, or inside a tag where
|
|
2058
|
+
// we insert the sentinel string.
|
|
2059
|
+
const l = strings.length - 1;
|
|
2060
|
+
// Stores the case-sensitive bound attribute names in the order of their
|
|
2061
|
+
// parts. ElementParts are also reflected in this array as undefined
|
|
2062
|
+
// rather than a string, to disambiguate from attribute bindings.
|
|
2063
|
+
const attrNames = [];
|
|
2064
|
+
let html = type === SVG_RESULT ? '<svg>' : '';
|
|
2065
|
+
// When we're inside a raw text tag (not it's text content), the regex
|
|
2066
|
+
// will still be tagRegex so we can find attributes, but will switch to
|
|
2067
|
+
// this regex when the tag ends.
|
|
2068
|
+
let rawTextEndRegex;
|
|
2069
|
+
// The current parsing state, represented as a reference to one of the
|
|
2070
|
+
// regexes
|
|
2071
|
+
let regex = textEndRegex;
|
|
2072
|
+
for (let i = 0; i < l; i++) {
|
|
2073
|
+
const s = strings[i];
|
|
2074
|
+
// The index of the end of the last attribute name. When this is
|
|
2075
|
+
// positive at end of a string, it means we're in an attribute value
|
|
2076
|
+
// position and need to rewrite the attribute name.
|
|
2077
|
+
// We also use a special value of -2 to indicate that we encountered
|
|
2078
|
+
// the end of a string in attribute name position.
|
|
2079
|
+
let attrNameEndIndex = -1;
|
|
2080
|
+
let attrName;
|
|
2081
|
+
let lastIndex = 0;
|
|
2082
|
+
let match;
|
|
2083
|
+
// The conditions in this loop handle the current parse state, and the
|
|
2084
|
+
// assignments to the `regex` variable are the state transitions.
|
|
2085
|
+
while (lastIndex < s.length) {
|
|
2086
|
+
// Make sure we start searching from where we previously left off
|
|
2087
|
+
regex.lastIndex = lastIndex;
|
|
2088
|
+
match = regex.exec(s);
|
|
2089
|
+
if (match === null) {
|
|
2090
|
+
break;
|
|
2379
2091
|
}
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
value = strings[0];
|
|
2385
|
-
let i, v;
|
|
2386
|
-
for (i = 0; i < strings.length - 1; i++) {
|
|
2387
|
-
v = resolveDirective(this, values[valueIndex + i], directiveParent, i);
|
|
2388
|
-
if (v === noChange) {
|
|
2389
|
-
// If the user-provided value is `noChange`, use the previous value
|
|
2390
|
-
v = this._$committedValue[i];
|
|
2092
|
+
lastIndex = regex.lastIndex;
|
|
2093
|
+
if (regex === textEndRegex) {
|
|
2094
|
+
if (match[COMMENT_START] === '!--') {
|
|
2095
|
+
regex = commentEndRegex;
|
|
2391
2096
|
}
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
value = nothing;
|
|
2097
|
+
else if (match[COMMENT_START] !== undefined) {
|
|
2098
|
+
// We started a weird comment, like </{
|
|
2099
|
+
regex = comment2EndRegex;
|
|
2396
2100
|
}
|
|
2397
|
-
else if (
|
|
2398
|
-
|
|
2101
|
+
else if (match[TAG_NAME] !== undefined) {
|
|
2102
|
+
if (rawTextElement.test(match[TAG_NAME])) {
|
|
2103
|
+
// Record if we encounter a raw-text element. We'll switch to
|
|
2104
|
+
// this regex at the end of the tag.
|
|
2105
|
+
rawTextEndRegex = new RegExp(`</${match[TAG_NAME]}`, 'g');
|
|
2106
|
+
}
|
|
2107
|
+
regex = tagEndRegex;
|
|
2399
2108
|
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2109
|
+
else if (match[DYNAMIC_TAG_NAME] !== undefined) {
|
|
2110
|
+
{
|
|
2111
|
+
throw new Error('Bindings in tag names are not supported. Please use static templates instead. ' +
|
|
2112
|
+
'See https://lit.dev/docs/templates/expressions/#static-expressions');
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
else if (regex === tagEndRegex) {
|
|
2117
|
+
if (match[ENTIRE_MATCH] === '>') {
|
|
2118
|
+
// End of a tag. If we had started a raw-text element, use that
|
|
2119
|
+
// regex
|
|
2120
|
+
regex = rawTextEndRegex ?? textEndRegex;
|
|
2121
|
+
// We may be ending an unquoted attribute value, so make sure we
|
|
2122
|
+
// clear any pending attrNameEndIndex
|
|
2123
|
+
attrNameEndIndex = -1;
|
|
2124
|
+
}
|
|
2125
|
+
else if (match[ATTRIBUTE_NAME] === undefined) {
|
|
2126
|
+
// Attribute name position
|
|
2127
|
+
attrNameEndIndex = -2;
|
|
2128
|
+
}
|
|
2129
|
+
else {
|
|
2130
|
+
attrNameEndIndex = regex.lastIndex - match[SPACES_AND_EQUALS].length;
|
|
2131
|
+
attrName = match[ATTRIBUTE_NAME];
|
|
2132
|
+
regex =
|
|
2133
|
+
match[QUOTE_CHAR] === undefined
|
|
2134
|
+
? tagEndRegex
|
|
2135
|
+
: match[QUOTE_CHAR] === '"'
|
|
2136
|
+
? doubleQuoteAttrEndRegex
|
|
2137
|
+
: singleQuoteAttrEndRegex;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
else if (regex === doubleQuoteAttrEndRegex ||
|
|
2141
|
+
regex === singleQuoteAttrEndRegex) {
|
|
2142
|
+
regex = tagEndRegex;
|
|
2143
|
+
}
|
|
2144
|
+
else if (regex === commentEndRegex || regex === comment2EndRegex) {
|
|
2145
|
+
regex = textEndRegex;
|
|
2146
|
+
}
|
|
2147
|
+
else {
|
|
2148
|
+
// Not one of the five state regexes, so it must be the dynamically
|
|
2149
|
+
// created raw text regex and we're at the close of that element.
|
|
2150
|
+
regex = tagEndRegex;
|
|
2151
|
+
rawTextEndRegex = undefined;
|
|
2403
2152
|
}
|
|
2404
2153
|
}
|
|
2405
|
-
|
|
2406
|
-
|
|
2154
|
+
{
|
|
2155
|
+
// If we have a attrNameEndIndex, which indicates that we should
|
|
2156
|
+
// rewrite the attribute name, assert that we're in a valid attribute
|
|
2157
|
+
// position - either in a tag, or a quoted attribute value.
|
|
2158
|
+
console.assert(attrNameEndIndex === -1 ||
|
|
2159
|
+
regex === tagEndRegex ||
|
|
2160
|
+
regex === singleQuoteAttrEndRegex ||
|
|
2161
|
+
regex === doubleQuoteAttrEndRegex, 'unexpected parse state B');
|
|
2407
2162
|
}
|
|
2163
|
+
// We have four cases:
|
|
2164
|
+
// 1. We're in text position, and not in a raw text element
|
|
2165
|
+
// (regex === textEndRegex): insert a comment marker.
|
|
2166
|
+
// 2. We have a non-negative attrNameEndIndex which means we need to
|
|
2167
|
+
// rewrite the attribute name to add a bound attribute suffix.
|
|
2168
|
+
// 3. We're at the non-first binding in a multi-binding attribute, use a
|
|
2169
|
+
// plain marker.
|
|
2170
|
+
// 4. We're somewhere else inside the tag. If we're in attribute name
|
|
2171
|
+
// position (attrNameEndIndex === -2), add a sequential suffix to
|
|
2172
|
+
// generate a unique attribute name.
|
|
2173
|
+
// Detect a binding next to self-closing tag end and insert a space to
|
|
2174
|
+
// separate the marker from the tag end:
|
|
2175
|
+
const end = regex === tagEndRegex && strings[i + 1].startsWith('/>') ? ' ' : '';
|
|
2176
|
+
html +=
|
|
2177
|
+
regex === textEndRegex
|
|
2178
|
+
? s + nodeMarker
|
|
2179
|
+
: attrNameEndIndex >= 0
|
|
2180
|
+
? (attrNames.push(attrName),
|
|
2181
|
+
s.slice(0, attrNameEndIndex) +
|
|
2182
|
+
boundAttributeSuffix +
|
|
2183
|
+
s.slice(attrNameEndIndex)) +
|
|
2184
|
+
marker +
|
|
2185
|
+
end
|
|
2186
|
+
: s + marker + (attrNameEndIndex === -2 ? i : end);
|
|
2408
2187
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2188
|
+
const htmlResult = html + (strings[l] || '<?>') + (type === SVG_RESULT ? '</svg>' : '');
|
|
2189
|
+
// Returned as an array for terseness
|
|
2190
|
+
return [trustFromTemplateString(strings, htmlResult), attrNames];
|
|
2191
|
+
};
|
|
2192
|
+
class Template {
|
|
2193
|
+
constructor(
|
|
2194
|
+
// This property needs to remain unminified.
|
|
2195
|
+
{ strings, ['_$litType$']: type }, options) {
|
|
2196
|
+
this.parts = [];
|
|
2197
|
+
let node;
|
|
2198
|
+
let nodeIndex = 0;
|
|
2199
|
+
let attrNameIndex = 0;
|
|
2200
|
+
const partCount = strings.length - 1;
|
|
2201
|
+
const parts = this.parts;
|
|
2202
|
+
// Create template element
|
|
2203
|
+
const [html, attrNames] = getTemplateHtml(strings, type);
|
|
2204
|
+
this.el = Template.createElement(html, options);
|
|
2205
|
+
walker.currentNode = this.el.content;
|
|
2206
|
+
// Re-parent SVG nodes into template root
|
|
2207
|
+
if (type === SVG_RESULT) {
|
|
2208
|
+
const svgElement = this.el.content.firstChild;
|
|
2209
|
+
svgElement.replaceWith(...svgElement.childNodes);
|
|
2413
2210
|
}
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2211
|
+
// Walk the template to find binding markers and create TemplateParts
|
|
2212
|
+
while ((node = walker.nextNode()) !== null && parts.length < partCount) {
|
|
2213
|
+
if (node.nodeType === 1) {
|
|
2214
|
+
{
|
|
2215
|
+
const tag = node.localName;
|
|
2216
|
+
// Warn if `textarea` includes an expression and throw if `template`
|
|
2217
|
+
// does since these are not supported. We do this by checking
|
|
2218
|
+
// innerHTML for anything that looks like a marker. This catches
|
|
2219
|
+
// cases like bindings in textarea there markers turn into text nodes.
|
|
2220
|
+
if (/^(?:textarea|template)$/i.test(tag) &&
|
|
2221
|
+
node.innerHTML.includes(marker)) {
|
|
2222
|
+
const m = `Expressions are not supported inside \`${tag}\` ` +
|
|
2223
|
+
`elements. See https://lit.dev/msg/expression-in-${tag} for more ` +
|
|
2224
|
+
`information.`;
|
|
2225
|
+
if (tag === 'template') {
|
|
2226
|
+
throw new Error(m);
|
|
2227
|
+
}
|
|
2228
|
+
else
|
|
2229
|
+
issueWarning$1('', m);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
// TODO (justinfagnani): for attempted dynamic tag names, we don't
|
|
2233
|
+
// increment the bindingIndex, and it'll be off by 1 in the element
|
|
2234
|
+
// and off by two after it.
|
|
2235
|
+
if (node.hasAttributes()) {
|
|
2236
|
+
for (const name of node.getAttributeNames()) {
|
|
2237
|
+
if (name.endsWith(boundAttributeSuffix)) {
|
|
2238
|
+
const realName = attrNames[attrNameIndex++];
|
|
2239
|
+
const value = node.getAttribute(name);
|
|
2240
|
+
const statics = value.split(marker);
|
|
2241
|
+
const m = /([.?@])?(.*)/.exec(realName);
|
|
2242
|
+
parts.push({
|
|
2243
|
+
type: ATTRIBUTE_PART,
|
|
2244
|
+
index: nodeIndex,
|
|
2245
|
+
name: m[2],
|
|
2246
|
+
strings: statics,
|
|
2247
|
+
ctor: m[1] === '.'
|
|
2248
|
+
? PropertyPart
|
|
2249
|
+
: m[1] === '?'
|
|
2250
|
+
? BooleanAttributePart
|
|
2251
|
+
: m[1] === '@'
|
|
2252
|
+
? EventPart
|
|
2253
|
+
: AttributePart,
|
|
2254
|
+
});
|
|
2255
|
+
node.removeAttribute(name);
|
|
2256
|
+
}
|
|
2257
|
+
else if (name.startsWith(marker)) {
|
|
2258
|
+
parts.push({
|
|
2259
|
+
type: ELEMENT_PART,
|
|
2260
|
+
index: nodeIndex,
|
|
2261
|
+
});
|
|
2262
|
+
node.removeAttribute(name);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
// TODO (justinfagnani): benchmark the regex against testing for each
|
|
2267
|
+
// of the 3 raw text element names.
|
|
2268
|
+
if (rawTextElement.test(node.tagName)) {
|
|
2269
|
+
// For raw text elements we need to split the text content on
|
|
2270
|
+
// markers, create a Text node for each segment, and create
|
|
2271
|
+
// a TemplatePart for each marker.
|
|
2272
|
+
const strings = node.textContent.split(marker);
|
|
2273
|
+
const lastIndex = strings.length - 1;
|
|
2274
|
+
if (lastIndex > 0) {
|
|
2275
|
+
node.textContent = trustedTypes
|
|
2276
|
+
? trustedTypes.emptyScript
|
|
2277
|
+
: '';
|
|
2278
|
+
// Generate a new text node for each literal section
|
|
2279
|
+
// These nodes are also used as the markers for node parts
|
|
2280
|
+
// We can't use empty text nodes as markers because they're
|
|
2281
|
+
// normalized when cloning in IE (could simplify when
|
|
2282
|
+
// IE is no longer supported)
|
|
2283
|
+
for (let i = 0; i < lastIndex; i++) {
|
|
2284
|
+
node.append(strings[i], createMarker());
|
|
2285
|
+
// Walk past the marker node we just added
|
|
2286
|
+
walker.nextNode();
|
|
2287
|
+
parts.push({ type: CHILD_PART, index: ++nodeIndex });
|
|
2288
|
+
}
|
|
2289
|
+
// Note because this marker is added after the walker's current
|
|
2290
|
+
// node, it will be walked to in the outer loop (and ignored), so
|
|
2291
|
+
// we don't need to adjust nodeIndex here
|
|
2292
|
+
node.append(strings[lastIndex], createMarker());
|
|
2293
|
+
}
|
|
2418
2294
|
}
|
|
2419
|
-
value = this._sanitizer(value ?? '');
|
|
2420
2295
|
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
this.type = PROPERTY_PART;
|
|
2437
|
-
}
|
|
2438
|
-
/** @internal */
|
|
2439
|
-
_commitValue(value) {
|
|
2440
|
-
{
|
|
2441
|
-
if (this._sanitizer === undefined) {
|
|
2442
|
-
this._sanitizer = sanitizerFactoryInternal(this.element, this.name, 'property');
|
|
2296
|
+
else if (node.nodeType === 8) {
|
|
2297
|
+
const data = node.data;
|
|
2298
|
+
if (data === markerMatch) {
|
|
2299
|
+
parts.push({ type: CHILD_PART, index: nodeIndex });
|
|
2300
|
+
}
|
|
2301
|
+
else {
|
|
2302
|
+
let i = -1;
|
|
2303
|
+
while ((i = node.data.indexOf(marker, i + 1)) !== -1) {
|
|
2304
|
+
// Comment node has a binding marker inside, make an inactive part
|
|
2305
|
+
// The binding won't work, but subsequent bindings will
|
|
2306
|
+
parts.push({ type: COMMENT_PART, index: nodeIndex });
|
|
2307
|
+
// Move to the end of the match
|
|
2308
|
+
i += marker.length - 1;
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2443
2311
|
}
|
|
2444
|
-
|
|
2445
|
-
}
|
|
2446
|
-
debugLogEvent &&
|
|
2447
|
-
debugLogEvent({
|
|
2448
|
-
kind: 'commit property',
|
|
2449
|
-
element: this.element,
|
|
2450
|
-
name: this.name,
|
|
2451
|
-
value,
|
|
2452
|
-
options: this.options,
|
|
2453
|
-
});
|
|
2454
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2455
|
-
this.element[this.name] = value === nothing ? undefined : value;
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
class BooleanAttributePart extends AttributePart {
|
|
2459
|
-
constructor() {
|
|
2460
|
-
super(...arguments);
|
|
2461
|
-
this.type = BOOLEAN_ATTRIBUTE_PART;
|
|
2462
|
-
}
|
|
2463
|
-
/** @internal */
|
|
2464
|
-
_commitValue(value) {
|
|
2465
|
-
debugLogEvent &&
|
|
2466
|
-
debugLogEvent({
|
|
2467
|
-
kind: 'commit boolean attribute',
|
|
2468
|
-
element: this.element,
|
|
2469
|
-
name: this.name,
|
|
2470
|
-
value: !!(value && value !== nothing),
|
|
2471
|
-
options: this.options,
|
|
2472
|
-
});
|
|
2473
|
-
wrap(this.element).toggleAttribute(this.name, !!value && value !== nothing);
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
class EventPart extends AttributePart {
|
|
2477
|
-
constructor(element, name, strings, parent, options) {
|
|
2478
|
-
super(element, name, strings, parent, options);
|
|
2479
|
-
this.type = EVENT_PART;
|
|
2480
|
-
if (this.strings !== undefined) {
|
|
2481
|
-
throw new Error(`A \`<${element.localName}>\` has a \`@${name}=...\` listener with ` +
|
|
2482
|
-
'invalid content. Event listeners in templates must have exactly ' +
|
|
2483
|
-
'one expression and no surrounding text.');
|
|
2312
|
+
nodeIndex++;
|
|
2484
2313
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2314
|
+
{
|
|
2315
|
+
// If there was a duplicate attribute on a tag, then when the tag is
|
|
2316
|
+
// parsed into an element the attribute gets de-duplicated. We can detect
|
|
2317
|
+
// this mismatch if we haven't precisely consumed every attribute name
|
|
2318
|
+
// when preparing the template. This works because `attrNames` is built
|
|
2319
|
+
// from the template string and `attrNameIndex` comes from processing the
|
|
2320
|
+
// resulting DOM.
|
|
2321
|
+
if (attrNames.length !== attrNameIndex) {
|
|
2322
|
+
throw new Error(`Detected duplicate attribute bindings. This occurs if your template ` +
|
|
2323
|
+
`has duplicate attributes on an element tag. For example ` +
|
|
2324
|
+
`"<input ?disabled=\${true} ?disabled=\${false}>" contains a ` +
|
|
2325
|
+
`duplicate "disabled" attribute. The error was detected in ` +
|
|
2326
|
+
`the following template: \n` +
|
|
2327
|
+
'`' +
|
|
2328
|
+
strings.join('${...}') +
|
|
2329
|
+
'`');
|
|
2330
|
+
}
|
|
2494
2331
|
}
|
|
2495
|
-
|
|
2496
|
-
//
|
|
2497
|
-
//
|
|
2498
|
-
const shouldRemoveListener = (newListener === nothing && oldListener !== nothing) ||
|
|
2499
|
-
newListener.capture !==
|
|
2500
|
-
oldListener.capture ||
|
|
2501
|
-
newListener.once !==
|
|
2502
|
-
oldListener.once ||
|
|
2503
|
-
newListener.passive !==
|
|
2504
|
-
oldListener.passive;
|
|
2505
|
-
// If the new value is not nothing and we removed the listener, we have
|
|
2506
|
-
// to add the part as a listener.
|
|
2507
|
-
const shouldAddListener = newListener !== nothing &&
|
|
2508
|
-
(oldListener === nothing || shouldRemoveListener);
|
|
2332
|
+
// We could set walker.currentNode to another node here to prevent a memory
|
|
2333
|
+
// leak, but every time we prepare a template, we immediately render it
|
|
2334
|
+
// and re-use the walker in new TemplateInstance._clone().
|
|
2509
2335
|
debugLogEvent &&
|
|
2510
2336
|
debugLogEvent({
|
|
2511
|
-
kind: '
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
removeListener: shouldRemoveListener,
|
|
2517
|
-
addListener: shouldAddListener,
|
|
2518
|
-
oldListener,
|
|
2337
|
+
kind: 'template prep',
|
|
2338
|
+
template: this,
|
|
2339
|
+
clonableTemplate: this.el,
|
|
2340
|
+
parts: this.parts,
|
|
2341
|
+
strings,
|
|
2519
2342
|
});
|
|
2520
|
-
|
|
2521
|
-
|
|
2343
|
+
}
|
|
2344
|
+
// Overridden via `litHtmlPolyfillSupport` to provide platform support.
|
|
2345
|
+
/** @nocollapse */
|
|
2346
|
+
static createElement(html, _options) {
|
|
2347
|
+
const el = d.createElement('template');
|
|
2348
|
+
el.innerHTML = html;
|
|
2349
|
+
return el;
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
function resolveDirective(part, value, parent = part, attributeIndex) {
|
|
2353
|
+
// Bail early if the value is explicitly noChange. Note, this means any
|
|
2354
|
+
// nested directive is still attached and is not run.
|
|
2355
|
+
if (value === noChange) {
|
|
2356
|
+
return value;
|
|
2357
|
+
}
|
|
2358
|
+
let currentDirective = attributeIndex !== undefined
|
|
2359
|
+
? parent.__directives?.[attributeIndex]
|
|
2360
|
+
: parent.__directive;
|
|
2361
|
+
const nextDirectiveConstructor = isPrimitive(value)
|
|
2362
|
+
? undefined
|
|
2363
|
+
: // This property needs to remain unminified.
|
|
2364
|
+
value['_$litDirective$'];
|
|
2365
|
+
if (currentDirective?.constructor !== nextDirectiveConstructor) {
|
|
2366
|
+
// This property needs to remain unminified.
|
|
2367
|
+
currentDirective?.['_$notifyDirectiveConnectionChanged']?.(false);
|
|
2368
|
+
if (nextDirectiveConstructor === undefined) {
|
|
2369
|
+
currentDirective = undefined;
|
|
2522
2370
|
}
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
// patch addEventListener?
|
|
2527
|
-
this.element.addEventListener(this.name, this, newListener);
|
|
2371
|
+
else {
|
|
2372
|
+
currentDirective = new nextDirectiveConstructor(part);
|
|
2373
|
+
currentDirective._$initialize(part, parent, attributeIndex);
|
|
2528
2374
|
}
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
if (typeof this._$committedValue === 'function') {
|
|
2533
|
-
this._$committedValue.call(this.options?.host ?? this.element, event);
|
|
2375
|
+
if (attributeIndex !== undefined) {
|
|
2376
|
+
(parent.__directives ??= [])[attributeIndex] =
|
|
2377
|
+
currentDirective;
|
|
2534
2378
|
}
|
|
2535
2379
|
else {
|
|
2536
|
-
|
|
2380
|
+
parent.__directive = currentDirective;
|
|
2537
2381
|
}
|
|
2538
2382
|
}
|
|
2383
|
+
if (currentDirective !== undefined) {
|
|
2384
|
+
value = resolveDirective(part, currentDirective._$resolve(part, value.values), currentDirective, attributeIndex);
|
|
2385
|
+
}
|
|
2386
|
+
return value;
|
|
2539
2387
|
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2388
|
+
/**
|
|
2389
|
+
* An updateable instance of a Template. Holds references to the Parts used to
|
|
2390
|
+
* update the template instance.
|
|
2391
|
+
*/
|
|
2392
|
+
class TemplateInstance {
|
|
2393
|
+
constructor(template, parent) {
|
|
2394
|
+
this._$parts = [];
|
|
2544
2395
|
/** @internal */
|
|
2545
2396
|
this._$disconnectableChildren = undefined;
|
|
2397
|
+
this._$template = template;
|
|
2546
2398
|
this._$parent = parent;
|
|
2547
|
-
|
|
2399
|
+
}
|
|
2400
|
+
// Called by ChildPart parentNode getter
|
|
2401
|
+
get parentNode() {
|
|
2402
|
+
return this._$parent.parentNode;
|
|
2548
2403
|
}
|
|
2549
2404
|
// See comment in Disconnectable interface for why this is a getter
|
|
2550
2405
|
get _$isConnected() {
|
|
2551
2406
|
return this._$parent._$isConnected;
|
|
2552
2407
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
* @param value Any [renderable
|
|
2589
|
-
* value](https://lit.dev/docs/templates/expressions/#child-expressions),
|
|
2590
|
-
* typically a {@linkcode TemplateResult} created by evaluating a template tag
|
|
2591
|
-
* like {@linkcode html} or {@linkcode svg}.
|
|
2592
|
-
* @param container A DOM container to render to. The first render will append
|
|
2593
|
-
* the rendered value to the container, and subsequent renders will
|
|
2594
|
-
* efficiently update the rendered value if the same result type was
|
|
2595
|
-
* previously rendered there.
|
|
2596
|
-
* @param options See {@linkcode RenderOptions} for options documentation.
|
|
2597
|
-
* @see
|
|
2598
|
-
* {@link https://lit.dev/docs/libraries/standalone-templates/#rendering-lit-html-templates| Rendering Lit HTML Templates}
|
|
2599
|
-
*/
|
|
2600
|
-
const render = (value, container, options) => {
|
|
2601
|
-
if (container == null) {
|
|
2602
|
-
// Give a clearer error message than
|
|
2603
|
-
// Uncaught TypeError: Cannot read properties of null (reading
|
|
2604
|
-
// '_$litPart$')
|
|
2605
|
-
// which reads like an internal Lit error.
|
|
2606
|
-
throw new TypeError(`The container to render into may not be ${container}`);
|
|
2607
|
-
}
|
|
2608
|
-
const renderId = debugLogRenderId++ ;
|
|
2609
|
-
const partOwnerNode = options?.renderBefore ?? container;
|
|
2610
|
-
// This property needs to remain unminified.
|
|
2611
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2612
|
-
let part = partOwnerNode['_$litPart$'];
|
|
2613
|
-
debugLogEvent &&
|
|
2614
|
-
debugLogEvent({
|
|
2615
|
-
kind: 'begin render',
|
|
2616
|
-
id: renderId,
|
|
2617
|
-
value,
|
|
2618
|
-
container,
|
|
2619
|
-
options,
|
|
2620
|
-
part,
|
|
2621
|
-
});
|
|
2622
|
-
if (part === undefined) {
|
|
2623
|
-
const endNode = options?.renderBefore ?? null;
|
|
2624
|
-
// This property needs to remain unminified.
|
|
2625
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2626
|
-
partOwnerNode['_$litPart$'] = part = new ChildPart(container.insertBefore(createMarker(), endNode), endNode, undefined, options ?? {});
|
|
2627
|
-
}
|
|
2628
|
-
part._$setValue(value);
|
|
2629
|
-
debugLogEvent &&
|
|
2630
|
-
debugLogEvent({
|
|
2631
|
-
kind: 'end render',
|
|
2632
|
-
id: renderId,
|
|
2633
|
-
value,
|
|
2634
|
-
container,
|
|
2635
|
-
options,
|
|
2636
|
-
part,
|
|
2637
|
-
});
|
|
2638
|
-
return part;
|
|
2639
|
-
};
|
|
2640
|
-
{
|
|
2641
|
-
render.setSanitizer = setSanitizer;
|
|
2642
|
-
render.createSanitizer = createSanitizer;
|
|
2643
|
-
{
|
|
2644
|
-
render._testOnlyClearSanitizerFactoryDoNotCallOrElse =
|
|
2645
|
-
_testOnlyClearSanitizerFactoryDoNotCallOrElse;
|
|
2408
|
+
// This method is separate from the constructor because we need to return a
|
|
2409
|
+
// DocumentFragment and we don't want to hold onto it with an instance field.
|
|
2410
|
+
_clone(options) {
|
|
2411
|
+
const { el: { content }, parts: parts, } = this._$template;
|
|
2412
|
+
const fragment = (options?.creationScope ?? d).importNode(content, true);
|
|
2413
|
+
walker.currentNode = fragment;
|
|
2414
|
+
let node = walker.nextNode();
|
|
2415
|
+
let nodeIndex = 0;
|
|
2416
|
+
let partIndex = 0;
|
|
2417
|
+
let templatePart = parts[0];
|
|
2418
|
+
while (templatePart !== undefined) {
|
|
2419
|
+
if (nodeIndex === templatePart.index) {
|
|
2420
|
+
let part;
|
|
2421
|
+
if (templatePart.type === CHILD_PART) {
|
|
2422
|
+
part = new ChildPart(node, node.nextSibling, this, options);
|
|
2423
|
+
}
|
|
2424
|
+
else if (templatePart.type === ATTRIBUTE_PART) {
|
|
2425
|
+
part = new templatePart.ctor(node, templatePart.name, templatePart.strings, this, options);
|
|
2426
|
+
}
|
|
2427
|
+
else if (templatePart.type === ELEMENT_PART) {
|
|
2428
|
+
part = new ElementPart(node, this, options);
|
|
2429
|
+
}
|
|
2430
|
+
this._$parts.push(part);
|
|
2431
|
+
templatePart = parts[++partIndex];
|
|
2432
|
+
}
|
|
2433
|
+
if (nodeIndex !== templatePart?.index) {
|
|
2434
|
+
node = walker.nextNode();
|
|
2435
|
+
nodeIndex++;
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
// We need to set the currentNode away from the cloned tree so that we
|
|
2439
|
+
// don't hold onto the tree even if the tree is detached and should be
|
|
2440
|
+
// freed.
|
|
2441
|
+
walker.currentNode = d;
|
|
2442
|
+
return fragment;
|
|
2646
2443
|
}
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
issuedWarnings.add(warning);
|
|
2444
|
+
_update(values) {
|
|
2445
|
+
let i = 0;
|
|
2446
|
+
for (const part of this._$parts) {
|
|
2447
|
+
if (part !== undefined) {
|
|
2448
|
+
debugLogEvent &&
|
|
2449
|
+
debugLogEvent({
|
|
2450
|
+
kind: 'set part',
|
|
2451
|
+
part,
|
|
2452
|
+
value: values[i],
|
|
2453
|
+
valueIndex: i,
|
|
2454
|
+
values,
|
|
2455
|
+
templateInstance: this,
|
|
2456
|
+
});
|
|
2457
|
+
if (part.strings !== undefined) {
|
|
2458
|
+
part._$setValue(values, part, i);
|
|
2459
|
+
// The number of values the part consumes is part.strings.length - 1
|
|
2460
|
+
// since values are in between template spans. We increment i by 1
|
|
2461
|
+
// later in the loop, so increment it by part.strings.length - 2 here
|
|
2462
|
+
i += part.strings.length - 2;
|
|
2463
|
+
}
|
|
2464
|
+
else {
|
|
2465
|
+
part._$setValue(values[i]);
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
i++;
|
|
2673
2469
|
}
|
|
2674
|
-
}
|
|
2470
|
+
}
|
|
2675
2471
|
}
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
this.
|
|
2692
|
-
this.
|
|
2472
|
+
class ChildPart {
|
|
2473
|
+
// See comment in Disconnectable interface for why this is a getter
|
|
2474
|
+
get _$isConnected() {
|
|
2475
|
+
// ChildParts that are not at the root should always be created with a
|
|
2476
|
+
// parent; only RootChildNode's won't, so they return the local isConnected
|
|
2477
|
+
// state
|
|
2478
|
+
return this._$parent?._$isConnected ?? this.__isConnected;
|
|
2479
|
+
}
|
|
2480
|
+
constructor(startNode, endNode, parent, options) {
|
|
2481
|
+
this.type = CHILD_PART;
|
|
2482
|
+
this._$committedValue = nothing;
|
|
2483
|
+
// The following fields will be patched onto ChildParts when required by
|
|
2484
|
+
// AsyncDirective
|
|
2485
|
+
/** @internal */
|
|
2486
|
+
this._$disconnectableChildren = undefined;
|
|
2487
|
+
this._$startNode = startNode;
|
|
2488
|
+
this._$endNode = endNode;
|
|
2489
|
+
this._$parent = parent;
|
|
2490
|
+
this.options = options;
|
|
2491
|
+
// Note __isConnected is only ever accessed on RootParts (i.e. when there is
|
|
2492
|
+
// no _$parent); the value on a non-root-part is "don't care", but checking
|
|
2493
|
+
// for parent would be more code
|
|
2494
|
+
this.__isConnected = options?.isConnected ?? true;
|
|
2495
|
+
{
|
|
2496
|
+
// Explicitly initialize for consistent class shape.
|
|
2497
|
+
this._textSanitizer = undefined;
|
|
2498
|
+
}
|
|
2693
2499
|
}
|
|
2694
2500
|
/**
|
|
2695
|
-
*
|
|
2501
|
+
* The parent node into which the part renders its content.
|
|
2502
|
+
*
|
|
2503
|
+
* A ChildPart's content consists of a range of adjacent child nodes of
|
|
2504
|
+
* `.parentNode`, possibly bordered by 'marker nodes' (`.startNode` and
|
|
2505
|
+
* `.endNode`).
|
|
2506
|
+
*
|
|
2507
|
+
* - If both `.startNode` and `.endNode` are non-null, then the part's content
|
|
2508
|
+
* consists of all siblings between `.startNode` and `.endNode`, exclusively.
|
|
2509
|
+
*
|
|
2510
|
+
* - If `.startNode` is non-null but `.endNode` is null, then the part's
|
|
2511
|
+
* content consists of all siblings following `.startNode`, up to and
|
|
2512
|
+
* including the last child of `.parentNode`. If `.endNode` is non-null, then
|
|
2513
|
+
* `.startNode` will always be non-null.
|
|
2514
|
+
*
|
|
2515
|
+
* - If both `.endNode` and `.startNode` are null, then the part's content
|
|
2516
|
+
* consists of all child nodes of `.parentNode`.
|
|
2696
2517
|
*/
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2518
|
+
get parentNode() {
|
|
2519
|
+
let parentNode = wrap(this._$startNode).parentNode;
|
|
2520
|
+
const parent = this._$parent;
|
|
2521
|
+
if (parent !== undefined &&
|
|
2522
|
+
parentNode?.nodeType === 11 /* Node.DOCUMENT_FRAGMENT */) {
|
|
2523
|
+
// If the parentNode is a DocumentFragment, it may be because the DOM is
|
|
2524
|
+
// still in the cloned fragment during initial render; if so, get the real
|
|
2525
|
+
// parentNode the part will be committed into by asking the parent.
|
|
2526
|
+
parentNode = parent.parentNode;
|
|
2527
|
+
}
|
|
2528
|
+
return parentNode;
|
|
2706
2529
|
}
|
|
2707
2530
|
/**
|
|
2708
|
-
*
|
|
2709
|
-
*
|
|
2710
|
-
* this method will *not* trigger another update.
|
|
2711
|
-
* @param changedProperties Map of changed properties with old values
|
|
2712
|
-
* @category updates
|
|
2531
|
+
* The part's leading marker node, if any. See `.parentNode` for more
|
|
2532
|
+
* information.
|
|
2713
2533
|
*/
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2534
|
+
get startNode() {
|
|
2535
|
+
return this._$startNode;
|
|
2536
|
+
}
|
|
2537
|
+
/**
|
|
2538
|
+
* The part's trailing marker node, if any. See `.parentNode` for more
|
|
2539
|
+
* information.
|
|
2540
|
+
*/
|
|
2541
|
+
get endNode() {
|
|
2542
|
+
return this._$endNode;
|
|
2543
|
+
}
|
|
2544
|
+
_$setValue(value, directiveParent = this) {
|
|
2545
|
+
if (this.parentNode === null) {
|
|
2546
|
+
throw new Error(`This \`ChildPart\` has no \`parentNode\` and therefore cannot accept a value. This likely means the element containing the part was manipulated in an unsupported way outside of Lit's control such that the part's marker nodes were ejected from DOM. For example, setting the element's \`innerHTML\` or \`textContent\` can do this.`);
|
|
2547
|
+
}
|
|
2548
|
+
value = resolveDirective(this, value, directiveParent);
|
|
2549
|
+
if (isPrimitive(value)) {
|
|
2550
|
+
// Non-rendering child values. It's important that these do not render
|
|
2551
|
+
// empty text nodes to avoid issues with preventing default <slot>
|
|
2552
|
+
// fallback content.
|
|
2553
|
+
if (value === nothing || value == null || value === '') {
|
|
2554
|
+
if (this._$committedValue !== nothing) {
|
|
2555
|
+
debugLogEvent &&
|
|
2556
|
+
debugLogEvent({
|
|
2557
|
+
kind: 'commit nothing to child',
|
|
2558
|
+
start: this._$startNode,
|
|
2559
|
+
end: this._$endNode,
|
|
2560
|
+
parent: this._$parent,
|
|
2561
|
+
options: this.options,
|
|
2562
|
+
});
|
|
2563
|
+
this._$clear();
|
|
2564
|
+
}
|
|
2565
|
+
this._$committedValue = nothing;
|
|
2566
|
+
}
|
|
2567
|
+
else if (value !== this._$committedValue && value !== noChange) {
|
|
2568
|
+
this._commitText(value);
|
|
2569
|
+
}
|
|
2570
|
+
// This property needs to remain unminified.
|
|
2571
|
+
}
|
|
2572
|
+
else if (value['_$litType$'] !== undefined) {
|
|
2573
|
+
this._commitTemplateResult(value);
|
|
2574
|
+
}
|
|
2575
|
+
else if (value.nodeType !== undefined) {
|
|
2576
|
+
if (this.options?.host === value) {
|
|
2577
|
+
this._commitText(`[probable mistake: rendered a template's host in itself ` +
|
|
2578
|
+
`(commonly caused by writing \${this} in a template]`);
|
|
2579
|
+
console.warn(`Attempted to render the template host`, value, `inside itself. This is almost always a mistake, and in dev mode `, `we render some warning text. In production however, we'll `, `render it, which will usually result in an error, and sometimes `, `in the element disappearing from the DOM.`);
|
|
2580
|
+
return;
|
|
2581
|
+
}
|
|
2582
|
+
this._commitNode(value);
|
|
2583
|
+
}
|
|
2584
|
+
else if (isIterable(value)) {
|
|
2585
|
+
this._commitIterable(value);
|
|
2586
|
+
}
|
|
2587
|
+
else {
|
|
2588
|
+
// Fallback, will render the string representation
|
|
2589
|
+
this._commitText(value);
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
_insert(node) {
|
|
2593
|
+
return wrap(wrap(this._$startNode).parentNode).insertBefore(node, this._$endNode);
|
|
2594
|
+
}
|
|
2595
|
+
_commitNode(value) {
|
|
2596
|
+
if (this._$committedValue !== value) {
|
|
2597
|
+
this._$clear();
|
|
2598
|
+
if (sanitizerFactoryInternal !== noopSanitizer) {
|
|
2599
|
+
const parentNodeName = this._$startNode.parentNode?.nodeName;
|
|
2600
|
+
if (parentNodeName === 'STYLE' || parentNodeName === 'SCRIPT') {
|
|
2601
|
+
let message = 'Forbidden';
|
|
2602
|
+
{
|
|
2603
|
+
if (parentNodeName === 'STYLE') {
|
|
2604
|
+
message =
|
|
2605
|
+
`Lit does not support binding inside style nodes. ` +
|
|
2606
|
+
`This is a security risk, as style injection attacks can ` +
|
|
2607
|
+
`exfiltrate data and spoof UIs. ` +
|
|
2608
|
+
`Consider instead using css\`...\` literals ` +
|
|
2609
|
+
`to compose styles, and make do dynamic styling with ` +
|
|
2610
|
+
`css custom properties, ::parts, <slot>s, ` +
|
|
2611
|
+
`and by mutating the DOM rather than stylesheets.`;
|
|
2612
|
+
}
|
|
2613
|
+
else {
|
|
2614
|
+
message =
|
|
2615
|
+
`Lit does not support binding inside script nodes. ` +
|
|
2616
|
+
`This is a security risk, as it could allow arbitrary ` +
|
|
2617
|
+
`code execution.`;
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
throw new Error(message);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
debugLogEvent &&
|
|
2624
|
+
debugLogEvent({
|
|
2625
|
+
kind: 'commit node',
|
|
2626
|
+
start: this._$startNode,
|
|
2627
|
+
parent: this._$parent,
|
|
2628
|
+
value: value,
|
|
2629
|
+
options: this.options,
|
|
2630
|
+
});
|
|
2631
|
+
this._$committedValue = this._insert(value);
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
_commitText(value) {
|
|
2635
|
+
// If the committed value is a primitive it means we called _commitText on
|
|
2636
|
+
// the previous render, and we know that this._$startNode.nextSibling is a
|
|
2637
|
+
// Text node. We can now just replace the text content (.data) of the node.
|
|
2638
|
+
if (this._$committedValue !== nothing &&
|
|
2639
|
+
isPrimitive(this._$committedValue)) {
|
|
2640
|
+
const node = wrap(this._$startNode).nextSibling;
|
|
2641
|
+
{
|
|
2642
|
+
if (this._textSanitizer === undefined) {
|
|
2643
|
+
this._textSanitizer = createSanitizer(node, 'data', 'property');
|
|
2644
|
+
}
|
|
2645
|
+
value = this._textSanitizer(value);
|
|
2646
|
+
}
|
|
2647
|
+
debugLogEvent &&
|
|
2648
|
+
debugLogEvent({
|
|
2649
|
+
kind: 'commit text',
|
|
2650
|
+
node,
|
|
2651
|
+
value,
|
|
2652
|
+
options: this.options,
|
|
2653
|
+
});
|
|
2654
|
+
node.data = value;
|
|
2655
|
+
}
|
|
2656
|
+
else {
|
|
2657
|
+
{
|
|
2658
|
+
const textNode = d.createTextNode('');
|
|
2659
|
+
this._commitNode(textNode);
|
|
2660
|
+
// When setting text content, for security purposes it matters a lot
|
|
2661
|
+
// what the parent is. For example, <style> and <script> need to be
|
|
2662
|
+
// handled with care, while <span> does not. So first we need to put a
|
|
2663
|
+
// text node into the document, then we can sanitize its content.
|
|
2664
|
+
if (this._textSanitizer === undefined) {
|
|
2665
|
+
this._textSanitizer = createSanitizer(textNode, 'data', 'property');
|
|
2666
|
+
}
|
|
2667
|
+
value = this._textSanitizer(value);
|
|
2668
|
+
debugLogEvent &&
|
|
2669
|
+
debugLogEvent({
|
|
2670
|
+
kind: 'commit text',
|
|
2671
|
+
node: textNode,
|
|
2672
|
+
value,
|
|
2673
|
+
options: this.options,
|
|
2674
|
+
});
|
|
2675
|
+
textNode.data = value;
|
|
2676
|
+
}
|
|
2721
2677
|
}
|
|
2722
|
-
|
|
2723
|
-
this.__childPart = render(value, this.renderRoot, this.renderOptions);
|
|
2724
|
-
}
|
|
2725
|
-
/**
|
|
2726
|
-
* Invoked when the component is added to the document's DOM.
|
|
2727
|
-
*
|
|
2728
|
-
* In `connectedCallback()` you should setup tasks that should only occur when
|
|
2729
|
-
* the element is connected to the document. The most common of these is
|
|
2730
|
-
* adding event listeners to nodes external to the element, like a keydown
|
|
2731
|
-
* event handler added to the window.
|
|
2732
|
-
*
|
|
2733
|
-
* ```ts
|
|
2734
|
-
* connectedCallback() {
|
|
2735
|
-
* super.connectedCallback();
|
|
2736
|
-
* addEventListener('keydown', this._handleKeydown);
|
|
2737
|
-
* }
|
|
2738
|
-
* ```
|
|
2739
|
-
*
|
|
2740
|
-
* Typically, anything done in `connectedCallback()` should be undone when the
|
|
2741
|
-
* element is disconnected, in `disconnectedCallback()`.
|
|
2742
|
-
*
|
|
2743
|
-
* @category lifecycle
|
|
2744
|
-
*/
|
|
2745
|
-
connectedCallback() {
|
|
2746
|
-
super.connectedCallback();
|
|
2747
|
-
this.__childPart?.setConnected(true);
|
|
2748
|
-
}
|
|
2749
|
-
/**
|
|
2750
|
-
* Invoked when the component is removed from the document's DOM.
|
|
2751
|
-
*
|
|
2752
|
-
* This callback is the main signal to the element that it may no longer be
|
|
2753
|
-
* used. `disconnectedCallback()` should ensure that nothing is holding a
|
|
2754
|
-
* reference to the element (such as event listeners added to nodes external
|
|
2755
|
-
* to the element), so that it is free to be garbage collected.
|
|
2756
|
-
*
|
|
2757
|
-
* ```ts
|
|
2758
|
-
* disconnectedCallback() {
|
|
2759
|
-
* super.disconnectedCallback();
|
|
2760
|
-
* window.removeEventListener('keydown', this._handleKeydown);
|
|
2761
|
-
* }
|
|
2762
|
-
* ```
|
|
2763
|
-
*
|
|
2764
|
-
* An element may be re-connected after being disconnected.
|
|
2765
|
-
*
|
|
2766
|
-
* @category lifecycle
|
|
2767
|
-
*/
|
|
2768
|
-
disconnectedCallback() {
|
|
2769
|
-
super.disconnectedCallback();
|
|
2770
|
-
this.__childPart?.setConnected(false);
|
|
2678
|
+
this._$committedValue = value;
|
|
2771
2679
|
}
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2680
|
+
_commitTemplateResult(result) {
|
|
2681
|
+
// This property needs to remain unminified.
|
|
2682
|
+
const { values, ['_$litType$']: type } = result;
|
|
2683
|
+
// If $litType$ is a number, result is a plain TemplateResult and we get
|
|
2684
|
+
// the template from the template cache. If not, result is a
|
|
2685
|
+
// CompiledTemplateResult and _$litType$ is a CompiledTemplate and we need
|
|
2686
|
+
// to create the <template> element the first time we see it.
|
|
2687
|
+
const template = typeof type === 'number'
|
|
2688
|
+
? this._$getTemplate(result)
|
|
2689
|
+
: (type.el === undefined &&
|
|
2690
|
+
(type.el = Template.createElement(trustFromTemplateString(type.h, type.h[0]), this.options)),
|
|
2691
|
+
type);
|
|
2692
|
+
if (this._$committedValue?._$template === template) {
|
|
2693
|
+
debugLogEvent &&
|
|
2694
|
+
debugLogEvent({
|
|
2695
|
+
kind: 'template updating',
|
|
2696
|
+
template,
|
|
2697
|
+
instance: this._$committedValue,
|
|
2698
|
+
parts: this._$committedValue._$parts,
|
|
2699
|
+
options: this.options,
|
|
2700
|
+
values,
|
|
2701
|
+
});
|
|
2702
|
+
this._$committedValue._update(values);
|
|
2703
|
+
}
|
|
2704
|
+
else {
|
|
2705
|
+
const instance = new TemplateInstance(template, this);
|
|
2706
|
+
const fragment = instance._clone(this.options);
|
|
2707
|
+
debugLogEvent &&
|
|
2708
|
+
debugLogEvent({
|
|
2709
|
+
kind: 'template instantiated',
|
|
2710
|
+
template,
|
|
2711
|
+
instance,
|
|
2712
|
+
parts: instance._$parts,
|
|
2713
|
+
options: this.options,
|
|
2714
|
+
fragment,
|
|
2715
|
+
values,
|
|
2716
|
+
});
|
|
2717
|
+
instance._update(values);
|
|
2718
|
+
debugLogEvent &&
|
|
2719
|
+
debugLogEvent({
|
|
2720
|
+
kind: 'template instantiated and updated',
|
|
2721
|
+
template,
|
|
2722
|
+
instance,
|
|
2723
|
+
parts: instance._$parts,
|
|
2724
|
+
options: this.options,
|
|
2725
|
+
fragment,
|
|
2726
|
+
values,
|
|
2727
|
+
});
|
|
2728
|
+
this._commitNode(fragment);
|
|
2729
|
+
this._$committedValue = instance;
|
|
2730
|
+
}
|
|
2781
2731
|
}
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
* optimizations. See @lit/reactive-element for more information.
|
|
2791
|
-
*/
|
|
2792
|
-
LitElement[JSCompiler_renameProperty('finalized')] = true;
|
|
2793
|
-
// Install hydration if available
|
|
2794
|
-
globalThis.litElementHydrateSupport?.({ LitElement });
|
|
2795
|
-
// Apply polyfills if available
|
|
2796
|
-
const polyfillSupport = globalThis.litElementPolyfillSupportDevMode
|
|
2797
|
-
;
|
|
2798
|
-
polyfillSupport?.({ LitElement });
|
|
2799
|
-
// IMPORTANT: do not change the property name or the assignment expression.
|
|
2800
|
-
// This line will be used in regexes to search for LitElement usage.
|
|
2801
|
-
(globalThis.litElementVersions ??= []).push('4.0.6');
|
|
2802
|
-
if (globalThis.litElementVersions.length > 1) {
|
|
2803
|
-
issueWarning$2('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
|
|
2804
|
-
`is not recommended.`);
|
|
2805
|
-
}
|
|
2806
|
-
|
|
2807
|
-
/**
|
|
2808
|
-
* @typedef {import('./types.js').ScopedElementsHost} ScopedElementsHost
|
|
2809
|
-
* @typedef {import('./types.js').ScopedElementsMap} ScopedElementsMap
|
|
2810
|
-
*/
|
|
2811
|
-
|
|
2812
|
-
const version = '3.0.0';
|
|
2813
|
-
const versions = window.scopedElementsVersions || (window.scopedElementsVersions = []);
|
|
2814
|
-
if (!versions.includes(version)) {
|
|
2815
|
-
versions.push(version);
|
|
2816
|
-
}
|
|
2817
|
-
|
|
2818
|
-
/**
|
|
2819
|
-
* @template {import('./types.js').Constructor<HTMLElement>} T
|
|
2820
|
-
* @param {T} superclass
|
|
2821
|
-
* @return {T & import('./types.js').Constructor<ScopedElementsHost>}
|
|
2822
|
-
*/
|
|
2823
|
-
const ScopedElementsMixinImplementation$1 = superclass =>
|
|
2824
|
-
/** @type {ScopedElementsHost} */
|
|
2825
|
-
class ScopedElementsHost extends superclass {
|
|
2826
|
-
/**
|
|
2827
|
-
* Obtains the scoped elements definitions map if specified.
|
|
2828
|
-
*
|
|
2829
|
-
* @type {ScopedElementsMap=}
|
|
2830
|
-
*/
|
|
2831
|
-
static scopedElements;
|
|
2832
|
-
|
|
2833
|
-
static get scopedElementsVersion() {
|
|
2834
|
-
return version;
|
|
2732
|
+
// Overridden via `litHtmlPolyfillSupport` to provide platform support.
|
|
2733
|
+
/** @internal */
|
|
2734
|
+
_$getTemplate(result) {
|
|
2735
|
+
let template = templateCache.get(result.strings);
|
|
2736
|
+
if (template === undefined) {
|
|
2737
|
+
templateCache.set(result.strings, (template = new Template(result)));
|
|
2738
|
+
}
|
|
2739
|
+
return template;
|
|
2835
2740
|
}
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2741
|
+
_commitIterable(value) {
|
|
2742
|
+
// For an Iterable, we create a new InstancePart per item, then set its
|
|
2743
|
+
// value to the item. This is a little bit of overhead for every item in
|
|
2744
|
+
// an Iterable, but it lets us recurse easily and efficiently update Arrays
|
|
2745
|
+
// of TemplateResults that will be commonly returned from expressions like:
|
|
2746
|
+
// array.map((i) => html`${i}`), by reusing existing TemplateInstances.
|
|
2747
|
+
// If value is an array, then the previous render was of an
|
|
2748
|
+
// iterable and value will contain the ChildParts from the previous
|
|
2749
|
+
// render. If value is not an array, clear this part and make a new
|
|
2750
|
+
// array for ChildParts.
|
|
2751
|
+
if (!isArray(this._$committedValue)) {
|
|
2752
|
+
this._$committedValue = [];
|
|
2753
|
+
this._$clear();
|
|
2754
|
+
}
|
|
2755
|
+
// Lets us keep track of how many items we stamped so we can clear leftover
|
|
2756
|
+
// items from a previous render
|
|
2757
|
+
const itemParts = this._$committedValue;
|
|
2758
|
+
let partIndex = 0;
|
|
2759
|
+
let itemPart;
|
|
2760
|
+
for (const item of value) {
|
|
2761
|
+
if (partIndex === itemParts.length) {
|
|
2762
|
+
// If no existing part, create a new one
|
|
2763
|
+
// TODO (justinfagnani): test perf impact of always creating two parts
|
|
2764
|
+
// instead of sharing parts between nodes
|
|
2765
|
+
// https://github.com/lit/lit/issues/1266
|
|
2766
|
+
itemParts.push((itemPart = new ChildPart(this._insert(createMarker()), this._insert(createMarker()), this, this.options)));
|
|
2767
|
+
}
|
|
2768
|
+
else {
|
|
2769
|
+
// Reuse an existing part
|
|
2770
|
+
itemPart = itemParts[partIndex];
|
|
2771
|
+
}
|
|
2772
|
+
itemPart._$setValue(item);
|
|
2773
|
+
partIndex++;
|
|
2774
|
+
}
|
|
2775
|
+
if (partIndex < itemParts.length) {
|
|
2776
|
+
// itemParts always have end nodes
|
|
2777
|
+
this._$clear(itemPart && wrap(itemPart._$endNode).nextSibling, partIndex);
|
|
2778
|
+
// Truncate the parts array so _value reflects the current state
|
|
2779
|
+
itemParts.length = partIndex;
|
|
2780
|
+
}
|
|
2847
2781
|
}
|
|
2848
|
-
|
|
2849
2782
|
/**
|
|
2850
|
-
*
|
|
2783
|
+
* Removes the nodes contained within this Part from the DOM.
|
|
2851
2784
|
*
|
|
2852
|
-
* @param
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
// @ts-ignore
|
|
2868
|
-
(this.registry === this.constructor.__registry &&
|
|
2869
|
-
!Object.prototype.hasOwnProperty.call(this.constructor, '__registry'));
|
|
2870
|
-
|
|
2871
|
-
/**
|
|
2872
|
-
* Create a new registry if:
|
|
2873
|
-
* - the registry is not defined
|
|
2874
|
-
* - this class doesn't have its own registry *AND* has no shared registry
|
|
2875
|
-
* This is important specifically for superclasses/inheritance
|
|
2876
|
-
*/
|
|
2877
|
-
if (shouldCreateRegistry) {
|
|
2878
|
-
this.registry = new CustomElementRegistry();
|
|
2879
|
-
for (const [tagName, klass] of Object.entries(scopedElements ?? {})) {
|
|
2880
|
-
this.registry.define(tagName, klass);
|
|
2881
|
-
}
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
|
-
return super.attachShadow({
|
|
2885
|
-
...options,
|
|
2886
|
-
// The polyfill currently expects the registry to be passed as `customElements`
|
|
2887
|
-
customElements: this.registry,
|
|
2888
|
-
// But the proposal has moved forward, and renamed it to `registry`
|
|
2889
|
-
// For backwards compatibility, we pass it as both
|
|
2890
|
-
registry: this.registry,
|
|
2891
|
-
});
|
|
2892
|
-
}
|
|
2893
|
-
};
|
|
2894
|
-
|
|
2895
|
-
const ScopedElementsMixin$1 = dedupeMixin(ScopedElementsMixinImplementation$1);
|
|
2896
|
-
|
|
2897
|
-
/**
|
|
2898
|
-
* @typedef {import('./types.js').ScopedElementsHost} ScopedElementsHost
|
|
2899
|
-
* @typedef {import('./types.js').ScopedElementsMap} ScopedElementsMap
|
|
2900
|
-
* @typedef {import('lit').CSSResultOrNative} CSSResultOrNative
|
|
2901
|
-
* @typedef {import('lit').LitElement} LitElement
|
|
2902
|
-
* @typedef {typeof import('lit').LitElement} TypeofLitElement
|
|
2903
|
-
* @typedef {import('@open-wc/dedupe-mixin').Constructor<LitElement>} LitElementConstructor
|
|
2904
|
-
* @typedef {import('@open-wc/dedupe-mixin').Constructor<ScopedElementsHost>} ScopedElementsHostConstructor
|
|
2905
|
-
*/
|
|
2906
|
-
|
|
2907
|
-
/**
|
|
2908
|
-
* @template {LitElementConstructor} T
|
|
2909
|
-
* @param {T} superclass
|
|
2910
|
-
* @return {T & ScopedElementsHostConstructor}
|
|
2911
|
-
*/
|
|
2912
|
-
const ScopedElementsMixinImplementation = superclass =>
|
|
2913
|
-
/** @type {ScopedElementsHost} */
|
|
2914
|
-
class ScopedElementsHost extends ScopedElementsMixin$1(superclass) {
|
|
2915
|
-
createRenderRoot() {
|
|
2916
|
-
const { shadowRootOptions, elementStyles } = /** @type {TypeofLitElement} */ (
|
|
2917
|
-
this.constructor
|
|
2918
|
-
);
|
|
2919
|
-
|
|
2920
|
-
const shadowRoot = this.attachShadow(shadowRootOptions);
|
|
2921
|
-
// @ts-ignore
|
|
2922
|
-
this.renderOptions.creationScope = shadowRoot;
|
|
2923
|
-
|
|
2924
|
-
adoptStyles(shadowRoot, elementStyles);
|
|
2925
|
-
|
|
2926
|
-
this.renderOptions.renderBefore ??= shadowRoot.firstChild;
|
|
2927
|
-
|
|
2928
|
-
return shadowRoot;
|
|
2785
|
+
* @param start Start node to clear from, for clearing a subset of the part's
|
|
2786
|
+
* DOM (used when truncating iterables)
|
|
2787
|
+
* @param from When `start` is specified, the index within the iterable from
|
|
2788
|
+
* which ChildParts are being removed, used for disconnecting directives in
|
|
2789
|
+
* those Parts.
|
|
2790
|
+
*
|
|
2791
|
+
* @internal
|
|
2792
|
+
*/
|
|
2793
|
+
_$clear(start = wrap(this._$startNode).nextSibling, from) {
|
|
2794
|
+
this._$notifyConnectionChanged?.(false, true, from);
|
|
2795
|
+
while (start && start !== this._$endNode) {
|
|
2796
|
+
const n = wrap(start).nextSibling;
|
|
2797
|
+
wrap(start).remove();
|
|
2798
|
+
start = n;
|
|
2799
|
+
}
|
|
2929
2800
|
}
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
issueWarning$1 = (code, warning) => {
|
|
2946
|
-
warning += ` See https://lit.dev/msg/${code} for more information.`;
|
|
2947
|
-
if (!issuedWarnings.has(warning)) {
|
|
2948
|
-
console.warn(warning);
|
|
2949
|
-
issuedWarnings.add(warning);
|
|
2801
|
+
/**
|
|
2802
|
+
* Implementation of RootPart's `isConnected`. Note that this metod
|
|
2803
|
+
* should only be called on `RootPart`s (the `ChildPart` returned from a
|
|
2804
|
+
* top-level `render()` call). It has no effect on non-root ChildParts.
|
|
2805
|
+
* @param isConnected Whether to set
|
|
2806
|
+
* @internal
|
|
2807
|
+
*/
|
|
2808
|
+
setConnected(isConnected) {
|
|
2809
|
+
if (this._$parent === undefined) {
|
|
2810
|
+
this.__isConnected = isConnected;
|
|
2811
|
+
this._$notifyConnectionChanged?.(isConnected);
|
|
2812
|
+
}
|
|
2813
|
+
else {
|
|
2814
|
+
throw new Error('part.setConnected() may only be called on a ' +
|
|
2815
|
+
'RootPart returned from render().');
|
|
2950
2816
|
}
|
|
2951
|
-
};
|
|
2952
|
-
}
|
|
2953
|
-
const legacyProperty = (options, proto, name) => {
|
|
2954
|
-
const hasOwnProperty = proto.hasOwnProperty(name);
|
|
2955
|
-
proto.constructor.createProperty(name, hasOwnProperty ? { ...options, wrapped: true } : options);
|
|
2956
|
-
// For accessors (which have a descriptor on the prototype) we need to
|
|
2957
|
-
// return a descriptor, otherwise TypeScript overwrites the descriptor we
|
|
2958
|
-
// define in createProperty() with the original descriptor. We don't do this
|
|
2959
|
-
// for fields, which don't have a descriptor, because this could overwrite
|
|
2960
|
-
// descriptor defined by other decorators.
|
|
2961
|
-
return hasOwnProperty
|
|
2962
|
-
? Object.getOwnPropertyDescriptor(proto, name)
|
|
2963
|
-
: undefined;
|
|
2964
|
-
};
|
|
2965
|
-
// This is duplicated from a similar variable in reactive-element.ts, but
|
|
2966
|
-
// actually makes sense to have this default defined with the decorator, so
|
|
2967
|
-
// that different decorators could have different defaults.
|
|
2968
|
-
const defaultPropertyDeclaration = {
|
|
2969
|
-
attribute: true,
|
|
2970
|
-
type: String,
|
|
2971
|
-
converter: defaultConverter,
|
|
2972
|
-
reflect: false,
|
|
2973
|
-
hasChanged: notEqual,
|
|
2974
|
-
};
|
|
2975
|
-
/**
|
|
2976
|
-
* Wraps a class accessor or setter so that `requestUpdate()` is called with the
|
|
2977
|
-
* property name and old value when the accessor is set.
|
|
2978
|
-
*/
|
|
2979
|
-
const standardProperty = (options = defaultPropertyDeclaration, target, context) => {
|
|
2980
|
-
const { kind, metadata } = context;
|
|
2981
|
-
if (metadata == null) {
|
|
2982
|
-
issueWarning$1('missing-class-metadata', `The class ${target} is missing decorator metadata. This ` +
|
|
2983
|
-
`could mean that you're using a compiler that supports decorators ` +
|
|
2984
|
-
`but doesn't support decorator metadata, such as TypeScript 5.1. ` +
|
|
2985
|
-
`Please update your compiler.`);
|
|
2986
2817
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2818
|
+
}
|
|
2819
|
+
class AttributePart {
|
|
2820
|
+
get tagName() {
|
|
2821
|
+
return this.element.tagName;
|
|
2991
2822
|
}
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
// replace a field with accessors. The user must use the new `accessor`
|
|
2996
|
-
// keyword instead.
|
|
2997
|
-
const { name } = context;
|
|
2998
|
-
return {
|
|
2999
|
-
set(v) {
|
|
3000
|
-
const oldValue = target.get.call(this);
|
|
3001
|
-
target.set.call(this, v);
|
|
3002
|
-
this.requestUpdate(name, oldValue, options);
|
|
3003
|
-
},
|
|
3004
|
-
init(v) {
|
|
3005
|
-
if (v !== undefined) {
|
|
3006
|
-
this._$changeProperty(name, undefined, options);
|
|
3007
|
-
}
|
|
3008
|
-
return v;
|
|
3009
|
-
},
|
|
3010
|
-
};
|
|
2823
|
+
// See comment in Disconnectable interface for why this is a getter
|
|
2824
|
+
get _$isConnected() {
|
|
2825
|
+
return this._$parent._$isConnected;
|
|
3011
2826
|
}
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
2827
|
+
constructor(element, name, strings, parent, options) {
|
|
2828
|
+
this.type = ATTRIBUTE_PART;
|
|
2829
|
+
/** @internal */
|
|
2830
|
+
this._$committedValue = nothing;
|
|
2831
|
+
/** @internal */
|
|
2832
|
+
this._$disconnectableChildren = undefined;
|
|
2833
|
+
this.element = element;
|
|
2834
|
+
this.name = name;
|
|
2835
|
+
this._$parent = parent;
|
|
2836
|
+
this.options = options;
|
|
2837
|
+
if (strings.length > 2 || strings[0] !== '' || strings[1] !== '') {
|
|
2838
|
+
this._$committedValue = new Array(strings.length - 1).fill(new String());
|
|
2839
|
+
this.strings = strings;
|
|
2840
|
+
}
|
|
2841
|
+
else {
|
|
2842
|
+
this._$committedValue = nothing;
|
|
2843
|
+
}
|
|
2844
|
+
{
|
|
2845
|
+
this._sanitizer = undefined;
|
|
2846
|
+
}
|
|
3019
2847
|
}
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
if (
|
|
3084
|
-
// We check for Reflect.decorate each time, in case the zombiefill
|
|
3085
|
-
// is applied via lazy loading some Angular code.
|
|
3086
|
-
Reflect.decorate &&
|
|
3087
|
-
typeof name !== 'object') {
|
|
3088
|
-
// If we're called as a legacy decorator, and Reflect.decorate is present
|
|
3089
|
-
// then we have no guarantees that the returned descriptor will be
|
|
3090
|
-
// defined on the class, so we must apply it directly ourselves.
|
|
3091
|
-
Object.defineProperty(obj, name, descriptor);
|
|
2848
|
+
/**
|
|
2849
|
+
* Sets the value of this part by resolving the value from possibly multiple
|
|
2850
|
+
* values and static strings and committing it to the DOM.
|
|
2851
|
+
* If this part is single-valued, `this._strings` will be undefined, and the
|
|
2852
|
+
* method will be called with a single value argument. If this part is
|
|
2853
|
+
* multi-value, `this._strings` will be defined, and the method is called
|
|
2854
|
+
* with the value array of the part's owning TemplateInstance, and an offset
|
|
2855
|
+
* into the value array from which the values should be read.
|
|
2856
|
+
* This method is overloaded this way to eliminate short-lived array slices
|
|
2857
|
+
* of the template instance values, and allow a fast-path for single-valued
|
|
2858
|
+
* parts.
|
|
2859
|
+
*
|
|
2860
|
+
* @param value The part value, or an array of values for multi-valued parts
|
|
2861
|
+
* @param valueIndex the index to start reading values from. `undefined` for
|
|
2862
|
+
* single-valued parts
|
|
2863
|
+
* @param noCommit causes the part to not commit its value to the DOM. Used
|
|
2864
|
+
* in hydration to prime attribute parts with their first-rendered value,
|
|
2865
|
+
* but not set the attribute, and in SSR to no-op the DOM operation and
|
|
2866
|
+
* capture the value for serialization.
|
|
2867
|
+
*
|
|
2868
|
+
* @internal
|
|
2869
|
+
*/
|
|
2870
|
+
_$setValue(value, directiveParent = this, valueIndex, noCommit) {
|
|
2871
|
+
const strings = this.strings;
|
|
2872
|
+
// Whether any of the values has changed, for dirty-checking
|
|
2873
|
+
let change = false;
|
|
2874
|
+
if (strings === undefined) {
|
|
2875
|
+
// Single-value binding case
|
|
2876
|
+
value = resolveDirective(this, value, directiveParent, 0);
|
|
2877
|
+
change =
|
|
2878
|
+
!isPrimitive(value) ||
|
|
2879
|
+
(value !== this._$committedValue && value !== noChange);
|
|
2880
|
+
if (change) {
|
|
2881
|
+
this._$committedValue = value;
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
else {
|
|
2885
|
+
// Interpolation case
|
|
2886
|
+
const values = value;
|
|
2887
|
+
value = strings[0];
|
|
2888
|
+
let i, v;
|
|
2889
|
+
for (i = 0; i < strings.length - 1; i++) {
|
|
2890
|
+
v = resolveDirective(this, values[valueIndex + i], directiveParent, i);
|
|
2891
|
+
if (v === noChange) {
|
|
2892
|
+
// If the user-provided value is `noChange`, use the previous value
|
|
2893
|
+
v = this._$committedValue[i];
|
|
2894
|
+
}
|
|
2895
|
+
change ||=
|
|
2896
|
+
!isPrimitive(v) || v !== this._$committedValue[i];
|
|
2897
|
+
if (v === nothing) {
|
|
2898
|
+
value = nothing;
|
|
2899
|
+
}
|
|
2900
|
+
else if (value !== nothing) {
|
|
2901
|
+
value += (v ?? '') + strings[i + 1];
|
|
2902
|
+
}
|
|
2903
|
+
// We always record each value, even if one is `nothing`, for future
|
|
2904
|
+
// change detection.
|
|
2905
|
+
this._$committedValue[i] = v;
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
if (change && !noCommit) {
|
|
2909
|
+
this._commitValue(value);
|
|
2910
|
+
}
|
|
3092
2911
|
}
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
* @license
|
|
3098
|
-
* Copyright 2017 Google LLC
|
|
3099
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
3100
|
-
*/
|
|
3101
|
-
let issueWarning;
|
|
3102
|
-
{
|
|
3103
|
-
// Ensure warnings are issued only 1x, even if multiple versions of Lit
|
|
3104
|
-
// are loaded.
|
|
3105
|
-
const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
|
|
3106
|
-
// Issue a warning, if we haven't already.
|
|
3107
|
-
issueWarning = (code, warning) => {
|
|
3108
|
-
warning += code
|
|
3109
|
-
? ` See https://lit.dev/msg/${code} for more information.`
|
|
3110
|
-
: '';
|
|
3111
|
-
if (!issuedWarnings.has(warning)) {
|
|
3112
|
-
console.warn(warning);
|
|
3113
|
-
issuedWarnings.add(warning);
|
|
2912
|
+
/** @internal */
|
|
2913
|
+
_commitValue(value) {
|
|
2914
|
+
if (value === nothing) {
|
|
2915
|
+
wrap(this.element).removeAttribute(this.name);
|
|
3114
2916
|
}
|
|
3115
|
-
|
|
2917
|
+
else {
|
|
2918
|
+
{
|
|
2919
|
+
if (this._sanitizer === undefined) {
|
|
2920
|
+
this._sanitizer = sanitizerFactoryInternal(this.element, this.name, 'attribute');
|
|
2921
|
+
}
|
|
2922
|
+
value = this._sanitizer(value ?? '');
|
|
2923
|
+
}
|
|
2924
|
+
debugLogEvent &&
|
|
2925
|
+
debugLogEvent({
|
|
2926
|
+
kind: 'commit attribute',
|
|
2927
|
+
element: this.element,
|
|
2928
|
+
name: this.name,
|
|
2929
|
+
value,
|
|
2930
|
+
options: this.options,
|
|
2931
|
+
});
|
|
2932
|
+
wrap(this.element).setAttribute(this.name, (value ?? ''));
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
3116
2935
|
}
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
* ```ts
|
|
3128
|
-
* class MyElement {
|
|
3129
|
-
* @query('#first')
|
|
3130
|
-
* first: HTMLDivElement;
|
|
3131
|
-
*
|
|
3132
|
-
* render() {
|
|
3133
|
-
* return html`
|
|
3134
|
-
* <div id="first"></div>
|
|
3135
|
-
* <div id="second"></div>
|
|
3136
|
-
* `;
|
|
3137
|
-
* }
|
|
3138
|
-
* }
|
|
3139
|
-
* ```
|
|
3140
|
-
* @category Decorator
|
|
3141
|
-
*/
|
|
3142
|
-
function query(selector, cache) {
|
|
3143
|
-
return ((protoOrTarget, nameOrContext, descriptor) => {
|
|
3144
|
-
const doQuery = (el) => {
|
|
3145
|
-
const result = (el.renderRoot?.querySelector(selector) ?? null);
|
|
3146
|
-
if (result === null && cache && !el.hasUpdated) {
|
|
3147
|
-
const name = typeof nameOrContext === 'object'
|
|
3148
|
-
? nameOrContext.name
|
|
3149
|
-
: nameOrContext;
|
|
3150
|
-
issueWarning('', `@query'd field ${JSON.stringify(String(name))} with the 'cache' ` +
|
|
3151
|
-
`flag set for selector '${selector}' has been accessed before ` +
|
|
3152
|
-
`the first update and returned null. This is expected if the ` +
|
|
3153
|
-
`renderRoot tree has not been provided beforehand (e.g. via ` +
|
|
3154
|
-
`Declarative Shadow DOM). Therefore the value hasn't been cached.`);
|
|
2936
|
+
class PropertyPart extends AttributePart {
|
|
2937
|
+
constructor() {
|
|
2938
|
+
super(...arguments);
|
|
2939
|
+
this.type = PROPERTY_PART;
|
|
2940
|
+
}
|
|
2941
|
+
/** @internal */
|
|
2942
|
+
_commitValue(value) {
|
|
2943
|
+
{
|
|
2944
|
+
if (this._sanitizer === undefined) {
|
|
2945
|
+
this._sanitizer = sanitizerFactoryInternal(this.element, this.name, 'property');
|
|
3155
2946
|
}
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
2947
|
+
value = this._sanitizer(value);
|
|
2948
|
+
}
|
|
2949
|
+
debugLogEvent &&
|
|
2950
|
+
debugLogEvent({
|
|
2951
|
+
kind: 'commit property',
|
|
2952
|
+
element: this.element,
|
|
2953
|
+
name: this.name,
|
|
2954
|
+
value,
|
|
2955
|
+
options: this.options,
|
|
2956
|
+
});
|
|
2957
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2958
|
+
this.element[this.name] = value === nothing ? undefined : value;
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
class BooleanAttributePart extends AttributePart {
|
|
2962
|
+
constructor() {
|
|
2963
|
+
super(...arguments);
|
|
2964
|
+
this.type = BOOLEAN_ATTRIBUTE_PART;
|
|
2965
|
+
}
|
|
2966
|
+
/** @internal */
|
|
2967
|
+
_commitValue(value) {
|
|
2968
|
+
debugLogEvent &&
|
|
2969
|
+
debugLogEvent({
|
|
2970
|
+
kind: 'commit boolean attribute',
|
|
2971
|
+
element: this.element,
|
|
2972
|
+
name: this.name,
|
|
2973
|
+
value: !!(value && value !== nothing),
|
|
2974
|
+
options: this.options,
|
|
2975
|
+
});
|
|
2976
|
+
wrap(this.element).toggleAttribute(this.name, !!value && value !== nothing);
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
class EventPart extends AttributePart {
|
|
2980
|
+
constructor(element, name, strings, parent, options) {
|
|
2981
|
+
super(element, name, strings, parent, options);
|
|
2982
|
+
this.type = EVENT_PART;
|
|
2983
|
+
if (this.strings !== undefined) {
|
|
2984
|
+
throw new Error(`A \`<${element.localName}>\` has a \`@${name}=...\` listener with ` +
|
|
2985
|
+
'invalid content. Event listeners in templates must have exactly ' +
|
|
2986
|
+
'one expression and no surrounding text.');
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
// EventPart does not use the base _$setValue/_resolveValue implementation
|
|
2990
|
+
// since the dirty checking is more complex
|
|
2991
|
+
/** @internal */
|
|
2992
|
+
_$setValue(newListener, directiveParent = this) {
|
|
2993
|
+
newListener =
|
|
2994
|
+
resolveDirective(this, newListener, directiveParent, 0) ?? nothing;
|
|
2995
|
+
if (newListener === noChange) {
|
|
2996
|
+
return;
|
|
2997
|
+
}
|
|
2998
|
+
const oldListener = this._$committedValue;
|
|
2999
|
+
// If the new value is nothing or any options change we have to remove the
|
|
3000
|
+
// part as a listener.
|
|
3001
|
+
const shouldRemoveListener = (newListener === nothing && oldListener !== nothing) ||
|
|
3002
|
+
newListener.capture !==
|
|
3003
|
+
oldListener.capture ||
|
|
3004
|
+
newListener.once !==
|
|
3005
|
+
oldListener.once ||
|
|
3006
|
+
newListener.passive !==
|
|
3007
|
+
oldListener.passive;
|
|
3008
|
+
// If the new value is not nothing and we removed the listener, we have
|
|
3009
|
+
// to add the part as a listener.
|
|
3010
|
+
const shouldAddListener = newListener !== nothing &&
|
|
3011
|
+
(oldListener === nothing || shouldRemoveListener);
|
|
3012
|
+
debugLogEvent &&
|
|
3013
|
+
debugLogEvent({
|
|
3014
|
+
kind: 'commit event listener',
|
|
3015
|
+
element: this.element,
|
|
3016
|
+
name: this.name,
|
|
3017
|
+
value: newListener,
|
|
3018
|
+
options: this.options,
|
|
3019
|
+
removeListener: shouldRemoveListener,
|
|
3020
|
+
addListener: shouldAddListener,
|
|
3021
|
+
oldListener,
|
|
3194
3022
|
});
|
|
3023
|
+
if (shouldRemoveListener) {
|
|
3024
|
+
this.element.removeEventListener(this.name, this, oldListener);
|
|
3025
|
+
}
|
|
3026
|
+
if (shouldAddListener) {
|
|
3027
|
+
// Beware: IE11 and Chrome 41 don't like using the listener as the
|
|
3028
|
+
// options object. Figure out how to deal w/ this in IE11 - maybe
|
|
3029
|
+
// patch addEventListener?
|
|
3030
|
+
this.element.addEventListener(this.name, this, newListener);
|
|
3031
|
+
}
|
|
3032
|
+
this._$committedValue = newListener;
|
|
3033
|
+
}
|
|
3034
|
+
handleEvent(event) {
|
|
3035
|
+
if (typeof this._$committedValue === 'function') {
|
|
3036
|
+
this._$committedValue.call(this.options?.host ?? this.element, event);
|
|
3195
3037
|
}
|
|
3196
3038
|
else {
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3039
|
+
this._$committedValue.handleEvent(event);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
class ElementPart {
|
|
3044
|
+
constructor(element, parent, options) {
|
|
3045
|
+
this.element = element;
|
|
3046
|
+
this.type = ELEMENT_PART;
|
|
3047
|
+
/** @internal */
|
|
3048
|
+
this._$disconnectableChildren = undefined;
|
|
3049
|
+
this._$parent = parent;
|
|
3050
|
+
this.options = options;
|
|
3051
|
+
}
|
|
3052
|
+
// See comment in Disconnectable interface for why this is a getter
|
|
3053
|
+
get _$isConnected() {
|
|
3054
|
+
return this._$parent._$isConnected;
|
|
3055
|
+
}
|
|
3056
|
+
_$setValue(value) {
|
|
3057
|
+
debugLogEvent &&
|
|
3058
|
+
debugLogEvent({
|
|
3059
|
+
kind: 'commit to element binding',
|
|
3060
|
+
element: this.element,
|
|
3061
|
+
value,
|
|
3062
|
+
options: this.options,
|
|
3203
3063
|
});
|
|
3204
|
-
|
|
3205
|
-
}
|
|
3064
|
+
resolveDirective(this, value);
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
// Apply polyfills if available
|
|
3068
|
+
const polyfillSupport$1 = global.litHtmlPolyfillSupportDevMode
|
|
3069
|
+
;
|
|
3070
|
+
polyfillSupport$1?.(Template, ChildPart);
|
|
3071
|
+
// IMPORTANT: do not change the property name or the assignment expression.
|
|
3072
|
+
// This line will be used in regexes to search for lit-html usage.
|
|
3073
|
+
(global.litHtmlVersions ??= []).push('3.1.4');
|
|
3074
|
+
if (global.litHtmlVersions.length > 1) {
|
|
3075
|
+
issueWarning$1('multiple-versions', `Multiple versions of Lit loaded. ` +
|
|
3076
|
+
`Loading multiple versions is not recommended.`);
|
|
3077
|
+
}
|
|
3078
|
+
/**
|
|
3079
|
+
* Renders a value, usually a lit-html TemplateResult, to the container.
|
|
3080
|
+
*
|
|
3081
|
+
* This example renders the text "Hello, Zoe!" inside a paragraph tag, appending
|
|
3082
|
+
* it to the container `document.body`.
|
|
3083
|
+
*
|
|
3084
|
+
* ```js
|
|
3085
|
+
* import {html, render} from 'lit';
|
|
3086
|
+
*
|
|
3087
|
+
* const name = "Zoe";
|
|
3088
|
+
* render(html`<p>Hello, ${name}!</p>`, document.body);
|
|
3089
|
+
* ```
|
|
3090
|
+
*
|
|
3091
|
+
* @param value Any [renderable
|
|
3092
|
+
* value](https://lit.dev/docs/templates/expressions/#child-expressions),
|
|
3093
|
+
* typically a {@linkcode TemplateResult} created by evaluating a template tag
|
|
3094
|
+
* like {@linkcode html} or {@linkcode svg}.
|
|
3095
|
+
* @param container A DOM container to render to. The first render will append
|
|
3096
|
+
* the rendered value to the container, and subsequent renders will
|
|
3097
|
+
* efficiently update the rendered value if the same result type was
|
|
3098
|
+
* previously rendered there.
|
|
3099
|
+
* @param options See {@linkcode RenderOptions} for options documentation.
|
|
3100
|
+
* @see
|
|
3101
|
+
* {@link https://lit.dev/docs/libraries/standalone-templates/#rendering-lit-html-templates| Rendering Lit HTML Templates}
|
|
3102
|
+
*/
|
|
3103
|
+
const render = (value, container, options) => {
|
|
3104
|
+
if (container == null) {
|
|
3105
|
+
// Give a clearer error message than
|
|
3106
|
+
// Uncaught TypeError: Cannot read properties of null (reading
|
|
3107
|
+
// '_$litPart$')
|
|
3108
|
+
// which reads like an internal Lit error.
|
|
3109
|
+
throw new TypeError(`The container to render into may not be ${container}`);
|
|
3110
|
+
}
|
|
3111
|
+
const renderId = debugLogRenderId++ ;
|
|
3112
|
+
const partOwnerNode = options?.renderBefore ?? container;
|
|
3113
|
+
// This property needs to remain unminified.
|
|
3114
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3115
|
+
let part = partOwnerNode['_$litPart$'];
|
|
3116
|
+
debugLogEvent &&
|
|
3117
|
+
debugLogEvent({
|
|
3118
|
+
kind: 'begin render',
|
|
3119
|
+
id: renderId,
|
|
3120
|
+
value,
|
|
3121
|
+
container,
|
|
3122
|
+
options,
|
|
3123
|
+
part,
|
|
3124
|
+
});
|
|
3125
|
+
if (part === undefined) {
|
|
3126
|
+
const endNode = options?.renderBefore ?? null;
|
|
3127
|
+
// This property needs to remain unminified.
|
|
3128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3129
|
+
partOwnerNode['_$litPart$'] = part = new ChildPart(container.insertBefore(createMarker(), endNode), endNode, undefined, options ?? {});
|
|
3130
|
+
}
|
|
3131
|
+
part._$setValue(value);
|
|
3132
|
+
debugLogEvent &&
|
|
3133
|
+
debugLogEvent({
|
|
3134
|
+
kind: 'end render',
|
|
3135
|
+
id: renderId,
|
|
3136
|
+
value,
|
|
3137
|
+
container,
|
|
3138
|
+
options,
|
|
3139
|
+
part,
|
|
3140
|
+
});
|
|
3141
|
+
return part;
|
|
3142
|
+
};
|
|
3143
|
+
{
|
|
3144
|
+
render.setSanitizer = setSanitizer;
|
|
3145
|
+
render.createSanitizer = createSanitizer;
|
|
3146
|
+
{
|
|
3147
|
+
render._testOnlyClearSanitizerFactoryDoNotCallOrElse =
|
|
3148
|
+
_testOnlyClearSanitizerFactoryDoNotCallOrElse;
|
|
3149
|
+
}
|
|
3206
3150
|
}
|
|
3207
3151
|
|
|
3208
3152
|
/**
|
|
@@ -3893,6 +3837,164 @@
|
|
|
3893
3837
|
*/
|
|
3894
3838
|
const html = withStatic(html$1);
|
|
3895
3839
|
|
|
3840
|
+
/**
|
|
3841
|
+
* @license
|
|
3842
|
+
* Copyright 2017 Google LLC
|
|
3843
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
3844
|
+
*/
|
|
3845
|
+
/*
|
|
3846
|
+
* When using Closure Compiler, JSCompiler_renameProperty(property, object) is
|
|
3847
|
+
* replaced at compile time by the munged name for object[property]. We cannot
|
|
3848
|
+
* alias this function, so we have to use a small shim that has the same
|
|
3849
|
+
* behavior when not compiling.
|
|
3850
|
+
*/
|
|
3851
|
+
/*@__INLINE__*/
|
|
3852
|
+
const JSCompiler_renameProperty = (prop, _obj) => prop;
|
|
3853
|
+
let issueWarning;
|
|
3854
|
+
{
|
|
3855
|
+
// Ensure warnings are issued only 1x, even if multiple versions of Lit
|
|
3856
|
+
// are loaded.
|
|
3857
|
+
const issuedWarnings = (globalThis.litIssuedWarnings ??= new Set());
|
|
3858
|
+
// Issue a warning, if we haven't already.
|
|
3859
|
+
issueWarning = (code, warning) => {
|
|
3860
|
+
warning += ` See https://lit.dev/msg/${code} for more information.`;
|
|
3861
|
+
if (!issuedWarnings.has(warning)) {
|
|
3862
|
+
console.warn(warning);
|
|
3863
|
+
issuedWarnings.add(warning);
|
|
3864
|
+
}
|
|
3865
|
+
};
|
|
3866
|
+
}
|
|
3867
|
+
/**
|
|
3868
|
+
* Base element class that manages element properties and attributes, and
|
|
3869
|
+
* renders a lit-html template.
|
|
3870
|
+
*
|
|
3871
|
+
* To define a component, subclass `LitElement` and implement a
|
|
3872
|
+
* `render` method to provide the component's template. Define properties
|
|
3873
|
+
* using the {@linkcode LitElement.properties properties} property or the
|
|
3874
|
+
* {@linkcode property} decorator.
|
|
3875
|
+
*/
|
|
3876
|
+
class LitElement extends ReactiveElement {
|
|
3877
|
+
constructor() {
|
|
3878
|
+
super(...arguments);
|
|
3879
|
+
/**
|
|
3880
|
+
* @category rendering
|
|
3881
|
+
*/
|
|
3882
|
+
this.renderOptions = { host: this };
|
|
3883
|
+
this.__childPart = undefined;
|
|
3884
|
+
}
|
|
3885
|
+
/**
|
|
3886
|
+
* @category rendering
|
|
3887
|
+
*/
|
|
3888
|
+
createRenderRoot() {
|
|
3889
|
+
const renderRoot = super.createRenderRoot();
|
|
3890
|
+
// When adoptedStyleSheets are shimmed, they are inserted into the
|
|
3891
|
+
// shadowRoot by createRenderRoot. Adjust the renderBefore node so that
|
|
3892
|
+
// any styles in Lit content render before adoptedStyleSheets. This is
|
|
3893
|
+
// important so that adoptedStyleSheets have precedence over styles in
|
|
3894
|
+
// the shadowRoot.
|
|
3895
|
+
this.renderOptions.renderBefore ??= renderRoot.firstChild;
|
|
3896
|
+
return renderRoot;
|
|
3897
|
+
}
|
|
3898
|
+
/**
|
|
3899
|
+
* Updates the element. This method reflects property values to attributes
|
|
3900
|
+
* and calls `render` to render DOM via lit-html. Setting properties inside
|
|
3901
|
+
* this method will *not* trigger another update.
|
|
3902
|
+
* @param changedProperties Map of changed properties with old values
|
|
3903
|
+
* @category updates
|
|
3904
|
+
*/
|
|
3905
|
+
update(changedProperties) {
|
|
3906
|
+
// Setting properties in `render` should not trigger an update. Since
|
|
3907
|
+
// updates are allowed after super.update, it's important to call `render`
|
|
3908
|
+
// before that.
|
|
3909
|
+
const value = this.render();
|
|
3910
|
+
if (!this.hasUpdated) {
|
|
3911
|
+
this.renderOptions.isConnected = this.isConnected;
|
|
3912
|
+
}
|
|
3913
|
+
super.update(changedProperties);
|
|
3914
|
+
this.__childPart = render(value, this.renderRoot, this.renderOptions);
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* Invoked when the component is added to the document's DOM.
|
|
3918
|
+
*
|
|
3919
|
+
* In `connectedCallback()` you should setup tasks that should only occur when
|
|
3920
|
+
* the element is connected to the document. The most common of these is
|
|
3921
|
+
* adding event listeners to nodes external to the element, like a keydown
|
|
3922
|
+
* event handler added to the window.
|
|
3923
|
+
*
|
|
3924
|
+
* ```ts
|
|
3925
|
+
* connectedCallback() {
|
|
3926
|
+
* super.connectedCallback();
|
|
3927
|
+
* addEventListener('keydown', this._handleKeydown);
|
|
3928
|
+
* }
|
|
3929
|
+
* ```
|
|
3930
|
+
*
|
|
3931
|
+
* Typically, anything done in `connectedCallback()` should be undone when the
|
|
3932
|
+
* element is disconnected, in `disconnectedCallback()`.
|
|
3933
|
+
*
|
|
3934
|
+
* @category lifecycle
|
|
3935
|
+
*/
|
|
3936
|
+
connectedCallback() {
|
|
3937
|
+
super.connectedCallback();
|
|
3938
|
+
this.__childPart?.setConnected(true);
|
|
3939
|
+
}
|
|
3940
|
+
/**
|
|
3941
|
+
* Invoked when the component is removed from the document's DOM.
|
|
3942
|
+
*
|
|
3943
|
+
* This callback is the main signal to the element that it may no longer be
|
|
3944
|
+
* used. `disconnectedCallback()` should ensure that nothing is holding a
|
|
3945
|
+
* reference to the element (such as event listeners added to nodes external
|
|
3946
|
+
* to the element), so that it is free to be garbage collected.
|
|
3947
|
+
*
|
|
3948
|
+
* ```ts
|
|
3949
|
+
* disconnectedCallback() {
|
|
3950
|
+
* super.disconnectedCallback();
|
|
3951
|
+
* window.removeEventListener('keydown', this._handleKeydown);
|
|
3952
|
+
* }
|
|
3953
|
+
* ```
|
|
3954
|
+
*
|
|
3955
|
+
* An element may be re-connected after being disconnected.
|
|
3956
|
+
*
|
|
3957
|
+
* @category lifecycle
|
|
3958
|
+
*/
|
|
3959
|
+
disconnectedCallback() {
|
|
3960
|
+
super.disconnectedCallback();
|
|
3961
|
+
this.__childPart?.setConnected(false);
|
|
3962
|
+
}
|
|
3963
|
+
/**
|
|
3964
|
+
* Invoked on each update to perform rendering tasks. This method may return
|
|
3965
|
+
* any value renderable by lit-html's `ChildPart` - typically a
|
|
3966
|
+
* `TemplateResult`. Setting properties inside this method will *not* trigger
|
|
3967
|
+
* the element to update.
|
|
3968
|
+
* @category rendering
|
|
3969
|
+
*/
|
|
3970
|
+
render() {
|
|
3971
|
+
return noChange;
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
// This property needs to remain unminified.
|
|
3975
|
+
LitElement['_$litElement$'] = true;
|
|
3976
|
+
/**
|
|
3977
|
+
* Ensure this class is marked as `finalized` as an optimization ensuring
|
|
3978
|
+
* it will not needlessly try to `finalize`.
|
|
3979
|
+
*
|
|
3980
|
+
* Note this property name is a string to prevent breaking Closure JS Compiler
|
|
3981
|
+
* optimizations. See @lit/reactive-element for more information.
|
|
3982
|
+
*/
|
|
3983
|
+
LitElement[JSCompiler_renameProperty('finalized')] = true;
|
|
3984
|
+
// Install hydration if available
|
|
3985
|
+
globalThis.litElementHydrateSupport?.({ LitElement });
|
|
3986
|
+
// Apply polyfills if available
|
|
3987
|
+
const polyfillSupport = globalThis.litElementPolyfillSupportDevMode
|
|
3988
|
+
;
|
|
3989
|
+
polyfillSupport?.({ LitElement });
|
|
3990
|
+
// IMPORTANT: do not change the property name or the assignment expression.
|
|
3991
|
+
// This line will be used in regexes to search for LitElement usage.
|
|
3992
|
+
(globalThis.litElementVersions ??= []).push('4.0.6');
|
|
3993
|
+
if (globalThis.litElementVersions.length > 1) {
|
|
3994
|
+
issueWarning('multiple-versions', `Multiple versions of Lit loaded. Loading multiple versions ` +
|
|
3995
|
+
`is not recommended.`);
|
|
3996
|
+
}
|
|
3997
|
+
|
|
3896
3998
|
var css_248z$b = css`.card{word-wrap:break-word;background-clip:border-box;background-color:var(--sgds-body-bg);border:var(--sgds-border-width) solid var(--sgds-border-color-translucent);border-radius:var(--sgds-border-radius);box-shadow:none;display:flex;flex-direction:column;height:auto;min-width:0;position:relative}.card,.card-body{color:var(--sgds-body-color)}.card-body{flex:1 1 auto;padding:var(--sgds-spacer-4)}.card-title{color:var(--sgds-body-color);margin-bottom:var(--sgds-spacer-2)}.card-subtitle,.card-text:last-child{margin-bottom:0}slot[name=card-image]::slotted(img){border-top-left-radius:calc(var(--sgds-border-radius) - var(--sgds-border-width));border-top-right-radius:calc(var(--sgds-border-radius) - var(--sgds-border-width))}slot[name=card-link]::slotted(*){font-weight:700}`;
|
|
3897
3999
|
|
|
3898
4000
|
var css_248z$a = css`.text-primary{color:var(--sgds-primary-rgb)!important}.text-secondary{color:var(--sgds-secondary-rgb)!important}.text-success{color:var(--sgds-success-rgb)!important}.text-info{color:var(--sgds-info-rgb)!important}.text-warning{color:var(--sgds-warning-rgb)!important}.text-danger{color:var(--sgds-danger-rgb)!important}.text-light{color:var(--sgds-light-rgb)!important}.text-dark{color:var(--sgds-dark-rgb)!important}.text-muted{color:var(--sgds-secondary-color)!important}`;
|