@pritzlaff/nano-app 0.0.0-stage → 0.5.2
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/AGENTS.md +66 -0
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/app/app.css +160 -0
- package/app/bundle/nano-ui.js +2554 -0
- package/app/examples/auth/example.auth.js +6 -0
- package/app/examples/auth/nano.json +46 -0
- package/app/examples/chat/example.chat.js +6 -0
- package/app/examples/chat/example.messaging.js +3 -0
- package/app/examples/chat/nano.json +115 -0
- package/app/examples/drift/example.drift.js +3 -0
- package/app/examples/drift/nano.json +31 -0
- package/app/examples/kv/example.kv.js +3 -0
- package/app/examples/nano.json +356 -0
- package/app/examples/originkey/_nano/bundle/nano-ui.js +212 -0
- package/app/examples/originkey/_nano/sandbox/boot.js +1 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-2gg2vg5g.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-5h5dssvv.js +3 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-72b5e6vd.js +17 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-87v2yejk.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-hm29e227.js +7 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-jtgk4ch8.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-mqaje7vc.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-mxgap7rs.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-qy0mwf7y.js +1 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-wanb7xw1.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-class-map.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-decorators.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-directive.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-if-defined.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-ref.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-repeat.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-style-map.js +1 -0
- package/app/examples/originkey/_nano/shared/lit.js +1 -0
- package/app/examples/originkey/_nano/shared/nano-core.js +1 -0
- package/app/examples/originkey/_nano/shared/nano-elements.js +280 -0
- package/app/examples/originkey/_nano/shared/typebox-value.js +1 -0
- package/app/examples/originkey/_nano/shared/typebox.js +1 -0
- package/app/examples/originkey/example.originkey.js +6 -0
- package/app/examples/originkey/frame.html +1 -0
- package/app/examples/originkey/nano.json +50 -0
- package/app/examples/raft/example.raft.js +30 -0
- package/app/examples/raft/nano.json +74 -0
- package/app/examples/slice/nano.json +63 -0
- package/app/examples/slice/shout.js +14 -0
- package/app/examples/template/acme.template.js +20 -0
- package/app/examples/template/index.js +241 -0
- package/app/examples/template/nano.json +35 -0
- package/app/examples/todo/example.todo.js +8 -0
- package/app/examples/todo/nano.json +77 -0
- package/app/examples/typing/nano.json +33 -0
- package/app/favicon.svg +1 -0
- package/app/index.html +152 -0
- package/app/main.js +15908 -0
- package/app/react/index.html +50 -0
- package/app/react/main.js +9 -0
- package/app/sandbox/boot.js +980 -0
- package/app/shared/chunks/nano-core-296y9rgd.js +4321 -0
- package/app/shared/chunks/nano-core-2zz7d74m.js +16 -0
- package/app/shared/chunks/nano-core-35ryhkm1.js +33 -0
- package/app/shared/chunks/nano-core-5a3r312d.js +866 -0
- package/app/shared/chunks/nano-core-89mtxedm.js +186 -0
- package/app/shared/chunks/nano-core-bf13r20v.js +77 -0
- package/app/shared/chunks/nano-core-g3414rnc.js +248 -0
- package/app/shared/chunks/nano-core-hyg0qdwg.js +547 -0
- package/app/shared/chunks/nano-core-sxgrxy03.js +53 -0
- package/app/shared/chunks/nano-core-wg5c961d.js +4564 -0
- package/app/shared/lit-class-map.js +60 -0
- package/app/shared/lit-decorators.js +228 -0
- package/app/shared/lit-directive.js +11 -0
- package/app/shared/lit-if-defined.js +10 -0
- package/app/shared/lit-ref.js +12 -0
- package/app/shared/lit-repeat.js +141 -0
- package/app/shared/lit-style-map.js +67 -0
- package/app/shared/lit.js +47 -0
- package/app/shared/nano-core.js +2516 -0
- package/app/shared/nano-elements.js +1178 -0
- package/app/shared/typebox-value.js +78 -0
- package/app/shared/typebox.js +580 -0
- package/app/shared/versions.json +6 -0
- package/bin/nano-app.ts +34 -0
- package/package.json +22 -4
- package/src/events.ts +11 -0
- package/src/serve.ts +68 -0
- package/src/watch.ts +27 -0
|
@@ -0,0 +1,866 @@
|
|
|
1
|
+
// ../../node_modules/.bun/lit-html@3.3.3/node_modules/lit-html/development/lit-html.js
|
|
2
|
+
var DEV_MODE = true;
|
|
3
|
+
var ENABLE_EXTRA_SECURITY_HOOKS = true;
|
|
4
|
+
var ENABLE_SHADYDOM_NOPATCH = true;
|
|
5
|
+
var NODE_MODE = false;
|
|
6
|
+
var global = globalThis;
|
|
7
|
+
var debugLogEvent = DEV_MODE ? (event) => {
|
|
8
|
+
const shouldEmit = global.emitLitDebugLogEvents;
|
|
9
|
+
if (!shouldEmit) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
global.dispatchEvent(new CustomEvent("lit-debug", {
|
|
13
|
+
detail: event
|
|
14
|
+
}));
|
|
15
|
+
} : undefined;
|
|
16
|
+
var debugLogRenderId = 0;
|
|
17
|
+
var issueWarning;
|
|
18
|
+
if (DEV_MODE) {
|
|
19
|
+
global.litIssuedWarnings ??= new Set;
|
|
20
|
+
issueWarning = (code, warning) => {
|
|
21
|
+
warning += code ? ` See https://lit.dev/msg/${code} for more information.` : "";
|
|
22
|
+
if (!global.litIssuedWarnings.has(warning) && !global.litIssuedWarnings.has(code)) {
|
|
23
|
+
console.warn(warning);
|
|
24
|
+
global.litIssuedWarnings.add(warning);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
queueMicrotask(() => {
|
|
28
|
+
issueWarning("dev-mode", `Lit is in dev mode. Not recommended for production!`);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
var wrap = ENABLE_SHADYDOM_NOPATCH && global.ShadyDOM?.inUse && global.ShadyDOM?.noPatch === true ? global.ShadyDOM.wrap : (node) => node;
|
|
32
|
+
var trustedTypes = global.trustedTypes;
|
|
33
|
+
var policy = trustedTypes ? trustedTypes.createPolicy("lit-html", {
|
|
34
|
+
createHTML: (s) => s
|
|
35
|
+
}) : undefined;
|
|
36
|
+
var identityFunction = (value) => value;
|
|
37
|
+
var noopSanitizer = (_node, _name, _type) => identityFunction;
|
|
38
|
+
var setSanitizer = (newSanitizer) => {
|
|
39
|
+
if (!ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (sanitizerFactoryInternal !== noopSanitizer) {
|
|
43
|
+
throw new Error(`Attempted to overwrite existing lit-html security policy.` + ` setSanitizeDOMValueFactory should be called at most once.`);
|
|
44
|
+
}
|
|
45
|
+
sanitizerFactoryInternal = newSanitizer;
|
|
46
|
+
};
|
|
47
|
+
var _testOnlyClearSanitizerFactoryDoNotCallOrElse = () => {
|
|
48
|
+
sanitizerFactoryInternal = noopSanitizer;
|
|
49
|
+
};
|
|
50
|
+
var createSanitizer = (node, name, type) => {
|
|
51
|
+
return sanitizerFactoryInternal(node, name, type);
|
|
52
|
+
};
|
|
53
|
+
var boundAttributeSuffix = "$lit$";
|
|
54
|
+
var marker = `lit$${Math.random().toFixed(9).slice(2)}$`;
|
|
55
|
+
var markerMatch = "?" + marker;
|
|
56
|
+
var nodeMarker = `<${markerMatch}>`;
|
|
57
|
+
var d = NODE_MODE && global.document === undefined ? {
|
|
58
|
+
createTreeWalker() {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
} : document;
|
|
62
|
+
var createMarker = () => d.createComment("");
|
|
63
|
+
var isPrimitive = (value) => value === null || typeof value != "object" && typeof value != "function";
|
|
64
|
+
var isArray = Array.isArray;
|
|
65
|
+
var isIterable = (value) => isArray(value) || typeof value?.[Symbol.iterator] === "function";
|
|
66
|
+
var SPACE_CHAR = `[
|
|
67
|
+
\f\r]`;
|
|
68
|
+
var ATTR_VALUE_CHAR = `[^
|
|
69
|
+
\f\r"'\`<>=]`;
|
|
70
|
+
var NAME_CHAR = `[^\\s"'>=/]`;
|
|
71
|
+
var textEndRegex = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g;
|
|
72
|
+
var COMMENT_START = 1;
|
|
73
|
+
var TAG_NAME = 2;
|
|
74
|
+
var DYNAMIC_TAG_NAME = 3;
|
|
75
|
+
var commentEndRegex = /-->/g;
|
|
76
|
+
var comment2EndRegex = />/g;
|
|
77
|
+
var tagEndRegex = new RegExp(`>|${SPACE_CHAR}(?:(${NAME_CHAR}+)(${SPACE_CHAR}*=${SPACE_CHAR}*(?:${ATTR_VALUE_CHAR}|("|')|))|$)`, "g");
|
|
78
|
+
var ENTIRE_MATCH = 0;
|
|
79
|
+
var ATTRIBUTE_NAME = 1;
|
|
80
|
+
var SPACES_AND_EQUALS = 2;
|
|
81
|
+
var QUOTE_CHAR = 3;
|
|
82
|
+
var singleQuoteAttrEndRegex = /'/g;
|
|
83
|
+
var doubleQuoteAttrEndRegex = /"/g;
|
|
84
|
+
var rawTextElement = /^(?:script|style|textarea|title)$/i;
|
|
85
|
+
var HTML_RESULT = 1;
|
|
86
|
+
var SVG_RESULT = 2;
|
|
87
|
+
var MATHML_RESULT = 3;
|
|
88
|
+
var ATTRIBUTE_PART = 1;
|
|
89
|
+
var CHILD_PART = 2;
|
|
90
|
+
var PROPERTY_PART = 3;
|
|
91
|
+
var BOOLEAN_ATTRIBUTE_PART = 4;
|
|
92
|
+
var EVENT_PART = 5;
|
|
93
|
+
var ELEMENT_PART = 6;
|
|
94
|
+
var COMMENT_PART = 7;
|
|
95
|
+
var tag = (type) => (strings, ...values) => {
|
|
96
|
+
if (DEV_MODE && strings.some((s) => s === undefined)) {
|
|
97
|
+
console.warn(`Some template strings are undefined.
|
|
98
|
+
` + "This is probably caused by illegal octal escape sequences.");
|
|
99
|
+
}
|
|
100
|
+
if (DEV_MODE) {
|
|
101
|
+
if (values.some((val) => val?.["_$litStatic$"])) {
|
|
102
|
+
issueWarning("", `Static values 'literal' or 'unsafeStatic' cannot be used as values to non-static templates.
|
|
103
|
+
` + `Please use the static 'html' tag function. See https://lit.dev/docs/templates/expressions/#static-expressions`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
["_$litType$"]: type,
|
|
108
|
+
strings,
|
|
109
|
+
values
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
var html = tag(HTML_RESULT);
|
|
113
|
+
var svg = tag(SVG_RESULT);
|
|
114
|
+
var mathml = tag(MATHML_RESULT);
|
|
115
|
+
var noChange = Symbol.for("lit-noChange");
|
|
116
|
+
var nothing = Symbol.for("lit-nothing");
|
|
117
|
+
var templateCache = new WeakMap;
|
|
118
|
+
var walker = d.createTreeWalker(d, 129);
|
|
119
|
+
var sanitizerFactoryInternal = noopSanitizer;
|
|
120
|
+
function trustFromTemplateString(tsa, stringFromTSA) {
|
|
121
|
+
if (!isArray(tsa) || !tsa.hasOwnProperty("raw")) {
|
|
122
|
+
let message = "invalid template strings array";
|
|
123
|
+
if (DEV_MODE) {
|
|
124
|
+
message = `
|
|
125
|
+
Internal Error: expected template strings to be an array
|
|
126
|
+
with a 'raw' field. Faking a template strings array by
|
|
127
|
+
calling html or svg like an ordinary function is effectively
|
|
128
|
+
the same as calling unsafeHtml and can lead to major security
|
|
129
|
+
issues, e.g. opening your code up to XSS attacks.
|
|
130
|
+
If you're using the html or svg tagged template functions normally
|
|
131
|
+
and still seeing this error, please file a bug at
|
|
132
|
+
https://github.com/lit/lit/issues/new?template=bug_report.md
|
|
133
|
+
and include information about your build tooling, if any.
|
|
134
|
+
`.trim().replace(/\n */g, `
|
|
135
|
+
`);
|
|
136
|
+
}
|
|
137
|
+
throw new Error(message);
|
|
138
|
+
}
|
|
139
|
+
return policy !== undefined ? policy.createHTML(stringFromTSA) : stringFromTSA;
|
|
140
|
+
}
|
|
141
|
+
var getTemplateHtml = (strings, type) => {
|
|
142
|
+
const l = strings.length - 1;
|
|
143
|
+
const attrNames = [];
|
|
144
|
+
let html2 = type === SVG_RESULT ? "<svg>" : type === MATHML_RESULT ? "<math>" : "";
|
|
145
|
+
let rawTextEndRegex;
|
|
146
|
+
let regex = textEndRegex;
|
|
147
|
+
for (let i = 0;i < l; i++) {
|
|
148
|
+
const s = strings[i];
|
|
149
|
+
let attrNameEndIndex = -1;
|
|
150
|
+
let attrName;
|
|
151
|
+
let lastIndex = 0;
|
|
152
|
+
let match;
|
|
153
|
+
while (lastIndex < s.length) {
|
|
154
|
+
regex.lastIndex = lastIndex;
|
|
155
|
+
match = regex.exec(s);
|
|
156
|
+
if (match === null) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
lastIndex = regex.lastIndex;
|
|
160
|
+
if (regex === textEndRegex) {
|
|
161
|
+
if (match[COMMENT_START] === "!--") {
|
|
162
|
+
regex = commentEndRegex;
|
|
163
|
+
} else if (match[COMMENT_START] !== undefined) {
|
|
164
|
+
regex = comment2EndRegex;
|
|
165
|
+
} else if (match[TAG_NAME] !== undefined) {
|
|
166
|
+
if (rawTextElement.test(match[TAG_NAME])) {
|
|
167
|
+
rawTextEndRegex = new RegExp(`</${match[TAG_NAME]}`, "g");
|
|
168
|
+
}
|
|
169
|
+
regex = tagEndRegex;
|
|
170
|
+
} else if (match[DYNAMIC_TAG_NAME] !== undefined) {
|
|
171
|
+
if (DEV_MODE) {
|
|
172
|
+
throw new Error("Bindings in tag names are not supported. Please use static templates instead. " + "See https://lit.dev/docs/templates/expressions/#static-expressions");
|
|
173
|
+
}
|
|
174
|
+
regex = tagEndRegex;
|
|
175
|
+
}
|
|
176
|
+
} else if (regex === tagEndRegex) {
|
|
177
|
+
if (match[ENTIRE_MATCH] === ">") {
|
|
178
|
+
regex = rawTextEndRegex ?? textEndRegex;
|
|
179
|
+
attrNameEndIndex = -1;
|
|
180
|
+
} else if (match[ATTRIBUTE_NAME] === undefined) {
|
|
181
|
+
attrNameEndIndex = -2;
|
|
182
|
+
} else {
|
|
183
|
+
attrNameEndIndex = regex.lastIndex - match[SPACES_AND_EQUALS].length;
|
|
184
|
+
attrName = match[ATTRIBUTE_NAME];
|
|
185
|
+
regex = match[QUOTE_CHAR] === undefined ? tagEndRegex : match[QUOTE_CHAR] === '"' ? doubleQuoteAttrEndRegex : singleQuoteAttrEndRegex;
|
|
186
|
+
}
|
|
187
|
+
} else if (regex === doubleQuoteAttrEndRegex || regex === singleQuoteAttrEndRegex) {
|
|
188
|
+
regex = tagEndRegex;
|
|
189
|
+
} else if (regex === commentEndRegex || regex === comment2EndRegex) {
|
|
190
|
+
regex = textEndRegex;
|
|
191
|
+
} else {
|
|
192
|
+
regex = tagEndRegex;
|
|
193
|
+
rawTextEndRegex = undefined;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (DEV_MODE) {
|
|
197
|
+
console.assert(attrNameEndIndex === -1 || regex === tagEndRegex || regex === singleQuoteAttrEndRegex || regex === doubleQuoteAttrEndRegex, "unexpected parse state B");
|
|
198
|
+
}
|
|
199
|
+
const end = regex === tagEndRegex && strings[i + 1].startsWith("/>") ? " " : "";
|
|
200
|
+
html2 += regex === textEndRegex ? s + nodeMarker : attrNameEndIndex >= 0 ? (attrNames.push(attrName), s.slice(0, attrNameEndIndex) + boundAttributeSuffix + s.slice(attrNameEndIndex)) + marker + end : s + marker + (attrNameEndIndex === -2 ? i : end);
|
|
201
|
+
}
|
|
202
|
+
const htmlResult = html2 + (strings[l] || "<?>") + (type === SVG_RESULT ? "</svg>" : type === MATHML_RESULT ? "</math>" : "");
|
|
203
|
+
return [trustFromTemplateString(strings, htmlResult), attrNames];
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
class Template {
|
|
207
|
+
constructor({ strings, ["_$litType$"]: type }, options) {
|
|
208
|
+
this.parts = [];
|
|
209
|
+
let node;
|
|
210
|
+
let nodeIndex = 0;
|
|
211
|
+
let attrNameIndex = 0;
|
|
212
|
+
const partCount = strings.length - 1;
|
|
213
|
+
const parts = this.parts;
|
|
214
|
+
const [html2, attrNames] = getTemplateHtml(strings, type);
|
|
215
|
+
this.el = Template.createElement(html2, options);
|
|
216
|
+
walker.currentNode = this.el.content;
|
|
217
|
+
if (type === SVG_RESULT || type === MATHML_RESULT) {
|
|
218
|
+
const wrapper = this.el.content.firstChild;
|
|
219
|
+
wrapper.replaceWith(...wrapper.childNodes);
|
|
220
|
+
}
|
|
221
|
+
while ((node = walker.nextNode()) !== null && parts.length < partCount) {
|
|
222
|
+
if (node.nodeType === 1) {
|
|
223
|
+
if (DEV_MODE) {
|
|
224
|
+
const tag2 = node.localName;
|
|
225
|
+
if (/^(?:textarea|template)$/i.test(tag2) && node.innerHTML.includes(marker)) {
|
|
226
|
+
const m = `Expressions are not supported inside \`${tag2}\` ` + `elements. See https://lit.dev/msg/expression-in-${tag2} for more ` + `information.`;
|
|
227
|
+
if (tag2 === "template") {
|
|
228
|
+
throw new Error(m);
|
|
229
|
+
} else
|
|
230
|
+
issueWarning("", m);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (node.hasAttributes()) {
|
|
234
|
+
for (const name of node.getAttributeNames()) {
|
|
235
|
+
if (name.endsWith(boundAttributeSuffix)) {
|
|
236
|
+
const realName = attrNames[attrNameIndex++];
|
|
237
|
+
const value = node.getAttribute(name);
|
|
238
|
+
const statics = value.split(marker);
|
|
239
|
+
const m = /([.?@])?(.*)/.exec(realName);
|
|
240
|
+
parts.push({
|
|
241
|
+
type: ATTRIBUTE_PART,
|
|
242
|
+
index: nodeIndex,
|
|
243
|
+
name: m[2],
|
|
244
|
+
strings: statics,
|
|
245
|
+
ctor: m[1] === "." ? PropertyPart : m[1] === "?" ? BooleanAttributePart : m[1] === "@" ? EventPart : AttributePart
|
|
246
|
+
});
|
|
247
|
+
node.removeAttribute(name);
|
|
248
|
+
} else if (name.startsWith(marker)) {
|
|
249
|
+
parts.push({
|
|
250
|
+
type: ELEMENT_PART,
|
|
251
|
+
index: nodeIndex
|
|
252
|
+
});
|
|
253
|
+
node.removeAttribute(name);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (rawTextElement.test(node.tagName)) {
|
|
258
|
+
const strings2 = node.textContent.split(marker);
|
|
259
|
+
const lastIndex = strings2.length - 1;
|
|
260
|
+
if (lastIndex > 0) {
|
|
261
|
+
node.textContent = trustedTypes ? trustedTypes.emptyScript : "";
|
|
262
|
+
for (let i = 0;i < lastIndex; i++) {
|
|
263
|
+
node.append(strings2[i], createMarker());
|
|
264
|
+
walker.nextNode();
|
|
265
|
+
parts.push({ type: CHILD_PART, index: ++nodeIndex });
|
|
266
|
+
}
|
|
267
|
+
node.append(strings2[lastIndex], createMarker());
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
} else if (node.nodeType === 8) {
|
|
271
|
+
const data = node.data;
|
|
272
|
+
if (data === markerMatch) {
|
|
273
|
+
parts.push({ type: CHILD_PART, index: nodeIndex });
|
|
274
|
+
} else {
|
|
275
|
+
let i = -1;
|
|
276
|
+
while ((i = node.data.indexOf(marker, i + 1)) !== -1) {
|
|
277
|
+
parts.push({ type: COMMENT_PART, index: nodeIndex });
|
|
278
|
+
i += marker.length - 1;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
nodeIndex++;
|
|
283
|
+
}
|
|
284
|
+
if (DEV_MODE) {
|
|
285
|
+
if (attrNames.length !== attrNameIndex) {
|
|
286
|
+
throw new Error(`Detected duplicate attribute bindings. This occurs if your template ` + `has duplicate attributes on an element tag. For example ` + `"<input ?disabled=\${true} ?disabled=\${false}>" contains a ` + `duplicate "disabled" attribute. The error was detected in ` + `the following template:
|
|
287
|
+
` + "`" + strings.join("${...}") + "`");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
debugLogEvent && debugLogEvent({
|
|
291
|
+
kind: "template prep",
|
|
292
|
+
template: this,
|
|
293
|
+
clonableTemplate: this.el,
|
|
294
|
+
parts: this.parts,
|
|
295
|
+
strings
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
static createElement(html2, _options) {
|
|
299
|
+
const el = d.createElement("template");
|
|
300
|
+
el.innerHTML = html2;
|
|
301
|
+
return el;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function resolveDirective(part, value, parent = part, attributeIndex) {
|
|
305
|
+
if (value === noChange) {
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
let currentDirective = attributeIndex !== undefined ? parent.__directives?.[attributeIndex] : parent.__directive;
|
|
309
|
+
const nextDirectiveConstructor = isPrimitive(value) ? undefined : value["_$litDirective$"];
|
|
310
|
+
if (currentDirective?.constructor !== nextDirectiveConstructor) {
|
|
311
|
+
currentDirective?.["_$notifyDirectiveConnectionChanged"]?.(false);
|
|
312
|
+
if (nextDirectiveConstructor === undefined) {
|
|
313
|
+
currentDirective = undefined;
|
|
314
|
+
} else {
|
|
315
|
+
currentDirective = new nextDirectiveConstructor(part);
|
|
316
|
+
currentDirective._$initialize(part, parent, attributeIndex);
|
|
317
|
+
}
|
|
318
|
+
if (attributeIndex !== undefined) {
|
|
319
|
+
(parent.__directives ??= [])[attributeIndex] = currentDirective;
|
|
320
|
+
} else {
|
|
321
|
+
parent.__directive = currentDirective;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (currentDirective !== undefined) {
|
|
325
|
+
value = resolveDirective(part, currentDirective._$resolve(part, value.values), currentDirective, attributeIndex);
|
|
326
|
+
}
|
|
327
|
+
return value;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
class TemplateInstance {
|
|
331
|
+
constructor(template, parent) {
|
|
332
|
+
this._$parts = [];
|
|
333
|
+
this._$disconnectableChildren = undefined;
|
|
334
|
+
this._$template = template;
|
|
335
|
+
this._$parent = parent;
|
|
336
|
+
}
|
|
337
|
+
get parentNode() {
|
|
338
|
+
return this._$parent.parentNode;
|
|
339
|
+
}
|
|
340
|
+
get _$isConnected() {
|
|
341
|
+
return this._$parent._$isConnected;
|
|
342
|
+
}
|
|
343
|
+
_clone(options) {
|
|
344
|
+
const { el: { content }, parts } = this._$template;
|
|
345
|
+
const fragment = (options?.creationScope ?? d).importNode(content, true);
|
|
346
|
+
walker.currentNode = fragment;
|
|
347
|
+
let node = walker.nextNode();
|
|
348
|
+
let nodeIndex = 0;
|
|
349
|
+
let partIndex = 0;
|
|
350
|
+
let templatePart = parts[0];
|
|
351
|
+
while (templatePart !== undefined) {
|
|
352
|
+
if (nodeIndex === templatePart.index) {
|
|
353
|
+
let part;
|
|
354
|
+
if (templatePart.type === CHILD_PART) {
|
|
355
|
+
part = new ChildPart(node, node.nextSibling, this, options);
|
|
356
|
+
} else if (templatePart.type === ATTRIBUTE_PART) {
|
|
357
|
+
part = new templatePart.ctor(node, templatePart.name, templatePart.strings, this, options);
|
|
358
|
+
} else if (templatePart.type === ELEMENT_PART) {
|
|
359
|
+
part = new ElementPart(node, this, options);
|
|
360
|
+
}
|
|
361
|
+
this._$parts.push(part);
|
|
362
|
+
templatePart = parts[++partIndex];
|
|
363
|
+
}
|
|
364
|
+
if (nodeIndex !== templatePart?.index) {
|
|
365
|
+
node = walker.nextNode();
|
|
366
|
+
nodeIndex++;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
walker.currentNode = d;
|
|
370
|
+
return fragment;
|
|
371
|
+
}
|
|
372
|
+
_update(values) {
|
|
373
|
+
let i = 0;
|
|
374
|
+
for (const part of this._$parts) {
|
|
375
|
+
if (part !== undefined) {
|
|
376
|
+
debugLogEvent && debugLogEvent({
|
|
377
|
+
kind: "set part",
|
|
378
|
+
part,
|
|
379
|
+
value: values[i],
|
|
380
|
+
valueIndex: i,
|
|
381
|
+
values,
|
|
382
|
+
templateInstance: this
|
|
383
|
+
});
|
|
384
|
+
if (part.strings !== undefined) {
|
|
385
|
+
part._$setValue(values, part, i);
|
|
386
|
+
i += part.strings.length - 2;
|
|
387
|
+
} else {
|
|
388
|
+
part._$setValue(values[i]);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
i++;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
class ChildPart {
|
|
397
|
+
get _$isConnected() {
|
|
398
|
+
return this._$parent?._$isConnected ?? this.__isConnected;
|
|
399
|
+
}
|
|
400
|
+
constructor(startNode, endNode, parent, options) {
|
|
401
|
+
this.type = CHILD_PART;
|
|
402
|
+
this._$committedValue = nothing;
|
|
403
|
+
this._$disconnectableChildren = undefined;
|
|
404
|
+
this._$startNode = startNode;
|
|
405
|
+
this._$endNode = endNode;
|
|
406
|
+
this._$parent = parent;
|
|
407
|
+
this.options = options;
|
|
408
|
+
this.__isConnected = options?.isConnected ?? true;
|
|
409
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
410
|
+
this._textSanitizer = undefined;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
get parentNode() {
|
|
414
|
+
let parentNode = wrap(this._$startNode).parentNode;
|
|
415
|
+
const parent = this._$parent;
|
|
416
|
+
if (parent !== undefined && parentNode?.nodeType === 11) {
|
|
417
|
+
parentNode = parent.parentNode;
|
|
418
|
+
}
|
|
419
|
+
return parentNode;
|
|
420
|
+
}
|
|
421
|
+
get startNode() {
|
|
422
|
+
return this._$startNode;
|
|
423
|
+
}
|
|
424
|
+
get endNode() {
|
|
425
|
+
return this._$endNode;
|
|
426
|
+
}
|
|
427
|
+
_$setValue(value, directiveParent = this) {
|
|
428
|
+
if (DEV_MODE && this.parentNode === null) {
|
|
429
|
+
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.`);
|
|
430
|
+
}
|
|
431
|
+
value = resolveDirective(this, value, directiveParent);
|
|
432
|
+
if (isPrimitive(value)) {
|
|
433
|
+
if (value === nothing || value == null || value === "") {
|
|
434
|
+
if (this._$committedValue !== nothing) {
|
|
435
|
+
debugLogEvent && debugLogEvent({
|
|
436
|
+
kind: "commit nothing to child",
|
|
437
|
+
start: this._$startNode,
|
|
438
|
+
end: this._$endNode,
|
|
439
|
+
parent: this._$parent,
|
|
440
|
+
options: this.options
|
|
441
|
+
});
|
|
442
|
+
this._$clear();
|
|
443
|
+
}
|
|
444
|
+
this._$committedValue = nothing;
|
|
445
|
+
} else if (value !== this._$committedValue && value !== noChange) {
|
|
446
|
+
this._commitText(value);
|
|
447
|
+
}
|
|
448
|
+
} else if (value["_$litType$"] !== undefined) {
|
|
449
|
+
this._commitTemplateResult(value);
|
|
450
|
+
} else if (value.nodeType !== undefined) {
|
|
451
|
+
if (DEV_MODE && this.options?.host === value) {
|
|
452
|
+
this._commitText(`[probable mistake: rendered a template's host in itself ` + `(commonly caused by writing \${this} in a template]`);
|
|
453
|
+
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.`);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
this._commitNode(value);
|
|
457
|
+
} else if (isIterable(value)) {
|
|
458
|
+
this._commitIterable(value);
|
|
459
|
+
} else {
|
|
460
|
+
this._commitText(value);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
_insert(node) {
|
|
464
|
+
return wrap(wrap(this._$startNode).parentNode).insertBefore(node, this._$endNode);
|
|
465
|
+
}
|
|
466
|
+
_commitNode(value) {
|
|
467
|
+
if (this._$committedValue !== value) {
|
|
468
|
+
this._$clear();
|
|
469
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS && sanitizerFactoryInternal !== noopSanitizer) {
|
|
470
|
+
const parentNodeName = this._$startNode.parentNode?.nodeName;
|
|
471
|
+
if (parentNodeName === "STYLE" || parentNodeName === "SCRIPT") {
|
|
472
|
+
let message = "Forbidden";
|
|
473
|
+
if (DEV_MODE) {
|
|
474
|
+
if (parentNodeName === "STYLE") {
|
|
475
|
+
message = `Lit does not support binding inside style nodes. ` + `This is a security risk, as style injection attacks can ` + `exfiltrate data and spoof UIs. ` + `Consider instead using css\`...\` literals ` + `to compose styles, and do dynamic styling with ` + `css custom properties, ::parts, <slot>s, ` + `and by mutating the DOM rather than stylesheets.`;
|
|
476
|
+
} else {
|
|
477
|
+
message = `Lit does not support binding inside script nodes. ` + `This is a security risk, as it could allow arbitrary ` + `code execution.`;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
throw new Error(message);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
debugLogEvent && debugLogEvent({
|
|
484
|
+
kind: "commit node",
|
|
485
|
+
start: this._$startNode,
|
|
486
|
+
parent: this._$parent,
|
|
487
|
+
value,
|
|
488
|
+
options: this.options
|
|
489
|
+
});
|
|
490
|
+
this._$committedValue = this._insert(value);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
_commitText(value) {
|
|
494
|
+
if (this._$committedValue !== nothing && isPrimitive(this._$committedValue)) {
|
|
495
|
+
const node = wrap(this._$startNode).nextSibling;
|
|
496
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
497
|
+
if (this._textSanitizer === undefined) {
|
|
498
|
+
this._textSanitizer = createSanitizer(node, "data", "property");
|
|
499
|
+
}
|
|
500
|
+
value = this._textSanitizer(value);
|
|
501
|
+
}
|
|
502
|
+
debugLogEvent && debugLogEvent({
|
|
503
|
+
kind: "commit text",
|
|
504
|
+
node,
|
|
505
|
+
value,
|
|
506
|
+
options: this.options
|
|
507
|
+
});
|
|
508
|
+
node.data = value;
|
|
509
|
+
} else {
|
|
510
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
511
|
+
const textNode = d.createTextNode("");
|
|
512
|
+
this._commitNode(textNode);
|
|
513
|
+
if (this._textSanitizer === undefined) {
|
|
514
|
+
this._textSanitizer = createSanitizer(textNode, "data", "property");
|
|
515
|
+
}
|
|
516
|
+
value = this._textSanitizer(value);
|
|
517
|
+
debugLogEvent && debugLogEvent({
|
|
518
|
+
kind: "commit text",
|
|
519
|
+
node: textNode,
|
|
520
|
+
value,
|
|
521
|
+
options: this.options
|
|
522
|
+
});
|
|
523
|
+
textNode.data = value;
|
|
524
|
+
} else {
|
|
525
|
+
this._commitNode(d.createTextNode(value));
|
|
526
|
+
debugLogEvent && debugLogEvent({
|
|
527
|
+
kind: "commit text",
|
|
528
|
+
node: wrap(this._$startNode).nextSibling,
|
|
529
|
+
value,
|
|
530
|
+
options: this.options
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
this._$committedValue = value;
|
|
535
|
+
}
|
|
536
|
+
_commitTemplateResult(result) {
|
|
537
|
+
const { values, ["_$litType$"]: type } = result;
|
|
538
|
+
const template = typeof type === "number" ? this._$getTemplate(result) : (type.el === undefined && (type.el = Template.createElement(trustFromTemplateString(type.h, type.h[0]), this.options)), type);
|
|
539
|
+
if (this._$committedValue?._$template === template) {
|
|
540
|
+
debugLogEvent && debugLogEvent({
|
|
541
|
+
kind: "template updating",
|
|
542
|
+
template,
|
|
543
|
+
instance: this._$committedValue,
|
|
544
|
+
parts: this._$committedValue._$parts,
|
|
545
|
+
options: this.options,
|
|
546
|
+
values
|
|
547
|
+
});
|
|
548
|
+
this._$committedValue._update(values);
|
|
549
|
+
} else {
|
|
550
|
+
const instance = new TemplateInstance(template, this);
|
|
551
|
+
const fragment = instance._clone(this.options);
|
|
552
|
+
debugLogEvent && debugLogEvent({
|
|
553
|
+
kind: "template instantiated",
|
|
554
|
+
template,
|
|
555
|
+
instance,
|
|
556
|
+
parts: instance._$parts,
|
|
557
|
+
options: this.options,
|
|
558
|
+
fragment,
|
|
559
|
+
values
|
|
560
|
+
});
|
|
561
|
+
instance._update(values);
|
|
562
|
+
debugLogEvent && debugLogEvent({
|
|
563
|
+
kind: "template instantiated and updated",
|
|
564
|
+
template,
|
|
565
|
+
instance,
|
|
566
|
+
parts: instance._$parts,
|
|
567
|
+
options: this.options,
|
|
568
|
+
fragment,
|
|
569
|
+
values
|
|
570
|
+
});
|
|
571
|
+
this._commitNode(fragment);
|
|
572
|
+
this._$committedValue = instance;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
_$getTemplate(result) {
|
|
576
|
+
let template = templateCache.get(result.strings);
|
|
577
|
+
if (template === undefined) {
|
|
578
|
+
templateCache.set(result.strings, template = new Template(result));
|
|
579
|
+
}
|
|
580
|
+
return template;
|
|
581
|
+
}
|
|
582
|
+
_commitIterable(value) {
|
|
583
|
+
if (!isArray(this._$committedValue)) {
|
|
584
|
+
this._$committedValue = [];
|
|
585
|
+
this._$clear();
|
|
586
|
+
}
|
|
587
|
+
const itemParts = this._$committedValue;
|
|
588
|
+
let partIndex = 0;
|
|
589
|
+
let itemPart;
|
|
590
|
+
for (const item of value) {
|
|
591
|
+
if (partIndex === itemParts.length) {
|
|
592
|
+
itemParts.push(itemPart = new ChildPart(this._insert(createMarker()), this._insert(createMarker()), this, this.options));
|
|
593
|
+
} else {
|
|
594
|
+
itemPart = itemParts[partIndex];
|
|
595
|
+
}
|
|
596
|
+
itemPart._$setValue(item);
|
|
597
|
+
partIndex++;
|
|
598
|
+
}
|
|
599
|
+
if (partIndex < itemParts.length) {
|
|
600
|
+
this._$clear(itemPart && wrap(itemPart._$endNode).nextSibling, partIndex);
|
|
601
|
+
itemParts.length = partIndex;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
_$clear(start = wrap(this._$startNode).nextSibling, from) {
|
|
605
|
+
this._$notifyConnectionChanged?.(false, true, from);
|
|
606
|
+
while (start !== this._$endNode) {
|
|
607
|
+
const n = wrap(start).nextSibling;
|
|
608
|
+
wrap(start).remove();
|
|
609
|
+
start = n;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
setConnected(isConnected) {
|
|
613
|
+
if (this._$parent === undefined) {
|
|
614
|
+
this.__isConnected = isConnected;
|
|
615
|
+
this._$notifyConnectionChanged?.(isConnected);
|
|
616
|
+
} else if (DEV_MODE) {
|
|
617
|
+
throw new Error("part.setConnected() may only be called on a " + "RootPart returned from render().");
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
class AttributePart {
|
|
623
|
+
get tagName() {
|
|
624
|
+
return this.element.tagName;
|
|
625
|
+
}
|
|
626
|
+
get _$isConnected() {
|
|
627
|
+
return this._$parent._$isConnected;
|
|
628
|
+
}
|
|
629
|
+
constructor(element, name, strings, parent, options) {
|
|
630
|
+
this.type = ATTRIBUTE_PART;
|
|
631
|
+
this._$committedValue = nothing;
|
|
632
|
+
this._$disconnectableChildren = undefined;
|
|
633
|
+
this.element = element;
|
|
634
|
+
this.name = name;
|
|
635
|
+
this._$parent = parent;
|
|
636
|
+
this.options = options;
|
|
637
|
+
if (strings.length > 2 || strings[0] !== "" || strings[1] !== "") {
|
|
638
|
+
this._$committedValue = new Array(strings.length - 1).fill(new String);
|
|
639
|
+
this.strings = strings;
|
|
640
|
+
} else {
|
|
641
|
+
this._$committedValue = nothing;
|
|
642
|
+
}
|
|
643
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
644
|
+
this._sanitizer = undefined;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
_$setValue(value, directiveParent = this, valueIndex, noCommit) {
|
|
648
|
+
const strings = this.strings;
|
|
649
|
+
let change = false;
|
|
650
|
+
if (strings === undefined) {
|
|
651
|
+
value = resolveDirective(this, value, directiveParent, 0);
|
|
652
|
+
change = !isPrimitive(value) || value !== this._$committedValue && value !== noChange;
|
|
653
|
+
if (change) {
|
|
654
|
+
this._$committedValue = value;
|
|
655
|
+
}
|
|
656
|
+
} else {
|
|
657
|
+
const values = value;
|
|
658
|
+
value = strings[0];
|
|
659
|
+
let i, v;
|
|
660
|
+
for (i = 0;i < strings.length - 1; i++) {
|
|
661
|
+
v = resolveDirective(this, values[valueIndex + i], directiveParent, i);
|
|
662
|
+
if (v === noChange) {
|
|
663
|
+
v = this._$committedValue[i];
|
|
664
|
+
}
|
|
665
|
+
change ||= !isPrimitive(v) || v !== this._$committedValue[i];
|
|
666
|
+
if (v === nothing) {
|
|
667
|
+
value = nothing;
|
|
668
|
+
} else if (value !== nothing) {
|
|
669
|
+
value += (v ?? "") + strings[i + 1];
|
|
670
|
+
}
|
|
671
|
+
this._$committedValue[i] = v;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (change && !noCommit) {
|
|
675
|
+
this._commitValue(value);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
_commitValue(value) {
|
|
679
|
+
if (value === nothing) {
|
|
680
|
+
wrap(this.element).removeAttribute(this.name);
|
|
681
|
+
} else {
|
|
682
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
683
|
+
if (this._sanitizer === undefined) {
|
|
684
|
+
this._sanitizer = sanitizerFactoryInternal(this.element, this.name, "attribute");
|
|
685
|
+
}
|
|
686
|
+
value = this._sanitizer(value ?? "");
|
|
687
|
+
}
|
|
688
|
+
debugLogEvent && debugLogEvent({
|
|
689
|
+
kind: "commit attribute",
|
|
690
|
+
element: this.element,
|
|
691
|
+
name: this.name,
|
|
692
|
+
value,
|
|
693
|
+
options: this.options
|
|
694
|
+
});
|
|
695
|
+
wrap(this.element).setAttribute(this.name, value ?? "");
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
class PropertyPart extends AttributePart {
|
|
701
|
+
constructor() {
|
|
702
|
+
super(...arguments);
|
|
703
|
+
this.type = PROPERTY_PART;
|
|
704
|
+
}
|
|
705
|
+
_commitValue(value) {
|
|
706
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
707
|
+
if (this._sanitizer === undefined) {
|
|
708
|
+
this._sanitizer = sanitizerFactoryInternal(this.element, this.name, "property");
|
|
709
|
+
}
|
|
710
|
+
value = this._sanitizer(value);
|
|
711
|
+
}
|
|
712
|
+
debugLogEvent && debugLogEvent({
|
|
713
|
+
kind: "commit property",
|
|
714
|
+
element: this.element,
|
|
715
|
+
name: this.name,
|
|
716
|
+
value,
|
|
717
|
+
options: this.options
|
|
718
|
+
});
|
|
719
|
+
this.element[this.name] = value === nothing ? undefined : value;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
class BooleanAttributePart extends AttributePart {
|
|
724
|
+
constructor() {
|
|
725
|
+
super(...arguments);
|
|
726
|
+
this.type = BOOLEAN_ATTRIBUTE_PART;
|
|
727
|
+
}
|
|
728
|
+
_commitValue(value) {
|
|
729
|
+
debugLogEvent && debugLogEvent({
|
|
730
|
+
kind: "commit boolean attribute",
|
|
731
|
+
element: this.element,
|
|
732
|
+
name: this.name,
|
|
733
|
+
value: !!(value && value !== nothing),
|
|
734
|
+
options: this.options
|
|
735
|
+
});
|
|
736
|
+
wrap(this.element).toggleAttribute(this.name, !!value && value !== nothing);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
class EventPart extends AttributePart {
|
|
741
|
+
constructor(element, name, strings, parent, options) {
|
|
742
|
+
super(element, name, strings, parent, options);
|
|
743
|
+
this.type = EVENT_PART;
|
|
744
|
+
if (DEV_MODE && this.strings !== undefined) {
|
|
745
|
+
throw new Error(`A \`<${element.localName}>\` has a \`@${name}=...\` listener with ` + "invalid content. Event listeners in templates must have exactly " + "one expression and no surrounding text.");
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
_$setValue(newListener, directiveParent = this) {
|
|
749
|
+
newListener = resolveDirective(this, newListener, directiveParent, 0) ?? nothing;
|
|
750
|
+
if (newListener === noChange) {
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
const oldListener = this._$committedValue;
|
|
754
|
+
const shouldRemoveListener = newListener === nothing && oldListener !== nothing || newListener.capture !== oldListener.capture || newListener.once !== oldListener.once || newListener.passive !== oldListener.passive;
|
|
755
|
+
const shouldAddListener = newListener !== nothing && (oldListener === nothing || shouldRemoveListener);
|
|
756
|
+
debugLogEvent && debugLogEvent({
|
|
757
|
+
kind: "commit event listener",
|
|
758
|
+
element: this.element,
|
|
759
|
+
name: this.name,
|
|
760
|
+
value: newListener,
|
|
761
|
+
options: this.options,
|
|
762
|
+
removeListener: shouldRemoveListener,
|
|
763
|
+
addListener: shouldAddListener,
|
|
764
|
+
oldListener
|
|
765
|
+
});
|
|
766
|
+
if (shouldRemoveListener) {
|
|
767
|
+
this.element.removeEventListener(this.name, this, oldListener);
|
|
768
|
+
}
|
|
769
|
+
if (shouldAddListener) {
|
|
770
|
+
this.element.addEventListener(this.name, this, newListener);
|
|
771
|
+
}
|
|
772
|
+
this._$committedValue = newListener;
|
|
773
|
+
}
|
|
774
|
+
handleEvent(event) {
|
|
775
|
+
if (typeof this._$committedValue === "function") {
|
|
776
|
+
this._$committedValue.call(this.options?.host ?? this.element, event);
|
|
777
|
+
} else {
|
|
778
|
+
this._$committedValue.handleEvent(event);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
class ElementPart {
|
|
784
|
+
constructor(element, parent, options) {
|
|
785
|
+
this.element = element;
|
|
786
|
+
this.type = ELEMENT_PART;
|
|
787
|
+
this._$disconnectableChildren = undefined;
|
|
788
|
+
this._$parent = parent;
|
|
789
|
+
this.options = options;
|
|
790
|
+
}
|
|
791
|
+
get _$isConnected() {
|
|
792
|
+
return this._$parent._$isConnected;
|
|
793
|
+
}
|
|
794
|
+
_$setValue(value) {
|
|
795
|
+
debugLogEvent && debugLogEvent({
|
|
796
|
+
kind: "commit to element binding",
|
|
797
|
+
element: this.element,
|
|
798
|
+
value,
|
|
799
|
+
options: this.options
|
|
800
|
+
});
|
|
801
|
+
resolveDirective(this, value);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
var _$LH = {
|
|
805
|
+
_boundAttributeSuffix: boundAttributeSuffix,
|
|
806
|
+
_marker: marker,
|
|
807
|
+
_markerMatch: markerMatch,
|
|
808
|
+
_HTML_RESULT: HTML_RESULT,
|
|
809
|
+
_getTemplateHtml: getTemplateHtml,
|
|
810
|
+
_TemplateInstance: TemplateInstance,
|
|
811
|
+
_isIterable: isIterable,
|
|
812
|
+
_resolveDirective: resolveDirective,
|
|
813
|
+
_ChildPart: ChildPart,
|
|
814
|
+
_AttributePart: AttributePart,
|
|
815
|
+
_BooleanAttributePart: BooleanAttributePart,
|
|
816
|
+
_EventPart: EventPart,
|
|
817
|
+
_PropertyPart: PropertyPart,
|
|
818
|
+
_ElementPart: ElementPart
|
|
819
|
+
};
|
|
820
|
+
var polyfillSupport = DEV_MODE ? global.litHtmlPolyfillSupportDevMode : global.litHtmlPolyfillSupport;
|
|
821
|
+
polyfillSupport?.(Template, ChildPart);
|
|
822
|
+
(global.litHtmlVersions ??= []).push("3.3.3");
|
|
823
|
+
if (DEV_MODE && global.litHtmlVersions.length > 1) {
|
|
824
|
+
queueMicrotask(() => {
|
|
825
|
+
issueWarning("multiple-versions", `Multiple versions of Lit loaded. ` + `Loading multiple versions is not recommended.`);
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
var render = (value, container, options) => {
|
|
829
|
+
if (DEV_MODE && container == null) {
|
|
830
|
+
throw new TypeError(`The container to render into may not be ${container}`);
|
|
831
|
+
}
|
|
832
|
+
const renderId = DEV_MODE ? debugLogRenderId++ : 0;
|
|
833
|
+
const partOwnerNode = options?.renderBefore ?? container;
|
|
834
|
+
let part = partOwnerNode["_$litPart$"];
|
|
835
|
+
debugLogEvent && debugLogEvent({
|
|
836
|
+
kind: "begin render",
|
|
837
|
+
id: renderId,
|
|
838
|
+
value,
|
|
839
|
+
container,
|
|
840
|
+
options,
|
|
841
|
+
part
|
|
842
|
+
});
|
|
843
|
+
if (part === undefined) {
|
|
844
|
+
const endNode = options?.renderBefore ?? null;
|
|
845
|
+
partOwnerNode["_$litPart$"] = part = new ChildPart(container.insertBefore(createMarker(), endNode), endNode, undefined, options ?? {});
|
|
846
|
+
}
|
|
847
|
+
part._$setValue(value);
|
|
848
|
+
debugLogEvent && debugLogEvent({
|
|
849
|
+
kind: "end render",
|
|
850
|
+
id: renderId,
|
|
851
|
+
value,
|
|
852
|
+
container,
|
|
853
|
+
options,
|
|
854
|
+
part
|
|
855
|
+
});
|
|
856
|
+
return part;
|
|
857
|
+
};
|
|
858
|
+
if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
859
|
+
render.setSanitizer = setSanitizer;
|
|
860
|
+
render.createSanitizer = createSanitizer;
|
|
861
|
+
if (DEV_MODE) {
|
|
862
|
+
render._testOnlyClearSanitizerFactoryDoNotCallOrElse = _testOnlyClearSanitizerFactoryDoNotCallOrElse;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
export { html, svg, mathml, noChange, nothing, _$LH, render };
|