@stencil/core 5.0.0-alpha.8 → 5.0.0-beta.0
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/README.md +94 -0
- package/dist/app-data/index.d.ts +2 -0
- package/dist/{runtime/app-data → app-data}/index.js +5 -2
- package/dist/client-BRu0GtRn.mjs +2368 -0
- package/dist/compiler/index.d.mts +167 -3
- package/dist/compiler/index.mjs +3 -3
- package/dist/compiler/utils/index.d.mts +272 -2
- package/dist/compiler/utils/index.mjs +4 -3
- package/dist/{compiler-B3pUYg_P.mjs → compiler-NrvbUOX1.mjs} +2904 -1269
- package/dist/declarations/stencil-ext-modules.d.ts +5 -5
- package/dist/declarations/stencil-public-compiler.d.ts +208 -62
- package/dist/declarations/stencil-public-docs.d.ts +9 -0
- package/dist/declarations/stencil-public-runtime.d.ts +91 -6
- package/dist/fragment-Di1hWOC8.mjs +4 -0
- package/dist/{regular-expression-CFVJOTUh.mjs → helpers-Cpp3qc3u.mjs} +31 -15
- package/dist/index-BOrz3rbJ.d.mts +100 -0
- package/dist/{index-BuveMLxy.d.ts → index-DnISpqrd.d.ts} +150 -10
- package/dist/{index-CVhWFUM0.d.mts → index-RrQfiPWK.d.mts} +490 -841
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +91 -2
- package/dist/jsx-runtime.mjs +2 -1
- package/dist/{node-10UamZmn.mjs → node-75gQKkFz.mjs} +60 -58
- package/dist/{chunk-z9aeyW2b.mjs → rolldown-runtime-BhDjJH2R.mjs} +1 -1
- package/dist/runtime/client/lazy.js +483 -347
- package/dist/runtime/client/runtime.d.ts +150 -39
- package/dist/runtime/client/runtime.js +483 -347
- package/dist/runtime/index.d.ts +6 -32
- package/dist/runtime/index.js +482 -345
- package/dist/runtime/server/index.d.mts +81 -9
- package/dist/runtime/server/index.mjs +419 -193
- package/dist/runtime/server/runner.d.mts +3 -0
- package/dist/runtime/server/runner.mjs +321 -338
- package/dist/signals/index.d.ts +2 -0
- package/dist/signals/index.js +5 -2
- package/dist/sys/node/index.d.mts +1 -2
- package/dist/sys/node/index.mjs +1 -1
- package/dist/sys/node/worker.d.mts +1 -1
- package/dist/sys/node/worker.mjs +6 -3
- package/dist/testing/index.d.mts +4716 -105
- package/dist/testing/index.mjs +7744 -791
- package/dist/util-IKfWWLJo.mjs +724 -0
- package/dist/validation-DAdGTrys.mjs +791 -0
- package/package.json +33 -33
- package/dist/client-Dd-NB5Ei.mjs +0 -4833
- package/dist/index-ch-cf-bZ.d.mts +0 -205
- package/dist/runtime/app-data/index.d.ts +0 -2
- package/dist/validation-ByxKj8bC.mjs +0 -1458
- /package/{LICENSE.md → LICENSE} +0 -0
- /package/dist/{runtime/app-globals → app-globals}/index.d.ts +0 -0
- /package/dist/{runtime/app-globals → app-globals}/index.js +0 -0
|
@@ -0,0 +1,2368 @@
|
|
|
1
|
+
import { B as HOST_FLAGS, C as CMP_FLAGS, G as NODE_TYPES, Z as SVG_NS, o as isComplexType, s as isDef, x as queryNonceMetaTagContent } from "./helpers-Cpp3qc3u.mjs";
|
|
2
|
+
import { effect } from "@preact/signals-core";
|
|
3
|
+
//#region src/app-data/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* A collection of default build flags for a Stencil project.
|
|
6
|
+
*
|
|
7
|
+
* This collection can be found throughout the Stencil codebase, often imported from the `virtual:app-data` module like so:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { BUILD } from 'virtual:app-data';
|
|
10
|
+
* ```
|
|
11
|
+
* and is used to determine if a portion of the output of a Stencil _project_'s compilation step can be eliminated.
|
|
12
|
+
*
|
|
13
|
+
* e.g. When `BUILD.allRenderFn` evaluates to `false`, the compiler will eliminate conditional statements like:
|
|
14
|
+
* ```ts
|
|
15
|
+
* if (BUILD.allRenderFn) {
|
|
16
|
+
* // some code that will be eliminated if BUILD.allRenderFn is false
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* `virtual:app-data`, the module that `BUILD` is imported from, is an alias for `@stencil/core/app-data`, and is
|
|
21
|
+
* partially referenced by {@link STENCIL_APP_DATA_ID}. The `src/compiler/bundle/app-data-plugin.ts` references
|
|
22
|
+
* `STENCIL_APP_DATA_ID` uses it to replace these defaults with {@link BuildConditionals} that are derived from a
|
|
23
|
+
* Stencil project's contents (i.e. metadata from the components). This replacement happens at a Stencil project's
|
|
24
|
+
* compile time. Such code can be found at `src/compiler/app-core/app-data.ts`.
|
|
25
|
+
*/
|
|
26
|
+
const BUILD = {
|
|
27
|
+
allRenderFn: false,
|
|
28
|
+
element: true,
|
|
29
|
+
event: true,
|
|
30
|
+
hasRenderFn: true,
|
|
31
|
+
hostListener: true,
|
|
32
|
+
hostListenerTargetWindow: true,
|
|
33
|
+
hostListenerTargetDocument: true,
|
|
34
|
+
hostListenerTargetBody: true,
|
|
35
|
+
hostListenerTarget: true,
|
|
36
|
+
member: true,
|
|
37
|
+
method: true,
|
|
38
|
+
mode: true,
|
|
39
|
+
observeAttribute: true,
|
|
40
|
+
prop: true,
|
|
41
|
+
propMutable: true,
|
|
42
|
+
reflect: true,
|
|
43
|
+
scoped: true,
|
|
44
|
+
shadowDom: true,
|
|
45
|
+
shadowModeClosed: false,
|
|
46
|
+
slot: true,
|
|
47
|
+
cssAnnotations: true,
|
|
48
|
+
state: true,
|
|
49
|
+
style: true,
|
|
50
|
+
formAssociated: true,
|
|
51
|
+
svg: true,
|
|
52
|
+
updatable: true,
|
|
53
|
+
vdomAttribute: true,
|
|
54
|
+
vdomXlink: true,
|
|
55
|
+
vdomClass: true,
|
|
56
|
+
vdomFunctional: true,
|
|
57
|
+
vdomKey: true,
|
|
58
|
+
vdomListener: true,
|
|
59
|
+
vdomRef: true,
|
|
60
|
+
vdomPropOrAttr: true,
|
|
61
|
+
vdomPropOrAttrPrefix: true,
|
|
62
|
+
vdomRender: true,
|
|
63
|
+
vdomStyle: true,
|
|
64
|
+
vdomText: true,
|
|
65
|
+
propChangeCallback: true,
|
|
66
|
+
taskQueue: true,
|
|
67
|
+
lifecycle: true,
|
|
68
|
+
serializer: true,
|
|
69
|
+
deserializer: true,
|
|
70
|
+
patchAll: true,
|
|
71
|
+
patchChildren: true,
|
|
72
|
+
patchClone: true,
|
|
73
|
+
patchInsert: true,
|
|
74
|
+
hotModuleReplacement: false,
|
|
75
|
+
isDebug: false,
|
|
76
|
+
isDev: false,
|
|
77
|
+
isTesting: false,
|
|
78
|
+
hydrateServerSide: false,
|
|
79
|
+
hydrateClientSide: true,
|
|
80
|
+
lifecycleDOMEvents: false,
|
|
81
|
+
lazyLoad: false,
|
|
82
|
+
profile: false,
|
|
83
|
+
slotRelocation: true,
|
|
84
|
+
lightDomPatches: true,
|
|
85
|
+
slotChildNodes: true,
|
|
86
|
+
slotCloneNode: true,
|
|
87
|
+
slotDomMutations: true,
|
|
88
|
+
slotTextContent: true,
|
|
89
|
+
hydratedAttribute: false,
|
|
90
|
+
hydratedClass: true,
|
|
91
|
+
invisiblePrehydration: true,
|
|
92
|
+
staticHydrationStyles: false,
|
|
93
|
+
propBoolean: true,
|
|
94
|
+
propNumber: true,
|
|
95
|
+
propString: true,
|
|
96
|
+
constructableCSS: true,
|
|
97
|
+
devTools: false,
|
|
98
|
+
shadowDelegatesFocus: true,
|
|
99
|
+
shadowSlotAssignmentManual: false,
|
|
100
|
+
shadowClonable: true,
|
|
101
|
+
shadowSerializable: true,
|
|
102
|
+
initializeNextTick: false,
|
|
103
|
+
asyncLoading: true,
|
|
104
|
+
asyncQueue: false
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/client/client-build.ts
|
|
108
|
+
const Build = {
|
|
109
|
+
isDev: BUILD.isDev,
|
|
110
|
+
isBrowser: true,
|
|
111
|
+
isServer: false,
|
|
112
|
+
isTesting: BUILD.isTesting
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/client/client-host-ref.ts
|
|
116
|
+
/**
|
|
117
|
+
* Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
|
|
118
|
+
*
|
|
119
|
+
* @param ref the runtime ref of interest
|
|
120
|
+
* @returns the Host reference (if found) or undefined
|
|
121
|
+
*/
|
|
122
|
+
const getHostRef = (ref) => {
|
|
123
|
+
if (ref.__s_ghr) return ref.__s_ghr();
|
|
124
|
+
};
|
|
125
|
+
const isMemberInElement = (elm, memberName) => memberName in elm;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/client/client-log.ts
|
|
128
|
+
let customError;
|
|
129
|
+
const consoleError = (e, el) => (customError || console.error)(e, el);
|
|
130
|
+
const STENCIL_DEV_MODE = BUILD.isTesting ? ["STENCIL:"] : ["%cstencil", "color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px"];
|
|
131
|
+
const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
|
|
132
|
+
const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
|
|
133
|
+
const setErrorHandler = (handler) => customError = handler;
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/client/client-load-module.ts
|
|
136
|
+
/*!__STENCIL_STATIC_IMPORT_SWITCH__*/
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/client/client-style.ts
|
|
139
|
+
const styles = /*@__PURE__*/ new Map();
|
|
140
|
+
const modeResolutionChain = [];
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/runtime/runtime-constants.ts
|
|
143
|
+
/**
|
|
144
|
+
* Bit flags for recording various properties of VDom nodes
|
|
145
|
+
*/
|
|
146
|
+
const VNODE_FLAGS = {
|
|
147
|
+
/**
|
|
148
|
+
* Whether or not a vdom node is a slot reference
|
|
149
|
+
*/
|
|
150
|
+
isSlotReference: 1,
|
|
151
|
+
/**
|
|
152
|
+
* Whether or not a slot element has fallback content
|
|
153
|
+
*/
|
|
154
|
+
isSlotFallback: 2,
|
|
155
|
+
/**
|
|
156
|
+
* Whether or not an element is a host element
|
|
157
|
+
*/
|
|
158
|
+
isHost: 4
|
|
159
|
+
};
|
|
160
|
+
const PLATFORM_FLAGS = {
|
|
161
|
+
/**
|
|
162
|
+
* designates a node in the DOM as being actively moved by the runtime
|
|
163
|
+
*/
|
|
164
|
+
isTmpDisconnected: 1,
|
|
165
|
+
appLoaded: 2,
|
|
166
|
+
queueSync: 4,
|
|
167
|
+
queueMask: 6
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* A (subset) of node types which are relevant for the Stencil runtime. These
|
|
171
|
+
* values are based on the values which can possibly be returned by the
|
|
172
|
+
* `.nodeType` property of a DOM node. See here for details:
|
|
173
|
+
*
|
|
174
|
+
* {@link https://dom.spec.whatwg.org/#ref-for-dom-node-nodetype%E2%91%A0}
|
|
175
|
+
*/
|
|
176
|
+
const NODE_TYPE = {
|
|
177
|
+
ElementNode: 1,
|
|
178
|
+
TextNode: 3,
|
|
179
|
+
CommentNode: 8,
|
|
180
|
+
DocumentNode: 9,
|
|
181
|
+
DocumentTypeNode: 10,
|
|
182
|
+
DocumentFragment: 11
|
|
183
|
+
};
|
|
184
|
+
const HYDRATED_STYLE_ID = "sty-id";
|
|
185
|
+
const HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
|
|
186
|
+
/**
|
|
187
|
+
* Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
|
|
188
|
+
*
|
|
189
|
+
* Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
|
|
190
|
+
* support as of Stencil v4.
|
|
191
|
+
*/
|
|
192
|
+
const SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
|
|
193
|
+
const XLINK_NS = "http://www.w3.org/1999/xlink";
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/client/client-window.ts
|
|
196
|
+
const win = typeof window !== "undefined" ? window : {};
|
|
197
|
+
win.HTMLElement;
|
|
198
|
+
const plt = {
|
|
199
|
+
$flags$: 0,
|
|
200
|
+
$resourcesUrl$: "",
|
|
201
|
+
jmp: (h) => h(),
|
|
202
|
+
raf: (h) => requestAnimationFrame(h),
|
|
203
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
204
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
205
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts)
|
|
206
|
+
};
|
|
207
|
+
const setPlatformHelpers = (helpers) => {
|
|
208
|
+
Object.assign(plt, helpers);
|
|
209
|
+
};
|
|
210
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
211
|
+
const supportsConstructableStylesheets = BUILD.constructableCSS ? /*@__PURE__*/ (() => {
|
|
212
|
+
try {
|
|
213
|
+
if (!win.document.adoptedStyleSheets) return false;
|
|
214
|
+
return typeof new CSSStyleSheet().replaceSync === "function";
|
|
215
|
+
} catch {}
|
|
216
|
+
return false;
|
|
217
|
+
})() : false;
|
|
218
|
+
const supportsMutableAdoptedStyleSheets = supportsConstructableStylesheets ? /*@__PURE__*/ (() => !!win.document && Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, "length").writable)() : false;
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/client/client-task-queue.ts
|
|
221
|
+
let queueCongestion = 0;
|
|
222
|
+
let queuePending = false;
|
|
223
|
+
const queueDomReads = [];
|
|
224
|
+
const queueDomWrites = [];
|
|
225
|
+
const queueDomWritesLow = [];
|
|
226
|
+
const scheduleFlush = () => win.document?.hidden ? nextTick(flush) : plt.raf(flush);
|
|
227
|
+
const queueTask = (queue, write) => (cb) => {
|
|
228
|
+
queue.push(cb);
|
|
229
|
+
if (!queuePending) {
|
|
230
|
+
queuePending = true;
|
|
231
|
+
if (write && plt.$flags$ & PLATFORM_FLAGS.queueSync) nextTick(flush);
|
|
232
|
+
else scheduleFlush();
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
const consume = (queue) => {
|
|
236
|
+
for (let i = 0; i < queue.length; i++) try {
|
|
237
|
+
queue[i](performance.now());
|
|
238
|
+
} catch (e) {
|
|
239
|
+
consoleError(e);
|
|
240
|
+
}
|
|
241
|
+
queue.length = 0;
|
|
242
|
+
};
|
|
243
|
+
const consumeTimeout = (queue, timeout) => {
|
|
244
|
+
let i = 0;
|
|
245
|
+
let ts = 0;
|
|
246
|
+
while (i < queue.length && (ts = performance.now()) < timeout) try {
|
|
247
|
+
queue[i++](ts);
|
|
248
|
+
} catch (e) {
|
|
249
|
+
consoleError(e);
|
|
250
|
+
}
|
|
251
|
+
if (i === queue.length) queue.length = 0;
|
|
252
|
+
else if (i !== 0) queue.splice(0, i);
|
|
253
|
+
};
|
|
254
|
+
const flush = () => {
|
|
255
|
+
if (BUILD.asyncQueue) queueCongestion++;
|
|
256
|
+
consume(queueDomReads);
|
|
257
|
+
if (BUILD.asyncQueue) {
|
|
258
|
+
const timeout = (plt.$flags$ & PLATFORM_FLAGS.queueMask) === PLATFORM_FLAGS.appLoaded ? performance.now() + 14 * Math.ceil(queueCongestion * (1 / 10)) : Infinity;
|
|
259
|
+
consumeTimeout(queueDomWrites, timeout);
|
|
260
|
+
consumeTimeout(queueDomWritesLow, timeout);
|
|
261
|
+
if (queueDomWrites.length > 0) {
|
|
262
|
+
queueDomWritesLow.push(...queueDomWrites);
|
|
263
|
+
queueDomWrites.length = 0;
|
|
264
|
+
}
|
|
265
|
+
if (queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0) scheduleFlush();
|
|
266
|
+
else queueCongestion = 0;
|
|
267
|
+
} else {
|
|
268
|
+
consume(queueDomWrites);
|
|
269
|
+
if (queuePending = queueDomReads.length > 0) scheduleFlush();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
const nextTick = (cb) => promiseResolve().then(cb);
|
|
273
|
+
const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
|
|
274
|
+
const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/runtime/asset-path.ts
|
|
277
|
+
const getAssetPath = (path) => {
|
|
278
|
+
const base = plt.$resourcesUrl$ || new URL(".", import.meta.url).href;
|
|
279
|
+
const assetUrl = new URL(path, base);
|
|
280
|
+
return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
|
|
281
|
+
};
|
|
282
|
+
const setAssetPath = (path) => plt.$resourcesUrl$ = path;
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/runtime/slot-polyfill-utils.ts
|
|
285
|
+
/**
|
|
286
|
+
* Adjust the `.hidden` property as-needed on any nodes in a DOM subtree which
|
|
287
|
+
* are slot fallback nodes - `<slot-fb>...</slot-fb>`
|
|
288
|
+
*
|
|
289
|
+
* A slot fallback node should be visible by default. Then, it should be
|
|
290
|
+
* conditionally hidden if:
|
|
291
|
+
*
|
|
292
|
+
* - it has a sibling with a `slot` property set to its slot name or if
|
|
293
|
+
* - it is a default fallback slot node, in which case we hide if it has any
|
|
294
|
+
* content
|
|
295
|
+
*
|
|
296
|
+
* @param elm the element of interest
|
|
297
|
+
*/
|
|
298
|
+
const updateFallbackSlotVisibility = (elm) => {
|
|
299
|
+
const childNodes = internalCall(elm, "childNodes");
|
|
300
|
+
if (elm.tagName && elm.tagName.includes("-") && elm["s-cr"] && elm.tagName !== "SLOT-FB") getHostSlotNodes(childNodes, elm.tagName).forEach((slotNode) => {
|
|
301
|
+
if (slotNode.nodeType === NODE_TYPE.ElementNode && slotNode.tagName === "SLOT-FB") {
|
|
302
|
+
if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) slotNode.hidden = true;
|
|
303
|
+
else slotNode.hidden = false;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
let i = 0;
|
|
307
|
+
for (i = 0; i < childNodes.length; i++) {
|
|
308
|
+
const childNode = childNodes[i];
|
|
309
|
+
if (childNode.nodeType === NODE_TYPE.ElementNode && internalCall(childNode, "childNodes").length) updateFallbackSlotVisibility(childNode);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* Get's the child nodes of a component that are actually slotted.
|
|
314
|
+
* It does this by using root nodes of a component; for each slotted node there is a
|
|
315
|
+
* corresponding slot location node which points to the slotted node (via `['s-nr']`).
|
|
316
|
+
*
|
|
317
|
+
* This is only required until all patches are unified / switched on all the time (then we can rely on `childNodes`)
|
|
318
|
+
* either under 'lightDomPatches' or on by default
|
|
319
|
+
* @param childNodes all 'internal' child nodes of the component
|
|
320
|
+
* @returns An array of slotted reference nodes.
|
|
321
|
+
*/
|
|
322
|
+
const getSlottedChildNodes = (childNodes) => {
|
|
323
|
+
const result = [];
|
|
324
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
325
|
+
const slottedNode = childNodes[i]["s-nr"] || void 0;
|
|
326
|
+
if (slottedNode && slottedNode.isConnected) result.push(slottedNode);
|
|
327
|
+
}
|
|
328
|
+
return result;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Recursively searches a series of child nodes for slot node/s, optionally with a provided slot name.
|
|
332
|
+
* @param childNodes the nodes to search for a slot with a specific name. Should be an element's root nodes.
|
|
333
|
+
* @param hostName the host name of the slot to match on.
|
|
334
|
+
* @param slotName the name of the slot to match on.
|
|
335
|
+
* @returns a reference to the slot node that matches the provided name, `null` otherwise
|
|
336
|
+
*/
|
|
337
|
+
function getHostSlotNodes(childNodes, hostName, slotName) {
|
|
338
|
+
let i = 0;
|
|
339
|
+
let slottedNodes = [];
|
|
340
|
+
let childNode;
|
|
341
|
+
for (; i < childNodes.length; i++) {
|
|
342
|
+
childNode = childNodes[i];
|
|
343
|
+
if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
|
|
344
|
+
slottedNodes.push(childNode);
|
|
345
|
+
if (typeof slotName !== "undefined") return slottedNodes;
|
|
346
|
+
}
|
|
347
|
+
slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
|
|
348
|
+
}
|
|
349
|
+
return slottedNodes;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Get all 'child' sibling nodes of a slot node
|
|
353
|
+
* @param slot - the slot node to get the child nodes from
|
|
354
|
+
* @param slotName - the name of the slot to match on
|
|
355
|
+
* @param includeSlot - whether to include the slot node in the result
|
|
356
|
+
* @returns child nodes of the slot node
|
|
357
|
+
*/
|
|
358
|
+
const getSlotChildSiblings = (slot, slotName, includeSlot = true) => {
|
|
359
|
+
const childNodes = [];
|
|
360
|
+
if (includeSlot && slot["s-sr"] || !slot["s-sr"]) childNodes.push(slot);
|
|
361
|
+
let node = slot;
|
|
362
|
+
while (node = node.nextSibling) if (getSlotName(node) === slotName && (includeSlot || !node["s-sr"])) childNodes.push(node);
|
|
363
|
+
return childNodes;
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Check whether a node is located in a given named slot.
|
|
367
|
+
*
|
|
368
|
+
* @param nodeToRelocate the node of interest
|
|
369
|
+
* @param slotName the slot name to check
|
|
370
|
+
* @returns whether the node is located in the slot or not
|
|
371
|
+
*/
|
|
372
|
+
const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
|
|
373
|
+
if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) {
|
|
374
|
+
if (nodeToRelocate.getAttribute("slot") === null && slotName === "") return true;
|
|
375
|
+
if (nodeToRelocate.getAttribute("slot") === slotName) return true;
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
if (typeof nodeToRelocate["s-sa"] === "string") return nodeToRelocate["s-sa"] === slotName;
|
|
379
|
+
return slotName === "";
|
|
380
|
+
};
|
|
381
|
+
const getSlotName = (node) => typeof node["s-sn"] === "string" ? node["s-sn"] : node.nodeType === 1 && node.getAttribute("slot") || void 0;
|
|
382
|
+
/**
|
|
383
|
+
* Add `assignedElements` and `assignedNodes` methods on a fake slot node
|
|
384
|
+
*
|
|
385
|
+
* @param node - slot node to patch
|
|
386
|
+
*/
|
|
387
|
+
function patchSlotNode(node) {
|
|
388
|
+
if (node.assignedElements || node.assignedNodes || !node["s-sr"]) return;
|
|
389
|
+
const assignedFactory = (elementsOnly) => function(opts) {
|
|
390
|
+
const toReturn = [];
|
|
391
|
+
const slotName = this["s-sn"];
|
|
392
|
+
if (opts?.flatten) {
|
|
393
|
+
if (BUILD.isDev) console.error("Flattening is not supported for Stencil non-shadow slots. You can use `.childNodes` for nested slot fallback content.");
|
|
394
|
+
else console.error("Flattening not supported for Stencil non-shadow slots");
|
|
395
|
+
}
|
|
396
|
+
const parent = this["s-cr"].parentElement;
|
|
397
|
+
(parent.__childNodes ? parent.childNodes : getSlottedChildNodes(parent.childNodes)).forEach((n) => {
|
|
398
|
+
if (slotName === getSlotName(n)) toReturn.push(n);
|
|
399
|
+
});
|
|
400
|
+
if (elementsOnly) return toReturn.filter((n) => n.nodeType === NODE_TYPE.ElementNode);
|
|
401
|
+
return toReturn;
|
|
402
|
+
}.bind(node);
|
|
403
|
+
node.assignedElements = assignedFactory(true);
|
|
404
|
+
node.assignedNodes = assignedFactory(false);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Dispatches a `slotchange` event on a fake `<slot />` node.
|
|
408
|
+
*
|
|
409
|
+
* @param elm the slot node to dispatch the event from
|
|
410
|
+
*/
|
|
411
|
+
function dispatchSlotChangeEvent(elm) {
|
|
412
|
+
elm.name = elm["s-sn"] || "";
|
|
413
|
+
elm.dispatchEvent(new CustomEvent("slotchange", {
|
|
414
|
+
bubbles: false,
|
|
415
|
+
cancelable: false,
|
|
416
|
+
composed: false
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Find the slot node that a slotted node belongs to
|
|
421
|
+
*
|
|
422
|
+
* @param slottedNode - the slotted node to find the slot for
|
|
423
|
+
* @param parentHost - the parent host element of the slotted node
|
|
424
|
+
* @returns the slot node and slot name
|
|
425
|
+
*/
|
|
426
|
+
function findSlotFromSlottedNode(slottedNode, parentHost) {
|
|
427
|
+
parentHost = parentHost || slottedNode["s-ol"]?.parentElement;
|
|
428
|
+
if (!parentHost) return {
|
|
429
|
+
slotNode: null,
|
|
430
|
+
slotName: ""
|
|
431
|
+
};
|
|
432
|
+
const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
|
|
433
|
+
return {
|
|
434
|
+
slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
|
|
435
|
+
slotName
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/runtime/dom-extras.ts
|
|
440
|
+
/**
|
|
441
|
+
* Patches the `parentNode` accessor of a non-shadow slotted node
|
|
442
|
+
*
|
|
443
|
+
* @param node the slotted node to be patched
|
|
444
|
+
*/
|
|
445
|
+
const patchParentNode = (node) => {
|
|
446
|
+
if (!node || node.__parentNode) return;
|
|
447
|
+
patchHostOriginalAccessor("parentNode", node);
|
|
448
|
+
Object.defineProperty(node, "parentNode", {
|
|
449
|
+
get: function() {
|
|
450
|
+
return this["s-ol"]?.parentNode || this.__parentNode;
|
|
451
|
+
},
|
|
452
|
+
set: function(value) {
|
|
453
|
+
this.__parentNode = value;
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
const validElementPatches = [
|
|
458
|
+
"children",
|
|
459
|
+
"nextElementSibling",
|
|
460
|
+
"previousElementSibling"
|
|
461
|
+
];
|
|
462
|
+
const validNodesPatches = [
|
|
463
|
+
"childNodes",
|
|
464
|
+
"firstChild",
|
|
465
|
+
"lastChild",
|
|
466
|
+
"nextSibling",
|
|
467
|
+
"previousSibling",
|
|
468
|
+
"textContent",
|
|
469
|
+
"parentNode"
|
|
470
|
+
];
|
|
471
|
+
/**
|
|
472
|
+
* Patches a node or element; making it's original accessor method available under a new name.
|
|
473
|
+
* e.g. `nextSibling` -> `__nextSibling`
|
|
474
|
+
*
|
|
475
|
+
* @param accessorName - the name of the accessor to patch
|
|
476
|
+
* @param node - the node to patch
|
|
477
|
+
*/
|
|
478
|
+
function patchHostOriginalAccessor(accessorName, node) {
|
|
479
|
+
/**
|
|
480
|
+
* skip this method if a component was imported from a non-browser environment
|
|
481
|
+
*/
|
|
482
|
+
if (!globalThis.Node || !globalThis.Element) return;
|
|
483
|
+
let accessor;
|
|
484
|
+
if (validElementPatches.includes(accessorName)) accessor = Object.getOwnPropertyDescriptor(Element.prototype, accessorName);
|
|
485
|
+
else if (validNodesPatches.includes(accessorName)) accessor = Object.getOwnPropertyDescriptor(Node.prototype, accessorName);
|
|
486
|
+
if (!accessor) accessor = Object.getOwnPropertyDescriptor(node, accessorName);
|
|
487
|
+
if (accessor) Object.defineProperty(node, "__" + accessorName, accessor);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Get the original / internal accessor or method of a node or element.
|
|
491
|
+
*
|
|
492
|
+
* @param node - the node to get the accessor from
|
|
493
|
+
* @param method - the name of the accessor to get
|
|
494
|
+
*
|
|
495
|
+
* @returns the original accessor or method of the node
|
|
496
|
+
*/
|
|
497
|
+
function internalCall(node, method) {
|
|
498
|
+
if ("__" + method in node) {
|
|
499
|
+
const toReturn = node["__" + method];
|
|
500
|
+
if (typeof toReturn !== "function") return toReturn;
|
|
501
|
+
return toReturn.bind(node);
|
|
502
|
+
} else {
|
|
503
|
+
if (typeof node[method] !== "function") return node[method];
|
|
504
|
+
return node[method].bind(node);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/runtime/element.ts
|
|
509
|
+
const getElement = (ref) => BUILD.lazyLoad ? getHostRef(ref)?.$hostElement$ : ref;
|
|
510
|
+
/**
|
|
511
|
+
* Get the shadow root for a Stencil component's host element.
|
|
512
|
+
* This works for both open and closed shadow DOM modes.
|
|
513
|
+
*
|
|
514
|
+
* For closed shadow DOM, `element.shadowRoot` returns `null` by design,
|
|
515
|
+
* but Stencil stores the reference internally so components can still
|
|
516
|
+
* access their own shadow root.
|
|
517
|
+
*
|
|
518
|
+
* @param element The host element (from @Element() decorator)
|
|
519
|
+
* @returns The shadow root, or null if no shadow root exists
|
|
520
|
+
*/
|
|
521
|
+
const getShadowRoot = (element) => {
|
|
522
|
+
if (BUILD.shadowModeClosed && element.__shadowRoot) return element.__shadowRoot;
|
|
523
|
+
return element.shadowRoot;
|
|
524
|
+
};
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/runtime/profile.ts
|
|
527
|
+
let i = 0;
|
|
528
|
+
const createTime = (fnName, tagName = "") => {
|
|
529
|
+
if (BUILD.profile && performance.mark) {
|
|
530
|
+
const key = `st:${fnName}:${tagName}:${i++}`;
|
|
531
|
+
performance.mark(key);
|
|
532
|
+
return () => performance.measure(`[Stencil] ${fnName}() <${tagName}>`, key);
|
|
533
|
+
} else return () => {};
|
|
534
|
+
};
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/runtime/styles.ts
|
|
537
|
+
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
538
|
+
/**
|
|
539
|
+
* Get or initialize the set of applied style scope IDs for a container element.
|
|
540
|
+
*
|
|
541
|
+
* @param container the container element to track styles for
|
|
542
|
+
* @returns the set of applied scope IDs
|
|
543
|
+
*/
|
|
544
|
+
const getAppliedStyles = (container) => {
|
|
545
|
+
let applied = rootAppliedStyles.get(container);
|
|
546
|
+
if (!applied) {
|
|
547
|
+
applied = /* @__PURE__ */ new Set();
|
|
548
|
+
rootAppliedStyles.set(container, applied);
|
|
549
|
+
}
|
|
550
|
+
return applied;
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Safely adopt a stylesheet into a container's adoptedStyleSheets.
|
|
554
|
+
* Handles both mutable and immutable adoptedStyleSheets arrays.
|
|
555
|
+
*
|
|
556
|
+
* @param container the shadow root or document to adopt styles into
|
|
557
|
+
* @param sheet the CSSStyleSheet to adopt
|
|
558
|
+
* @param prepend if true, add to beginning; if false, add to end
|
|
559
|
+
*/
|
|
560
|
+
const adoptStylesheet = (container, sheet, prepend = false) => {
|
|
561
|
+
if (supportsMutableAdoptedStyleSheets) {
|
|
562
|
+
if (prepend) container.adoptedStyleSheets.unshift(sheet);
|
|
563
|
+
else container.adoptedStyleSheets.push(sheet);
|
|
564
|
+
} else if (prepend) container.adoptedStyleSheets = [sheet, ...container.adoptedStyleSheets];
|
|
565
|
+
else container.adoptedStyleSheets = [...container.adoptedStyleSheets, sheet];
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
568
|
+
* Create a CSSStyleSheet for the correct window context.
|
|
569
|
+
* Constructable stylesheets can't be shared between windows,
|
|
570
|
+
* so we need to create one for the current window.
|
|
571
|
+
*
|
|
572
|
+
* @param container the container node (used to determine the window context)
|
|
573
|
+
* @param cssText the CSS text to populate the stylesheet with
|
|
574
|
+
* @returns a new CSSStyleSheet for the correct window
|
|
575
|
+
*/
|
|
576
|
+
const createStylesheetForWindow = (container, cssText) => {
|
|
577
|
+
const sheet = new (container.defaultView ?? (container.ownerDocument?.defaultView) ?? win).CSSStyleSheet();
|
|
578
|
+
sheet.replaceSync(cssText);
|
|
579
|
+
return sheet;
|
|
580
|
+
};
|
|
581
|
+
/**
|
|
582
|
+
* Get the style for a component, appending slot fallback CSS if needed.
|
|
583
|
+
* Returns a new value without mutating the cached style.
|
|
584
|
+
*
|
|
585
|
+
* @param style - the style string or CSSStyleSheet to process
|
|
586
|
+
* @returns the style (string or CSSStyleSheet) with slot CSS appended if needed, or undefined
|
|
587
|
+
*/
|
|
588
|
+
const getStyleWithSlotCss = (style) => {
|
|
589
|
+
if (!style) return SLOT_FB_CSS;
|
|
590
|
+
if (typeof style === "string") return style + SLOT_FB_CSS;
|
|
591
|
+
return style;
|
|
592
|
+
};
|
|
593
|
+
/**
|
|
594
|
+
* Attach the styles for a given component to the DOM
|
|
595
|
+
*
|
|
596
|
+
* If the element uses shadow or is already attached to the DOM then we can
|
|
597
|
+
* create a stylesheet inside of its associated document fragment, otherwise
|
|
598
|
+
* we'll stick the stylesheet into the document head.
|
|
599
|
+
*
|
|
600
|
+
* @param styleContainerNode the node within which a style element for the
|
|
601
|
+
* component of interest should be added
|
|
602
|
+
* @param cmpMeta runtime metadata for the component of interest
|
|
603
|
+
* @param mode an optional current mode
|
|
604
|
+
* @returns the scope ID for the component of interest
|
|
605
|
+
*/
|
|
606
|
+
const addStyle = (styleContainerNode, cmpMeta, mode) => {
|
|
607
|
+
const scopeId = getScopeId(cmpMeta, mode);
|
|
608
|
+
if (!win.document) return scopeId;
|
|
609
|
+
let style = styles.get(scopeId);
|
|
610
|
+
if (cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) style = getStyleWithSlotCss(style);
|
|
611
|
+
const isClosedShadowSSR = BUILD.hydrateServerSide && BUILD.shadowModeClosed && cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss && cmpMeta.$flags$ & CMP_FLAGS.shadowModeClosed;
|
|
612
|
+
if (styleContainerNode.nodeType !== NODE_TYPE.DocumentFragment && !isClosedShadowSSR) styleContainerNode = win.document;
|
|
613
|
+
if (style) {
|
|
614
|
+
if (typeof style === "string") {
|
|
615
|
+
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
616
|
+
const appliedStyles = getAppliedStyles(styleContainerNode);
|
|
617
|
+
let styleElm;
|
|
618
|
+
const existingStyleElm = (BUILD.hydrateClientSide || BUILD.hotModuleReplacement) && styleContainerNode.querySelector(`[sty-id="${scopeId}"]`);
|
|
619
|
+
if (existingStyleElm) existingStyleElm.textContent = style;
|
|
620
|
+
else if (!appliedStyles.has(scopeId)) {
|
|
621
|
+
styleElm = win.document.createElement("style");
|
|
622
|
+
styleElm.textContent = style;
|
|
623
|
+
const nonce = plt.$nonce$ ?? queryNonceMetaTagContent(win.document);
|
|
624
|
+
if (nonce != null) styleElm.setAttribute("nonce", nonce);
|
|
625
|
+
if (BUILD.hydrateServerSide && (cmpMeta.$flags$ & CMP_FLAGS.scopedCssEncapsulation || cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss || cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) || BUILD.hotModuleReplacement) styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
|
|
626
|
+
if (BUILD.hotModuleReplacement && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation) styleElm.setAttribute("data-slot-fb", "");
|
|
627
|
+
/**
|
|
628
|
+
* attach styles at the end of the head tag if we render scoped components
|
|
629
|
+
*/
|
|
630
|
+
if (!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation)) {
|
|
631
|
+
if (styleContainerNode.nodeName === "HEAD") {
|
|
632
|
+
/**
|
|
633
|
+
* if the page contains preconnect links, we want to insert the styles
|
|
634
|
+
* after the last preconnect link to ensure the styles are preloaded
|
|
635
|
+
*/
|
|
636
|
+
const preconnectLinks = styleContainerNode.querySelectorAll("link[rel=preconnect]");
|
|
637
|
+
const referenceNode = preconnectLinks.length > 0 ? preconnectLinks[preconnectLinks.length - 1].nextSibling : styleContainerNode.querySelector("style");
|
|
638
|
+
styleContainerNode.insertBefore(styleElm, referenceNode?.parentNode === styleContainerNode ? referenceNode : null);
|
|
639
|
+
} else if ("host" in styleContainerNode) {
|
|
640
|
+
if (supportsConstructableStylesheets) {
|
|
641
|
+
const stylesheet = createStylesheetForWindow(styleContainerNode, style);
|
|
642
|
+
adoptStylesheet(styleContainerNode, stylesheet, true);
|
|
643
|
+
} else {
|
|
644
|
+
/**
|
|
645
|
+
* If a scoped component is used within a shadow root and constructable stylesheets are
|
|
646
|
+
* not supported, we want to insert the styles at the beginning of the shadow root node.
|
|
647
|
+
*
|
|
648
|
+
* However, if there is already a style node in the shadow root, we just append
|
|
649
|
+
* the styles to the existing node.
|
|
650
|
+
*
|
|
651
|
+
* Note: order of how styles are applied is important. The new style node
|
|
652
|
+
* should be inserted before the existing style node.
|
|
653
|
+
*
|
|
654
|
+
* During HMR, create separate style elements for scoped components so they can be
|
|
655
|
+
* updated independently without affecting other components' styles.
|
|
656
|
+
*/
|
|
657
|
+
const existingStyleContainer = styleContainerNode.querySelector("style");
|
|
658
|
+
if (existingStyleContainer && !BUILD.hotModuleReplacement) existingStyleContainer.textContent = style + existingStyleContainer.textContent;
|
|
659
|
+
else styleContainerNode.prepend(styleElm);
|
|
660
|
+
}
|
|
661
|
+
} else styleContainerNode.append(styleElm);
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* attach styles at the beginning of a shadow root node if we render shadow components
|
|
665
|
+
*/
|
|
666
|
+
if (cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) {
|
|
667
|
+
if (isClosedShadowSSR) styleContainerNode.prepend(styleElm);
|
|
668
|
+
else styleContainerNode.insertBefore(styleElm, null);
|
|
669
|
+
}
|
|
670
|
+
if (appliedStyles) appliedStyles.add(scopeId);
|
|
671
|
+
}
|
|
672
|
+
} else if (BUILD.constructableCSS) {
|
|
673
|
+
const appliedStyles = getAppliedStyles(styleContainerNode);
|
|
674
|
+
if (!appliedStyles.has(scopeId)) {
|
|
675
|
+
const currentWindow = styleContainerNode.defaultView ?? styleContainerNode.ownerDocument.defaultView;
|
|
676
|
+
let stylesheet;
|
|
677
|
+
if (style.constructor === currentWindow.CSSStyleSheet) stylesheet = style;
|
|
678
|
+
else {
|
|
679
|
+
stylesheet = new currentWindow.CSSStyleSheet();
|
|
680
|
+
for (let i = 0; i < style.cssRules.length; i++) stylesheet.insertRule(style.cssRules[i].cssText, i);
|
|
681
|
+
}
|
|
682
|
+
adoptStylesheet(styleContainerNode, stylesheet);
|
|
683
|
+
appliedStyles.add(scopeId);
|
|
684
|
+
if (BUILD.hydrateClientSide && "host" in styleContainerNode) {
|
|
685
|
+
const ssrStyleElm = styleContainerNode.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`);
|
|
686
|
+
if (ssrStyleElm) writeTask(() => ssrStyleElm.remove());
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return scopeId;
|
|
692
|
+
};
|
|
693
|
+
/**
|
|
694
|
+
* Add styles for a given component to the DOM, optionally handling 'scoped'
|
|
695
|
+
* encapsulation by adding an appropriate class name to the host element.
|
|
696
|
+
*
|
|
697
|
+
* @param hostRef the host reference for the component of interest
|
|
698
|
+
*/
|
|
699
|
+
const attachStyles = (hostRef) => {
|
|
700
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
701
|
+
const elm = hostRef.$hostElement$;
|
|
702
|
+
const flags = cmpMeta.$flags$;
|
|
703
|
+
const endAttachStyles = createTime("attachStyles", cmpMeta.$tagName$);
|
|
704
|
+
let styleContainerNode;
|
|
705
|
+
const shadowRoot = BUILD.shadowDom ? getShadowRoot(elm) : null;
|
|
706
|
+
if (shadowRoot) styleContainerNode = shadowRoot;
|
|
707
|
+
else if (BUILD.hydrateServerSide && BUILD.shadowModeClosed && flags & CMP_FLAGS.shadowNeedsScopedCss && flags & CMP_FLAGS.shadowModeClosed) styleContainerNode = elm;
|
|
708
|
+
else styleContainerNode = elm.getRootNode();
|
|
709
|
+
const scopeId = addStyle(styleContainerNode, cmpMeta, hostRef.$modeName$);
|
|
710
|
+
if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & CMP_FLAGS.needsScopedEncapsulation) {
|
|
711
|
+
elm["s-sc"] = scopeId;
|
|
712
|
+
elm.classList.add(scopeId + "-h");
|
|
713
|
+
}
|
|
714
|
+
endAttachStyles();
|
|
715
|
+
};
|
|
716
|
+
/**
|
|
717
|
+
* Get the scope ID for a given component
|
|
718
|
+
*
|
|
719
|
+
* @param cmp runtime metadata for the component of interest
|
|
720
|
+
* @param mode the current mode (optional)
|
|
721
|
+
* @returns a scope ID for the component of interest
|
|
722
|
+
*/
|
|
723
|
+
const getScopeId = (cmp, mode) => "sc-" + (BUILD.mode && mode && cmp.$flags$ & CMP_FLAGS.hasMode ? cmp.$tagName$ + "-" + mode : cmp.$tagName$);
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region src/runtime/event-emitter.ts
|
|
726
|
+
/**
|
|
727
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
728
|
+
* @param elm the target of the Event
|
|
729
|
+
* @param name the name to give the custom Event
|
|
730
|
+
* @param opts options for configuring a custom Event
|
|
731
|
+
* @returns the custom Event
|
|
732
|
+
*/
|
|
733
|
+
const emitEvent = (elm, name, opts) => {
|
|
734
|
+
const ev = plt.ce(name, opts);
|
|
735
|
+
elm.dispatchEvent(ev);
|
|
736
|
+
return ev;
|
|
737
|
+
};
|
|
738
|
+
const getRegistry = () => customElements;
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/runtime/vdom/set-accessor.ts
|
|
741
|
+
/**
|
|
742
|
+
* Production setAccessor() function based on Preact by
|
|
743
|
+
* Jason Miller (@developit)
|
|
744
|
+
* Licensed under the MIT License
|
|
745
|
+
* https://github.com/developit/preact/blob/master/LICENSE
|
|
746
|
+
*
|
|
747
|
+
* Modified for Stencil's compiler and vdom
|
|
748
|
+
*/
|
|
749
|
+
/** Per-element, per-attribute signal subscription disposers. */
|
|
750
|
+
const signalAttrDisposers = /* @__PURE__ */ new WeakMap();
|
|
751
|
+
const disposeAllSignalAttrs = (elm) => {
|
|
752
|
+
if (!BUILD.vdomSignals) return;
|
|
753
|
+
const map = signalAttrDisposers.get(elm);
|
|
754
|
+
if (map) {
|
|
755
|
+
map.forEach((d) => d());
|
|
756
|
+
signalAttrDisposers.delete(elm);
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* When running a VDom render set properties present on a VDom node onto the
|
|
761
|
+
* corresponding HTML element.
|
|
762
|
+
*
|
|
763
|
+
* Note that this function has special functionality for the `class`,
|
|
764
|
+
* `style`, `key`, and `ref` attributes, as well as event handlers (like
|
|
765
|
+
* `onClick`, etc). All others are just passed through as-is.
|
|
766
|
+
*
|
|
767
|
+
* @param elm the HTMLElement onto which attributes should be set
|
|
768
|
+
* @param memberName the name of the attribute to set
|
|
769
|
+
* @param oldValue the old value for the attribute
|
|
770
|
+
* @param newValue the new value for the attribute
|
|
771
|
+
* @param isSvg whether we're in an svg context or not
|
|
772
|
+
* @param flags bitflags for Vdom variables
|
|
773
|
+
* @param initialRender whether this is the first render of the VDom
|
|
774
|
+
*/
|
|
775
|
+
const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialRender) => {
|
|
776
|
+
if (oldValue === newValue) return;
|
|
777
|
+
if (BUILD.vdomSignals && isSignalLike(newValue)) {
|
|
778
|
+
const attrMap = signalAttrDisposers.get(elm) ?? /* @__PURE__ */ new Map();
|
|
779
|
+
attrMap.get(memberName)?.();
|
|
780
|
+
if (!signalAttrDisposers.has(elm)) signalAttrDisposers.set(elm, attrMap);
|
|
781
|
+
let prevVal = oldValue;
|
|
782
|
+
attrMap.set(memberName, effect(() => {
|
|
783
|
+
const curVal = newValue.value;
|
|
784
|
+
setAccessor(elm, memberName, prevVal, curVal, isSvg, flags);
|
|
785
|
+
prevVal = curVal;
|
|
786
|
+
}));
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
if (BUILD.vdomSignals && isSignalLike(oldValue)) {
|
|
790
|
+
const attrMap = signalAttrDisposers.get(elm);
|
|
791
|
+
if (attrMap) {
|
|
792
|
+
attrMap.get(memberName)?.();
|
|
793
|
+
attrMap.delete(memberName);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
let isProp = isMemberInElement(elm, memberName);
|
|
797
|
+
let ln = memberName.toLowerCase();
|
|
798
|
+
if (BUILD.vdomClass && memberName === "class") {
|
|
799
|
+
const classList = elm.classList;
|
|
800
|
+
const oldClasses = parseClassList(oldValue);
|
|
801
|
+
let newClasses = parseClassList(newValue);
|
|
802
|
+
if (BUILD.hydrateClientSide && (elm["s-si"] || elm["s-sc"]) && initialRender) {
|
|
803
|
+
const scopeId = elm["s-sc"] || elm["s-si"];
|
|
804
|
+
newClasses.push(scopeId);
|
|
805
|
+
oldClasses.forEach((c) => {
|
|
806
|
+
if (c.startsWith(scopeId)) newClasses.push(c);
|
|
807
|
+
});
|
|
808
|
+
newClasses = [...new Set(newClasses)].filter((c) => c);
|
|
809
|
+
classList.add(...newClasses);
|
|
810
|
+
} else {
|
|
811
|
+
classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
|
|
812
|
+
classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
|
|
813
|
+
}
|
|
814
|
+
} else if (BUILD.vdomStyle && memberName === "style") {
|
|
815
|
+
if (BUILD.updatable) {
|
|
816
|
+
for (const prop in oldValue) if (!newValue || newValue[prop] == null) {
|
|
817
|
+
if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.removeProperty(prop);
|
|
818
|
+
else elm.style[prop] = "";
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
for (const prop in newValue) if (!oldValue || newValue[prop] !== oldValue[prop]) {
|
|
822
|
+
if (!BUILD.hydrateServerSide && prop.includes("-")) elm.style.setProperty(prop, newValue[prop]);
|
|
823
|
+
else elm.style[prop] = newValue[prop];
|
|
824
|
+
}
|
|
825
|
+
} else if (BUILD.vdomKey && memberName === "key") {} else if (BUILD.vdomRef && memberName === "ref") {
|
|
826
|
+
if (newValue) queueRefAttachment(newValue, elm);
|
|
827
|
+
} else if (BUILD.vdomListener && (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) && memberName[0] === "o" && memberName[1] === "n") {
|
|
828
|
+
if (memberName[2] === "-") memberName = memberName.slice(3);
|
|
829
|
+
else if (isMemberInElement(win, ln)) memberName = ln.slice(2);
|
|
830
|
+
else memberName = ln[2] + memberName.slice(3);
|
|
831
|
+
if (oldValue || newValue) {
|
|
832
|
+
const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
|
|
833
|
+
memberName = memberName.replace(/*@__PURE__*/ new RegExp(CAPTURE_EVENT_SUFFIX + "$"), "");
|
|
834
|
+
if (oldValue) plt.rel(elm, memberName, oldValue, capture);
|
|
835
|
+
if (newValue) plt.ael(elm, memberName, newValue, capture);
|
|
836
|
+
}
|
|
837
|
+
} else if (BUILD.vdomPropOrAttrPrefix && memberName[0] === "a" && memberName.startsWith("attr:")) {
|
|
838
|
+
const propName = memberName.slice(5);
|
|
839
|
+
let attrName;
|
|
840
|
+
if (BUILD.member) {
|
|
841
|
+
const hostRef = getHostRef(elm);
|
|
842
|
+
if (hostRef && hostRef.$cmpMeta$ && hostRef.$cmpMeta$.$members$) {
|
|
843
|
+
const memberMeta = hostRef.$cmpMeta$.$members$[propName];
|
|
844
|
+
if (memberMeta && memberMeta[1]) attrName = memberMeta[1];
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (!attrName) attrName = propName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
848
|
+
if (newValue == null || newValue === false) {
|
|
849
|
+
if (newValue !== false || elm.getAttribute(attrName) === "") elm.removeAttribute(attrName);
|
|
850
|
+
} else elm.setAttribute(attrName, newValue === true ? "" : newValue);
|
|
851
|
+
return;
|
|
852
|
+
} else if (BUILD.vdomPropOrAttrPrefix && memberName[0] === "p" && memberName.startsWith("prop:")) {
|
|
853
|
+
const propName = memberName.slice(5);
|
|
854
|
+
try {
|
|
855
|
+
elm[propName] = newValue;
|
|
856
|
+
} catch {}
|
|
857
|
+
return;
|
|
858
|
+
} else if (BUILD.vdomPropOrAttr) {
|
|
859
|
+
const isComplex = isComplexType(newValue);
|
|
860
|
+
if (!BUILD.lazyLoad) {
|
|
861
|
+
const isStandardAttr = ln.startsWith("aria-") || ln.startsWith("data-");
|
|
862
|
+
if (!isProp && !isStandardAttr && elm.tagName?.includes("-") && elm.tagName !== "SLOT-FB" && typeof customElements !== "undefined" && !customElements.get(elm.tagName.toLowerCase())) {
|
|
863
|
+
if (!elm["s-pp"]) elm["s-pp"] = /* @__PURE__ */ new Map();
|
|
864
|
+
elm["s-pp"].set(memberName, newValue);
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
if ((isProp || isComplex && newValue !== null) && !isSvg) try {
|
|
869
|
+
if (!elm.tagName.includes("-")) {
|
|
870
|
+
const n = newValue == null ? "" : newValue;
|
|
871
|
+
if (memberName === "list") isProp = false;
|
|
872
|
+
else if (oldValue == null || elm[memberName] !== n) {
|
|
873
|
+
if (typeof elm.__lookupSetter__(memberName) === "function") elm[memberName] = n;
|
|
874
|
+
else elm.setAttribute(memberName, n);
|
|
875
|
+
}
|
|
876
|
+
} else if (elm[memberName] !== newValue) elm[memberName] = newValue;
|
|
877
|
+
} catch {}
|
|
878
|
+
/**
|
|
879
|
+
* Need to manually update attribute if:
|
|
880
|
+
* - memberName is not an attribute
|
|
881
|
+
* - if we are rendering the host element in order to reflect attribute
|
|
882
|
+
* - if it's a SVG, since properties might not work in <svg>
|
|
883
|
+
* - if the newValue is null/undefined or 'false'.
|
|
884
|
+
*/
|
|
885
|
+
let xlink = false;
|
|
886
|
+
if (BUILD.vdomXlink) {
|
|
887
|
+
if (ln !== (ln = ln.replace(/^xlink:?/, ""))) {
|
|
888
|
+
memberName = ln;
|
|
889
|
+
xlink = true;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
if (newValue == null || newValue === false) {
|
|
893
|
+
if (newValue !== false || elm.getAttribute(memberName) === "" || flags & VNODE_FLAGS.isHost && !isEnumeratedAttribute(memberName)) {
|
|
894
|
+
if (BUILD.vdomXlink && xlink) elm.removeAttributeNS(XLINK_NS, memberName);
|
|
895
|
+
else elm.removeAttribute(memberName);
|
|
896
|
+
}
|
|
897
|
+
} else if ((!isProp || flags & VNODE_FLAGS.isHost || isSvg) && !isComplex && elm.nodeType === NODE_TYPE.ElementNode) {
|
|
898
|
+
newValue = newValue === true ? "" : newValue;
|
|
899
|
+
if (BUILD.vdomXlink && xlink) elm.setAttributeNS(XLINK_NS, memberName, newValue);
|
|
900
|
+
else elm.setAttribute(memberName, newValue);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
/**
|
|
905
|
+
* Attribute names that are enumerated (tri-state true/false/unset) rather than
|
|
906
|
+
* plain boolean-presence attributes. An explicit `"false"` string on one of
|
|
907
|
+
* these is semantically different from the attribute being absent, so a
|
|
908
|
+
* reflected `false` value must not clear a pre-existing literal value.
|
|
909
|
+
*/
|
|
910
|
+
const ENUMERATED_ATTRIBUTES = /*@__PURE__*/ new Set([
|
|
911
|
+
"draggable",
|
|
912
|
+
"contenteditable",
|
|
913
|
+
"spellcheck"
|
|
914
|
+
]);
|
|
915
|
+
const isEnumeratedAttribute = (attrName) => ENUMERATED_ATTRIBUTES.has(attrName) || attrName.startsWith("aria-");
|
|
916
|
+
const parseClassListRegex = /\s/;
|
|
917
|
+
/**
|
|
918
|
+
* Parsed a string of classnames into an array
|
|
919
|
+
* @param value className string, e.g. "foo bar baz"
|
|
920
|
+
* @returns list of classes, e.g. ["foo", "bar", "baz"]
|
|
921
|
+
*/
|
|
922
|
+
const parseClassList = (value) => {
|
|
923
|
+
if (typeof value === "object" && value && "baseVal" in value) value = value.baseVal;
|
|
924
|
+
if (!value || typeof value !== "string") return [];
|
|
925
|
+
return value.split(parseClassListRegex);
|
|
926
|
+
};
|
|
927
|
+
const CAPTURE_EVENT_SUFFIX = "Capture";
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region src/runtime/vdom/update-element.ts
|
|
930
|
+
/**
|
|
931
|
+
* Handle updating attributes on the component element based on the current
|
|
932
|
+
* values present in the virtual DOM.
|
|
933
|
+
*
|
|
934
|
+
* If the component of interest uses shadow DOM these are added to the shadow
|
|
935
|
+
* root's host element.
|
|
936
|
+
*
|
|
937
|
+
* @param oldVnode an old virtual DOM node or null
|
|
938
|
+
* @param newVnode a new virtual DOM node
|
|
939
|
+
* @param isSvgMode whether or not we're in an SVG context
|
|
940
|
+
* @param isInitialRender whether this is the first render of the VDOM
|
|
941
|
+
*/
|
|
942
|
+
const updateElement = (oldVnode, newVnode, isSvgMode, isInitialRender) => {
|
|
943
|
+
const oldVnodeAttrs = oldVnode && oldVnode.$attrs$ || {};
|
|
944
|
+
const newVnodeAttrs = newVnode.$attrs$ || {};
|
|
945
|
+
const oldKeys = Object.keys(oldVnodeAttrs);
|
|
946
|
+
const newKeys = Object.keys(newVnodeAttrs);
|
|
947
|
+
if (!BUILD.updatable && newKeys.length === 0) return;
|
|
948
|
+
if (BUILD.updatable && oldKeys.length === 0 && newKeys.length === 0) return;
|
|
949
|
+
const elm = newVnode.$elm$.nodeType === NODE_TYPE.DocumentFragment && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
|
|
950
|
+
if (BUILD.updatable) {
|
|
951
|
+
for (const memberName of sortedAttrNames(oldKeys)) if (!(memberName in newVnodeAttrs)) setAccessor(elm, memberName, oldVnodeAttrs[memberName], void 0, isSvgMode, newVnode.$flags$, isInitialRender);
|
|
952
|
+
}
|
|
953
|
+
for (const memberName of sortedAttrNames(newKeys)) setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$, isInitialRender);
|
|
954
|
+
};
|
|
955
|
+
/**
|
|
956
|
+
* Sort a list of attribute names to ensure that all the attribute names which
|
|
957
|
+
* are _not_ `"ref"` come before `"ref"`. Preserve the order of the non-ref
|
|
958
|
+
* attributes.
|
|
959
|
+
*
|
|
960
|
+
* **Note**: if the supplied attributes do not include `'ref'` then the same
|
|
961
|
+
* (by reference) array will be returned without modification.
|
|
962
|
+
*
|
|
963
|
+
* @param attrNames attribute names to sort
|
|
964
|
+
* @returns a list of attribute names, sorted if they include `"ref"`
|
|
965
|
+
*/
|
|
966
|
+
function sortedAttrNames(attrNames) {
|
|
967
|
+
if (!BUILD.vdomRef) return attrNames;
|
|
968
|
+
return attrNames.includes("ref") ? [...attrNames.filter((attr) => attr !== "ref"), "ref"] : attrNames;
|
|
969
|
+
}
|
|
970
|
+
//#endregion
|
|
971
|
+
//#region src/runtime/vdom/vdom-render.ts
|
|
972
|
+
/**
|
|
973
|
+
* Virtual DOM patching algorithm based on Snabbdom by
|
|
974
|
+
* Simon Friis Vindum (@paldepind)
|
|
975
|
+
* Licensed under the MIT License
|
|
976
|
+
* https://github.com/snabbdom/snabbdom/blob/master/LICENSE
|
|
977
|
+
*
|
|
978
|
+
* Modified for Stencil's renderer and slot projection
|
|
979
|
+
*/
|
|
980
|
+
let scopeId;
|
|
981
|
+
let contentRef;
|
|
982
|
+
let hostTagName;
|
|
983
|
+
let useNativeShadowDom = false;
|
|
984
|
+
let checkSlotFallbackVisibility = false;
|
|
985
|
+
let checkSlotRelocate = false;
|
|
986
|
+
let isSvgMode = false;
|
|
987
|
+
/**
|
|
988
|
+
* Queues for ref callbacks that need to be called during rendering.
|
|
989
|
+
* These ensure that ref callbacks are called in the correct order:
|
|
990
|
+
* first all removal callbacks (with null), then all attachment callbacks (with elements).
|
|
991
|
+
*/
|
|
992
|
+
const refCallbacksToRemove = [];
|
|
993
|
+
const refCallbacksToAttach = [];
|
|
994
|
+
/** Disposers for signal subscriptions on individual DOM nodes (text nodes, <s-show> wrappers). */
|
|
995
|
+
const signalNodeDisposers = /* @__PURE__ */ new WeakMap();
|
|
996
|
+
const disposeSignalVNode = (vnode) => {
|
|
997
|
+
const elm = vnode.$elm$;
|
|
998
|
+
if (elm) {
|
|
999
|
+
const dispose = signalNodeDisposers.get(elm);
|
|
1000
|
+
if (dispose) {
|
|
1001
|
+
dispose();
|
|
1002
|
+
signalNodeDisposers.delete(elm);
|
|
1003
|
+
}
|
|
1004
|
+
disposeAllSignalAttrs(elm);
|
|
1005
|
+
}
|
|
1006
|
+
vnode.$children$?.forEach(disposeSignalVNode);
|
|
1007
|
+
};
|
|
1008
|
+
/**
|
|
1009
|
+
* Create a DOM Node corresponding to one of the children of a given VNode.
|
|
1010
|
+
*
|
|
1011
|
+
* @param oldParentVNode the parent VNode from the previous render
|
|
1012
|
+
* @param newParentVNode the parent VNode from the current render
|
|
1013
|
+
* @param childIndex the index of the VNode, in the _new_ parent node's
|
|
1014
|
+
* children, for which we will create a new DOM node
|
|
1015
|
+
* @returns the newly created node
|
|
1016
|
+
*/
|
|
1017
|
+
const createElm = (oldParentVNode, newParentVNode, childIndex) => {
|
|
1018
|
+
const newVNode = newParentVNode.$children$[childIndex];
|
|
1019
|
+
let i = 0;
|
|
1020
|
+
let elm;
|
|
1021
|
+
let childNode;
|
|
1022
|
+
let oldVNode;
|
|
1023
|
+
if (BUILD.slotRelocation && !useNativeShadowDom) {
|
|
1024
|
+
checkSlotRelocate = true;
|
|
1025
|
+
if (newVNode.$tag$ === "slot") newVNode.$flags$ |= newVNode.$children$ ? VNODE_FLAGS.isSlotFallback : VNODE_FLAGS.isSlotReference;
|
|
1026
|
+
}
|
|
1027
|
+
if (BUILD.isDev && newVNode.$elm$) consoleDevError(`The JSX ${newVNode.$text$ !== null ? `"${newVNode.$text$}" text` : `"${String(newVNode.$tag$)}" element`} node should not be shared within the same renderer. The renderer caches element lookups in order to improve performance. However, a side effect from this is that the exact same JSX node should not be reused. For more information please see https://stenciljs.com/docs/templating-jsx#avoid-shared-jsx-nodes`);
|
|
1028
|
+
if (BUILD.vdomText && newVNode.$text$ != null) {
|
|
1029
|
+
elm = newVNode.$elm$ = win.document.createTextNode(newVNode.$text$);
|
|
1030
|
+
if (BUILD.vdomSignals && newVNode.$signal$) {
|
|
1031
|
+
const textSig = newVNode.$signal$;
|
|
1032
|
+
const textNode = elm;
|
|
1033
|
+
signalNodeDisposers.set(textNode, effect(() => {
|
|
1034
|
+
textNode.data = String(textSig.value);
|
|
1035
|
+
}));
|
|
1036
|
+
}
|
|
1037
|
+
} else if (BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
|
|
1038
|
+
elm = newVNode.$elm$ = BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : win.document.createTextNode("");
|
|
1039
|
+
if (typeof newVNode.$attrs$?.slot === "string") elm["s-sa"] = newVNode.$attrs$.slot;
|
|
1040
|
+
if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
|
|
1041
|
+
} else {
|
|
1042
|
+
if (BUILD.svg && !isSvgMode) isSvgMode = newVNode.$tag$ === "svg";
|
|
1043
|
+
if (!win.document) throw new Error("No DOM environment available for rendering.");
|
|
1044
|
+
const tag = !useNativeShadowDom && BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotFallback ? "slot-fb" : newVNode.$tag$;
|
|
1045
|
+
const _reg = getRegistry();
|
|
1046
|
+
const registryOpts = _reg !== win.customElements && tag.includes("-") ? { customElementRegistry: _reg } : void 0;
|
|
1047
|
+
elm = newVNode.$elm$ = BUILD.svg && isSvgMode ? win.document.createElementNS(SVG_NS, tag) : win.document.createElement(tag, registryOpts);
|
|
1048
|
+
if (BUILD.svg && isSvgMode && newVNode.$tag$ === "foreignObject") isSvgMode = false;
|
|
1049
|
+
if (BUILD.vdomAttribute) updateElement(null, newVNode, isSvgMode);
|
|
1050
|
+
if ((BUILD.scoped || BUILD.hydrateServerSide && CMP_FLAGS.shadowNeedsScopedCss) && isDef(scopeId) && elm["s-si"] !== scopeId) elm.classList.add(elm["s-si"] = scopeId);
|
|
1051
|
+
if (newVNode.$children$) {
|
|
1052
|
+
const appendTarget = newVNode.$tag$ === "template" ? elm.content : elm;
|
|
1053
|
+
for (i = 0; i < newVNode.$children$.length; ++i) {
|
|
1054
|
+
childNode = createElm(oldParentVNode, newVNode, i);
|
|
1055
|
+
if (childNode) appendTarget.appendChild(childNode);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
if (BUILD.svg) {
|
|
1059
|
+
if (newVNode.$tag$ === "svg") isSvgMode = false;
|
|
1060
|
+
else if (elm.tagName === "foreignObject") isSvgMode = true;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
elm["s-hn"] = hostTagName;
|
|
1064
|
+
if (BUILD.slotRelocation) {
|
|
1065
|
+
if (newVNode.$flags$ & (VNODE_FLAGS.isSlotFallback | VNODE_FLAGS.isSlotReference)) {
|
|
1066
|
+
elm["s-sr"] = true;
|
|
1067
|
+
elm["s-cr"] = contentRef;
|
|
1068
|
+
elm["s-sn"] = newVNode.$name$ || "";
|
|
1069
|
+
elm["s-rf"] = newVNode.$attrs$?.ref;
|
|
1070
|
+
patchSlotNode(elm);
|
|
1071
|
+
oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
|
|
1072
|
+
if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) relocateToHostRoot(oldParentVNode.$elm$);
|
|
1073
|
+
if (BUILD.scoped || BUILD.hydrateServerSide && CMP_FLAGS.shadowNeedsScopedCss) addRemoveSlotScopedClass(contentRef, elm, newParentVNode.$elm$, oldParentVNode?.$elm$);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return elm;
|
|
1077
|
+
};
|
|
1078
|
+
/**
|
|
1079
|
+
* Relocates all child nodes of an element that were a part of a previous slot relocation
|
|
1080
|
+
* to the root of the Stencil component currently being rendered. This happens when a parent
|
|
1081
|
+
* element of a slot reference node dynamically changes and triggers a re-render. We cannot use
|
|
1082
|
+
* `putBackInOriginalLocation()` because that may relocate nodes to elements that will not be re-rendered
|
|
1083
|
+
* and so they will not be relocated again.
|
|
1084
|
+
*
|
|
1085
|
+
* @param parentElm The element potentially containing relocated nodes.
|
|
1086
|
+
*/
|
|
1087
|
+
const relocateToHostRoot = (parentElm) => {
|
|
1088
|
+
plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
|
|
1089
|
+
const host = parentElm.closest(hostTagName.toLowerCase());
|
|
1090
|
+
if (host != null) {
|
|
1091
|
+
const contentRefNode = Array.from(host.__childNodes || host.childNodes).find((ref) => ref["s-cr"]);
|
|
1092
|
+
const childNodeArray = Array.from(parentElm.__childNodes || parentElm.childNodes);
|
|
1093
|
+
for (const childNode of contentRefNode ? childNodeArray.reverse() : childNodeArray) if (childNode["s-sh"] != null) {
|
|
1094
|
+
insertBefore(host, childNode, contentRefNode ?? null);
|
|
1095
|
+
childNode["s-sh"] = void 0;
|
|
1096
|
+
checkSlotRelocate = true;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
|
|
1100
|
+
};
|
|
1101
|
+
/**
|
|
1102
|
+
* Puts `<slot>` nodes and any slotted nodes back to their original location (wherever they were before being slotted).
|
|
1103
|
+
*
|
|
1104
|
+
* @param parentElm - The parent element of the nodes to relocate.
|
|
1105
|
+
* @param recursive - Whether or not to relocate nodes in child nodes as well.
|
|
1106
|
+
*/
|
|
1107
|
+
const putBackInOriginalLocation = (parentElm, recursive) => {
|
|
1108
|
+
plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
|
|
1109
|
+
const oldSlotChildNodes = Array.from(parentElm.__childNodes || parentElm.childNodes);
|
|
1110
|
+
if (parentElm["s-sr"]) {
|
|
1111
|
+
let node = parentElm;
|
|
1112
|
+
while (node = node.nextSibling) if (node && node["s-sn"] === parentElm["s-sn"] && node["s-sh"] === hostTagName) oldSlotChildNodes.push(node);
|
|
1113
|
+
}
|
|
1114
|
+
for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
|
|
1115
|
+
const childNode = oldSlotChildNodes[i];
|
|
1116
|
+
if (childNode["s-hn"] !== hostTagName && childNode["s-ol"]) {
|
|
1117
|
+
insertBefore(referenceNode(childNode).parentNode, childNode, referenceNode(childNode));
|
|
1118
|
+
childNode["s-ol"].remove();
|
|
1119
|
+
childNode["s-ol"] = void 0;
|
|
1120
|
+
childNode["s-sh"] = void 0;
|
|
1121
|
+
checkSlotRelocate = true;
|
|
1122
|
+
}
|
|
1123
|
+
if (recursive) putBackInOriginalLocation(childNode, recursive);
|
|
1124
|
+
}
|
|
1125
|
+
plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
|
|
1126
|
+
};
|
|
1127
|
+
/**
|
|
1128
|
+
* Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
|
|
1129
|
+
* add them to the DOM in the appropriate place.
|
|
1130
|
+
*
|
|
1131
|
+
* @param parentElm the DOM node which should be used as a parent for the new
|
|
1132
|
+
* DOM nodes
|
|
1133
|
+
* @param before a child of the `parentElm` which the new children should be
|
|
1134
|
+
* inserted before (optional)
|
|
1135
|
+
* @param parentVNode the parent virtual DOM node
|
|
1136
|
+
* @param vnodes the new child virtual DOM nodes to produce DOM nodes for
|
|
1137
|
+
* @param startIdx the index in the child virtual DOM nodes at which to start
|
|
1138
|
+
* creating DOM nodes (inclusive)
|
|
1139
|
+
* @param endIdx the index in the child virtual DOM nodes at which to stop
|
|
1140
|
+
* creating DOM nodes (inclusive)
|
|
1141
|
+
*/
|
|
1142
|
+
const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
|
1143
|
+
let containerElm = BUILD.slotRelocation && parentElm["s-cr"] && parentElm["s-cr"].parentNode || parentElm;
|
|
1144
|
+
let childNode;
|
|
1145
|
+
if (BUILD.shadowDom && containerElm.tagName === hostTagName) {
|
|
1146
|
+
const shadow = getShadowRoot(containerElm);
|
|
1147
|
+
if (shadow) containerElm = shadow;
|
|
1148
|
+
}
|
|
1149
|
+
if (parentVNode.$tag$ === "template") containerElm = containerElm.content;
|
|
1150
|
+
for (; startIdx <= endIdx; ++startIdx) if (vnodes[startIdx]) {
|
|
1151
|
+
childNode = createElm(null, parentVNode, startIdx);
|
|
1152
|
+
if (childNode) {
|
|
1153
|
+
vnodes[startIdx].$elm$ = childNode;
|
|
1154
|
+
insertBefore(containerElm, childNode, BUILD.slotRelocation ? referenceNode(before) : before);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
/**
|
|
1159
|
+
* Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
|
|
1160
|
+
* This can be used to, for instance, clean up after a list of children which
|
|
1161
|
+
* should no longer be shown.
|
|
1162
|
+
*
|
|
1163
|
+
* This function also handles some of Stencil's slot relocation logic.
|
|
1164
|
+
*
|
|
1165
|
+
* @param vnodes a list of virtual DOM nodes to remove
|
|
1166
|
+
* @param startIdx the index at which to start removing nodes (inclusive)
|
|
1167
|
+
* @param endIdx the index at which to stop removing nodes (inclusive)
|
|
1168
|
+
*/
|
|
1169
|
+
const removeVnodes = (vnodes, startIdx, endIdx) => {
|
|
1170
|
+
for (let index = startIdx; index <= endIdx; ++index) {
|
|
1171
|
+
const vnode = vnodes[index];
|
|
1172
|
+
if (vnode) {
|
|
1173
|
+
const elm = vnode.$elm$;
|
|
1174
|
+
nullifyVNodeRefs(vnode);
|
|
1175
|
+
if (BUILD.vdomSignals) disposeSignalVNode(vnode);
|
|
1176
|
+
if (elm) {
|
|
1177
|
+
if (BUILD.slotRelocation) {
|
|
1178
|
+
checkSlotFallbackVisibility = true;
|
|
1179
|
+
if (elm["s-ol"]) elm["s-ol"].remove();
|
|
1180
|
+
else putBackInOriginalLocation(elm, true);
|
|
1181
|
+
}
|
|
1182
|
+
elm.remove();
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
/**
|
|
1188
|
+
* Reconcile the children of a new VNode with the children of an old VNode by
|
|
1189
|
+
* traversing the two collections of children, identifying nodes that are
|
|
1190
|
+
* conserved or changed, calling out to `patch` to make any necessary
|
|
1191
|
+
* updates to the DOM, and rearranging DOM nodes as needed.
|
|
1192
|
+
*
|
|
1193
|
+
* The algorithm for reconciling children works by analyzing two 'windows' onto
|
|
1194
|
+
* the two arrays of children (`oldCh` and `newCh`). We keep track of the
|
|
1195
|
+
* 'windows' by storing start and end indices and references to the
|
|
1196
|
+
* corresponding array entries. Initially the two 'windows' are basically equal
|
|
1197
|
+
* to the entire array, but we progressively narrow the windows until there are
|
|
1198
|
+
* no children left to update by doing the following:
|
|
1199
|
+
*
|
|
1200
|
+
* 1. Skip any `null` entries at the beginning or end of the two arrays, so
|
|
1201
|
+
* that if we have an initial array like the following we'll end up dealing
|
|
1202
|
+
* only with a window bounded by the highlighted elements:
|
|
1203
|
+
*
|
|
1204
|
+
* [null, null, VNode1 , ... , VNode2, null, null]
|
|
1205
|
+
* ^^^^^^ ^^^^^^
|
|
1206
|
+
*
|
|
1207
|
+
* 2. Check to see if the elements at the head and tail positions are equal
|
|
1208
|
+
* across the windows. This will basically detect elements which haven't
|
|
1209
|
+
* been added, removed, or changed position, i.e. if you had the following
|
|
1210
|
+
* VNode elements (represented as HTML):
|
|
1211
|
+
*
|
|
1212
|
+
* oldVNode: `<div><p><span>HEY</span></p></div>`
|
|
1213
|
+
* newVNode: `<div><p><span>THERE</span></p></div>`
|
|
1214
|
+
*
|
|
1215
|
+
* Then when comparing the children of the `<div>` tag we check the equality
|
|
1216
|
+
* of the VNodes corresponding to the `<p>` tags and, since they are the
|
|
1217
|
+
* same tag in the same position, we'd be able to avoid completely
|
|
1218
|
+
* re-rendering the subtree under them with a new DOM element and would just
|
|
1219
|
+
* call out to `patch` to handle reconciling their children and so on.
|
|
1220
|
+
*
|
|
1221
|
+
* 3. Check, for both windows, to see if the element at the beginning of the
|
|
1222
|
+
* window corresponds to the element at the end of the other window. This is
|
|
1223
|
+
* a heuristic which will let us identify _some_ situations in which
|
|
1224
|
+
* elements have changed position, for instance it _should_ detect that the
|
|
1225
|
+
* children nodes themselves have not changed but merely moved in the
|
|
1226
|
+
* following example:
|
|
1227
|
+
*
|
|
1228
|
+
* oldVNode: `<div><element-one /><element-two /></div>`
|
|
1229
|
+
* newVNode: `<div><element-two /><element-one /></div>`
|
|
1230
|
+
*
|
|
1231
|
+
* If we find cases like this then we also need to move the concrete DOM
|
|
1232
|
+
* elements corresponding to the moved children to write the re-order to the
|
|
1233
|
+
* DOM.
|
|
1234
|
+
*
|
|
1235
|
+
* 4. Finally, if VNodes have the `key` attribute set on them we check for any
|
|
1236
|
+
* nodes in the old children which have the same key as the first element in
|
|
1237
|
+
* our window on the new children. If we find such a node we handle calling
|
|
1238
|
+
* out to `patch`, moving relevant DOM nodes, and so on, in accordance with
|
|
1239
|
+
* what we find.
|
|
1240
|
+
*
|
|
1241
|
+
* Finally, once we've narrowed our 'windows' to the point that either of them
|
|
1242
|
+
* collapse (i.e. they have length 0) we then handle any remaining VNode
|
|
1243
|
+
* insertion or deletion that needs to happen to get a DOM state that correctly
|
|
1244
|
+
* reflects the new child VNodes. If, for instance, after our window on the old
|
|
1245
|
+
* children has collapsed we still have more nodes on the new children that
|
|
1246
|
+
* we haven't dealt with yet then we need to add them, or if the new children
|
|
1247
|
+
* collapse but we still have unhandled _old_ children then we need to make
|
|
1248
|
+
* sure the corresponding DOM nodes are removed.
|
|
1249
|
+
*
|
|
1250
|
+
* @param parentElm the node into which the parent VNode is rendered
|
|
1251
|
+
* @param oldCh the old children of the parent node
|
|
1252
|
+
* @param newVNode the new VNode which will replace the parent
|
|
1253
|
+
* @param newCh the new children of the parent node
|
|
1254
|
+
* @param isInitialRender whether or not this is the first render of the vdom
|
|
1255
|
+
*/
|
|
1256
|
+
const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = false) => {
|
|
1257
|
+
let oldStartIdx = 0;
|
|
1258
|
+
let newStartIdx = 0;
|
|
1259
|
+
let idxInOld = 0;
|
|
1260
|
+
let i = 0;
|
|
1261
|
+
let oldEndIdx = oldCh.length - 1;
|
|
1262
|
+
let oldStartVnode = oldCh[0];
|
|
1263
|
+
let oldEndVnode = oldCh[oldEndIdx];
|
|
1264
|
+
let newEndIdx = newCh.length - 1;
|
|
1265
|
+
let newStartVnode = newCh[0];
|
|
1266
|
+
let newEndVnode = newCh[newEndIdx];
|
|
1267
|
+
let node;
|
|
1268
|
+
let elmToMove;
|
|
1269
|
+
const containerElm = newVNode.$tag$ === "template" ? parentElm.content : parentElm;
|
|
1270
|
+
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) if (oldStartVnode == null) oldStartVnode = oldCh[++oldStartIdx];
|
|
1271
|
+
else if (oldEndVnode == null) oldEndVnode = oldCh[--oldEndIdx];
|
|
1272
|
+
else if (newStartVnode == null) newStartVnode = newCh[++newStartIdx];
|
|
1273
|
+
else if (newEndVnode == null) newEndVnode = newCh[--newEndIdx];
|
|
1274
|
+
else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
|
|
1275
|
+
patch(oldStartVnode, newStartVnode, isInitialRender);
|
|
1276
|
+
oldStartVnode = oldCh[++oldStartIdx];
|
|
1277
|
+
newStartVnode = newCh[++newStartIdx];
|
|
1278
|
+
} else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
|
|
1279
|
+
patch(oldEndVnode, newEndVnode, isInitialRender);
|
|
1280
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
1281
|
+
newEndVnode = newCh[--newEndIdx];
|
|
1282
|
+
} else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
|
|
1283
|
+
if (BUILD.slotRelocation && (oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
|
|
1284
|
+
patch(oldStartVnode, newEndVnode, isInitialRender);
|
|
1285
|
+
insertBefore(containerElm, oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
|
1286
|
+
oldStartVnode = oldCh[++oldStartIdx];
|
|
1287
|
+
newEndVnode = newCh[--newEndIdx];
|
|
1288
|
+
} else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
|
|
1289
|
+
if (BUILD.slotRelocation && (oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
|
|
1290
|
+
patch(oldEndVnode, newStartVnode, isInitialRender);
|
|
1291
|
+
insertBefore(containerElm, oldEndVnode.$elm$, oldStartVnode.$elm$);
|
|
1292
|
+
oldEndVnode = oldCh[--oldEndIdx];
|
|
1293
|
+
newStartVnode = newCh[++newStartIdx];
|
|
1294
|
+
} else {
|
|
1295
|
+
idxInOld = -1;
|
|
1296
|
+
if (BUILD.vdomKey) {
|
|
1297
|
+
for (i = oldStartIdx; i <= oldEndIdx; ++i) if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
|
|
1298
|
+
idxInOld = i;
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
if (BUILD.vdomKey && idxInOld >= 0) {
|
|
1303
|
+
elmToMove = oldCh[idxInOld];
|
|
1304
|
+
if (elmToMove.$tag$ !== newStartVnode.$tag$) node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
|
|
1305
|
+
else {
|
|
1306
|
+
patch(elmToMove, newStartVnode, isInitialRender);
|
|
1307
|
+
oldCh[idxInOld] = void 0;
|
|
1308
|
+
node = elmToMove.$elm$;
|
|
1309
|
+
}
|
|
1310
|
+
newStartVnode = newCh[++newStartIdx];
|
|
1311
|
+
} else {
|
|
1312
|
+
node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
|
|
1313
|
+
newStartVnode = newCh[++newStartIdx];
|
|
1314
|
+
}
|
|
1315
|
+
if (node) {
|
|
1316
|
+
if (BUILD.slotRelocation) insertBefore(referenceNode(oldStartVnode.$elm$).parentNode, node, referenceNode(oldStartVnode.$elm$));
|
|
1317
|
+
else insertBefore(oldStartVnode.$elm$.parentNode, node, oldStartVnode.$elm$);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
if (oldStartIdx > oldEndIdx) addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
1321
|
+
else if (BUILD.updatable && newStartIdx > newEndIdx) removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
1322
|
+
};
|
|
1323
|
+
/**
|
|
1324
|
+
* Compare two VNodes to determine if they are the same
|
|
1325
|
+
*
|
|
1326
|
+
* **NB**: This function is an equality _heuristic_ based on the available
|
|
1327
|
+
* information set on the two VNodes and can be misleading under certain
|
|
1328
|
+
* circumstances. In particular, if the two nodes do not have `key` attrs
|
|
1329
|
+
* (available under `$key$` on VNodes) then the function falls back on merely
|
|
1330
|
+
* checking that they have the same tag.
|
|
1331
|
+
*
|
|
1332
|
+
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
1333
|
+
* changing order within a `children` array or something along those lines then
|
|
1334
|
+
* we could obtain a false negative and then have to do needless re-rendering
|
|
1335
|
+
* (i.e. we'd say two VNodes aren't equal when in fact they should be).
|
|
1336
|
+
*
|
|
1337
|
+
* @param leftVNode the first VNode to check
|
|
1338
|
+
* @param rightVNode the second VNode to check
|
|
1339
|
+
* @param isInitialRender whether or not this is the first render of the vdom
|
|
1340
|
+
* @returns whether they're equal or not
|
|
1341
|
+
*/
|
|
1342
|
+
const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
|
|
1343
|
+
if (leftVNode.$tag$ === rightVNode.$tag$) {
|
|
1344
|
+
if (BUILD.slotRelocation && leftVNode.$tag$ === "slot") return leftVNode.$name$ === rightVNode.$name$;
|
|
1345
|
+
if (BUILD.vdomKey && !isInitialRender) return leftVNode.$key$ === rightVNode.$key$;
|
|
1346
|
+
if (isInitialRender && !leftVNode.$key$ && rightVNode.$key$) leftVNode.$key$ = rightVNode.$key$;
|
|
1347
|
+
return true;
|
|
1348
|
+
}
|
|
1349
|
+
return false;
|
|
1350
|
+
};
|
|
1351
|
+
/**
|
|
1352
|
+
* Returns the reference node (a comment which represents the
|
|
1353
|
+
* original location of a node in the vdom - before it was moved to its slot)
|
|
1354
|
+
* of a given node.
|
|
1355
|
+
*
|
|
1356
|
+
* (slot nodes can be relocated to a new location in the dom because of
|
|
1357
|
+
* some other component's slot)
|
|
1358
|
+
* @param node the node to find the original location reference node for
|
|
1359
|
+
* @returns reference node
|
|
1360
|
+
*/
|
|
1361
|
+
const referenceNode = (node) => node && node["s-ol"] || node;
|
|
1362
|
+
/**
|
|
1363
|
+
* Handle reconciling an outdated VNode with a new one which corresponds to
|
|
1364
|
+
* it. This function handles flushing updates to the DOM and reconciling the
|
|
1365
|
+
* children of the two nodes (if any).
|
|
1366
|
+
*
|
|
1367
|
+
* @param oldVNode an old VNode whose DOM element and children we want to update
|
|
1368
|
+
* @param newVNode a new VNode representing an updated version of the old one
|
|
1369
|
+
* @param isInitialRender whether or not this is the first render of the vdom
|
|
1370
|
+
*/
|
|
1371
|
+
const patch = (oldVNode, newVNode, isInitialRender = false) => {
|
|
1372
|
+
const elm = newVNode.$elm$ = oldVNode.$elm$;
|
|
1373
|
+
const oldChildren = oldVNode.$children$;
|
|
1374
|
+
const newChildren = newVNode.$children$;
|
|
1375
|
+
const tag = newVNode.$tag$;
|
|
1376
|
+
const text = newVNode.$text$;
|
|
1377
|
+
let defaultHolder;
|
|
1378
|
+
if (!BUILD.vdomText || text == null) {
|
|
1379
|
+
if (BUILD.svg) isSvgMode = tag === "svg" ? true : tag === "foreignObject" ? false : isSvgMode;
|
|
1380
|
+
if (BUILD.vdomAttribute || BUILD.reflect) {
|
|
1381
|
+
if (BUILD.slot && tag === "slot" && !useNativeShadowDom) {
|
|
1382
|
+
if (oldVNode.$name$ !== newVNode.$name$) {
|
|
1383
|
+
newVNode.$elm$["s-sn"] = newVNode.$name$ || "";
|
|
1384
|
+
relocateToHostRoot(newVNode.$elm$.parentElement);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
updateElement(oldVNode, newVNode, isSvgMode, isInitialRender);
|
|
1388
|
+
}
|
|
1389
|
+
if (BUILD.updatable && oldChildren !== null && newChildren !== null) updateChildren(elm, oldChildren, newVNode, newChildren, isInitialRender);
|
|
1390
|
+
else if (newChildren !== null) {
|
|
1391
|
+
if (BUILD.updatable && BUILD.vdomText && oldVNode.$text$ !== null) elm.textContent = "";
|
|
1392
|
+
addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
|
|
1393
|
+
} else if (!isInitialRender && BUILD.updatable && oldChildren !== null) removeVnodes(oldChildren, 0, oldChildren.length - 1);
|
|
1394
|
+
else if (BUILD.hydrateClientSide && isInitialRender && BUILD.updatable && oldChildren !== null && newChildren === null) newVNode.$children$ = oldChildren;
|
|
1395
|
+
if (BUILD.svg && isSvgMode && tag === "svg") isSvgMode = false;
|
|
1396
|
+
} else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm["s-cr"])) defaultHolder.parentNode.textContent = text;
|
|
1397
|
+
else if (BUILD.vdomText && oldVNode.$text$ !== text) elm.data = text;
|
|
1398
|
+
};
|
|
1399
|
+
/**
|
|
1400
|
+
* Component-global information about nodes which are either currently being
|
|
1401
|
+
* relocated or will be shortly.
|
|
1402
|
+
*/
|
|
1403
|
+
const relocateNodes = [];
|
|
1404
|
+
/**
|
|
1405
|
+
* When a forwarded `<slot>` gets relocated, drag along any content already forwarded through it,
|
|
1406
|
+
* to wherever it just landed (or nowhere, to be hidden, if it didn't match anything).
|
|
1407
|
+
*
|
|
1408
|
+
* Runs as its own pass after {@link markSlotContentForRelocation} rather than inside it, so that
|
|
1409
|
+
* function's matching order - which hydration's node/comment ordering depends on - is untouched.
|
|
1410
|
+
*/
|
|
1411
|
+
const carryContentWithRelocatedSlotRefs = () => {
|
|
1412
|
+
for (const relocateData of relocateNodes.slice()) {
|
|
1413
|
+
const marker = relocateData.$nodeToRelocate$;
|
|
1414
|
+
if (!marker["s-sr"]) continue;
|
|
1415
|
+
const carriedSiblings = getSlotChildSiblings(marker, marker["s-sn"] || "", false);
|
|
1416
|
+
for (const carriedSibling of carriedSiblings) {
|
|
1417
|
+
if (!carriedSibling["s-ol"]) continue;
|
|
1418
|
+
let siblingRelocateData = relocateNodes.find((r) => r.$nodeToRelocate$ === carriedSibling);
|
|
1419
|
+
if (!siblingRelocateData) {
|
|
1420
|
+
siblingRelocateData = { $nodeToRelocate$: carriedSibling };
|
|
1421
|
+
relocateNodes.push(siblingRelocateData);
|
|
1422
|
+
}
|
|
1423
|
+
siblingRelocateData.$slotRefNode$ = relocateData.$slotRefNode$;
|
|
1424
|
+
if (relocateData.$slotRefNode$) carriedSibling["s-sh"] = relocateData.$slotRefNode$["s-hn"];
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
/**
|
|
1429
|
+
* Mark the contents of a slot for relocation via adding references to them to
|
|
1430
|
+
* the {@link relocateNodes} data structure. The actual work of relocating them
|
|
1431
|
+
* will then be handled in {@link renderVdom}.
|
|
1432
|
+
*
|
|
1433
|
+
* @param elm a render node whose child nodes need to be relocated
|
|
1434
|
+
*/
|
|
1435
|
+
const markSlotContentForRelocation = (elm) => {
|
|
1436
|
+
let node;
|
|
1437
|
+
let hostContentNodes;
|
|
1438
|
+
let j;
|
|
1439
|
+
const children = elm.__childNodes || elm.childNodes;
|
|
1440
|
+
for (const childNode of children) {
|
|
1441
|
+
if (childNode["s-sr"] && (node = childNode["s-cr"]) && node.parentNode) {
|
|
1442
|
+
hostContentNodes = node.parentNode.__childNodes || node.parentNode.childNodes;
|
|
1443
|
+
const slotName = childNode["s-sn"];
|
|
1444
|
+
for (j = hostContentNodes.length - 1; j >= 0; j--) {
|
|
1445
|
+
node = hostContentNodes[j];
|
|
1446
|
+
if (!node["s-cn"] && !node["s-nr"] && node["s-hn"] !== childNode["s-hn"] && (!node["s-sh"] || node["s-sh"] !== childNode["s-hn"])) {
|
|
1447
|
+
if (isNodeLocatedInSlot(node, slotName)) {
|
|
1448
|
+
let relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
|
|
1449
|
+
checkSlotFallbackVisibility = true;
|
|
1450
|
+
node["s-sn"] = node["s-sn"] || slotName;
|
|
1451
|
+
if (relocateNodeData) {
|
|
1452
|
+
relocateNodeData.$nodeToRelocate$["s-sh"] = childNode["s-hn"];
|
|
1453
|
+
relocateNodeData.$slotRefNode$ = childNode;
|
|
1454
|
+
} else {
|
|
1455
|
+
node["s-sh"] = childNode["s-hn"];
|
|
1456
|
+
relocateNodes.push({
|
|
1457
|
+
$slotRefNode$: childNode,
|
|
1458
|
+
$nodeToRelocate$: node
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
if (node["s-sr"]) relocateNodes.map((relocateNode) => {
|
|
1462
|
+
if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node["s-sn"])) {
|
|
1463
|
+
relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
|
|
1464
|
+
if (relocateNodeData && !relocateNode.$slotRefNode$) relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
} else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) relocateNodes.push({ $nodeToRelocate$: node });
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (childNode.nodeType === NODE_TYPE.ElementNode) markSlotContentForRelocation(childNode);
|
|
1472
|
+
}
|
|
1473
|
+
};
|
|
1474
|
+
/**
|
|
1475
|
+
* 'Nullify' any VDom `ref` callbacks on a VDom node or its children by calling
|
|
1476
|
+
* them with `null`. This signals that the DOM element corresponding to the VDom
|
|
1477
|
+
* node has been removed from the DOM.
|
|
1478
|
+
*
|
|
1479
|
+
* @param vNode a virtual DOM node
|
|
1480
|
+
*/
|
|
1481
|
+
const nullifyVNodeRefs = (vNode) => {
|
|
1482
|
+
if (BUILD.vdomRef) {
|
|
1483
|
+
if (vNode.$attrs$ && vNode.$attrs$.ref) refCallbacksToRemove.push(() => vNode.$attrs$.ref(null));
|
|
1484
|
+
if (vNode.$children$) vNode.$children$.map(nullifyVNodeRefs);
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
/**
|
|
1488
|
+
* Queue a ref callback to be called with an element during rendering.
|
|
1489
|
+
* This ensures ref callbacks are called in the correct order.
|
|
1490
|
+
*
|
|
1491
|
+
* @param refCallback the ref callback function to queue
|
|
1492
|
+
* @param elm the element to pass to the callback
|
|
1493
|
+
*/
|
|
1494
|
+
const queueRefAttachment = (refCallback, elm) => {
|
|
1495
|
+
if (BUILD.vdomRef) refCallbacksToAttach.push(() => refCallback(elm));
|
|
1496
|
+
};
|
|
1497
|
+
/**
|
|
1498
|
+
* Flush all queued ref callbacks in the correct order:
|
|
1499
|
+
* first all removal callbacks (with null), then all attachment callbacks (with elements).
|
|
1500
|
+
* This ensures that when elements are replaced/reordered, the ref is always left
|
|
1501
|
+
* pointing to the current element, not null.
|
|
1502
|
+
*/
|
|
1503
|
+
const flushQueuedRefCallbacks = () => {
|
|
1504
|
+
if (BUILD.vdomRef) {
|
|
1505
|
+
refCallbacksToRemove.forEach((cb) => cb());
|
|
1506
|
+
refCallbacksToRemove.length = 0;
|
|
1507
|
+
refCallbacksToAttach.forEach((cb) => cb());
|
|
1508
|
+
refCallbacksToAttach.length = 0;
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
/**
|
|
1512
|
+
* Inserts a node before a reference node as a child of a specified parent node.
|
|
1513
|
+
* Additionally, adds parent elements' scope ids as class names to the new node.
|
|
1514
|
+
*
|
|
1515
|
+
* @param parent parent node
|
|
1516
|
+
* @param newNode element to be inserted
|
|
1517
|
+
* @param reference anchor element
|
|
1518
|
+
* @param isInitialLoad whether or not this is the first render
|
|
1519
|
+
* @returns inserted node
|
|
1520
|
+
*/
|
|
1521
|
+
const insertBefore = (parent, newNode, reference, isInitialLoad) => {
|
|
1522
|
+
if (BUILD.slotRelocation) {
|
|
1523
|
+
if (BUILD.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
|
|
1524
|
+
else if (typeof newNode["s-sn"] === "string") {
|
|
1525
|
+
const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
|
|
1526
|
+
if ((BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchParentNode(newNode);
|
|
1527
|
+
parent.insertBefore(newNode, reference);
|
|
1528
|
+
const { slotNode } = findSlotFromSlottedNode(newNode);
|
|
1529
|
+
if (slotNode && !isInitialLoad) dispatchSlotChangeEvent(slotNode);
|
|
1530
|
+
return newNode;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
if (BUILD.slotRelocation && parent?.__insertBefore) return parent.__insertBefore(newNode, reference);
|
|
1534
|
+
else return parent?.insertBefore(newNode, reference);
|
|
1535
|
+
};
|
|
1536
|
+
/**
|
|
1537
|
+
* Adds or removes a scoped class to the parent element of a slotted node.
|
|
1538
|
+
* This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
|
|
1539
|
+
* in `scoped: true` components.
|
|
1540
|
+
*
|
|
1541
|
+
* @param reference - Content Reference Node. Used to get the scope id of the parent component.
|
|
1542
|
+
* @param slotNode - the `<slot>` node to apply the class for
|
|
1543
|
+
* @param newParent - the slots' new parent element that requires the scoped class
|
|
1544
|
+
* @param oldParent - optionally, an old parent element that may no longer require the scoped class
|
|
1545
|
+
*/
|
|
1546
|
+
function addRemoveSlotScopedClass(reference, slotNode, newParent, oldParent) {
|
|
1547
|
+
let slotScopeId;
|
|
1548
|
+
if (reference && typeof slotNode["s-sn"] === "string" && !!slotNode["s-sr"] && reference.parentNode && reference.parentNode["s-sc"] && (slotScopeId = slotNode["s-si"] || reference.parentNode["s-sc"])) {
|
|
1549
|
+
const scopeName = slotNode["s-sn"];
|
|
1550
|
+
const hostName = slotNode["s-hn"];
|
|
1551
|
+
newParent.classList?.add(slotScopeId + "-s");
|
|
1552
|
+
if (oldParent && oldParent.classList?.contains(slotScopeId + "-s")) {
|
|
1553
|
+
let child = (oldParent.__childNodes || oldParent.childNodes)[0];
|
|
1554
|
+
let found = false;
|
|
1555
|
+
while (child) {
|
|
1556
|
+
if (child["s-sn"] !== scopeName && child["s-hn"] === hostName && !!child["s-sr"]) {
|
|
1557
|
+
found = true;
|
|
1558
|
+
break;
|
|
1559
|
+
}
|
|
1560
|
+
child = child.nextSibling;
|
|
1561
|
+
}
|
|
1562
|
+
if (!found) oldParent.classList.remove(slotScopeId + "-s");
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* The main entry point for Stencil's virtual DOM-based rendering engine
|
|
1568
|
+
*
|
|
1569
|
+
* Given a {@link d.HostRef} container and some virtual DOM nodes, this
|
|
1570
|
+
* function will handle creating a virtual DOM tree with a single root, patching
|
|
1571
|
+
* the current virtual DOM tree onto an old one (if any), dealing with slot
|
|
1572
|
+
* relocation, and reflecting attributes.
|
|
1573
|
+
*
|
|
1574
|
+
* @param hostRef data needed to root and render the virtual DOM tree, such as
|
|
1575
|
+
* the DOM node into which it should be rendered.
|
|
1576
|
+
* @param renderFnResults the virtual DOM nodes to be rendered
|
|
1577
|
+
* @param isInitialLoad whether or not this is the first call after page load
|
|
1578
|
+
*/
|
|
1579
|
+
const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
|
|
1580
|
+
const hostElm = hostRef.$hostElement$;
|
|
1581
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
1582
|
+
const oldVNode = hostRef.$vnode$ || newVNode(null, null);
|
|
1583
|
+
const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
|
|
1584
|
+
hostTagName = hostElm.tagName;
|
|
1585
|
+
if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) throw new Error(`The <Host> must be the single root component.
|
|
1586
|
+
Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
|
|
1587
|
+
|
|
1588
|
+
The render() function should look like this instead:
|
|
1589
|
+
|
|
1590
|
+
render() {
|
|
1591
|
+
// Do not return an array
|
|
1592
|
+
return (
|
|
1593
|
+
<Host>{content}</Host>
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
`);
|
|
1597
|
+
if (BUILD.reflect && cmpMeta.$attrsToReflect$) {
|
|
1598
|
+
rootVnode.$attrs$ = rootVnode.$attrs$ || {};
|
|
1599
|
+
cmpMeta.$attrsToReflect$.forEach(([propName, attribute]) => {
|
|
1600
|
+
if (BUILD.serializer && hostRef.$serializerValues$.has(propName)) rootVnode.$attrs$[attribute] = hostRef.$serializerValues$.get(propName);
|
|
1601
|
+
else rootVnode.$attrs$[attribute] = hostElm[propName];
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
if (isInitialLoad && rootVnode.$attrs$) {
|
|
1605
|
+
for (const key of Object.keys(rootVnode.$attrs$)) if (hostElm.hasAttribute(key) && ![
|
|
1606
|
+
"key",
|
|
1607
|
+
"ref",
|
|
1608
|
+
"style",
|
|
1609
|
+
"class"
|
|
1610
|
+
].includes(key)) rootVnode.$attrs$[key] = hostElm[key];
|
|
1611
|
+
}
|
|
1612
|
+
rootVnode.$tag$ = null;
|
|
1613
|
+
rootVnode.$flags$ |= VNODE_FLAGS.isHost;
|
|
1614
|
+
hostRef.$vnode$ = rootVnode;
|
|
1615
|
+
rootVnode.$elm$ = oldVNode.$elm$ = BUILD.shadowDom ? getShadowRoot(hostElm) || hostElm : hostElm;
|
|
1616
|
+
if (BUILD.scoped || BUILD.shadowDom) scopeId = hostElm["s-sc"];
|
|
1617
|
+
useNativeShadowDom = !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && !(cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss);
|
|
1618
|
+
if (BUILD.slotRelocation) {
|
|
1619
|
+
contentRef = hostElm["s-cr"];
|
|
1620
|
+
checkSlotFallbackVisibility = false;
|
|
1621
|
+
}
|
|
1622
|
+
patch(oldVNode, rootVnode, isInitialLoad);
|
|
1623
|
+
if (BUILD.slotRelocation) {
|
|
1624
|
+
plt.$flags$ |= PLATFORM_FLAGS.isTmpDisconnected;
|
|
1625
|
+
if (checkSlotRelocate) {
|
|
1626
|
+
markSlotContentForRelocation(rootVnode.$elm$);
|
|
1627
|
+
carryContentWithRelocatedSlotRefs();
|
|
1628
|
+
for (const relocateData of relocateNodes) {
|
|
1629
|
+
const nodeToRelocate = relocateData.$nodeToRelocate$;
|
|
1630
|
+
if (!nodeToRelocate["s-ol"] && win.document) {
|
|
1631
|
+
const orgLocationNode = BUILD.isDebug || BUILD.hydrateServerSide ? originalLocationDebugNode(nodeToRelocate) : win.document.createTextNode("");
|
|
1632
|
+
orgLocationNode["s-nr"] = nodeToRelocate;
|
|
1633
|
+
insertBefore(nodeToRelocate.parentNode, nodeToRelocate["s-ol"] = orgLocationNode, nodeToRelocate, isInitialLoad);
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
for (const relocateData of relocateNodes) {
|
|
1637
|
+
const nodeToRelocate = relocateData.$nodeToRelocate$;
|
|
1638
|
+
const slotRefNode = relocateData.$slotRefNode$;
|
|
1639
|
+
if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode && isInitialLoad) nodeToRelocate["s-ih"] = !!nodeToRelocate.hidden;
|
|
1640
|
+
if (slotRefNode) {
|
|
1641
|
+
const parentNodeRef = slotRefNode.parentNode;
|
|
1642
|
+
let insertBeforeNode = slotRefNode.nextSibling;
|
|
1643
|
+
if (!BUILD.hydrateServerSide && insertBeforeNode && insertBeforeNode.nodeType === NODE_TYPE.ElementNode) {
|
|
1644
|
+
let orgLocationNode = nodeToRelocate["s-ol"]?.previousSibling;
|
|
1645
|
+
while (orgLocationNode) {
|
|
1646
|
+
let refNode = orgLocationNode["s-nr"] ?? null;
|
|
1647
|
+
if (refNode && refNode["s-sn"] === nodeToRelocate["s-sn"] && parentNodeRef === (refNode.__parentNode || refNode.parentNode)) {
|
|
1648
|
+
refNode = refNode.nextSibling;
|
|
1649
|
+
while (refNode === nodeToRelocate || refNode?.["s-sr"]) refNode = refNode?.nextSibling;
|
|
1650
|
+
if (!refNode || !refNode["s-nr"]) {
|
|
1651
|
+
insertBeforeNode = refNode;
|
|
1652
|
+
break;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
orgLocationNode = orgLocationNode.previousSibling;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
const parent = nodeToRelocate.__parentNode || nodeToRelocate.parentNode;
|
|
1659
|
+
const nextSibling = nodeToRelocate.__nextSibling || nodeToRelocate.nextSibling;
|
|
1660
|
+
if (!insertBeforeNode && parentNodeRef !== parent || nextSibling !== insertBeforeNode) {
|
|
1661
|
+
if (nodeToRelocate !== insertBeforeNode) {
|
|
1662
|
+
insertBefore(parentNodeRef, nodeToRelocate, insertBeforeNode, isInitialLoad);
|
|
1663
|
+
if (nodeToRelocate.nodeType === NODE_TYPE.CommentNode && nodeToRelocate.nodeValue.startsWith("s-nt-")) {
|
|
1664
|
+
const textNode = win.document.createTextNode(nodeToRelocate.nodeValue.replace(/^s-nt-/, ""));
|
|
1665
|
+
textNode["s-hn"] = nodeToRelocate["s-hn"];
|
|
1666
|
+
textNode["s-sn"] = nodeToRelocate["s-sn"];
|
|
1667
|
+
textNode["s-sh"] = nodeToRelocate["s-sh"];
|
|
1668
|
+
textNode["s-sr"] = nodeToRelocate["s-sr"];
|
|
1669
|
+
textNode["s-ol"] = nodeToRelocate["s-ol"];
|
|
1670
|
+
textNode["s-ol"]["s-nr"] = textNode;
|
|
1671
|
+
insertBefore(nodeToRelocate.parentNode, textNode, nodeToRelocate, isInitialLoad);
|
|
1672
|
+
nodeToRelocate.parentNode.removeChild(nodeToRelocate);
|
|
1673
|
+
}
|
|
1674
|
+
if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode && nodeToRelocate.tagName !== "SLOT-FB") nodeToRelocate.hidden = nodeToRelocate["s-ih"] ?? false;
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
if (nodeToRelocate && typeof slotRefNode["s-rf"] === "function") slotRefNode["s-rf"](slotRefNode);
|
|
1678
|
+
} else if (nodeToRelocate.nodeType === NODE_TYPE.ElementNode) nodeToRelocate.hidden = true;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
if (checkSlotFallbackVisibility) updateFallbackSlotVisibility(rootVnode.$elm$);
|
|
1682
|
+
plt.$flags$ &= ~PLATFORM_FLAGS.isTmpDisconnected;
|
|
1683
|
+
relocateNodes.length = 0;
|
|
1684
|
+
}
|
|
1685
|
+
if (BUILD.slotRelocation && !useNativeShadowDom && !(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation) && hostElm["s-cr"]) {
|
|
1686
|
+
const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
|
|
1687
|
+
for (const childNode of children) if (childNode["s-hn"] !== hostTagName && childNode["s-sh"] !== hostTagName) {
|
|
1688
|
+
if (isInitialLoad && childNode["s-ih"] == null) childNode["s-ih"] = childNode.hidden ?? false;
|
|
1689
|
+
if (childNode.nodeType === NODE_TYPE.ElementNode) childNode.hidden = true;
|
|
1690
|
+
else if (childNode.nodeType === NODE_TYPE.TextNode && !!childNode.nodeValue.trim()) {
|
|
1691
|
+
const textCommentNode = win.document.createComment("s-nt-" + childNode.nodeValue);
|
|
1692
|
+
textCommentNode["s-sn"] = childNode["s-sn"];
|
|
1693
|
+
insertBefore(childNode.parentNode, textCommentNode, childNode, isInitialLoad);
|
|
1694
|
+
childNode.parentNode.removeChild(childNode);
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
contentRef = void 0;
|
|
1699
|
+
flushQueuedRefCallbacks();
|
|
1700
|
+
};
|
|
1701
|
+
const slotReferenceDebugNode = (slotVNode) => win.document?.createComment(`<slot${slotVNode.$name$ ? " name=\"" + slotVNode.$name$ + "\"" : ""}> (host=${hostTagName.toLowerCase()})`);
|
|
1702
|
+
const originalLocationDebugNode = (nodeToRelocate) => win.document?.createComment(`org-location for ` + (nodeToRelocate.localName ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate["s-hn"]})` : `[${nodeToRelocate.textContent}]`));
|
|
1703
|
+
//#endregion
|
|
1704
|
+
//#region src/runtime/update-component.ts
|
|
1705
|
+
/**
|
|
1706
|
+
* Get a promise that resolves once `hostRef`'s real `connectedCallback` has fired for the first time.
|
|
1707
|
+
*
|
|
1708
|
+
* @param hostRef the component's host reference
|
|
1709
|
+
* @returns a promise that resolves once the component's real `connectedCallback` has fired
|
|
1710
|
+
*/
|
|
1711
|
+
const ensureFirstConnectPromise = (hostRef) => {
|
|
1712
|
+
if (!hostRef.$onFirstConnectPromise$) hostRef.$onFirstConnectPromise$ = new Promise((r) => hostRef.$onFirstConnectResolve$ = r);
|
|
1713
|
+
return hostRef.$onFirstConnectPromise$;
|
|
1714
|
+
};
|
|
1715
|
+
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
1716
|
+
if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent["s-p"]) {
|
|
1717
|
+
const index = ancestorComponent["s-p"].push(new Promise((r) => hostRef.$onRenderResolve$ = () => {
|
|
1718
|
+
ancestorComponent["s-p"].splice(index - 1, 1);
|
|
1719
|
+
r();
|
|
1720
|
+
}));
|
|
1721
|
+
if (ancestorComponent["s-pc"]) ancestorComponent["s-pc"].push(ensureFirstConnectPromise(hostRef));
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
1725
|
+
if (BUILD.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
|
|
1726
|
+
if (BUILD.asyncLoading && hostRef.$flags$ & HOST_FLAGS.isWaitingForChildren) {
|
|
1727
|
+
hostRef.$flags$ |= HOST_FLAGS.needsRerender;
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
|
1731
|
+
const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
|
|
1732
|
+
if (isInitialLoad) {
|
|
1733
|
+
const pendingConnects = BUILD.asyncLoading ? hostRef.$hostElement$["s-pc"] : void 0;
|
|
1734
|
+
if (pendingConnects && pendingConnects.length > 0) return Promise.all(pendingConnects).then(dispatch).catch(dispatch);
|
|
1735
|
+
queueMicrotask(() => {
|
|
1736
|
+
dispatch();
|
|
1737
|
+
});
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1740
|
+
return BUILD.taskQueue ? writeTask(dispatch) : dispatch();
|
|
1741
|
+
};
|
|
1742
|
+
/**
|
|
1743
|
+
* Dispatch initial-render and update lifecycle hooks, enqueuing calls to
|
|
1744
|
+
* component lifecycle methods like `componentWillLoad` as well as
|
|
1745
|
+
* {@link updateComponent}, which will kick off the virtual DOM re-render.
|
|
1746
|
+
*
|
|
1747
|
+
* @param hostRef a reference to a host DOM node
|
|
1748
|
+
* @param isInitialLoad whether we're on the initial load or not
|
|
1749
|
+
* @returns an empty Promise which is used to enqueue a series of operations for
|
|
1750
|
+
* the component
|
|
1751
|
+
*/
|
|
1752
|
+
const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
1753
|
+
const elm = hostRef.$hostElement$;
|
|
1754
|
+
const endSchedule = createTime("scheduleUpdate", hostRef.$cmpMeta$.$tagName$);
|
|
1755
|
+
const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
|
|
1756
|
+
/**
|
|
1757
|
+
* Given a user imports a component compiled with a `dist-custom-element`
|
|
1758
|
+
* output target into a Stencil project compiled with a `dist` output target,
|
|
1759
|
+
* then `instance` will be `undefined` as `hostRef` won't have a `lazyInstance`
|
|
1760
|
+
* property. In this case, the component will fail to render in one of the
|
|
1761
|
+
* subsequent functions.
|
|
1762
|
+
*
|
|
1763
|
+
* For this scenario to work the user needs to set the `externalRuntime` flag
|
|
1764
|
+
* for the `dist-custom-element` component that is being imported into the `dist`
|
|
1765
|
+
* Stencil project.
|
|
1766
|
+
*/
|
|
1767
|
+
if (!instance) {
|
|
1768
|
+
if (BUILD.isDev) throw new Error(`Can't render <${elm.tagName.toLowerCase()} /> - compiled without externalRuntime: true. See https://stenciljs.com/docs/custom-elements#externalruntime`);
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
let maybePromise;
|
|
1772
|
+
if (isInitialLoad) {
|
|
1773
|
+
if (BUILD.lazyLoad) {
|
|
1774
|
+
if (BUILD.hostListener) {
|
|
1775
|
+
hostRef.$flags$ |= HOST_FLAGS.isListenReady;
|
|
1776
|
+
if (hostRef.$queuedListeners$) {
|
|
1777
|
+
hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event, elm));
|
|
1778
|
+
hostRef.$queuedListeners$ = void 0;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
if (hostRef.$fetchedCbList$.length) hostRef.$fetchedCbList$.forEach((cb) => cb(elm));
|
|
1782
|
+
}
|
|
1783
|
+
if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillLoad");
|
|
1784
|
+
maybePromise = safeCall(instance, "componentWillLoad", void 0, elm);
|
|
1785
|
+
} else {
|
|
1786
|
+
if (BUILD.updatable && hostRef.$queuedPropChanges$) {
|
|
1787
|
+
const changes = hostRef.$queuedPropChanges$;
|
|
1788
|
+
hostRef.$queuedPropChanges$ = void 0;
|
|
1789
|
+
if (safeCall(instance, "componentShouldUpdate", changes, elm) === false) {
|
|
1790
|
+
hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillUpdate");
|
|
1795
|
+
maybePromise = safeCall(instance, "componentWillUpdate", void 0, elm);
|
|
1796
|
+
}
|
|
1797
|
+
if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentWillRender");
|
|
1798
|
+
maybePromise = enqueue(maybePromise, () => safeCall(instance, "componentWillRender", void 0, elm));
|
|
1799
|
+
endSchedule();
|
|
1800
|
+
return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
|
|
1801
|
+
};
|
|
1802
|
+
/**
|
|
1803
|
+
* This function uses a Promise to implement a simple first-in, first-out queue
|
|
1804
|
+
* of functions to be called.
|
|
1805
|
+
*
|
|
1806
|
+
* The queue is ordered on the basis of the first argument. If it's
|
|
1807
|
+
* `undefined`, then nothing is on the queue yet, so the provided function can
|
|
1808
|
+
* be called synchronously (although note that this function may return a
|
|
1809
|
+
* `Promise`). The idea is that then the return value of that enqueueing
|
|
1810
|
+
* operation is kept around, so that if it was a `Promise` then subsequent
|
|
1811
|
+
* functions can be enqueued by calling this function again with that `Promise`
|
|
1812
|
+
* as the first argument.
|
|
1813
|
+
*
|
|
1814
|
+
* @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
|
|
1815
|
+
* @param fn a function to enqueue
|
|
1816
|
+
* @returns either a `Promise` or the return value of the provided function
|
|
1817
|
+
*/
|
|
1818
|
+
const enqueue = (maybePromise, fn) => {
|
|
1819
|
+
if (isPromisey(maybePromise)) return maybePromise.then(fn).catch((err) => {
|
|
1820
|
+
console.error(err);
|
|
1821
|
+
fn();
|
|
1822
|
+
});
|
|
1823
|
+
const result = fn();
|
|
1824
|
+
return isPromisey(result) ? result : void 0;
|
|
1825
|
+
};
|
|
1826
|
+
/**
|
|
1827
|
+
* Check that a value is a `Promise`. To check, we first see if the value is an
|
|
1828
|
+
* instance of the `Promise` global. In a few circumstances, in particular if
|
|
1829
|
+
* the global has been overwritten, this is could be misleading, so we also do
|
|
1830
|
+
* a little 'duck typing' check to see if the `.then` property of the value is
|
|
1831
|
+
* defined and a function.
|
|
1832
|
+
*
|
|
1833
|
+
* @param maybePromise it might be a promise!
|
|
1834
|
+
* @returns whether it is or not
|
|
1835
|
+
*/
|
|
1836
|
+
const isPromisey = (maybePromise) => maybePromise instanceof Promise || maybePromise && maybePromise.then && typeof maybePromise.then === "function";
|
|
1837
|
+
/**
|
|
1838
|
+
* Update a component given reference to its host elements and so on.
|
|
1839
|
+
*
|
|
1840
|
+
* @param hostRef an object containing references to the element's host node,
|
|
1841
|
+
* VDom nodes, and other metadata
|
|
1842
|
+
* @param instance a reference to the underlying host element where it will be
|
|
1843
|
+
* rendered
|
|
1844
|
+
* @param isInitialLoad whether or not this function is being called as part of
|
|
1845
|
+
* the first render cycle
|
|
1846
|
+
* @returns a `Promise` if the update is asynchronous, otherwise `void`
|
|
1847
|
+
*/
|
|
1848
|
+
const updateComponent = (hostRef, instance, isInitialLoad) => {
|
|
1849
|
+
const elm = hostRef.$hostElement$;
|
|
1850
|
+
const endUpdate = createTime("update", hostRef.$cmpMeta$.$tagName$);
|
|
1851
|
+
const rc = elm["s-rc"];
|
|
1852
|
+
if (BUILD.style && isInitialLoad) attachStyles(hostRef);
|
|
1853
|
+
const endRender = createTime("render", hostRef.$cmpMeta$.$tagName$);
|
|
1854
|
+
if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
|
|
1855
|
+
if (BUILD.hydrateServerSide) return callRender(hostRef, instance, elm, isInitialLoad).then(() => {
|
|
1856
|
+
afterRender(hostRef, elm, rc, isInitialLoad, endRender, endUpdate);
|
|
1857
|
+
});
|
|
1858
|
+
callRender(hostRef, instance, elm, isInitialLoad);
|
|
1859
|
+
afterRender(hostRef, elm, rc, isInitialLoad, endRender, endUpdate);
|
|
1860
|
+
};
|
|
1861
|
+
const afterRender = (hostRef, elm, rc, isInitialLoad, endRender, endUpdate) => {
|
|
1862
|
+
if (BUILD.isDev) {
|
|
1863
|
+
hostRef.$renderCount$ = hostRef.$renderCount$ === void 0 ? 1 : hostRef.$renderCount$ + 1;
|
|
1864
|
+
hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
|
|
1865
|
+
}
|
|
1866
|
+
if (BUILD.hydrateServerSide) try {
|
|
1867
|
+
serverSideConnected(elm);
|
|
1868
|
+
if (isInitialLoad) {
|
|
1869
|
+
if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) elm["s-en"] = "";
|
|
1870
|
+
else if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.scopedCssEncapsulation) elm["s-en"] = "c";
|
|
1871
|
+
}
|
|
1872
|
+
} catch (e) {
|
|
1873
|
+
consoleError(e, elm);
|
|
1874
|
+
}
|
|
1875
|
+
if (BUILD.asyncLoading && rc) {
|
|
1876
|
+
rc.map((cb) => cb());
|
|
1877
|
+
elm["s-rc"] = void 0;
|
|
1878
|
+
}
|
|
1879
|
+
endRender();
|
|
1880
|
+
endUpdate();
|
|
1881
|
+
if (BUILD.asyncLoading) {
|
|
1882
|
+
const childrenPromises = elm["s-p"] ?? [];
|
|
1883
|
+
const postUpdate = () => postUpdateComponent(hostRef);
|
|
1884
|
+
if (childrenPromises.length === 0) postUpdate();
|
|
1885
|
+
else {
|
|
1886
|
+
Promise.all(childrenPromises).then(postUpdate).catch(postUpdate);
|
|
1887
|
+
hostRef.$flags$ |= HOST_FLAGS.isWaitingForChildren;
|
|
1888
|
+
childrenPromises.length = 0;
|
|
1889
|
+
}
|
|
1890
|
+
} else postUpdateComponent(hostRef);
|
|
1891
|
+
};
|
|
1892
|
+
let renderingRef = null;
|
|
1893
|
+
/**
|
|
1894
|
+
* Handle making the call to the VDom renderer with the proper context given
|
|
1895
|
+
* various build variables
|
|
1896
|
+
*
|
|
1897
|
+
* @param hostRef an object containing references to the element's host node,
|
|
1898
|
+
* VDom nodes, and other metadata
|
|
1899
|
+
* @param instance a reference to the underlying host element where it will be
|
|
1900
|
+
* rendered
|
|
1901
|
+
* @param elm the Host element for the component
|
|
1902
|
+
* @param isInitialLoad whether or not this function is being called as part of
|
|
1903
|
+
* @returns an empty promise
|
|
1904
|
+
*/
|
|
1905
|
+
const callRender = (hostRef, instance, elm, isInitialLoad) => {
|
|
1906
|
+
const allRenderFn = !!BUILD.allRenderFn;
|
|
1907
|
+
const lazyLoad = !!BUILD.lazyLoad;
|
|
1908
|
+
const updatable = !!BUILD.updatable;
|
|
1909
|
+
try {
|
|
1910
|
+
renderingRef = instance;
|
|
1911
|
+
/**
|
|
1912
|
+
* minification optimization: `allRenderFn` is `true` if all components have a `render`
|
|
1913
|
+
* method, so we can call the method immediately. If not, check before calling it.
|
|
1914
|
+
*/
|
|
1915
|
+
instance = allRenderFn ? instance.render() : instance.render && instance.render();
|
|
1916
|
+
if (updatable) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
|
|
1917
|
+
if (updatable || lazyLoad) hostRef.$flags$ |= HOST_FLAGS.hasRendered;
|
|
1918
|
+
if (BUILD.hasRenderFn || BUILD.reflect) {
|
|
1919
|
+
if (BUILD.vdomRender || BUILD.reflect) {
|
|
1920
|
+
if (BUILD.hydrateServerSide) return Promise.resolve(instance).then((value) => renderVdom(hostRef, value, isInitialLoad));
|
|
1921
|
+
else renderVdom(hostRef, instance, isInitialLoad);
|
|
1922
|
+
} else {
|
|
1923
|
+
const shadowRoot = elm.shadowRoot;
|
|
1924
|
+
if (hostRef.$cmpMeta$.$flags$ & CMP_FLAGS.shadowDomEncapsulation) shadowRoot.textContent = instance;
|
|
1925
|
+
else elm.textContent = instance;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
} catch (e) {
|
|
1929
|
+
consoleError(e, hostRef.$hostElement$);
|
|
1930
|
+
}
|
|
1931
|
+
renderingRef = null;
|
|
1932
|
+
return null;
|
|
1933
|
+
};
|
|
1934
|
+
const getRenderingRef = () => renderingRef;
|
|
1935
|
+
const postUpdateComponent = (hostRef) => {
|
|
1936
|
+
const tagName = hostRef.$cmpMeta$.$tagName$;
|
|
1937
|
+
const elm = hostRef.$hostElement$;
|
|
1938
|
+
const endPostUpdate = createTime("postUpdate", tagName);
|
|
1939
|
+
const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
|
|
1940
|
+
const ancestorComponent = hostRef.$ancestorComponent$;
|
|
1941
|
+
if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
|
|
1942
|
+
safeCall(instance, "componentDidRender", void 0, elm);
|
|
1943
|
+
if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
|
|
1944
|
+
if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidRender");
|
|
1945
|
+
if (!(hostRef.$flags$ & HOST_FLAGS.hasLoadedComponent)) {
|
|
1946
|
+
hostRef.$flags$ |= HOST_FLAGS.hasLoadedComponent;
|
|
1947
|
+
if (BUILD.asyncLoading && BUILD.cssAnnotations) addHydratedFlag(elm);
|
|
1948
|
+
if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnDidLoad;
|
|
1949
|
+
safeCall(instance, "componentDidLoad", void 0, elm);
|
|
1950
|
+
if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnDidLoad;
|
|
1951
|
+
if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidLoad");
|
|
1952
|
+
if (BUILD.propChangeCallback) hostRef.$flags$ |= HOST_FLAGS.isWatchReady;
|
|
1953
|
+
endPostUpdate();
|
|
1954
|
+
if (BUILD.asyncLoading) {
|
|
1955
|
+
hostRef.$onReadyResolve$(elm);
|
|
1956
|
+
if (!ancestorComponent) appDidLoad(tagName);
|
|
1957
|
+
}
|
|
1958
|
+
} else {
|
|
1959
|
+
if (BUILD.isDev) hostRef.$flags$ |= HOST_FLAGS.devOnRender;
|
|
1960
|
+
safeCall(instance, "componentDidUpdate", void 0, elm);
|
|
1961
|
+
if (BUILD.isDev) hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
|
|
1962
|
+
if (BUILD.lifecycleDOMEvents) emitLifecycleEvent(elm, "componentDidUpdate");
|
|
1963
|
+
endPostUpdate();
|
|
1964
|
+
}
|
|
1965
|
+
if (BUILD.method && BUILD.lazyLoad) hostRef.$onInstanceResolve$(elm);
|
|
1966
|
+
if (BUILD.asyncLoading) {
|
|
1967
|
+
if (hostRef.$onRenderResolve$) {
|
|
1968
|
+
hostRef.$onRenderResolve$();
|
|
1969
|
+
hostRef.$onRenderResolve$ = void 0;
|
|
1970
|
+
}
|
|
1971
|
+
if (hostRef.$flags$ & HOST_FLAGS.needsRerender) nextTick(() => scheduleUpdate(hostRef, false));
|
|
1972
|
+
hostRef.$flags$ &= ~(HOST_FLAGS.isWaitingForChildren | HOST_FLAGS.needsRerender);
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
const forceUpdate = (ref) => {
|
|
1976
|
+
if (BUILD.updatable && (Build.isBrowser || Build.isTesting)) {
|
|
1977
|
+
const hostRef = getHostRef(ref);
|
|
1978
|
+
const isConnected = hostRef?.$hostElement$?.isConnected;
|
|
1979
|
+
if (isConnected && (hostRef.$flags$ & (HOST_FLAGS.hasRendered | HOST_FLAGS.isQueuedForUpdate)) === HOST_FLAGS.hasRendered) scheduleUpdate(hostRef, false);
|
|
1980
|
+
return isConnected;
|
|
1981
|
+
}
|
|
1982
|
+
return false;
|
|
1983
|
+
};
|
|
1984
|
+
const appDidLoad = (who) => {
|
|
1985
|
+
if (BUILD.asyncQueue) plt.$flags$ |= PLATFORM_FLAGS.appLoaded;
|
|
1986
|
+
nextTick(() => emitEvent(win, "appload", { detail: { namespace: "app" } }));
|
|
1987
|
+
if (BUILD.hydrateClientSide) {
|
|
1988
|
+
if (plt.$orgLocNodes$?.size) plt.$orgLocNodes$.clear();
|
|
1989
|
+
}
|
|
1990
|
+
if (BUILD.profile && performance.measure) performance.measure(`[Stencil] app initial load (by ${who})`, "st:app:start");
|
|
1991
|
+
};
|
|
1992
|
+
/**
|
|
1993
|
+
* Allows to safely call a method, e.g. `componentDidLoad`, on an instance,
|
|
1994
|
+
* e.g. custom element node. If a build figures out that e.g. no component
|
|
1995
|
+
* has a `componentDidLoad` method, the instance method gets removed from the
|
|
1996
|
+
* output bundle and this function returns `undefined`.
|
|
1997
|
+
* @param instance any object that may or may not contain methods
|
|
1998
|
+
* @param method method name
|
|
1999
|
+
* @param arg single arbitrary argument
|
|
2000
|
+
* @param elm the element which made the call
|
|
2001
|
+
* @returns result of method call if it exists, otherwise `undefined`
|
|
2002
|
+
*/
|
|
2003
|
+
const safeCall = (instance, method, arg, elm) => {
|
|
2004
|
+
if (instance && instance[method]) try {
|
|
2005
|
+
return instance[method](arg);
|
|
2006
|
+
} catch (e) {
|
|
2007
|
+
consoleError(e, elm);
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
/**
|
|
2011
|
+
* For debugging purposes as `BUILD.lifecycleDOMEvents` is `false` by default and will
|
|
2012
|
+
* get removed by the compiler. Used for timing events to see how long they take.
|
|
2013
|
+
* @param elm the target of the Event
|
|
2014
|
+
* @param lifecycleName name of the event
|
|
2015
|
+
*/
|
|
2016
|
+
const emitLifecycleEvent = (elm, lifecycleName) => {
|
|
2017
|
+
if (BUILD.lifecycleDOMEvents) emitEvent(elm, "stencil_" + lifecycleName, {
|
|
2018
|
+
bubbles: true,
|
|
2019
|
+
composed: true,
|
|
2020
|
+
detail: { namespace: "app" }
|
|
2021
|
+
});
|
|
2022
|
+
};
|
|
2023
|
+
/**
|
|
2024
|
+
* Set the hydrated flag on a DOM element
|
|
2025
|
+
*
|
|
2026
|
+
* @param elm a reference to a DOM element
|
|
2027
|
+
* @returns undefined
|
|
2028
|
+
*/
|
|
2029
|
+
const addHydratedFlag = (elm) => BUILD.hydratedClass ? elm.classList.add(BUILD.hydratedSelectorName ?? "hydrated") : BUILD.hydratedAttribute ? elm.setAttribute(BUILD.hydratedSelectorName ?? "hydrated", "") : void 0;
|
|
2030
|
+
const serverSideConnected = (elm) => {
|
|
2031
|
+
const children = elm.children;
|
|
2032
|
+
if (children != null) for (let i = 0, ii = children.length; i < ii; i++) {
|
|
2033
|
+
const childElm = children[i];
|
|
2034
|
+
if (typeof childElm.connectedCallback === "function") childElm.connectedCallback();
|
|
2035
|
+
serverSideConnected(childElm);
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
//#endregion
|
|
2039
|
+
//#region src/runtime/signals.ts
|
|
2040
|
+
/**
|
|
2041
|
+
* Duck-type check for Signal objects. Cross-bundle-safe (no instanceof).
|
|
2042
|
+
* @param v value to test
|
|
2043
|
+
* @returns whether `v` implements the SignalLike interface
|
|
2044
|
+
*/
|
|
2045
|
+
const isSignalLike = (v) => v !== null && typeof v === "object" && typeof v.peek === "function" && typeof v.subscribe === "function";
|
|
2046
|
+
//#endregion
|
|
2047
|
+
//#region src/runtime/vdom/h.ts
|
|
2048
|
+
/**
|
|
2049
|
+
* Production h() function based on Preact by
|
|
2050
|
+
* Jason Miller (@developit)
|
|
2051
|
+
* Licensed under the MIT License
|
|
2052
|
+
* https://github.com/developit/preact/blob/master/LICENSE
|
|
2053
|
+
*
|
|
2054
|
+
* Modified for Stencil's compiler and vdom
|
|
2055
|
+
*/
|
|
2056
|
+
const h = (nodeName, vnodeData, ...children) => {
|
|
2057
|
+
if (typeof nodeName === "string") nodeName = transformTag(nodeName);
|
|
2058
|
+
let child = null;
|
|
2059
|
+
let key = null;
|
|
2060
|
+
let slotName = null;
|
|
2061
|
+
let simple = false;
|
|
2062
|
+
let lastSimple = false;
|
|
2063
|
+
const vNodeChildren = [];
|
|
2064
|
+
const walk = (c) => {
|
|
2065
|
+
for (let i = 0; i < c.length; i++) {
|
|
2066
|
+
child = c[i];
|
|
2067
|
+
if (Array.isArray(child)) walk(child);
|
|
2068
|
+
else if (child != null && typeof child !== "boolean") {
|
|
2069
|
+
if (BUILD.vdomSignals && isSignalLike(child)) {
|
|
2070
|
+
const sigVNode = newVNode(null, String(child.peek()));
|
|
2071
|
+
sigVNode.$signal$ = child;
|
|
2072
|
+
vNodeChildren.push(sigVNode);
|
|
2073
|
+
lastSimple = false;
|
|
2074
|
+
} else {
|
|
2075
|
+
if (simple = typeof nodeName !== "function" && !isComplexType(child)) child = String(child);
|
|
2076
|
+
else if (typeof nodeName !== "function" && child.$flags$ === void 0) {
|
|
2077
|
+
if (BUILD.isDev) consoleDevError(`vNode passed as children has unexpected type.
|
|
2078
|
+
Make sure it's using the correct h() function.
|
|
2079
|
+
Empty objects can also be the cause, look for JSX comments that became objects.`);
|
|
2080
|
+
else consoleError("Invalid vNode child");
|
|
2081
|
+
continue;
|
|
2082
|
+
}
|
|
2083
|
+
if (simple && lastSimple) vNodeChildren[vNodeChildren.length - 1].$text$ += child;
|
|
2084
|
+
else vNodeChildren.push(simple ? newVNode(null, child) : child);
|
|
2085
|
+
lastSimple = simple;
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
};
|
|
2090
|
+
walk(children);
|
|
2091
|
+
if (vnodeData && typeof vnodeData === "object") {
|
|
2092
|
+
if (BUILD.isDev && nodeName === "input") validateInputProperties(vnodeData);
|
|
2093
|
+
if (BUILD.vdomKey && vnodeData.key) key = vnodeData.key;
|
|
2094
|
+
if (BUILD.slotRelocation && vnodeData.name) slotName = vnodeData.name;
|
|
2095
|
+
if (BUILD.vdomClass) {
|
|
2096
|
+
const classData = vnodeData.class;
|
|
2097
|
+
if (classData && !(BUILD.vdomSignals && isSignalLike(classData))) vnodeData.class = typeof classData !== "object" ? classData : Object.keys(classData).filter((k) => classData[k]).join(" ");
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
if (BUILD.isDev && vNodeChildren.some(isHost)) consoleDevError(`The <Host> must be the single root component. Make sure:
|
|
2101
|
+
- You are NOT using hostData() and <Host> in the same component.
|
|
2102
|
+
- <Host> is used once, and it's the single root component of the render() function.`);
|
|
2103
|
+
if (BUILD.vdomFunctional && typeof nodeName === "function") return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
|
|
2104
|
+
const vnode = newVNode(nodeName, null);
|
|
2105
|
+
vnode.$attrs$ = vnodeData;
|
|
2106
|
+
if (vNodeChildren.length > 0) vnode.$children$ = vNodeChildren;
|
|
2107
|
+
if (BUILD.vdomKey) vnode.$key$ = key;
|
|
2108
|
+
if (BUILD.slotRelocation) vnode.$name$ = slotName;
|
|
2109
|
+
return vnode;
|
|
2110
|
+
};
|
|
2111
|
+
/**
|
|
2112
|
+
* A utility function for creating a virtual DOM node from a tag and some
|
|
2113
|
+
* possible text content.
|
|
2114
|
+
*
|
|
2115
|
+
* @param tag the tag for this element
|
|
2116
|
+
* @param text possible text content for the node
|
|
2117
|
+
* @returns a newly-minted virtual DOM node
|
|
2118
|
+
*/
|
|
2119
|
+
const newVNode = (tag, text) => {
|
|
2120
|
+
const vnode = {
|
|
2121
|
+
$flags$: 0,
|
|
2122
|
+
$tag$: tag,
|
|
2123
|
+
$text$: text ?? null,
|
|
2124
|
+
$elm$: null,
|
|
2125
|
+
$children$: null
|
|
2126
|
+
};
|
|
2127
|
+
if (BUILD.vdomAttribute) vnode.$attrs$ = null;
|
|
2128
|
+
if (BUILD.vdomKey) vnode.$key$ = null;
|
|
2129
|
+
if (BUILD.slotRelocation) vnode.$name$ = null;
|
|
2130
|
+
return vnode;
|
|
2131
|
+
};
|
|
2132
|
+
const Host = {};
|
|
2133
|
+
/**
|
|
2134
|
+
* Check whether a given node is a Host node or not
|
|
2135
|
+
*
|
|
2136
|
+
* @param node the virtual DOM node to check
|
|
2137
|
+
* @returns whether it's a Host node or not
|
|
2138
|
+
*/
|
|
2139
|
+
const isHost = (node) => node && node.$tag$ === Host;
|
|
2140
|
+
/**
|
|
2141
|
+
* Implementation of {@link d.FunctionalUtilities} for Stencil's VDom.
|
|
2142
|
+
*
|
|
2143
|
+
* Note that these functions convert from {@link d.VNode} to
|
|
2144
|
+
* {@link d.ChildNode} to give functional component developers a friendly
|
|
2145
|
+
* interface.
|
|
2146
|
+
*/
|
|
2147
|
+
const vdomFnUtils = {
|
|
2148
|
+
forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
|
|
2149
|
+
map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate)
|
|
2150
|
+
};
|
|
2151
|
+
/**
|
|
2152
|
+
* Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
|
|
2153
|
+
* friendlier public interface (hence, 'convertToPublic').
|
|
2154
|
+
*
|
|
2155
|
+
* @param node the virtual DOM node to convert
|
|
2156
|
+
* @returns a converted child node
|
|
2157
|
+
*/
|
|
2158
|
+
const convertToPublic = (node) => ({
|
|
2159
|
+
vattrs: node.$attrs$,
|
|
2160
|
+
vchildren: node.$children$,
|
|
2161
|
+
vkey: node.$key$,
|
|
2162
|
+
vname: node.$name$,
|
|
2163
|
+
vtag: node.$tag$,
|
|
2164
|
+
vtext: node.$text$
|
|
2165
|
+
});
|
|
2166
|
+
/**
|
|
2167
|
+
* Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
|
|
2168
|
+
* order to use the resulting object in the virtual DOM. The initial object was
|
|
2169
|
+
* likely created as part of presenting a public API, so converting it back
|
|
2170
|
+
* involved making it 'private' again (hence, `convertToPrivate`).
|
|
2171
|
+
*
|
|
2172
|
+
* @param node the child node to convert
|
|
2173
|
+
* @returns a converted virtual DOM node
|
|
2174
|
+
*/
|
|
2175
|
+
const convertToPrivate = (node) => {
|
|
2176
|
+
if (typeof node.vtag === "function") {
|
|
2177
|
+
const vnodeData = { ...node.vattrs };
|
|
2178
|
+
if (node.vkey) vnodeData.key = node.vkey;
|
|
2179
|
+
if (node.vname) vnodeData.name = node.vname;
|
|
2180
|
+
return h(node.vtag, vnodeData, ...node.vchildren || []);
|
|
2181
|
+
}
|
|
2182
|
+
const vnode = newVNode(node.vtag, node.vtext);
|
|
2183
|
+
vnode.$attrs$ = node.vattrs;
|
|
2184
|
+
vnode.$children$ = node.vchildren;
|
|
2185
|
+
vnode.$key$ = node.vkey;
|
|
2186
|
+
vnode.$name$ = node.vname;
|
|
2187
|
+
return vnode;
|
|
2188
|
+
};
|
|
2189
|
+
/**
|
|
2190
|
+
* Validates the ordering of attributes on an input element
|
|
2191
|
+
*
|
|
2192
|
+
* @param inputElm the vnode data (JSX props) for the element to validate
|
|
2193
|
+
*/
|
|
2194
|
+
const validateInputProperties = (inputElm) => {
|
|
2195
|
+
const props = Object.keys(inputElm);
|
|
2196
|
+
const value = props.indexOf("value");
|
|
2197
|
+
if (value === -1) return;
|
|
2198
|
+
const typeIndex = props.indexOf("type");
|
|
2199
|
+
const minIndex = props.indexOf("min");
|
|
2200
|
+
const maxIndex = props.indexOf("max");
|
|
2201
|
+
const stepIndex = props.indexOf("step");
|
|
2202
|
+
if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
|
|
2203
|
+
};
|
|
2204
|
+
//#endregion
|
|
2205
|
+
//#region src/runtime/mode.ts
|
|
2206
|
+
const setMode = (handler) => modeResolutionChain.push(handler);
|
|
2207
|
+
const getMode = (ref) => getHostRef(ref)?.$modeName$;
|
|
2208
|
+
//#endregion
|
|
2209
|
+
//#region src/runtime/mixin.ts
|
|
2210
|
+
const baseClass = BUILD.lazyLoad ? class {} : globalThis.HTMLElement || class {};
|
|
2211
|
+
function Mixin(...mixins) {
|
|
2212
|
+
return mixins.reduceRight((acc, mixin) => mixin(acc), baseClass);
|
|
2213
|
+
}
|
|
2214
|
+
//#endregion
|
|
2215
|
+
//#region src/runtime/reactive-controller.ts
|
|
2216
|
+
const ReactiveControllerHost = (Base) => class ReactiveControllerHostMixin extends Base {
|
|
2217
|
+
controllers = /* @__PURE__ */ new Set();
|
|
2218
|
+
#connected = false;
|
|
2219
|
+
#updateCompleteResolvers = [];
|
|
2220
|
+
addController(controller) {
|
|
2221
|
+
this.controllers.add(controller);
|
|
2222
|
+
if (this.#connected) controller.hostConnected?.();
|
|
2223
|
+
}
|
|
2224
|
+
removeController(controller) {
|
|
2225
|
+
this.controllers.delete(controller);
|
|
2226
|
+
}
|
|
2227
|
+
requestUpdate() {
|
|
2228
|
+
forceUpdate(this);
|
|
2229
|
+
}
|
|
2230
|
+
get updateComplete() {
|
|
2231
|
+
return new Promise((resolve) => this.#updateCompleteResolvers.push(resolve));
|
|
2232
|
+
}
|
|
2233
|
+
connectedCallback() {
|
|
2234
|
+
super.connectedCallback?.();
|
|
2235
|
+
this.#connected = true;
|
|
2236
|
+
const el = getElement(this);
|
|
2237
|
+
if (el && el !== this) {
|
|
2238
|
+
el.addController = (controller) => this.addController(controller);
|
|
2239
|
+
el.removeController = (controller) => this.removeController(controller);
|
|
2240
|
+
el.requestUpdate = () => this.requestUpdate();
|
|
2241
|
+
Object.defineProperty(el, "updateComplete", {
|
|
2242
|
+
configurable: true,
|
|
2243
|
+
get: () => this.updateComplete
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
this.controllers.forEach((c) => c.hostConnected?.());
|
|
2247
|
+
}
|
|
2248
|
+
disconnectedCallback() {
|
|
2249
|
+
super.disconnectedCallback?.();
|
|
2250
|
+
this.#connected = false;
|
|
2251
|
+
this.controllers.forEach((c) => c.hostDisconnected?.());
|
|
2252
|
+
}
|
|
2253
|
+
async componentWillLoad() {
|
|
2254
|
+
await super.componentWillLoad?.();
|
|
2255
|
+
await Promise.all([...this.controllers].map((c) => c.hostWillLoad?.()));
|
|
2256
|
+
}
|
|
2257
|
+
componentDidLoad() {
|
|
2258
|
+
super.componentDidLoad?.();
|
|
2259
|
+
this.controllers.forEach((c) => c.hostDidLoad?.());
|
|
2260
|
+
}
|
|
2261
|
+
async componentWillRender() {
|
|
2262
|
+
await super.componentWillRender?.();
|
|
2263
|
+
await Promise.all([...this.controllers].map((c) => c.hostWillRender?.()));
|
|
2264
|
+
}
|
|
2265
|
+
componentDidRender() {
|
|
2266
|
+
super.componentDidRender?.();
|
|
2267
|
+
this.controllers.forEach((c) => c.hostDidRender?.());
|
|
2268
|
+
const resolvers = this.#updateCompleteResolvers;
|
|
2269
|
+
this.#updateCompleteResolvers = [];
|
|
2270
|
+
resolvers.forEach((resolve) => resolve(true));
|
|
2271
|
+
}
|
|
2272
|
+
async componentWillUpdate() {
|
|
2273
|
+
await super.componentWillUpdate?.();
|
|
2274
|
+
await Promise.all([...this.controllers].map((c) => c.hostWillUpdate?.()));
|
|
2275
|
+
}
|
|
2276
|
+
componentDidUpdate() {
|
|
2277
|
+
super.componentDidUpdate?.();
|
|
2278
|
+
this.controllers.forEach((c) => c.hostDidUpdate?.());
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
//#endregion
|
|
2282
|
+
//#region src/runtime/render.ts
|
|
2283
|
+
/**
|
|
2284
|
+
* A WeakMap to persist HostRef objects across multiple render() calls to the
|
|
2285
|
+
* same container. This enables VNode diffing on re-renders - without it, each
|
|
2286
|
+
* call creates a fresh HostRef with no previous VNode, causing renderVdom to
|
|
2287
|
+
* replace the entire DOM subtree instead of patching only what changed.
|
|
2288
|
+
*/
|
|
2289
|
+
const hostRefCache = /* @__PURE__ */ new WeakMap();
|
|
2290
|
+
/**
|
|
2291
|
+
* Method to render a virtual DOM tree to a container element.
|
|
2292
|
+
*
|
|
2293
|
+
* Supports efficient re-renders: calling `render()` again on the same container
|
|
2294
|
+
* will diff the new VNode tree against the previous one and only update what changed,
|
|
2295
|
+
* preserving existing DOM elements and their state.
|
|
2296
|
+
*
|
|
2297
|
+
* @example
|
|
2298
|
+
* ```tsx
|
|
2299
|
+
* import { render } from '@stencil/core';
|
|
2300
|
+
*
|
|
2301
|
+
* const vnode = (
|
|
2302
|
+
* <div>
|
|
2303
|
+
* <h1>Hello, world!</h1>
|
|
2304
|
+
* </div>
|
|
2305
|
+
* );
|
|
2306
|
+
* render(vnode, document.body);
|
|
2307
|
+
* ```
|
|
2308
|
+
*
|
|
2309
|
+
* @param vnode - The virtual DOM tree to render
|
|
2310
|
+
* @param container - The container element to render the virtual DOM tree to
|
|
2311
|
+
*/
|
|
2312
|
+
function render(vnode, container) {
|
|
2313
|
+
let ref = hostRefCache.get(container);
|
|
2314
|
+
if (!ref) {
|
|
2315
|
+
ref = {
|
|
2316
|
+
$flags$: 0,
|
|
2317
|
+
$cmpMeta$: {
|
|
2318
|
+
$flags$: 0,
|
|
2319
|
+
$tagName$: container.tagName
|
|
2320
|
+
},
|
|
2321
|
+
$hostElement$: container
|
|
2322
|
+
};
|
|
2323
|
+
hostRefCache.set(container, ref);
|
|
2324
|
+
}
|
|
2325
|
+
renderVdom(ref, vnode);
|
|
2326
|
+
}
|
|
2327
|
+
//#endregion
|
|
2328
|
+
//#region src/runtime/tag-transform.ts
|
|
2329
|
+
let tagTransformer = void 0;
|
|
2330
|
+
/**
|
|
2331
|
+
* Transforms a tag name using the current tag transformer
|
|
2332
|
+
* @param tag - the tag to transform e.g. `my-tag`
|
|
2333
|
+
* @returns the transformed tag e.g. `new-my-tag`
|
|
2334
|
+
*/
|
|
2335
|
+
function transformTag(tag) {
|
|
2336
|
+
if (!tagTransformer) return tag;
|
|
2337
|
+
return tagTransformer(tag);
|
|
2338
|
+
}
|
|
2339
|
+
/**
|
|
2340
|
+
* Sets the tag transformer to be used when rendering custom elements
|
|
2341
|
+
* @param transformer the transformer function to use. Must return a string
|
|
2342
|
+
*/
|
|
2343
|
+
function setTagTransformer(transformer) {
|
|
2344
|
+
tagTransformer = transformer;
|
|
2345
|
+
}
|
|
2346
|
+
//#endregion
|
|
2347
|
+
//#region src/runtime/vdom/jsx-runtime.ts
|
|
2348
|
+
function jsx(type, props, key) {
|
|
2349
|
+
const { children, ...rest } = props ?? {};
|
|
2350
|
+
if (key !== void 0 && !("key" in rest)) rest.key = key;
|
|
2351
|
+
const attrs = hasKeys(rest) ? rest : null;
|
|
2352
|
+
if (children !== void 0) return Array.isArray(children) ? h(type, attrs, ...children) : h(type, attrs, children);
|
|
2353
|
+
return h(type, attrs);
|
|
2354
|
+
}
|
|
2355
|
+
/**
|
|
2356
|
+
* @alias
|
|
2357
|
+
*/
|
|
2358
|
+
const jsxs = jsx;
|
|
2359
|
+
/**
|
|
2360
|
+
* @alias
|
|
2361
|
+
*/
|
|
2362
|
+
const jsxDEV = jsx;
|
|
2363
|
+
function hasKeys(obj) {
|
|
2364
|
+
for (const _ in obj) return true;
|
|
2365
|
+
return false;
|
|
2366
|
+
}
|
|
2367
|
+
//#endregion
|
|
2368
|
+
export { setErrorHandler as C, HYDRATED_CSS as S, getAssetPath as _, transformTag as a, writeTask as b, Mixin as c, Host as d, h as f, getShadowRoot as g, getElement as h, setTagTransformer as i, getMode as l, getRenderingRef as m, jsxDEV as n, render as o, forceUpdate as p, jsxs as r, ReactiveControllerHost as s, jsx as t, setMode as u, setAssetPath as v, Build as w, setPlatformHelpers as x, readTask as y };
|