@sankhyalabs/sankhyablocks 1.4.0-beta.2 → 1.4.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/cjs/{index-b0b676c5.js → index-6fcf07f3.js} +159 -1515
  2. package/dist/cjs/loader.cjs.js +2 -18
  3. package/dist/cjs/sankhyablocks.cjs.js +4 -116
  4. package/dist/cjs/snk-application.cjs.entry.js +50 -214
  5. package/dist/cjs/snk-crud.cjs.entry.js +3 -3
  6. package/dist/cjs/snk-data-unit.cjs.entry.js +23 -23
  7. package/dist/cjs/snk-filter-bar_5.cjs.entry.js +902 -0
  8. package/dist/cjs/snk-filter-binary-select.cjs.entry.js +1 -1
  9. package/dist/cjs/snk-filter-detail.cjs.entry.js +3 -3
  10. package/dist/cjs/snk-filter-multi-select.cjs.entry.js +1 -1
  11. package/dist/cjs/snk-filter-number.cjs.entry.js +1 -1
  12. package/dist/cjs/snk-filter-period.cjs.entry.js +1 -1
  13. package/dist/cjs/snk-filter-personalized.cjs.entry.js +23 -22
  14. package/dist/cjs/snk-filter-search.cjs.entry.js +3 -3
  15. package/dist/cjs/snk-filter-text.cjs.entry.js +1 -1
  16. package/dist/cjs/{snk-form.cjs.entry.js → snk-form_2.cjs.entry.js} +119 -5
  17. package/dist/cjs/snk-pesquisa.cjs.entry.js +5 -5
  18. package/dist/cjs/{taskbar-elements-283c737e.js → taskbar-elements-aedfeae6.js} +1 -1
  19. package/dist/cjs/teste-pesquisa.cjs.entry.js +5 -5
  20. package/dist/components/index.js +0 -4
  21. package/dist/components/snk-application2.js +10 -174
  22. package/dist/components/snk-crud.js +1 -1
  23. package/dist/components/snk-data-unit.js +2 -2
  24. package/dist/components/snk-filter-bar2.js +4 -2
  25. package/dist/components/snk-filter-detail2.js +1 -1
  26. package/dist/components/snk-filter-item2.js +1 -1
  27. package/dist/components/snk-filter-list2.js +1 -1
  28. package/dist/components/snk-filter-modal2.js +4 -19
  29. package/dist/components/snk-filter-personalized.js +2 -1
  30. package/dist/components/snk-filter-search.js +1 -1
  31. package/dist/components/snk-form2.js +1 -1
  32. package/dist/components/snk-grid2.js +1 -1
  33. package/dist/components/snk-pesquisa2.js +1 -1
  34. package/dist/components/snk-taskbar2.js +1 -1
  35. package/dist/components/teste-pesquisa.js +1 -1
  36. package/dist/{sankhyablocks/index-2b4d2d14.js → esm/index-81dda3cf.js} +160 -1508
  37. package/dist/esm/loader.js +2 -18
  38. package/dist/esm/sankhyablocks.js +4 -116
  39. package/dist/esm/snk-application.entry.js +11 -175
  40. package/dist/esm/snk-crud.entry.js +2 -2
  41. package/dist/esm/snk-data-unit.entry.js +3 -3
  42. package/dist/esm/{snk-filter-bar.entry.js → snk-filter-bar_5.entry.js} +436 -4
  43. package/dist/esm/snk-filter-binary-select.entry.js +1 -1
  44. package/dist/esm/snk-filter-detail.entry.js +2 -2
  45. package/dist/esm/snk-filter-multi-select.entry.js +1 -1
  46. package/dist/esm/snk-filter-number.entry.js +1 -1
  47. package/dist/esm/snk-filter-period.entry.js +1 -1
  48. package/dist/esm/snk-filter-personalized.entry.js +3 -2
  49. package/dist/esm/snk-filter-search.entry.js +2 -2
  50. package/dist/esm/snk-filter-text.entry.js +1 -1
  51. package/dist/{sankhyablocks/snk-form.entry.js → esm/snk-form_2.entry.js} +117 -4
  52. package/dist/esm/snk-pesquisa.entry.js +2 -2
  53. package/dist/esm/{taskbar-elements-35d64ff9.js → taskbar-elements-38eb5d51.js} +1 -1
  54. package/dist/esm/teste-pesquisa.entry.js +2 -2
  55. package/dist/sankhyablocks/index.esm.js +0 -1
  56. package/dist/sankhyablocks/p-0352c0e2.entry.js +1 -0
  57. package/dist/sankhyablocks/p-07ebda01.entry.js +1 -0
  58. package/dist/sankhyablocks/p-322c0df2.entry.js +1 -0
  59. package/dist/sankhyablocks/p-46caa101.entry.js +1 -0
  60. package/dist/sankhyablocks/p-473cedf9.entry.js +1 -0
  61. package/dist/sankhyablocks/p-586e2522.js +1 -0
  62. package/dist/sankhyablocks/p-86f15ffe.js +1 -0
  63. package/dist/sankhyablocks/p-8f3c5709.entry.js +1 -0
  64. package/dist/sankhyablocks/p-97009a2c.entry.js +1 -0
  65. package/dist/sankhyablocks/p-9be74b46.entry.js +74 -0
  66. package/dist/sankhyablocks/p-9dd2b8cb.js +1 -0
  67. package/dist/sankhyablocks/p-a8b59c61.entry.js +1 -0
  68. package/dist/sankhyablocks/p-aecf3e0a.entry.js +1 -0
  69. package/dist/sankhyablocks/p-c1c3b5d8.entry.js +1 -0
  70. package/dist/sankhyablocks/p-c78cb79a.entry.js +1 -0
  71. package/dist/sankhyablocks/p-c9eec639.entry.js +1 -0
  72. package/dist/sankhyablocks/p-dc482a42.entry.js +1 -0
  73. package/dist/sankhyablocks/p-fac2b6a9.js +2 -0
  74. package/dist/sankhyablocks/p-fb705f81.entry.js +1 -0
  75. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -129
  76. package/package.json +1 -1
  77. package/react/components.d.ts +19 -0
  78. package/react/components.js +19 -0
  79. package/react/components.js.map +1 -1
  80. package/dist/cjs/app-globals-3a1e7e63.js +0 -5
  81. package/dist/cjs/css-shim-b8158822.js +0 -6
  82. package/dist/cjs/dom-36862b77.js +0 -75
  83. package/dist/cjs/index-84fe3b86.js +0 -20
  84. package/dist/cjs/index-93965c41.js +0 -141
  85. package/dist/cjs/index-e90ae303.js +0 -2408
  86. package/dist/cjs/shadow-css-346c0795.js +0 -389
  87. package/dist/cjs/snk-filter-bar.cjs.entry.js +0 -466
  88. package/dist/cjs/snk-filter-item.cjs.entry.js +0 -177
  89. package/dist/cjs/snk-filter-list.cjs.entry.js +0 -91
  90. package/dist/cjs/snk-filter-modal.cjs.entry.js +0 -37
  91. package/dist/cjs/snk-grid.cjs.entry.js +0 -79
  92. package/dist/cjs/snk-taskbar.cjs.entry.js +0 -160
  93. package/dist/cjs/taskbar-processor-6bd0d35c.js +0 -47
  94. package/dist/components/index2.js +0 -2394
  95. package/dist/components/index3.js +0 -139
  96. package/dist/esm/app-globals-0f993ce5.js +0 -3
  97. package/dist/esm/css-shim-b3f2ee8d.js +0 -4
  98. package/dist/esm/dom-665d6011.js +0 -73
  99. package/dist/esm/index-2b4d2d14.js +0 -3262
  100. package/dist/esm/index-5992b7e6.js +0 -139
  101. package/dist/esm/index-c683b2b0.js +0 -2394
  102. package/dist/esm/index-c71285cb.js +0 -17
  103. package/dist/esm/shadow-css-b18e99d7.js +0 -387
  104. package/dist/esm/snk-filter-item.entry.js +0 -173
  105. package/dist/esm/snk-filter-list.entry.js +0 -87
  106. package/dist/esm/snk-filter-modal.entry.js +0 -33
  107. package/dist/esm/snk-form.entry.js +0 -129
  108. package/dist/esm/snk-grid.entry.js +0 -75
  109. package/dist/esm/snk-taskbar.entry.js +0 -156
  110. package/dist/esm/taskbar-processor-aa6772c9.js +0 -45
  111. package/dist/sankhyablocks/SnkMessageBuilder-35a20271.js +0 -199
  112. package/dist/sankhyablocks/app-globals-0f993ce5.js +0 -3
  113. package/dist/sankhyablocks/css-shim-b3f2ee8d.js +0 -4
  114. package/dist/sankhyablocks/dom-665d6011.js +0 -73
  115. package/dist/sankhyablocks/filter-item-type.enum-a79b2fa8.js +0 -14
  116. package/dist/sankhyablocks/index-5992b7e6.js +0 -139
  117. package/dist/sankhyablocks/index-c683b2b0.js +0 -2394
  118. package/dist/sankhyablocks/index-c71285cb.js +0 -17
  119. package/dist/sankhyablocks/shadow-css-b18e99d7.js +0 -387
  120. package/dist/sankhyablocks/snk-application.entry.js +0 -8166
  121. package/dist/sankhyablocks/snk-crud.entry.js +0 -66
  122. package/dist/sankhyablocks/snk-data-unit.entry.js +0 -268
  123. package/dist/sankhyablocks/snk-filter-bar.entry.js +0 -462
  124. package/dist/sankhyablocks/snk-filter-binary-select.entry.js +0 -43
  125. package/dist/sankhyablocks/snk-filter-detail.entry.js +0 -80
  126. package/dist/sankhyablocks/snk-filter-item.entry.js +0 -173
  127. package/dist/sankhyablocks/snk-filter-list.entry.js +0 -87
  128. package/dist/sankhyablocks/snk-filter-modal.entry.js +0 -33
  129. package/dist/sankhyablocks/snk-filter-multi-select.entry.js +0 -19
  130. package/dist/sankhyablocks/snk-filter-number.entry.js +0 -20
  131. package/dist/sankhyablocks/snk-filter-period.entry.js +0 -33
  132. package/dist/sankhyablocks/snk-filter-personalized.entry.js +0 -85
  133. package/dist/sankhyablocks/snk-filter-search.entry.js +0 -40
  134. package/dist/sankhyablocks/snk-filter-text.entry.js +0 -18
  135. package/dist/sankhyablocks/snk-grid.entry.js +0 -75
  136. package/dist/sankhyablocks/snk-pesquisa.entry.js +0 -311
  137. package/dist/sankhyablocks/snk-taskbar.entry.js +0 -156
  138. package/dist/sankhyablocks/taskbar-elements-35d64ff9.js +0 -90
  139. package/dist/sankhyablocks/taskbar-processor-aa6772c9.js +0 -45
  140. package/dist/sankhyablocks/teste-pesquisa.entry.js +0 -33
@@ -1,3262 +0,0 @@
1
- const NAMESPACE = 'sankhyablocks';
2
- const BUILD = /* sankhyablocks */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: true, cmpDidRender: true, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: true, cmpWillRender: true, cmpWillUpdate: false, connectedCallback: true, constructableCSS: true, cssAnnotations: true, cssVarShim: false, devTools: false, disconnectedCallback: true, dynamicImportShim: false, element: false, event: true, hasRenderFn: true, hostListener: true, hostListenerTarget: false, hostListenerTargetBody: false, hostListenerTargetDocument: false, hostListenerTargetParent: false, hostListenerTargetWindow: false, hotModuleReplacement: false, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: true, isTesting: true, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: true, member: true, method: true, mode: false, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: true, propString: true, reflect: true, safari10: false, scoped: true, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, shadowDomShim: false, slot: true, slotChildNodesFix: false, slotRelocation: true, state: true, style: true, svg: false, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: true, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: false, vdomText: true, vdomXlink: false, watchCallback: true };
3
- const Env = /* sankhyablocks */ {};
4
-
5
- /**
6
- * Virtual DOM patching algorithm based on Snabbdom by
7
- * Simon Friis Vindum (@paldepind)
8
- * Licensed under the MIT License
9
- * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
10
- *
11
- * Modified for Stencil's renderer and slot projection
12
- */
13
- let scopeId;
14
- let contentRef;
15
- let hostTagName;
16
- let customError;
17
- let i = 0;
18
- let useNativeShadowDom = false;
19
- let checkSlotFallbackVisibility = false;
20
- let checkSlotRelocate = false;
21
- let isSvgMode = false;
22
- let renderingRef = null;
23
- let queueCongestion = 0;
24
- let queuePending = false;
25
- const Build = {
26
- isDev: BUILD.isDev ? true : false,
27
- isBrowser: true,
28
- isServer: false,
29
- isTesting: BUILD.isTesting ? true : false,
30
- };
31
- const Context = {};
32
- const getAssetPath = (path) => {
33
- const assetUrl = new URL(path, plt.$resourcesUrl$);
34
- return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
35
- };
36
- const setAssetPath = (path) => (plt.$resourcesUrl$ = path);
37
- const createTime = (fnName, tagName = '') => {
38
- if (BUILD.profile && performance.mark) {
39
- const key = `st:${fnName}:${tagName}:${i++}`;
40
- // Start
41
- performance.mark(key);
42
- // End
43
- return () => performance.measure(`[Stencil] ${fnName}() <${tagName}>`, key);
44
- }
45
- else {
46
- return () => {
47
- return;
48
- };
49
- }
50
- };
51
- const uniqueTime = (key, measureText) => {
52
- if (BUILD.profile && performance.mark) {
53
- if (performance.getEntriesByName(key).length === 0) {
54
- performance.mark(key);
55
- }
56
- return () => {
57
- if (performance.getEntriesByName(measureText).length === 0) {
58
- performance.measure(measureText, key);
59
- }
60
- };
61
- }
62
- else {
63
- return () => {
64
- return;
65
- };
66
- }
67
- };
68
- const inspect = (ref) => {
69
- const hostRef = getHostRef(ref);
70
- if (!hostRef) {
71
- return undefined;
72
- }
73
- const flags = hostRef.$flags$;
74
- const hostElement = hostRef.$hostElement$;
75
- return {
76
- renderCount: hostRef.$renderCount$,
77
- flags: {
78
- hasRendered: !!(flags & 2 /* HOST_FLAGS.hasRendered */),
79
- hasConnected: !!(flags & 1 /* HOST_FLAGS.hasConnected */),
80
- isWaitingForChildren: !!(flags & 4 /* HOST_FLAGS.isWaitingForChildren */),
81
- isConstructingInstance: !!(flags & 8 /* HOST_FLAGS.isConstructingInstance */),
82
- isQueuedForUpdate: !!(flags & 16 /* HOST_FLAGS.isQueuedForUpdate */),
83
- hasInitializedComponent: !!(flags & 32 /* HOST_FLAGS.hasInitializedComponent */),
84
- hasLoadedComponent: !!(flags & 64 /* HOST_FLAGS.hasLoadedComponent */),
85
- isWatchReady: !!(flags & 128 /* HOST_FLAGS.isWatchReady */),
86
- isListenReady: !!(flags & 256 /* HOST_FLAGS.isListenReady */),
87
- needsRerender: !!(flags & 512 /* HOST_FLAGS.needsRerender */),
88
- },
89
- instanceValues: hostRef.$instanceValues$,
90
- ancestorComponent: hostRef.$ancestorComponent$,
91
- hostElement,
92
- lazyInstance: hostRef.$lazyInstance$,
93
- vnode: hostRef.$vnode$,
94
- modeName: hostRef.$modeName$,
95
- onReadyPromise: hostRef.$onReadyPromise$,
96
- onReadyResolve: hostRef.$onReadyResolve$,
97
- onInstancePromise: hostRef.$onInstancePromise$,
98
- onInstanceResolve: hostRef.$onInstanceResolve$,
99
- onRenderResolve: hostRef.$onRenderResolve$,
100
- queuedListeners: hostRef.$queuedListeners$,
101
- rmListeners: hostRef.$rmListeners$,
102
- ['s-id']: hostElement['s-id'],
103
- ['s-cr']: hostElement['s-cr'],
104
- ['s-lr']: hostElement['s-lr'],
105
- ['s-p']: hostElement['s-p'],
106
- ['s-rc']: hostElement['s-rc'],
107
- ['s-sc']: hostElement['s-sc'],
108
- };
109
- };
110
- const installDevTools = () => {
111
- if (BUILD.devTools) {
112
- const stencil = (win.stencil = win.stencil || {});
113
- const originalInspect = stencil.inspect;
114
- stencil.inspect = (ref) => {
115
- let result = inspect(ref);
116
- if (!result && typeof originalInspect === 'function') {
117
- result = originalInspect(ref);
118
- }
119
- return result;
120
- };
121
- }
122
- };
123
- const CONTENT_REF_ID = 'r';
124
- const ORG_LOCATION_ID = 'o';
125
- const SLOT_NODE_ID = 's';
126
- const TEXT_NODE_ID = 't';
127
- const HYDRATE_ID = 's-id';
128
- const HYDRATED_STYLE_ID = 'sty-id';
129
- const HYDRATE_CHILD_ID = 'c-id';
130
- const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
131
- const XLINK_NS = 'http://www.w3.org/1999/xlink';
132
- /**
133
- * Default style mode id
134
- */
135
- /**
136
- * Reusable empty obj/array
137
- * Don't add values to these!!
138
- */
139
- const EMPTY_OBJ = {};
140
- /**
141
- * Namespaces
142
- */
143
- const SVG_NS = 'http://www.w3.org/2000/svg';
144
- const HTML_NS = 'http://www.w3.org/1999/xhtml';
145
- const isDef = (v) => v != null;
146
- const isComplexType = (o) => {
147
- // https://jsperf.com/typeof-fn-object/5
148
- o = typeof o;
149
- return o === 'object' || o === 'function';
150
- };
151
- /**
152
- * Production h() function based on Preact by
153
- * Jason Miller (@developit)
154
- * Licensed under the MIT License
155
- * https://github.com/developit/preact/blob/master/LICENSE
156
- *
157
- * Modified for Stencil's compiler and vdom
158
- */
159
- // const stack: any[] = [];
160
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
161
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
162
- const h = (nodeName, vnodeData, ...children) => {
163
- let child = null;
164
- let key = null;
165
- let slotName = null;
166
- let simple = false;
167
- let lastSimple = false;
168
- const vNodeChildren = [];
169
- const walk = (c) => {
170
- for (let i = 0; i < c.length; i++) {
171
- child = c[i];
172
- if (Array.isArray(child)) {
173
- walk(child);
174
- }
175
- else if (child != null && typeof child !== 'boolean') {
176
- if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
177
- child = String(child);
178
- }
179
- else if (BUILD.isDev && typeof nodeName !== 'function' && child.$flags$ === undefined) {
180
- consoleDevError(`vNode passed as children has unexpected type.
181
- Make sure it's using the correct h() function.
182
- Empty objects can also be the cause, look for JSX comments that became objects.`);
183
- }
184
- if (simple && lastSimple) {
185
- // If the previous child was simple (string), we merge both
186
- vNodeChildren[vNodeChildren.length - 1].$text$ += child;
187
- }
188
- else {
189
- // Append a new vNode, if it's text, we create a text vNode
190
- vNodeChildren.push(simple ? newVNode(null, child) : child);
191
- }
192
- lastSimple = simple;
193
- }
194
- }
195
- };
196
- walk(children);
197
- if (vnodeData) {
198
- if (BUILD.isDev && nodeName === 'input') {
199
- validateInputProperties(vnodeData);
200
- }
201
- // normalize class / classname attributes
202
- if (BUILD.vdomKey && vnodeData.key) {
203
- key = vnodeData.key;
204
- }
205
- if (BUILD.slotRelocation && vnodeData.name) {
206
- slotName = vnodeData.name;
207
- }
208
- if (BUILD.vdomClass) {
209
- const classData = vnodeData.className || vnodeData.class;
210
- if (classData) {
211
- vnodeData.class =
212
- typeof classData !== 'object'
213
- ? classData
214
- : Object.keys(classData)
215
- .filter((k) => classData[k])
216
- .join(' ');
217
- }
218
- }
219
- }
220
- if (BUILD.isDev && vNodeChildren.some(isHost)) {
221
- consoleDevError(`The <Host> must be the single root component. Make sure:
222
- - You are NOT using hostData() and <Host> in the same component.
223
- - <Host> is used once, and it's the single root component of the render() function.`);
224
- }
225
- if (BUILD.vdomFunctional && typeof nodeName === 'function') {
226
- // nodeName is a functional component
227
- return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
228
- }
229
- const vnode = newVNode(nodeName, null);
230
- vnode.$attrs$ = vnodeData;
231
- if (vNodeChildren.length > 0) {
232
- vnode.$children$ = vNodeChildren;
233
- }
234
- if (BUILD.vdomKey) {
235
- vnode.$key$ = key;
236
- }
237
- if (BUILD.slotRelocation) {
238
- vnode.$name$ = slotName;
239
- }
240
- return vnode;
241
- };
242
- const newVNode = (tag, text) => {
243
- const vnode = {
244
- $flags$: 0,
245
- $tag$: tag,
246
- $text$: text,
247
- $elm$: null,
248
- $children$: null,
249
- };
250
- if (BUILD.vdomAttribute) {
251
- vnode.$attrs$ = null;
252
- }
253
- if (BUILD.vdomKey) {
254
- vnode.$key$ = null;
255
- }
256
- if (BUILD.slotRelocation) {
257
- vnode.$name$ = null;
258
- }
259
- return vnode;
260
- };
261
- const Host = {};
262
- const isHost = (node) => node && node.$tag$ === Host;
263
- const vdomFnUtils = {
264
- forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
265
- map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
266
- };
267
- const convertToPublic = (node) => ({
268
- vattrs: node.$attrs$,
269
- vchildren: node.$children$,
270
- vkey: node.$key$,
271
- vname: node.$name$,
272
- vtag: node.$tag$,
273
- vtext: node.$text$,
274
- });
275
- const convertToPrivate = (node) => {
276
- if (typeof node.vtag === 'function') {
277
- const vnodeData = Object.assign({}, node.vattrs);
278
- if (node.vkey) {
279
- vnodeData.key = node.vkey;
280
- }
281
- if (node.vname) {
282
- vnodeData.name = node.vname;
283
- }
284
- return h(node.vtag, vnodeData, ...(node.vchildren || []));
285
- }
286
- const vnode = newVNode(node.vtag, node.vtext);
287
- vnode.$attrs$ = node.vattrs;
288
- vnode.$children$ = node.vchildren;
289
- vnode.$key$ = node.vkey;
290
- vnode.$name$ = node.vname;
291
- return vnode;
292
- };
293
- /**
294
- * Validates the ordering of attributes on an input element
295
- * @param inputElm the element to validate
296
- */
297
- const validateInputProperties = (inputElm) => {
298
- const props = Object.keys(inputElm);
299
- const value = props.indexOf('value');
300
- if (value === -1) {
301
- return;
302
- }
303
- const typeIndex = props.indexOf('type');
304
- const minIndex = props.indexOf('min');
305
- const maxIndex = props.indexOf('max');
306
- const stepIndex = props.indexOf('step');
307
- if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) {
308
- consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
309
- }
310
- };
311
- const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
312
- const endHydrate = createTime('hydrateClient', tagName);
313
- const shadowRoot = hostElm.shadowRoot;
314
- const childRenderNodes = [];
315
- const slotNodes = [];
316
- const shadowRootNodes = BUILD.shadowDom && shadowRoot ? [] : null;
317
- const vnode = (hostRef.$vnode$ = newVNode(tagName, null));
318
- if (!plt.$orgLocNodes$) {
319
- initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
320
- }
321
- hostElm[HYDRATE_ID] = hostId;
322
- hostElm.removeAttribute(HYDRATE_ID);
323
- clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
324
- childRenderNodes.map((c) => {
325
- const orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
326
- const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
327
- const node = c.$elm$;
328
- if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
329
- orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
330
- }
331
- if (!shadowRoot) {
332
- node['s-hn'] = tagName;
333
- if (orgLocationNode) {
334
- node['s-ol'] = orgLocationNode;
335
- node['s-ol']['s-nr'] = node;
336
- }
337
- }
338
- plt.$orgLocNodes$.delete(orgLocationId);
339
- });
340
- if (BUILD.shadowDom && shadowRoot) {
341
- shadowRootNodes.map((shadowRootNode) => {
342
- if (shadowRootNode) {
343
- shadowRoot.appendChild(shadowRootNode);
344
- }
345
- });
346
- }
347
- endHydrate();
348
- };
349
- const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) => {
350
- let childNodeType;
351
- let childIdSplt;
352
- let childVNode;
353
- let i;
354
- if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
355
- childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
356
- if (childNodeType) {
357
- // got the node data from the element's attribute
358
- // `${hostId}.${nodeId}.${depth}.${index}`
359
- childIdSplt = childNodeType.split('.');
360
- if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
361
- childVNode = {
362
- $flags$: 0,
363
- $hostId$: childIdSplt[0],
364
- $nodeId$: childIdSplt[1],
365
- $depth$: childIdSplt[2],
366
- $index$: childIdSplt[3],
367
- $tag$: node.tagName.toLowerCase(),
368
- $elm$: node,
369
- $attrs$: null,
370
- $children$: null,
371
- $key$: null,
372
- $name$: null,
373
- $text$: null,
374
- };
375
- childRenderNodes.push(childVNode);
376
- node.removeAttribute(HYDRATE_CHILD_ID);
377
- // this is a new child vnode
378
- // so ensure its parent vnode has the vchildren array
379
- if (!parentVNode.$children$) {
380
- parentVNode.$children$ = [];
381
- }
382
- // add our child vnode to a specific index of the vnode's children
383
- parentVNode.$children$[childVNode.$index$] = childVNode;
384
- // this is now the new parent vnode for all the next child checks
385
- parentVNode = childVNode;
386
- if (shadowRootNodes && childVNode.$depth$ === '0') {
387
- shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
388
- }
389
- }
390
- }
391
- // recursively drill down, end to start so we can remove nodes
392
- for (i = node.childNodes.length - 1; i >= 0; i--) {
393
- clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
394
- }
395
- if (node.shadowRoot) {
396
- // keep drilling down through the shadow root nodes
397
- for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
398
- clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
399
- }
400
- }
401
- }
402
- else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
403
- // `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
404
- childIdSplt = node.nodeValue.split('.');
405
- if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
406
- // comment node for either the host id or a 0 host id
407
- childNodeType = childIdSplt[0];
408
- childVNode = {
409
- $flags$: 0,
410
- $hostId$: childIdSplt[1],
411
- $nodeId$: childIdSplt[2],
412
- $depth$: childIdSplt[3],
413
- $index$: childIdSplt[4],
414
- $elm$: node,
415
- $attrs$: null,
416
- $children$: null,
417
- $key$: null,
418
- $name$: null,
419
- $tag$: null,
420
- $text$: null,
421
- };
422
- if (childNodeType === TEXT_NODE_ID) {
423
- childVNode.$elm$ = node.nextSibling;
424
- if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* NODE_TYPE.TextNode */) {
425
- childVNode.$text$ = childVNode.$elm$.textContent;
426
- childRenderNodes.push(childVNode);
427
- // remove the text comment since it's no longer needed
428
- node.remove();
429
- if (!parentVNode.$children$) {
430
- parentVNode.$children$ = [];
431
- }
432
- parentVNode.$children$[childVNode.$index$] = childVNode;
433
- if (shadowRootNodes && childVNode.$depth$ === '0') {
434
- shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
435
- }
436
- }
437
- }
438
- else if (childVNode.$hostId$ === hostId) {
439
- // this comment node is specifcally for this host id
440
- if (childNodeType === SLOT_NODE_ID) {
441
- // `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
442
- childVNode.$tag$ = 'slot';
443
- if (childIdSplt[5]) {
444
- node['s-sn'] = childVNode.$name$ = childIdSplt[5];
445
- }
446
- else {
447
- node['s-sn'] = '';
448
- }
449
- node['s-sr'] = true;
450
- if (BUILD.shadowDom && shadowRootNodes) {
451
- // browser support shadowRoot and this is a shadow dom component
452
- // create an actual slot element
453
- childVNode.$elm$ = doc.createElement(childVNode.$tag$);
454
- if (childVNode.$name$) {
455
- // add the slot name attribute
456
- childVNode.$elm$.setAttribute('name', childVNode.$name$);
457
- }
458
- // insert the new slot element before the slot comment
459
- node.parentNode.insertBefore(childVNode.$elm$, node);
460
- // remove the slot comment since it's not needed for shadow
461
- node.remove();
462
- if (childVNode.$depth$ === '0') {
463
- shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
464
- }
465
- }
466
- slotNodes.push(childVNode);
467
- if (!parentVNode.$children$) {
468
- parentVNode.$children$ = [];
469
- }
470
- parentVNode.$children$[childVNode.$index$] = childVNode;
471
- }
472
- else if (childNodeType === CONTENT_REF_ID) {
473
- // `${CONTENT_REF_ID}.${hostId}`;
474
- if (BUILD.shadowDom && shadowRootNodes) {
475
- // remove the content ref comment since it's not needed for shadow
476
- node.remove();
477
- }
478
- else if (BUILD.slotRelocation) {
479
- hostElm['s-cr'] = node;
480
- node['s-cn'] = true;
481
- }
482
- }
483
- }
484
- }
485
- }
486
- else if (parentVNode && parentVNode.$tag$ === 'style') {
487
- const vnode = newVNode(null, node.textContent);
488
- vnode.$elm$ = node;
489
- vnode.$index$ = '0';
490
- parentVNode.$children$ = [vnode];
491
- }
492
- };
493
- const initializeDocumentHydrate = (node, orgLocNodes) => {
494
- if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
495
- let i = 0;
496
- for (; i < node.childNodes.length; i++) {
497
- initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
498
- }
499
- if (node.shadowRoot) {
500
- for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
501
- initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
502
- }
503
- }
504
- }
505
- else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
506
- const childIdSplt = node.nodeValue.split('.');
507
- if (childIdSplt[0] === ORG_LOCATION_ID) {
508
- orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
509
- node.nodeValue = '';
510
- // useful to know if the original location is
511
- // the root light-dom of a shadow dom component
512
- node['s-en'] = childIdSplt[3];
513
- }
514
- }
515
- };
516
- // Private
517
- const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
518
- // Public
519
- const setMode = (handler) => modeResolutionChain.push(handler);
520
- const getMode = (ref) => getHostRef(ref).$modeName$;
521
- /**
522
- * Parse a new property value for a given property type.
523
- *
524
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
525
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
526
- * 1. `any`, the type given to `propValue` in the function signature
527
- * 2. the type stored from `propType`.
528
- *
529
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
530
- *
531
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
532
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
533
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
534
- * ```tsx
535
- * <my-cmp prop-val={0}></my-cmp>
536
- * ```
537
- *
538
- * HTML prop values on the other hand, will always a string
539
- *
540
- * @param propValue the new value to coerce to some type
541
- * @param propType the type of the prop, expressed as a binary number
542
- * @returns the parsed/coerced value
543
- */
544
- const parsePropertyValue = (propValue, propType) => {
545
- // ensure this value is of the correct prop type
546
- if (propValue != null && !isComplexType(propValue)) {
547
- if (BUILD.propBoolean && propType & 4 /* MEMBER_FLAGS.Boolean */) {
548
- // per the HTML spec, any string value means it is a boolean true value
549
- // but we'll cheat here and say that the string "false" is the boolean false
550
- return propValue === 'false' ? false : propValue === '' || !!propValue;
551
- }
552
- if (BUILD.propNumber && propType & 2 /* MEMBER_FLAGS.Number */) {
553
- // force it to be a number
554
- return parseFloat(propValue);
555
- }
556
- if (BUILD.propString && propType & 1 /* MEMBER_FLAGS.String */) {
557
- // could have been passed as a number or boolean
558
- // but we still want it as a string
559
- return String(propValue);
560
- }
561
- // redundant return here for better minification
562
- return propValue;
563
- }
564
- // not sure exactly what type we want
565
- // so no need to change to a different type
566
- return propValue;
567
- };
568
- const getElement = (ref) => (BUILD.lazyLoad ? getHostRef(ref).$hostElement$ : ref);
569
- const createEvent = (ref, name, flags) => {
570
- const elm = getElement(ref);
571
- return {
572
- emit: (detail) => {
573
- if (BUILD.isDev && !elm.isConnected) {
574
- consoleDevWarn(`The "${name}" event was emitted, but the dispatcher node is no longer connected to the dom.`);
575
- }
576
- return emitEvent(elm, name, {
577
- bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
578
- composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
579
- cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
580
- detail,
581
- });
582
- },
583
- };
584
- };
585
- /**
586
- * Helper function to create & dispatch a custom Event on a provided target
587
- * @param elm the target of the Event
588
- * @param name the name to give the custom Event
589
- * @param opts options for configuring a custom Event
590
- * @returns the custom Event
591
- */
592
- const emitEvent = (elm, name, opts) => {
593
- const ev = plt.ce(name, opts);
594
- elm.dispatchEvent(ev);
595
- return ev;
596
- };
597
- const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
598
- const registerStyle = (scopeId, cssText, allowCS) => {
599
- let style = styles.get(scopeId);
600
- if (supportsConstructableStylesheets && allowCS) {
601
- style = (style || new CSSStyleSheet());
602
- if (typeof style === 'string') {
603
- style = cssText;
604
- }
605
- else {
606
- style.replaceSync(cssText);
607
- }
608
- }
609
- else {
610
- style = cssText;
611
- }
612
- styles.set(scopeId, style);
613
- };
614
- const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
615
- let scopeId = getScopeId(cmpMeta, mode);
616
- const style = styles.get(scopeId);
617
- if (!BUILD.attachStyles) {
618
- return scopeId;
619
- }
620
- // if an element is NOT connected then getRootNode() will return the wrong root node
621
- // so the fallback is to always use the document for the root node in those cases
622
- styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
623
- if (style) {
624
- if (typeof style === 'string') {
625
- styleContainerNode = styleContainerNode.head || styleContainerNode;
626
- let appliedStyles = rootAppliedStyles.get(styleContainerNode);
627
- let styleElm;
628
- if (!appliedStyles) {
629
- rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
630
- }
631
- if (!appliedStyles.has(scopeId)) {
632
- if (BUILD.hydrateClientSide &&
633
- styleContainerNode.host &&
634
- (styleElm = styleContainerNode.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`))) {
635
- // This is only happening on native shadow-dom, do not needs CSS var shim
636
- styleElm.innerHTML = style;
637
- }
638
- else {
639
- if (BUILD.cssVarShim && plt.$cssShim$) {
640
- styleElm = plt.$cssShim$.createHostStyle(hostElm, scopeId, style, !!(cmpMeta.$flags$ & 10 /* CMP_FLAGS.needsScopedEncapsulation */));
641
- const newScopeId = styleElm['s-sc'];
642
- if (newScopeId) {
643
- scopeId = newScopeId;
644
- // we don't want to add this styleID to the appliedStyles Set
645
- // since the cssVarShim might need to apply several different
646
- // stylesheets for the same component
647
- appliedStyles = null;
648
- }
649
- }
650
- else {
651
- styleElm = doc.createElement('style');
652
- styleElm.innerHTML = style;
653
- }
654
- if (BUILD.hydrateServerSide || BUILD.hotModuleReplacement) {
655
- styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
656
- }
657
- styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
658
- }
659
- if (appliedStyles) {
660
- appliedStyles.add(scopeId);
661
- }
662
- }
663
- }
664
- else if (BUILD.constructableCSS && !styleContainerNode.adoptedStyleSheets.includes(style)) {
665
- styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
666
- }
667
- }
668
- return scopeId;
669
- };
670
- const attachStyles = (hostRef) => {
671
- const cmpMeta = hostRef.$cmpMeta$;
672
- const elm = hostRef.$hostElement$;
673
- const flags = cmpMeta.$flags$;
674
- const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
675
- const scopeId = addStyle(BUILD.shadowDom && supportsShadow && elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
676
- if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
677
- // only required when we're NOT using native shadow dom (slot)
678
- // or this browser doesn't support native shadow dom
679
- // and this host element was NOT created with SSR
680
- // let's pick out the inner content for slot projection
681
- // create a node to represent where the original
682
- // content was first placed, which is useful later on
683
- // DOM WRITE!!
684
- elm['s-sc'] = scopeId;
685
- elm.classList.add(scopeId + '-h');
686
- if (BUILD.scoped && flags & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
687
- elm.classList.add(scopeId + '-s');
688
- }
689
- }
690
- endAttachStyles();
691
- };
692
- const getScopeId = (cmp, mode) => 'sc-' + (BUILD.mode && mode && cmp.$flags$ & 32 /* CMP_FLAGS.hasMode */ ? cmp.$tagName$ + '-' + mode : cmp.$tagName$);
693
- const convertScopedToShadow = (css) => css.replace(/\/\*!@([^\/]+)\*\/[^\{]+\{/g, '$1{');
694
- /**
695
- * Production setAccessor() function based on Preact by
696
- * Jason Miller (@developit)
697
- * Licensed under the MIT License
698
- * https://github.com/developit/preact/blob/master/LICENSE
699
- *
700
- * Modified for Stencil's compiler and vdom
701
- */
702
- const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
703
- if (oldValue !== newValue) {
704
- let isProp = isMemberInElement(elm, memberName);
705
- let ln = memberName.toLowerCase();
706
- if (BUILD.vdomClass && memberName === 'class') {
707
- const classList = elm.classList;
708
- const oldClasses = parseClassList(oldValue);
709
- const newClasses = parseClassList(newValue);
710
- classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
711
- classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
712
- }
713
- else if (BUILD.vdomStyle && memberName === 'style') {
714
- // update style attribute, css properties and values
715
- if (BUILD.updatable) {
716
- for (const prop in oldValue) {
717
- if (!newValue || newValue[prop] == null) {
718
- if (!BUILD.hydrateServerSide && prop.includes('-')) {
719
- elm.style.removeProperty(prop);
720
- }
721
- else {
722
- elm.style[prop] = '';
723
- }
724
- }
725
- }
726
- }
727
- for (const prop in newValue) {
728
- if (!oldValue || newValue[prop] !== oldValue[prop]) {
729
- if (!BUILD.hydrateServerSide && prop.includes('-')) {
730
- elm.style.setProperty(prop, newValue[prop]);
731
- }
732
- else {
733
- elm.style[prop] = newValue[prop];
734
- }
735
- }
736
- }
737
- }
738
- else if (BUILD.vdomKey && memberName === 'key')
739
- ;
740
- else if (BUILD.vdomRef && memberName === 'ref') {
741
- // minifier will clean this up
742
- if (newValue) {
743
- newValue(elm);
744
- }
745
- }
746
- else if (BUILD.vdomListener &&
747
- (BUILD.lazyLoad ? !isProp : !elm.__lookupSetter__(memberName)) &&
748
- memberName[0] === 'o' &&
749
- memberName[1] === 'n') {
750
- // Event Handlers
751
- // so if the member name starts with "on" and the 3rd characters is
752
- // a capital letter, and it's not already a member on the element,
753
- // then we're assuming it's an event listener
754
- if (memberName[2] === '-') {
755
- // on- prefixed events
756
- // allows to be explicit about the dom event to listen without any magic
757
- // under the hood:
758
- // <my-cmp on-click> // listens for "click"
759
- // <my-cmp on-Click> // listens for "Click"
760
- // <my-cmp on-ionChange> // listens for "ionChange"
761
- // <my-cmp on-EVENTS> // listens for "EVENTS"
762
- memberName = memberName.slice(3);
763
- }
764
- else if (isMemberInElement(win, ln)) {
765
- // standard event
766
- // the JSX attribute could have been "onMouseOver" and the
767
- // member name "onmouseover" is on the window's prototype
768
- // so let's add the listener "mouseover", which is all lowercased
769
- memberName = ln.slice(2);
770
- }
771
- else {
772
- // custom event
773
- // the JSX attribute could have been "onMyCustomEvent"
774
- // so let's trim off the "on" prefix and lowercase the first character
775
- // and add the listener "myCustomEvent"
776
- // except for the first character, we keep the event name case
777
- memberName = ln[2] + memberName.slice(3);
778
- }
779
- if (oldValue) {
780
- plt.rel(elm, memberName, oldValue, false);
781
- }
782
- if (newValue) {
783
- plt.ael(elm, memberName, newValue, false);
784
- }
785
- }
786
- else if (BUILD.vdomPropOrAttr) {
787
- // Set property if it exists and it's not a SVG
788
- const isComplex = isComplexType(newValue);
789
- if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
790
- try {
791
- if (!elm.tagName.includes('-')) {
792
- const n = newValue == null ? '' : newValue;
793
- // Workaround for Safari, moving the <input> caret when re-assigning the same valued
794
- if (memberName === 'list') {
795
- isProp = false;
796
- }
797
- else if (oldValue == null || elm[memberName] != n) {
798
- elm[memberName] = n;
799
- }
800
- }
801
- else {
802
- elm[memberName] = newValue;
803
- }
804
- }
805
- catch (e) { }
806
- }
807
- /**
808
- * Need to manually update attribute if:
809
- * - memberName is not an attribute
810
- * - if we are rendering the host element in order to reflect attribute
811
- * - if it's a SVG, since properties might not work in <svg>
812
- * - if the newValue is null/undefined or 'false'.
813
- */
814
- let xlink = false;
815
- if (BUILD.vdomXlink) {
816
- if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
817
- memberName = ln;
818
- xlink = true;
819
- }
820
- }
821
- if (newValue == null || newValue === false) {
822
- if (newValue !== false || elm.getAttribute(memberName) === '') {
823
- if (BUILD.vdomXlink && xlink) {
824
- elm.removeAttributeNS(XLINK_NS, memberName);
825
- }
826
- else {
827
- elm.removeAttribute(memberName);
828
- }
829
- }
830
- }
831
- else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
832
- newValue = newValue === true ? '' : newValue;
833
- if (BUILD.vdomXlink && xlink) {
834
- elm.setAttributeNS(XLINK_NS, memberName, newValue);
835
- }
836
- else {
837
- elm.setAttribute(memberName, newValue);
838
- }
839
- }
840
- }
841
- }
842
- };
843
- const parseClassListRegex = /\s/;
844
- const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
845
- const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
846
- // if the element passed in is a shadow root, which is a document fragment
847
- // then we want to be adding attrs/props to the shadow root's "host" element
848
- // if it's not a shadow root, then we add attrs/props to the same element
849
- const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
850
- ? newVnode.$elm$.host
851
- : newVnode.$elm$;
852
- const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
853
- const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
854
- if (BUILD.updatable) {
855
- // remove attributes no longer present on the vnode by setting them to undefined
856
- for (memberName in oldVnodeAttrs) {
857
- if (!(memberName in newVnodeAttrs)) {
858
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
859
- }
860
- }
861
- }
862
- // add new & update changed attributes
863
- for (memberName in newVnodeAttrs) {
864
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
865
- }
866
- };
867
- /**
868
- * Create a DOM Node corresponding to one of the children of a given VNode.
869
- *
870
- * @param oldParentVNode the parent VNode from the previous render
871
- * @param newParentVNode the parent VNode from the current render
872
- * @param childIndex the index of the VNode, in the _new_ parent node's
873
- * children, for which we will create a new DOM node
874
- * @param parentElm the parent DOM node which our new node will be a child of
875
- * @returns the newly created node
876
- */
877
- const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
878
- // tslint:disable-next-line: prefer-const
879
- const newVNode = newParentVNode.$children$[childIndex];
880
- let i = 0;
881
- let elm;
882
- let childNode;
883
- let oldVNode;
884
- if (BUILD.slotRelocation && !useNativeShadowDom) {
885
- // remember for later we need to check to relocate nodes
886
- checkSlotRelocate = true;
887
- if (newVNode.$tag$ === 'slot') {
888
- if (scopeId) {
889
- // scoped css needs to add its scoped id to the parent element
890
- parentElm.classList.add(scopeId + '-s');
891
- }
892
- newVNode.$flags$ |= newVNode.$children$
893
- ? // slot element has fallback content
894
- 2 /* VNODE_FLAGS.isSlotFallback */
895
- : // slot element does not have fallback content
896
- 1 /* VNODE_FLAGS.isSlotReference */;
897
- }
898
- }
899
- if (BUILD.isDev && newVNode.$elm$) {
900
- consoleDevError(`The JSX ${newVNode.$text$ !== null ? `"${newVNode.$text$}" text` : `"${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`);
901
- }
902
- if (BUILD.vdomText && newVNode.$text$ !== null) {
903
- // create text node
904
- elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
905
- }
906
- else if (BUILD.slotRelocation && newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
907
- // create a slot reference node
908
- elm = newVNode.$elm$ =
909
- BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : doc.createTextNode('');
910
- }
911
- else {
912
- if (BUILD.svg && !isSvgMode) {
913
- isSvgMode = newVNode.$tag$ === 'svg';
914
- }
915
- // create element
916
- elm = newVNode.$elm$ = (BUILD.svg
917
- ? doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, BUILD.slotRelocation && newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
918
- ? 'slot-fb'
919
- : newVNode.$tag$)
920
- : doc.createElement(BUILD.slotRelocation && newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
921
- ? 'slot-fb'
922
- : newVNode.$tag$));
923
- if (BUILD.svg && isSvgMode && newVNode.$tag$ === 'foreignObject') {
924
- isSvgMode = false;
925
- }
926
- // add css classes, attrs, props, listeners, etc.
927
- if (BUILD.vdomAttribute) {
928
- updateElement(null, newVNode, isSvgMode);
929
- }
930
- if ((BUILD.shadowDom || BUILD.scoped) && isDef(scopeId) && elm['s-si'] !== scopeId) {
931
- // if there is a scopeId and this is the initial render
932
- // then let's add the scopeId as a css class
933
- elm.classList.add((elm['s-si'] = scopeId));
934
- }
935
- if (newVNode.$children$) {
936
- for (i = 0; i < newVNode.$children$.length; ++i) {
937
- // create the node
938
- childNode = createElm(oldParentVNode, newVNode, i, elm);
939
- // return node could have been null
940
- if (childNode) {
941
- // append our new node
942
- elm.appendChild(childNode);
943
- }
944
- }
945
- }
946
- if (BUILD.svg) {
947
- if (newVNode.$tag$ === 'svg') {
948
- // Only reset the SVG context when we're exiting <svg> element
949
- isSvgMode = false;
950
- }
951
- else if (elm.tagName === 'foreignObject') {
952
- // Reenter SVG context when we're exiting <foreignObject> element
953
- isSvgMode = true;
954
- }
955
- }
956
- }
957
- if (BUILD.slotRelocation) {
958
- elm['s-hn'] = hostTagName;
959
- if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
960
- // remember the content reference comment
961
- elm['s-sr'] = true;
962
- // remember the content reference comment
963
- elm['s-cr'] = contentRef;
964
- // remember the slot name, or empty string for default slot
965
- elm['s-sn'] = newVNode.$name$ || '';
966
- // check if we've got an old vnode for this slot
967
- oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
968
- if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
969
- // we've got an old slot vnode and the wrapper is being replaced
970
- // so let's move the old slot content back to it's original location
971
- putBackInOriginalLocation(oldParentVNode.$elm$, false);
972
- }
973
- }
974
- }
975
- return elm;
976
- };
977
- const putBackInOriginalLocation = (parentElm, recursive) => {
978
- plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
979
- const oldSlotChildNodes = parentElm.childNodes;
980
- for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
981
- const childNode = oldSlotChildNodes[i];
982
- if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
983
- // // this child node in the old element is from another component
984
- // // remove this node from the old slot's parent
985
- // childNode.remove();
986
- // and relocate it back to it's original location
987
- parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
988
- // remove the old original location comment entirely
989
- // later on the patch function will know what to do
990
- // and move this to the correct spot in need be
991
- childNode['s-ol'].remove();
992
- childNode['s-ol'] = undefined;
993
- checkSlotRelocate = true;
994
- }
995
- if (recursive) {
996
- putBackInOriginalLocation(childNode, recursive);
997
- }
998
- }
999
- plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1000
- };
1001
- const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
1002
- let containerElm = ((BUILD.slotRelocation && parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
1003
- let childNode;
1004
- if (BUILD.shadowDom && containerElm.shadowRoot && containerElm.tagName === hostTagName) {
1005
- containerElm = containerElm.shadowRoot;
1006
- }
1007
- for (; startIdx <= endIdx; ++startIdx) {
1008
- if (vnodes[startIdx]) {
1009
- childNode = createElm(null, parentVNode, startIdx, parentElm);
1010
- if (childNode) {
1011
- vnodes[startIdx].$elm$ = childNode;
1012
- containerElm.insertBefore(childNode, BUILD.slotRelocation ? referenceNode(before) : before);
1013
- }
1014
- }
1015
- }
1016
- };
1017
- const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
1018
- for (; startIdx <= endIdx; ++startIdx) {
1019
- if ((vnode = vnodes[startIdx])) {
1020
- elm = vnode.$elm$;
1021
- callNodeRefs(vnode);
1022
- if (BUILD.slotRelocation) {
1023
- // we're removing this element
1024
- // so it's possible we need to show slot fallback content now
1025
- checkSlotFallbackVisibility = true;
1026
- if (elm['s-ol']) {
1027
- // remove the original location comment
1028
- elm['s-ol'].remove();
1029
- }
1030
- else {
1031
- // it's possible that child nodes of the node
1032
- // that's being removed are slot nodes
1033
- putBackInOriginalLocation(elm, true);
1034
- }
1035
- }
1036
- // remove the vnode's element from the dom
1037
- elm.remove();
1038
- }
1039
- }
1040
- };
1041
- /**
1042
- * Reconcile the children of a new VNode with the children of an old VNode by
1043
- * traversing the two collections of children, identifying nodes that are
1044
- * conserved or changed, calling out to `patch` to make any necessary
1045
- * updates to the DOM, and rearranging DOM nodes as needed.
1046
- *
1047
- * The algorithm for reconciling children works by analyzing two 'windows' onto
1048
- * the two arrays of children (`oldCh` and `newCh`). We keep track of the
1049
- * 'windows' by storing start and end indices and references to the
1050
- * corresponding array entries. Initially the two 'windows' are basically equal
1051
- * to the entire array, but we progressively narrow the windows until there are
1052
- * no children left to update by doing the following:
1053
- *
1054
- * 1. Skip any `null` entries at the beginning or end of the two arrays, so
1055
- * that if we have an initial array like the following we'll end up dealing
1056
- * only with a window bounded by the highlighted elements:
1057
- *
1058
- * [null, null, VNode1 , ... , VNode2, null, null]
1059
- * ^^^^^^ ^^^^^^
1060
- *
1061
- * 2. Check to see if the elements at the head and tail positions are equal
1062
- * across the windows. This will basically detect elements which haven't
1063
- * been added, removed, or changed position, i.e. if you had the following
1064
- * VNode elements (represented as HTML):
1065
- *
1066
- * oldVNode: `<div><p><span>HEY</span></p></div>`
1067
- * newVNode: `<div><p><span>THERE</span></p></div>`
1068
- *
1069
- * Then when comparing the children of the `<div>` tag we check the equality
1070
- * of the VNodes corresponding to the `<p>` tags and, since they are the
1071
- * same tag in the same position, we'd be able to avoid completely
1072
- * re-rendering the subtree under them with a new DOM element and would just
1073
- * call out to `patch` to handle reconciling their children and so on.
1074
- *
1075
- * 3. Check, for both windows, to see if the element at the beginning of the
1076
- * window corresponds to the element at the end of the other window. This is
1077
- * a heuristic which will let us identify _some_ situations in which
1078
- * elements have changed position, for instance it _should_ detect that the
1079
- * children nodes themselves have not changed but merely moved in the
1080
- * following example:
1081
- *
1082
- * oldVNode: `<div><element-one /><element-two /></div>`
1083
- * newVNode: `<div><element-two /><element-one /></div>`
1084
- *
1085
- * If we find cases like this then we also need to move the concrete DOM
1086
- * elements corresponding to the moved children to write the re-order to the
1087
- * DOM.
1088
- *
1089
- * 4. Finally, if VNodes have the `key` attribute set on them we check for any
1090
- * nodes in the old children which have the same key as the first element in
1091
- * our window on the new children. If we find such a node we handle calling
1092
- * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
1093
- * what we find.
1094
- *
1095
- * Finally, once we've narrowed our 'windows' to the point that either of them
1096
- * collapse (i.e. they have length 0) we then handle any remaining VNode
1097
- * insertion or deletion that needs to happen to get a DOM state that correctly
1098
- * reflects the new child VNodes. If, for instance, after our window on the old
1099
- * children has collapsed we still have more nodes on the new children that
1100
- * we haven't dealt with yet then we need to add them, or if the new children
1101
- * collapse but we still have unhandled _old_ children then we need to make
1102
- * sure the corresponding DOM nodes are removed.
1103
- *
1104
- * @param parentElm the node into which the parent VNode is rendered
1105
- * @param oldCh the old children of the parent node
1106
- * @param newVNode the new VNode which will replace the parent
1107
- * @param newCh the new children of the parent node
1108
- */
1109
- const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
1110
- let oldStartIdx = 0;
1111
- let newStartIdx = 0;
1112
- let idxInOld = 0;
1113
- let i = 0;
1114
- let oldEndIdx = oldCh.length - 1;
1115
- let oldStartVnode = oldCh[0];
1116
- let oldEndVnode = oldCh[oldEndIdx];
1117
- let newEndIdx = newCh.length - 1;
1118
- let newStartVnode = newCh[0];
1119
- let newEndVnode = newCh[newEndIdx];
1120
- let node;
1121
- let elmToMove;
1122
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
1123
- if (oldStartVnode == null) {
1124
- // VNode might have been moved left
1125
- oldStartVnode = oldCh[++oldStartIdx];
1126
- }
1127
- else if (oldEndVnode == null) {
1128
- oldEndVnode = oldCh[--oldEndIdx];
1129
- }
1130
- else if (newStartVnode == null) {
1131
- newStartVnode = newCh[++newStartIdx];
1132
- }
1133
- else if (newEndVnode == null) {
1134
- newEndVnode = newCh[--newEndIdx];
1135
- }
1136
- else if (isSameVnode(oldStartVnode, newStartVnode)) {
1137
- // if the start nodes are the same then we should patch the new VNode
1138
- // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
1139
- // indices to reflect that. We don't need to move any DOM Nodes around
1140
- // since things are matched up in order.
1141
- patch(oldStartVnode, newStartVnode);
1142
- oldStartVnode = oldCh[++oldStartIdx];
1143
- newStartVnode = newCh[++newStartIdx];
1144
- }
1145
- else if (isSameVnode(oldEndVnode, newEndVnode)) {
1146
- // likewise, if the end nodes are the same we patch new onto old and
1147
- // decrement our end indices, and also likewise in this case we don't
1148
- // need to move any DOM Nodes.
1149
- patch(oldEndVnode, newEndVnode);
1150
- oldEndVnode = oldCh[--oldEndIdx];
1151
- newEndVnode = newCh[--newEndIdx];
1152
- }
1153
- else if (isSameVnode(oldStartVnode, newEndVnode)) {
1154
- // case: "Vnode moved right"
1155
- //
1156
- // We've found that the last node in our window on the new children is
1157
- // the same VNode as the _first_ node in our window on the old children
1158
- // we're dealing with now. Visually, this is the layout of these two
1159
- // nodes:
1160
- //
1161
- // newCh: [..., newStartVnode , ... , newEndVnode , ...]
1162
- // ^^^^^^^^^^^
1163
- // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
1164
- // ^^^^^^^^^^^^^
1165
- //
1166
- // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
1167
- // and move the DOM element for `oldStartVnode`.
1168
- if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
1169
- putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
1170
- }
1171
- patch(oldStartVnode, newEndVnode);
1172
- // We need to move the element for `oldStartVnode` into a position which
1173
- // will be appropriate for `newEndVnode`. For this we can use
1174
- // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
1175
- // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
1176
- // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
1177
- //
1178
- // <old-start-node />
1179
- // <some-intervening-node />
1180
- // <old-end-node />
1181
- // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
1182
- // <next-sibling />
1183
- //
1184
- // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
1185
- // the node for `oldStartVnode` at the end of the children of
1186
- // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
1187
- // aren't any siblings, and passing `null` to `Node.insertBefore` will
1188
- // append it to the children of the parent element.
1189
- parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
1190
- oldStartVnode = oldCh[++oldStartIdx];
1191
- newEndVnode = newCh[--newEndIdx];
1192
- }
1193
- else if (isSameVnode(oldEndVnode, newStartVnode)) {
1194
- // case: "Vnode moved left"
1195
- //
1196
- // We've found that the first node in our window on the new children is
1197
- // the same VNode as the _last_ node in our window on the old children.
1198
- // Visually, this is the layout of these two nodes:
1199
- //
1200
- // newCh: [..., newStartVnode , ... , newEndVnode , ...]
1201
- // ^^^^^^^^^^^^^
1202
- // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
1203
- // ^^^^^^^^^^^
1204
- //
1205
- // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
1206
- // (which will handle updating any changed attributes, reconciling their
1207
- // children etc) but we also need to move the DOM node to which
1208
- // `oldEndVnode` corresponds.
1209
- if (BUILD.slotRelocation && (oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
1210
- putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
1211
- }
1212
- patch(oldEndVnode, newStartVnode);
1213
- // We've already checked above if `oldStartVnode` and `newStartVnode` are
1214
- // the same node, so since we're here we know that they are not. Thus we
1215
- // can move the element for `oldEndVnode` _before_ the element for
1216
- // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
1217
- // future.
1218
- parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
1219
- oldEndVnode = oldCh[--oldEndIdx];
1220
- newStartVnode = newCh[++newStartIdx];
1221
- }
1222
- else {
1223
- // Here we do some checks to match up old and new nodes based on the
1224
- // `$key$` attribute, which is set by putting a `key="my-key"` attribute
1225
- // in the JSX for a DOM element in the implementation of a Stencil
1226
- // component.
1227
- //
1228
- // First we check to see if there are any nodes in the array of old
1229
- // children which have the same key as the first node in the new
1230
- // children.
1231
- idxInOld = -1;
1232
- if (BUILD.vdomKey) {
1233
- for (i = oldStartIdx; i <= oldEndIdx; ++i) {
1234
- if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
1235
- idxInOld = i;
1236
- break;
1237
- }
1238
- }
1239
- }
1240
- if (BUILD.vdomKey && idxInOld >= 0) {
1241
- // We found a node in the old children which matches up with the first
1242
- // node in the new children! So let's deal with that
1243
- elmToMove = oldCh[idxInOld];
1244
- if (elmToMove.$tag$ !== newStartVnode.$tag$) {
1245
- // the tag doesn't match so we'll need a new DOM element
1246
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
1247
- }
1248
- else {
1249
- patch(elmToMove, newStartVnode);
1250
- // invalidate the matching old node so that we won't try to update it
1251
- // again later on
1252
- oldCh[idxInOld] = undefined;
1253
- node = elmToMove.$elm$;
1254
- }
1255
- newStartVnode = newCh[++newStartIdx];
1256
- }
1257
- else {
1258
- // We either didn't find an element in the old children that matches
1259
- // the key of the first new child OR the build is not using `key`
1260
- // attributes at all. In either case we need to create a new element
1261
- // for the new node.
1262
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
1263
- newStartVnode = newCh[++newStartIdx];
1264
- }
1265
- if (node) {
1266
- // if we created a new node then handle inserting it to the DOM
1267
- if (BUILD.slotRelocation) {
1268
- parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
1269
- }
1270
- else {
1271
- oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
1272
- }
1273
- }
1274
- }
1275
- }
1276
- if (oldStartIdx > oldEndIdx) {
1277
- // we have some more new nodes to add which don't match up with old nodes
1278
- addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
1279
- }
1280
- else if (BUILD.updatable && newStartIdx > newEndIdx) {
1281
- // there are nodes in the `oldCh` array which no longer correspond to nodes
1282
- // in the new array, so lets remove them (which entails cleaning up the
1283
- // relevant DOM nodes)
1284
- removeVnodes(oldCh, oldStartIdx, oldEndIdx);
1285
- }
1286
- };
1287
- /**
1288
- * Compare two VNodes to determine if they are the same
1289
- *
1290
- * **NB**: This function is an equality _heuristic_ based on the available
1291
- * information set on the two VNodes and can be misleading under certain
1292
- * circumstances. In particular, if the two nodes do not have `key` attrs
1293
- * (available under `$key$` on VNodes) then the function falls back on merely
1294
- * checking that they have the same tag.
1295
- *
1296
- * So, in other words, if `key` attrs are not set on VNodes which may be
1297
- * changing order within a `children` array or something along those lines then
1298
- * we could obtain a false positive and then have to do needless re-rendering.
1299
- *
1300
- * @param leftVNode the first VNode to check
1301
- * @param rightVNode the second VNode to check
1302
- * @returns whether they're equal or not
1303
- */
1304
- const isSameVnode = (leftVNode, rightVNode) => {
1305
- // compare if two vnode to see if they're "technically" the same
1306
- // need to have the same element tag, and same key to be the same
1307
- if (leftVNode.$tag$ === rightVNode.$tag$) {
1308
- if (BUILD.slotRelocation && leftVNode.$tag$ === 'slot') {
1309
- return leftVNode.$name$ === rightVNode.$name$;
1310
- }
1311
- // this will be set if components in the build have `key` attrs set on them
1312
- if (BUILD.vdomKey) {
1313
- return leftVNode.$key$ === rightVNode.$key$;
1314
- }
1315
- return true;
1316
- }
1317
- return false;
1318
- };
1319
- const referenceNode = (node) => {
1320
- // this node was relocated to a new location in the dom
1321
- // because of some other component's slot
1322
- // but we still have an html comment in place of where
1323
- // it's original location was according to it's original vdom
1324
- return (node && node['s-ol']) || node;
1325
- };
1326
- const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
1327
- /**
1328
- * Handle reconciling an outdated VNode with a new one which corresponds to
1329
- * it. This function handles flushing updates to the DOM and reconciling the
1330
- * children of the two nodes (if any).
1331
- *
1332
- * @param oldVNode an old VNode whose DOM element and children we want to update
1333
- * @param newVNode a new VNode representing an updated version of the old one
1334
- */
1335
- const patch = (oldVNode, newVNode) => {
1336
- const elm = (newVNode.$elm$ = oldVNode.$elm$);
1337
- const oldChildren = oldVNode.$children$;
1338
- const newChildren = newVNode.$children$;
1339
- const tag = newVNode.$tag$;
1340
- const text = newVNode.$text$;
1341
- let defaultHolder;
1342
- if (!BUILD.vdomText || text === null) {
1343
- if (BUILD.svg) {
1344
- // test if we're rendering an svg element, or still rendering nodes inside of one
1345
- // only add this to the when the compiler sees we're using an svg somewhere
1346
- isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
1347
- }
1348
- if (BUILD.vdomAttribute || BUILD.reflect) {
1349
- if (BUILD.slot && tag === 'slot')
1350
- ;
1351
- else {
1352
- // either this is the first render of an element OR it's an update
1353
- // AND we already know it's possible it could have changed
1354
- // this updates the element's css classes, attrs, props, listeners, etc.
1355
- updateElement(oldVNode, newVNode, isSvgMode);
1356
- }
1357
- }
1358
- if (BUILD.updatable && oldChildren !== null && newChildren !== null) {
1359
- // looks like there's child vnodes for both the old and new vnodes
1360
- // so we need to call `updateChildren` to reconcile them
1361
- updateChildren(elm, oldChildren, newVNode, newChildren);
1362
- }
1363
- else if (newChildren !== null) {
1364
- // no old child vnodes, but there are new child vnodes to add
1365
- if (BUILD.updatable && BUILD.vdomText && oldVNode.$text$ !== null) {
1366
- // the old vnode was text, so be sure to clear it out
1367
- elm.textContent = '';
1368
- }
1369
- // add the new vnode children
1370
- addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
1371
- }
1372
- else if (BUILD.updatable && oldChildren !== null) {
1373
- // no new child vnodes, but there are old child vnodes to remove
1374
- removeVnodes(oldChildren, 0, oldChildren.length - 1);
1375
- }
1376
- if (BUILD.svg && isSvgMode && tag === 'svg') {
1377
- isSvgMode = false;
1378
- }
1379
- }
1380
- else if (BUILD.vdomText && BUILD.slotRelocation && (defaultHolder = elm['s-cr'])) {
1381
- // this element has slotted content
1382
- defaultHolder.parentNode.textContent = text;
1383
- }
1384
- else if (BUILD.vdomText && oldVNode.$text$ !== text) {
1385
- // update the text content for the text only vnode
1386
- // and also only if the text is different than before
1387
- elm.data = text;
1388
- }
1389
- };
1390
- const updateFallbackSlotVisibility = (elm) => {
1391
- // tslint:disable-next-line: prefer-const
1392
- const childNodes = elm.childNodes;
1393
- let childNode;
1394
- let i;
1395
- let ilen;
1396
- let j;
1397
- let slotNameAttr;
1398
- let nodeType;
1399
- for (i = 0, ilen = childNodes.length; i < ilen; i++) {
1400
- childNode = childNodes[i];
1401
- if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1402
- if (childNode['s-sr']) {
1403
- // this is a slot fallback node
1404
- // get the slot name for this slot reference node
1405
- slotNameAttr = childNode['s-sn'];
1406
- // by default always show a fallback slot node
1407
- // then hide it if there are other slots in the light dom
1408
- childNode.hidden = false;
1409
- for (j = 0; j < ilen; j++) {
1410
- nodeType = childNodes[j].nodeType;
1411
- if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
1412
- // this sibling node is from a different component OR is a named fallback slot node
1413
- if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
1414
- childNode.hidden = true;
1415
- break;
1416
- }
1417
- }
1418
- else {
1419
- // this is a default fallback slot node
1420
- // any element or text node (with content)
1421
- // should hide the default fallback slot node
1422
- if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
1423
- (nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
1424
- childNode.hidden = true;
1425
- break;
1426
- }
1427
- }
1428
- }
1429
- }
1430
- // keep drilling down
1431
- updateFallbackSlotVisibility(childNode);
1432
- }
1433
- }
1434
- };
1435
- const relocateNodes = [];
1436
- const relocateSlotContent = (elm) => {
1437
- // tslint:disable-next-line: prefer-const
1438
- let childNode;
1439
- let node;
1440
- let hostContentNodes;
1441
- let slotNameAttr;
1442
- let relocateNodeData;
1443
- let j;
1444
- let i = 0;
1445
- const childNodes = elm.childNodes;
1446
- const ilen = childNodes.length;
1447
- for (; i < ilen; i++) {
1448
- childNode = childNodes[i];
1449
- if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
1450
- // first got the content reference comment node
1451
- // then we got it's parent, which is where all the host content is in now
1452
- hostContentNodes = node.parentNode.childNodes;
1453
- slotNameAttr = childNode['s-sn'];
1454
- for (j = hostContentNodes.length - 1; j >= 0; j--) {
1455
- node = hostContentNodes[j];
1456
- if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
1457
- // let's do some relocating to its new home
1458
- // but never relocate a content reference node
1459
- // that is suppose to always represent the original content location
1460
- if (isNodeLocatedInSlot(node, slotNameAttr)) {
1461
- // it's possible we've already decided to relocate this node
1462
- relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1463
- // made some changes to slots
1464
- // let's make sure we also double check
1465
- // fallbacks are correctly hidden or shown
1466
- checkSlotFallbackVisibility = true;
1467
- node['s-sn'] = node['s-sn'] || slotNameAttr;
1468
- if (relocateNodeData) {
1469
- // previously we never found a slot home for this node
1470
- // but turns out we did, so let's remember it now
1471
- relocateNodeData.$slotRefNode$ = childNode;
1472
- }
1473
- else {
1474
- // add to our list of nodes to relocate
1475
- relocateNodes.push({
1476
- $slotRefNode$: childNode,
1477
- $nodeToRelocate$: node,
1478
- });
1479
- }
1480
- if (node['s-sr']) {
1481
- relocateNodes.map((relocateNode) => {
1482
- if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
1483
- relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1484
- if (relocateNodeData && !relocateNode.$slotRefNode$) {
1485
- relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1486
- }
1487
- }
1488
- });
1489
- }
1490
- }
1491
- else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
1492
- // so far this element does not have a slot home, not setting slotRefNode on purpose
1493
- // if we never find a home for this element then we'll need to hide it
1494
- relocateNodes.push({
1495
- $nodeToRelocate$: node,
1496
- });
1497
- }
1498
- }
1499
- }
1500
- }
1501
- if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1502
- relocateSlotContent(childNode);
1503
- }
1504
- }
1505
- };
1506
- const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
1507
- if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1508
- if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1509
- return true;
1510
- }
1511
- if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1512
- return true;
1513
- }
1514
- return false;
1515
- }
1516
- if (nodeToRelocate['s-sn'] === slotNameAttr) {
1517
- return true;
1518
- }
1519
- return slotNameAttr === '';
1520
- };
1521
- const callNodeRefs = (vNode) => {
1522
- if (BUILD.vdomRef) {
1523
- vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
1524
- vNode.$children$ && vNode.$children$.map(callNodeRefs);
1525
- }
1526
- };
1527
- const renderVdom = (hostRef, renderFnResults) => {
1528
- const hostElm = hostRef.$hostElement$;
1529
- const cmpMeta = hostRef.$cmpMeta$;
1530
- const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1531
- const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1532
- hostTagName = hostElm.tagName;
1533
- // <Host> runtime check
1534
- if (BUILD.isDev && Array.isArray(renderFnResults) && renderFnResults.some(isHost)) {
1535
- throw new Error(`The <Host> must be the single root component.
1536
- Looks like the render() function of "${hostTagName.toLowerCase()}" is returning an array that contains the <Host>.
1537
-
1538
- The render() function should look like this instead:
1539
-
1540
- render() {
1541
- // Do not return an array
1542
- return (
1543
- <Host>{content}</Host>
1544
- );
1545
- }
1546
- `);
1547
- }
1548
- if (BUILD.reflect && cmpMeta.$attrsToReflect$) {
1549
- rootVnode.$attrs$ = rootVnode.$attrs$ || {};
1550
- cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
1551
- }
1552
- rootVnode.$tag$ = null;
1553
- rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
1554
- hostRef.$vnode$ = rootVnode;
1555
- rootVnode.$elm$ = oldVNode.$elm$ = (BUILD.shadowDom ? hostElm.shadowRoot || hostElm : hostElm);
1556
- if (BUILD.scoped || BUILD.shadowDom) {
1557
- scopeId = hostElm['s-sc'];
1558
- }
1559
- if (BUILD.slotRelocation) {
1560
- contentRef = hostElm['s-cr'];
1561
- useNativeShadowDom = supportsShadow && (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1562
- // always reset
1563
- checkSlotFallbackVisibility = false;
1564
- }
1565
- // synchronous patch
1566
- patch(oldVNode, rootVnode);
1567
- if (BUILD.slotRelocation) {
1568
- // while we're moving nodes around existing nodes, temporarily disable
1569
- // the disconnectCallback from working
1570
- plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1571
- if (checkSlotRelocate) {
1572
- relocateSlotContent(rootVnode.$elm$);
1573
- let relocateData;
1574
- let nodeToRelocate;
1575
- let orgLocationNode;
1576
- let parentNodeRef;
1577
- let insertBeforeNode;
1578
- let refNode;
1579
- let i = 0;
1580
- for (; i < relocateNodes.length; i++) {
1581
- relocateData = relocateNodes[i];
1582
- nodeToRelocate = relocateData.$nodeToRelocate$;
1583
- if (!nodeToRelocate['s-ol']) {
1584
- // add a reference node marking this node's original location
1585
- // keep a reference to this node for later lookups
1586
- orgLocationNode =
1587
- BUILD.isDebug || BUILD.hydrateServerSide
1588
- ? originalLocationDebugNode(nodeToRelocate)
1589
- : doc.createTextNode('');
1590
- orgLocationNode['s-nr'] = nodeToRelocate;
1591
- nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1592
- }
1593
- }
1594
- for (i = 0; i < relocateNodes.length; i++) {
1595
- relocateData = relocateNodes[i];
1596
- nodeToRelocate = relocateData.$nodeToRelocate$;
1597
- if (relocateData.$slotRefNode$) {
1598
- // by default we're just going to insert it directly
1599
- // after the slot reference node
1600
- parentNodeRef = relocateData.$slotRefNode$.parentNode;
1601
- insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1602
- orgLocationNode = nodeToRelocate['s-ol'];
1603
- while ((orgLocationNode = orgLocationNode.previousSibling)) {
1604
- refNode = orgLocationNode['s-nr'];
1605
- if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1606
- refNode = refNode.nextSibling;
1607
- if (!refNode || !refNode['s-nr']) {
1608
- insertBeforeNode = refNode;
1609
- break;
1610
- }
1611
- }
1612
- }
1613
- if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
1614
- nodeToRelocate.nextSibling !== insertBeforeNode) {
1615
- // we've checked that it's worth while to relocate
1616
- // since that the node to relocate
1617
- // has a different next sibling or parent relocated
1618
- if (nodeToRelocate !== insertBeforeNode) {
1619
- if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1620
- // probably a component in the index.html that doesn't have it's hostname set
1621
- nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1622
- }
1623
- // add it back to the dom but in its new home
1624
- parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1625
- }
1626
- }
1627
- }
1628
- else {
1629
- // this node doesn't have a slot home to go to, so let's hide it
1630
- if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1631
- nodeToRelocate.hidden = true;
1632
- }
1633
- }
1634
- }
1635
- }
1636
- if (checkSlotFallbackVisibility) {
1637
- updateFallbackSlotVisibility(rootVnode.$elm$);
1638
- }
1639
- // done moving nodes around
1640
- // allow the disconnect callback to work again
1641
- plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1642
- // always reset
1643
- relocateNodes.length = 0;
1644
- }
1645
- };
1646
- // slot comment debug nodes only created with the `--debug` flag
1647
- // otherwise these nodes are text nodes w/out content
1648
- const slotReferenceDebugNode = (slotVNode) => doc.createComment(`<slot${slotVNode.$name$ ? ' name="' + slotVNode.$name$ + '"' : ''}> (host=${hostTagName.toLowerCase()})`);
1649
- const originalLocationDebugNode = (nodeToRelocate) => doc.createComment(`org-location for ` +
1650
- (nodeToRelocate.localName
1651
- ? `<${nodeToRelocate.localName}> (host=${nodeToRelocate['s-hn']})`
1652
- : `[${nodeToRelocate.textContent}]`));
1653
- const attachToAncestor = (hostRef, ancestorComponent) => {
1654
- if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
1655
- ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
1656
- }
1657
- };
1658
- const scheduleUpdate = (hostRef, isInitialLoad) => {
1659
- if (BUILD.taskQueue && BUILD.updatable) {
1660
- hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
1661
- }
1662
- if (BUILD.asyncLoading && hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
1663
- hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
1664
- return;
1665
- }
1666
- attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1667
- // there is no ancestor component or the ancestor component
1668
- // has already fired off its lifecycle update then
1669
- // fire off the initial update
1670
- const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1671
- return BUILD.taskQueue ? writeTask(dispatch) : dispatch();
1672
- };
1673
- const dispatchHooks = (hostRef, isInitialLoad) => {
1674
- const elm = hostRef.$hostElement$;
1675
- const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1676
- const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1677
- let promise;
1678
- if (isInitialLoad) {
1679
- if (BUILD.lazyLoad && BUILD.hostListener) {
1680
- hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
1681
- if (hostRef.$queuedListeners$) {
1682
- hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
1683
- hostRef.$queuedListeners$ = null;
1684
- }
1685
- }
1686
- emitLifecycleEvent(elm, 'componentWillLoad');
1687
- if (BUILD.cmpWillLoad) {
1688
- promise = safeCall(instance, 'componentWillLoad');
1689
- }
1690
- }
1691
- else {
1692
- emitLifecycleEvent(elm, 'componentWillUpdate');
1693
- if (BUILD.cmpWillUpdate) {
1694
- promise = safeCall(instance, 'componentWillUpdate');
1695
- }
1696
- }
1697
- emitLifecycleEvent(elm, 'componentWillRender');
1698
- if (BUILD.cmpWillRender) {
1699
- promise = then(promise, () => safeCall(instance, 'componentWillRender'));
1700
- }
1701
- endSchedule();
1702
- return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
1703
- };
1704
- const updateComponent = async (hostRef, instance, isInitialLoad) => {
1705
- // updateComponent
1706
- const elm = hostRef.$hostElement$;
1707
- const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1708
- const rc = elm['s-rc'];
1709
- if (BUILD.style && isInitialLoad) {
1710
- // DOM WRITE!
1711
- attachStyles(hostRef);
1712
- }
1713
- const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1714
- if (BUILD.isDev) {
1715
- hostRef.$flags$ |= 1024 /* HOST_FLAGS.devOnRender */;
1716
- }
1717
- if (BUILD.hydrateServerSide) {
1718
- await callRender(hostRef, instance, elm);
1719
- }
1720
- else {
1721
- callRender(hostRef, instance, elm);
1722
- }
1723
- if (BUILD.cssVarShim && plt.$cssShim$) {
1724
- plt.$cssShim$.updateHost(elm);
1725
- }
1726
- if (BUILD.isDev) {
1727
- hostRef.$renderCount$++;
1728
- hostRef.$flags$ &= ~1024 /* HOST_FLAGS.devOnRender */;
1729
- }
1730
- if (BUILD.hydrateServerSide) {
1731
- try {
1732
- // manually connected child components during server-side hydrate
1733
- serverSideConnected(elm);
1734
- if (isInitialLoad) {
1735
- // using only during server-side hydrate
1736
- if (hostRef.$cmpMeta$.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
1737
- elm['s-en'] = '';
1738
- }
1739
- else if (hostRef.$cmpMeta$.$flags$ & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
1740
- elm['s-en'] = 'c';
1741
- }
1742
- }
1743
- }
1744
- catch (e) {
1745
- consoleError(e, elm);
1746
- }
1747
- }
1748
- if (BUILD.asyncLoading && rc) {
1749
- // ok, so turns out there are some child host elements
1750
- // waiting on this parent element to load
1751
- // let's fire off all update callbacks waiting
1752
- rc.map((cb) => cb());
1753
- elm['s-rc'] = undefined;
1754
- }
1755
- endRender();
1756
- endUpdate();
1757
- if (BUILD.asyncLoading) {
1758
- const childrenPromises = elm['s-p'];
1759
- const postUpdate = () => postUpdateComponent(hostRef);
1760
- if (childrenPromises.length === 0) {
1761
- postUpdate();
1762
- }
1763
- else {
1764
- Promise.all(childrenPromises).then(postUpdate);
1765
- hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1766
- childrenPromises.length = 0;
1767
- }
1768
- }
1769
- else {
1770
- postUpdateComponent(hostRef);
1771
- }
1772
- };
1773
- const callRender = (hostRef, instance, elm) => {
1774
- // in order for bundlers to correctly treeshake the BUILD object
1775
- // we need to ensure BUILD is not deoptimized within a try/catch
1776
- // https://rollupjs.org/guide/en/#treeshake tryCatchDeoptimization
1777
- const allRenderFn = BUILD.allRenderFn ? true : false;
1778
- const lazyLoad = BUILD.lazyLoad ? true : false;
1779
- const taskQueue = BUILD.taskQueue ? true : false;
1780
- const updatable = BUILD.updatable ? true : false;
1781
- try {
1782
- renderingRef = instance;
1783
- instance = allRenderFn ? instance.render() : instance.render && instance.render();
1784
- if (updatable && taskQueue) {
1785
- hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1786
- }
1787
- if (updatable || lazyLoad) {
1788
- hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1789
- }
1790
- if (BUILD.hasRenderFn || BUILD.reflect) {
1791
- if (BUILD.vdomRender || BUILD.reflect) {
1792
- // looks like we've got child nodes to render into this host element
1793
- // or we need to update the css class/attrs on the host element
1794
- // DOM WRITE!
1795
- if (BUILD.hydrateServerSide) {
1796
- return Promise.resolve(instance).then((value) => renderVdom(hostRef, value));
1797
- }
1798
- else {
1799
- renderVdom(hostRef, instance);
1800
- }
1801
- }
1802
- else {
1803
- elm.textContent = instance;
1804
- }
1805
- }
1806
- }
1807
- catch (e) {
1808
- consoleError(e, hostRef.$hostElement$);
1809
- }
1810
- renderingRef = null;
1811
- return null;
1812
- };
1813
- const getRenderingRef = () => renderingRef;
1814
- const postUpdateComponent = (hostRef) => {
1815
- const tagName = hostRef.$cmpMeta$.$tagName$;
1816
- const elm = hostRef.$hostElement$;
1817
- const endPostUpdate = createTime('postUpdate', tagName);
1818
- const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1819
- const ancestorComponent = hostRef.$ancestorComponent$;
1820
- if (BUILD.cmpDidRender) {
1821
- if (BUILD.isDev) {
1822
- hostRef.$flags$ |= 1024 /* HOST_FLAGS.devOnRender */;
1823
- }
1824
- safeCall(instance, 'componentDidRender');
1825
- if (BUILD.isDev) {
1826
- hostRef.$flags$ &= ~1024 /* HOST_FLAGS.devOnRender */;
1827
- }
1828
- }
1829
- emitLifecycleEvent(elm, 'componentDidRender');
1830
- if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1831
- hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1832
- if (BUILD.asyncLoading && BUILD.cssAnnotations) {
1833
- // DOM WRITE!
1834
- addHydratedFlag(elm);
1835
- }
1836
- if (BUILD.cmpDidLoad) {
1837
- if (BUILD.isDev) {
1838
- hostRef.$flags$ |= 2048 /* HOST_FLAGS.devOnDidLoad */;
1839
- }
1840
- safeCall(instance, 'componentDidLoad');
1841
- if (BUILD.isDev) {
1842
- hostRef.$flags$ &= ~2048 /* HOST_FLAGS.devOnDidLoad */;
1843
- }
1844
- }
1845
- emitLifecycleEvent(elm, 'componentDidLoad');
1846
- endPostUpdate();
1847
- if (BUILD.asyncLoading) {
1848
- hostRef.$onReadyResolve$(elm);
1849
- if (!ancestorComponent) {
1850
- appDidLoad(tagName);
1851
- }
1852
- }
1853
- }
1854
- else {
1855
- if (BUILD.cmpDidUpdate) {
1856
- // we've already loaded this component
1857
- // fire off the user's componentDidUpdate method (if one was provided)
1858
- // componentDidUpdate runs AFTER render() has been called
1859
- // and all child components have finished updating
1860
- if (BUILD.isDev) {
1861
- hostRef.$flags$ |= 1024 /* HOST_FLAGS.devOnRender */;
1862
- }
1863
- safeCall(instance, 'componentDidUpdate');
1864
- if (BUILD.isDev) {
1865
- hostRef.$flags$ &= ~1024 /* HOST_FLAGS.devOnRender */;
1866
- }
1867
- }
1868
- emitLifecycleEvent(elm, 'componentDidUpdate');
1869
- endPostUpdate();
1870
- }
1871
- if (BUILD.hotModuleReplacement) {
1872
- elm['s-hmr-load'] && elm['s-hmr-load']();
1873
- }
1874
- if (BUILD.method && BUILD.lazyLoad) {
1875
- hostRef.$onInstanceResolve$(elm);
1876
- }
1877
- // load events fire from bottom to top
1878
- // the deepest elements load first then bubbles up
1879
- if (BUILD.asyncLoading) {
1880
- if (hostRef.$onRenderResolve$) {
1881
- hostRef.$onRenderResolve$();
1882
- hostRef.$onRenderResolve$ = undefined;
1883
- }
1884
- if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
1885
- nextTick(() => scheduleUpdate(hostRef, false));
1886
- }
1887
- hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
1888
- }
1889
- // ( •_•)
1890
- // ( •_•)>⌐■-■
1891
- // (⌐■_■)
1892
- };
1893
- const forceUpdate = (ref) => {
1894
- if (BUILD.updatable) {
1895
- const hostRef = getHostRef(ref);
1896
- const isConnected = hostRef.$hostElement$.isConnected;
1897
- if (isConnected &&
1898
- (hostRef.$flags$ & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1899
- scheduleUpdate(hostRef, false);
1900
- }
1901
- // Returns "true" when the forced update was successfully scheduled
1902
- return isConnected;
1903
- }
1904
- return false;
1905
- };
1906
- const appDidLoad = (who) => {
1907
- // on appload
1908
- // we have finish the first big initial render
1909
- if (BUILD.cssAnnotations) {
1910
- addHydratedFlag(doc.documentElement);
1911
- }
1912
- if (BUILD.asyncQueue) {
1913
- plt.$flags$ |= 2 /* PLATFORM_FLAGS.appLoaded */;
1914
- }
1915
- nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1916
- if (BUILD.profile && performance.measure) {
1917
- performance.measure(`[Stencil] ${NAMESPACE} initial load (by ${who})`, 'st:app:start');
1918
- }
1919
- };
1920
- const safeCall = (instance, method, arg) => {
1921
- if (instance && instance[method]) {
1922
- try {
1923
- return instance[method](arg);
1924
- }
1925
- catch (e) {
1926
- consoleError(e);
1927
- }
1928
- }
1929
- return undefined;
1930
- };
1931
- const then = (promise, thenFn) => {
1932
- return promise && promise.then ? promise.then(thenFn) : thenFn();
1933
- };
1934
- const emitLifecycleEvent = (elm, lifecycleName) => {
1935
- if (BUILD.lifecycleDOMEvents) {
1936
- emitEvent(elm, 'stencil_' + lifecycleName, {
1937
- bubbles: true,
1938
- composed: true,
1939
- detail: {
1940
- namespace: NAMESPACE,
1941
- },
1942
- });
1943
- }
1944
- };
1945
- const addHydratedFlag = (elm) => BUILD.hydratedClass
1946
- ? elm.classList.add('hydrated')
1947
- : BUILD.hydratedAttribute
1948
- ? elm.setAttribute('hydrated', '')
1949
- : undefined;
1950
- const serverSideConnected = (elm) => {
1951
- const children = elm.children;
1952
- if (children != null) {
1953
- for (let i = 0, ii = children.length; i < ii; i++) {
1954
- const childElm = children[i];
1955
- if (typeof childElm.connectedCallback === 'function') {
1956
- childElm.connectedCallback();
1957
- }
1958
- serverSideConnected(childElm);
1959
- }
1960
- }
1961
- };
1962
- const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1963
- const setValue = (ref, propName, newVal, cmpMeta) => {
1964
- // check our new property value against our internal value
1965
- const hostRef = getHostRef(ref);
1966
- const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
1967
- const oldVal = hostRef.$instanceValues$.get(propName);
1968
- const flags = hostRef.$flags$;
1969
- const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
1970
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1971
- // explicitly check for NaN on both sides, as `NaN === NaN` is always false
1972
- const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
1973
- const didValueChange = newVal !== oldVal && !areBothNaN;
1974
- if ((!BUILD.lazyLoad || !(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1975
- // gadzooks! the property's value has changed!!
1976
- // set our new value!
1977
- hostRef.$instanceValues$.set(propName, newVal);
1978
- if (BUILD.isDev) {
1979
- if (hostRef.$flags$ & 1024 /* HOST_FLAGS.devOnRender */) {
1980
- consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, '\nElement', elm, '\nNew value', newVal, '\nOld value', oldVal);
1981
- }
1982
- else if (hostRef.$flags$ & 2048 /* HOST_FLAGS.devOnDidLoad */) {
1983
- consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, '\nElement', elm, '\nNew value', newVal, '\nOld value', oldVal);
1984
- }
1985
- }
1986
- if (!BUILD.lazyLoad || instance) {
1987
- // get an array of method names of watch functions to call
1988
- if (BUILD.watchCallback && cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
1989
- const watchMethods = cmpMeta.$watchers$[propName];
1990
- if (watchMethods) {
1991
- // this instance is watching for when this property changed
1992
- watchMethods.map((watchMethodName) => {
1993
- try {
1994
- // fire off each of the watch methods that are watching this property
1995
- instance[watchMethodName](newVal, oldVal, propName);
1996
- }
1997
- catch (e) {
1998
- consoleError(e, elm);
1999
- }
2000
- });
2001
- }
2002
- }
2003
- if (BUILD.updatable &&
2004
- (flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
2005
- if (BUILD.cmpShouldUpdate && instance.componentShouldUpdate) {
2006
- if (instance.componentShouldUpdate(newVal, oldVal, propName) === false) {
2007
- return;
2008
- }
2009
- }
2010
- // looks like this value actually changed, so we've got work to do!
2011
- // but only if we've already rendered, otherwise just chill out
2012
- // queue that we need to do an update, but don't worry about queuing
2013
- // up millions cuz this function ensures it only runs once
2014
- scheduleUpdate(hostRef, false);
2015
- }
2016
- }
2017
- }
2018
- };
2019
- /**
2020
- * Attach a series of runtime constructs to a compiled Stencil component
2021
- * constructor, including getters and setters for the `@Prop` and `@State`
2022
- * decorators, callbacks for when attributes change, and so on.
2023
- *
2024
- * @param Cstr the constructor for a component that we need to process
2025
- * @param cmpMeta metadata collected previously about the component
2026
- * @param flags a number used to store a series of bit flags
2027
- * @returns a reference to the same constructor passed in (but now mutated)
2028
- */
2029
- const proxyComponent = (Cstr, cmpMeta, flags) => {
2030
- if (BUILD.member && cmpMeta.$members$) {
2031
- if (BUILD.watchCallback && Cstr.watchers) {
2032
- cmpMeta.$watchers$ = Cstr.watchers;
2033
- }
2034
- // It's better to have a const than two Object.entries()
2035
- const members = Object.entries(cmpMeta.$members$);
2036
- const prototype = Cstr.prototype;
2037
- members.map(([memberName, [memberFlags]]) => {
2038
- if ((BUILD.prop || BUILD.state) &&
2039
- (memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
2040
- ((!BUILD.lazyLoad || flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
2041
- // proxyComponent - prop
2042
- Object.defineProperty(prototype, memberName, {
2043
- get() {
2044
- // proxyComponent, get value
2045
- return getValue(this, memberName);
2046
- },
2047
- set(newValue) {
2048
- // only during dev time
2049
- if (BUILD.isDev) {
2050
- const ref = getHostRef(this);
2051
- if (
2052
- // we are proxying the instance (not element)
2053
- (flags & 1 /* PROXY_FLAGS.isElementConstructor */) === 0 &&
2054
- // the element is not constructing
2055
- (ref.$flags$ & 8 /* HOST_FLAGS.isConstructingInstance */) === 0 &&
2056
- // the member is a prop
2057
- (memberFlags & 31 /* MEMBER_FLAGS.Prop */) !== 0 &&
2058
- // the member is not mutable
2059
- (memberFlags & 1024 /* MEMBER_FLAGS.Mutable */) === 0) {
2060
- consoleDevWarn(`@Prop() "${memberName}" on <${cmpMeta.$tagName$}> is immutable but was modified from within the component.\nMore information: https://stenciljs.com/docs/properties#prop-mutability`);
2061
- }
2062
- }
2063
- // proxyComponent, set value
2064
- setValue(this, memberName, newValue, cmpMeta);
2065
- },
2066
- configurable: true,
2067
- enumerable: true,
2068
- });
2069
- }
2070
- else if (BUILD.lazyLoad &&
2071
- BUILD.method &&
2072
- flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
2073
- memberFlags & 64 /* MEMBER_FLAGS.Method */) {
2074
- // proxyComponent - method
2075
- Object.defineProperty(prototype, memberName, {
2076
- value(...args) {
2077
- const ref = getHostRef(this);
2078
- return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
2079
- },
2080
- });
2081
- }
2082
- });
2083
- if (BUILD.observeAttribute && (!BUILD.lazyLoad || flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
2084
- const attrNameToPropName = new Map();
2085
- prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
2086
- plt.jmp(() => {
2087
- const propName = attrNameToPropName.get(attrName);
2088
- // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
2089
- // in the case where an attribute was set inline.
2090
- // ```html
2091
- // <my-component some-attribute="some-value"></my-component>
2092
- // ```
2093
- //
2094
- // There is an edge case where a developer sets the attribute inline on a custom element and then
2095
- // programmatically changes it before it has been upgraded as shown below:
2096
- //
2097
- // ```html
2098
- // <!-- this component has _not_ been upgraded yet -->
2099
- // <my-component id="test" some-attribute="some-value"></my-component>
2100
- // <script>
2101
- // // grab non-upgraded component
2102
- // el = document.querySelector("#test");
2103
- // el.someAttribute = "another-value";
2104
- // // upgrade component
2105
- // customElements.define('my-component', MyComponent);
2106
- // </script>
2107
- // ```
2108
- // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
2109
- // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
2110
- // to the value that was set inline i.e. "some-value" from above example. When
2111
- // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
2112
- //
2113
- // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
2114
- // by connectedCallback as this attributeChangedCallback will not fire.
2115
- //
2116
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
2117
- //
2118
- // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
2119
- // properties here given that this goes against best practices outlined here
2120
- // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
2121
- if (this.hasOwnProperty(propName)) {
2122
- newValue = this[propName];
2123
- delete this[propName];
2124
- }
2125
- else if (prototype.hasOwnProperty(propName) &&
2126
- typeof this[propName] === 'number' &&
2127
- this[propName] == newValue) {
2128
- // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
2129
- // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
2130
- // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
2131
- return;
2132
- }
2133
- this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
2134
- });
2135
- };
2136
- // create an array of attributes to observe
2137
- // and also create a map of html attribute name to js property name
2138
- Cstr.observedAttributes = members
2139
- .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
2140
- .map(([propName, m]) => {
2141
- const attrName = m[1] || propName;
2142
- attrNameToPropName.set(attrName, propName);
2143
- if (BUILD.reflect && m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
2144
- cmpMeta.$attrsToReflect$.push([propName, attrName]);
2145
- }
2146
- return attrName;
2147
- });
2148
- }
2149
- }
2150
- return Cstr;
2151
- };
2152
- const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
2153
- // initializeComponent
2154
- if ((BUILD.lazyLoad || BUILD.hydrateServerSide || BUILD.style) &&
2155
- (hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
2156
- if (BUILD.lazyLoad || BUILD.hydrateClientSide) {
2157
- // we haven't initialized this element yet
2158
- hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
2159
- // lazy loaded components
2160
- // request the component's implementation to be
2161
- // wired up with the host element
2162
- Cstr = loadModule(cmpMeta, hostRef, hmrVersionId);
2163
- if (Cstr.then) {
2164
- // Await creates a micro-task avoid if possible
2165
- const endLoad = uniqueTime(`st:load:${cmpMeta.$tagName$}:${hostRef.$modeName$}`, `[Stencil] Load module for <${cmpMeta.$tagName$}>`);
2166
- Cstr = await Cstr;
2167
- endLoad();
2168
- }
2169
- if ((BUILD.isDev || BUILD.isDebug) && !Cstr) {
2170
- throw new Error(`Constructor for "${cmpMeta.$tagName$}#${hostRef.$modeName$}" was not found`);
2171
- }
2172
- if (BUILD.member && !Cstr.isProxied) {
2173
- // we've never proxied this Constructor before
2174
- // let's add the getters/setters to its prototype before
2175
- // the first time we create an instance of the implementation
2176
- if (BUILD.watchCallback) {
2177
- cmpMeta.$watchers$ = Cstr.watchers;
2178
- }
2179
- proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
2180
- Cstr.isProxied = true;
2181
- }
2182
- const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
2183
- // ok, time to construct the instance
2184
- // but let's keep track of when we start and stop
2185
- // so that the getters/setters don't incorrectly step on data
2186
- if (BUILD.member) {
2187
- hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
2188
- }
2189
- // construct the lazy-loaded component implementation
2190
- // passing the hostRef is very important during
2191
- // construction in order to directly wire together the
2192
- // host element and the lazy-loaded instance
2193
- try {
2194
- new Cstr(hostRef);
2195
- }
2196
- catch (e) {
2197
- consoleError(e);
2198
- }
2199
- if (BUILD.member) {
2200
- hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
2201
- }
2202
- if (BUILD.watchCallback) {
2203
- hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
2204
- }
2205
- endNewInstance();
2206
- fireConnectedCallback(hostRef.$lazyInstance$);
2207
- }
2208
- else {
2209
- // sync constructor component
2210
- Cstr = elm.constructor;
2211
- hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
2212
- // wait for the CustomElementRegistry to mark the component as ready before setting `isWatchReady`. Otherwise,
2213
- // watchers may fire prematurely if `customElements.get()`/`customElements.whenDefined()` resolves _before_
2214
- // Stencil has completed instantiating the component.
2215
- customElements.whenDefined(cmpMeta.$tagName$).then(() => (hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */));
2216
- }
2217
- if (BUILD.style && Cstr.style) {
2218
- // this component has styles but we haven't registered them yet
2219
- let style = Cstr.style;
2220
- if (BUILD.mode && typeof style !== 'string') {
2221
- style = style[(hostRef.$modeName$ = computeMode(elm))];
2222
- if (BUILD.hydrateServerSide && hostRef.$modeName$) {
2223
- elm.setAttribute('s-mode', hostRef.$modeName$);
2224
- }
2225
- }
2226
- const scopeId = getScopeId(cmpMeta, hostRef.$modeName$);
2227
- if (!styles.has(scopeId)) {
2228
- const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
2229
- if (!BUILD.hydrateServerSide &&
2230
- BUILD.shadowDom &&
2231
- BUILD.shadowDomShim &&
2232
- cmpMeta.$flags$ & 8 /* CMP_FLAGS.needsShadowDomShim */) {
2233
- style = await import('./shadow-css-b18e99d7.js').then((m) => m.scopeCss(style, scopeId, false));
2234
- }
2235
- registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
2236
- endRegisterStyles();
2237
- }
2238
- }
2239
- }
2240
- // we've successfully created a lazy instance
2241
- const ancestorComponent = hostRef.$ancestorComponent$;
2242
- const schedule = () => scheduleUpdate(hostRef, true);
2243
- if (BUILD.asyncLoading && ancestorComponent && ancestorComponent['s-rc']) {
2244
- // this is the initial load and this component it has an ancestor component
2245
- // but the ancestor component has NOT fired its will update lifecycle yet
2246
- // so let's just cool our jets and wait for the ancestor to continue first
2247
- // this will get fired off when the ancestor component
2248
- // finally gets around to rendering its lazy self
2249
- // fire off the initial update
2250
- ancestorComponent['s-rc'].push(schedule);
2251
- }
2252
- else {
2253
- schedule();
2254
- }
2255
- };
2256
- const fireConnectedCallback = (instance) => {
2257
- if (BUILD.lazyLoad && BUILD.connectedCallback) {
2258
- safeCall(instance, 'connectedCallback');
2259
- }
2260
- };
2261
- const connectedCallback = (elm) => {
2262
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
2263
- const hostRef = getHostRef(elm);
2264
- const cmpMeta = hostRef.$cmpMeta$;
2265
- const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
2266
- if (BUILD.hostListenerTargetParent) {
2267
- // only run if we have listeners being attached to a parent
2268
- addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, true);
2269
- }
2270
- if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
2271
- // first time this component has connected
2272
- hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
2273
- let hostId;
2274
- if (BUILD.hydrateClientSide) {
2275
- hostId = elm.getAttribute(HYDRATE_ID);
2276
- if (hostId) {
2277
- if (BUILD.shadowDom && supportsShadow && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2278
- const scopeId = BUILD.mode
2279
- ? addStyle(elm.shadowRoot, cmpMeta, elm.getAttribute('s-mode'))
2280
- : addStyle(elm.shadowRoot, cmpMeta);
2281
- elm.classList.remove(scopeId + '-h', scopeId + '-s');
2282
- }
2283
- initializeClientHydrate(elm, cmpMeta.$tagName$, hostId, hostRef);
2284
- }
2285
- }
2286
- if (BUILD.slotRelocation && !hostId) {
2287
- // initUpdate
2288
- // if the slot polyfill is required we'll need to put some nodes
2289
- // in here to act as original content anchors as we move nodes around
2290
- // host element has been connected to the DOM
2291
- if (BUILD.hydrateServerSide ||
2292
- ((BUILD.slot || BUILD.shadowDom) &&
2293
- cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
2294
- setContentReference(elm);
2295
- }
2296
- }
2297
- if (BUILD.asyncLoading) {
2298
- // find the first ancestor component (if there is one) and register
2299
- // this component as one of the actively loading child components for its ancestor
2300
- let ancestorComponent = elm;
2301
- while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
2302
- // climb up the ancestors looking for the first
2303
- // component that hasn't finished its lifecycle update yet
2304
- if ((BUILD.hydrateClientSide &&
2305
- ancestorComponent.nodeType === 1 /* NODE_TYPE.ElementNode */ &&
2306
- ancestorComponent.hasAttribute('s-id') &&
2307
- ancestorComponent['s-p']) ||
2308
- ancestorComponent['s-p']) {
2309
- // we found this components first ancestor component
2310
- // keep a reference to this component's ancestor component
2311
- attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
2312
- break;
2313
- }
2314
- }
2315
- }
2316
- // Lazy properties
2317
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
2318
- if (BUILD.prop && !BUILD.hydrateServerSide && cmpMeta.$members$) {
2319
- Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
2320
- if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
2321
- const value = elm[memberName];
2322
- delete elm[memberName];
2323
- elm[memberName] = value;
2324
- }
2325
- });
2326
- }
2327
- if (BUILD.initializeNextTick) {
2328
- // connectedCallback, taskQueue, initialLoad
2329
- // angular sets attribute AFTER connectCallback
2330
- // https://github.com/angular/angular/issues/18909
2331
- // https://github.com/angular/angular/issues/19940
2332
- nextTick(() => initializeComponent(elm, hostRef, cmpMeta));
2333
- }
2334
- else {
2335
- initializeComponent(elm, hostRef, cmpMeta);
2336
- }
2337
- }
2338
- else {
2339
- // not the first time this has connected
2340
- // reattach any event listeners to the host
2341
- // since they would have been removed when disconnected
2342
- addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
2343
- // fire off connectedCallback() on component instance
2344
- fireConnectedCallback(hostRef.$lazyInstance$);
2345
- }
2346
- endConnected();
2347
- }
2348
- };
2349
- const setContentReference = (elm) => {
2350
- // only required when we're NOT using native shadow dom (slot)
2351
- // or this browser doesn't support native shadow dom
2352
- // and this host element was NOT created with SSR
2353
- // let's pick out the inner content for slot projection
2354
- // create a node to represent where the original
2355
- // content was first placed, which is useful later on
2356
- const contentRefElm = (elm['s-cr'] = doc.createComment(BUILD.isDebug ? `content-ref (host=${elm.localName})` : ''));
2357
- contentRefElm['s-cn'] = true;
2358
- elm.insertBefore(contentRefElm, elm.firstChild);
2359
- };
2360
- const disconnectedCallback = (elm) => {
2361
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
2362
- const hostRef = getHostRef(elm);
2363
- const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
2364
- if (BUILD.hostListener) {
2365
- if (hostRef.$rmListeners$) {
2366
- hostRef.$rmListeners$.map((rmListener) => rmListener());
2367
- hostRef.$rmListeners$ = undefined;
2368
- }
2369
- }
2370
- // clear CSS var-shim tracking
2371
- if (BUILD.cssVarShim && plt.$cssShim$) {
2372
- plt.$cssShim$.removeHost(elm);
2373
- }
2374
- if (BUILD.lazyLoad && BUILD.disconnectedCallback) {
2375
- safeCall(instance, 'disconnectedCallback');
2376
- }
2377
- if (BUILD.cmpDidUnload) {
2378
- safeCall(instance, 'componentDidUnload');
2379
- }
2380
- }
2381
- };
2382
- const defineCustomElement = (Cstr, compactMeta) => {
2383
- customElements.define(compactMeta[1], proxyCustomElement(Cstr, compactMeta));
2384
- };
2385
- const proxyCustomElement = (Cstr, compactMeta) => {
2386
- const cmpMeta = {
2387
- $flags$: compactMeta[0],
2388
- $tagName$: compactMeta[1],
2389
- };
2390
- if (BUILD.member) {
2391
- cmpMeta.$members$ = compactMeta[2];
2392
- }
2393
- if (BUILD.hostListener) {
2394
- cmpMeta.$listeners$ = compactMeta[3];
2395
- }
2396
- if (BUILD.watchCallback) {
2397
- cmpMeta.$watchers$ = Cstr.$watchers$;
2398
- }
2399
- if (BUILD.reflect) {
2400
- cmpMeta.$attrsToReflect$ = [];
2401
- }
2402
- if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2403
- cmpMeta.$flags$ |= 8 /* CMP_FLAGS.needsShadowDomShim */;
2404
- }
2405
- const originalConnectedCallback = Cstr.prototype.connectedCallback;
2406
- const originalDisconnectedCallback = Cstr.prototype.disconnectedCallback;
2407
- Object.assign(Cstr.prototype, {
2408
- __registerHost() {
2409
- registerHost(this, cmpMeta);
2410
- },
2411
- connectedCallback() {
2412
- connectedCallback(this);
2413
- if (BUILD.connectedCallback && originalConnectedCallback) {
2414
- originalConnectedCallback.call(this);
2415
- }
2416
- },
2417
- disconnectedCallback() {
2418
- disconnectedCallback(this);
2419
- if (BUILD.disconnectedCallback && originalDisconnectedCallback) {
2420
- originalDisconnectedCallback.call(this);
2421
- }
2422
- },
2423
- __attachShadow() {
2424
- if (supportsShadow) {
2425
- if (BUILD.shadowDelegatesFocus) {
2426
- this.attachShadow({
2427
- mode: 'open',
2428
- delegatesFocus: !!(cmpMeta.$flags$ & 16 /* CMP_FLAGS.shadowDelegatesFocus */),
2429
- });
2430
- }
2431
- else {
2432
- this.attachShadow({ mode: 'open' });
2433
- }
2434
- }
2435
- else {
2436
- this.shadowRoot = this;
2437
- }
2438
- },
2439
- });
2440
- Cstr.is = cmpMeta.$tagName$;
2441
- return proxyComponent(Cstr, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */ | 2 /* PROXY_FLAGS.proxyState */);
2442
- };
2443
- const forceModeUpdate = (elm) => {
2444
- if (BUILD.style && BUILD.mode && !BUILD.lazyLoad) {
2445
- const mode = computeMode(elm);
2446
- const hostRef = getHostRef(elm);
2447
- if (hostRef.$modeName$ !== mode) {
2448
- const cmpMeta = hostRef.$cmpMeta$;
2449
- const oldScopeId = elm['s-sc'];
2450
- const scopeId = getScopeId(cmpMeta, mode);
2451
- const style = elm.constructor.style[mode];
2452
- const flags = cmpMeta.$flags$;
2453
- if (style) {
2454
- if (!styles.has(scopeId)) {
2455
- registerStyle(scopeId, style, !!(flags & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
2456
- }
2457
- hostRef.$modeName$ = mode;
2458
- elm.classList.remove(oldScopeId + '-h', oldScopeId + '-s');
2459
- attachStyles(hostRef);
2460
- forceUpdate(elm);
2461
- }
2462
- }
2463
- }
2464
- };
2465
- const patchCloneNode = (HostElementPrototype) => {
2466
- const orgCloneNode = HostElementPrototype.cloneNode;
2467
- HostElementPrototype.cloneNode = function (deep) {
2468
- const srcNode = this;
2469
- const isShadowDom = BUILD.shadowDom ? srcNode.shadowRoot && supportsShadow : false;
2470
- const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false);
2471
- if (BUILD.slot && !isShadowDom && deep) {
2472
- let i = 0;
2473
- let slotted, nonStencilNode;
2474
- const stencilPrivates = [
2475
- 's-id',
2476
- 's-cr',
2477
- 's-lr',
2478
- 's-rc',
2479
- 's-sc',
2480
- 's-p',
2481
- 's-cn',
2482
- 's-sr',
2483
- 's-sn',
2484
- 's-hn',
2485
- 's-ol',
2486
- 's-nr',
2487
- 's-si',
2488
- ];
2489
- for (; i < srcNode.childNodes.length; i++) {
2490
- slotted = srcNode.childNodes[i]['s-nr'];
2491
- nonStencilNode = stencilPrivates.every((privateField) => !srcNode.childNodes[i][privateField]);
2492
- if (slotted) {
2493
- if (BUILD.appendChildSlotFix && clonedNode.__appendChild) {
2494
- clonedNode.__appendChild(slotted.cloneNode(true));
2495
- }
2496
- else {
2497
- clonedNode.appendChild(slotted.cloneNode(true));
2498
- }
2499
- }
2500
- if (nonStencilNode) {
2501
- clonedNode.appendChild(srcNode.childNodes[i].cloneNode(true));
2502
- }
2503
- }
2504
- }
2505
- return clonedNode;
2506
- };
2507
- };
2508
- const patchSlotAppendChild = (HostElementPrototype) => {
2509
- HostElementPrototype.__appendChild = HostElementPrototype.appendChild;
2510
- HostElementPrototype.appendChild = function (newChild) {
2511
- const slotName = (newChild['s-sn'] = getSlotName(newChild));
2512
- const slotNode = getHostSlotNode(this.childNodes, slotName);
2513
- if (slotNode) {
2514
- const slotChildNodes = getHostSlotChildNodes(slotNode, slotName);
2515
- const appendAfter = slotChildNodes[slotChildNodes.length - 1];
2516
- return appendAfter.parentNode.insertBefore(newChild, appendAfter.nextSibling);
2517
- }
2518
- return this.__appendChild(newChild);
2519
- };
2520
- };
2521
- /**
2522
- * Patches the text content of an unnamed slotted node inside a scoped component
2523
- * @param hostElementPrototype the `Element` to be patched
2524
- * @param cmpMeta component runtime metadata used to determine if the component should be patched or not
2525
- */
2526
- const patchTextContent = (hostElementPrototype, cmpMeta) => {
2527
- if (BUILD.scoped && cmpMeta.$flags$ & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
2528
- const descriptor = Object.getOwnPropertyDescriptor(Node.prototype, 'textContent');
2529
- Object.defineProperty(hostElementPrototype, '__textContent', descriptor);
2530
- Object.defineProperty(hostElementPrototype, 'textContent', {
2531
- get() {
2532
- var _a;
2533
- // get the 'default slot', which would be the first slot in a shadow tree (if we were using one), whose name is
2534
- // the empty string
2535
- const slotNode = getHostSlotNode(this.childNodes, '');
2536
- // when a slot node is found, the textContent _may_ be found in the next sibling (text) node, depending on how
2537
- // nodes were reordered during the vdom render. first try to get the text content from the sibling.
2538
- if (((_a = slotNode === null || slotNode === void 0 ? void 0 : slotNode.nextSibling) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* NODE_TYPES.TEXT_NODE */) {
2539
- return slotNode.nextSibling.textContent;
2540
- }
2541
- else if (slotNode) {
2542
- return slotNode.textContent;
2543
- }
2544
- else {
2545
- // fallback to the original implementation
2546
- return this.__textContent;
2547
- }
2548
- },
2549
- set(value) {
2550
- var _a;
2551
- // get the 'default slot', which would be the first slot in a shadow tree (if we were using one), whose name is
2552
- // the empty string
2553
- const slotNode = getHostSlotNode(this.childNodes, '');
2554
- // when a slot node is found, the textContent _may_ need to be placed in the next sibling (text) node,
2555
- // depending on how nodes were reordered during the vdom render. first try to set the text content on the
2556
- // sibling.
2557
- if (((_a = slotNode === null || slotNode === void 0 ? void 0 : slotNode.nextSibling) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* NODE_TYPES.TEXT_NODE */) {
2558
- slotNode.nextSibling.textContent = value;
2559
- }
2560
- else if (slotNode) {
2561
- slotNode.textContent = value;
2562
- }
2563
- else {
2564
- // we couldn't find a slot, but that doesn't mean that there isn't one. if this check ran before the DOM
2565
- // loaded, we could have missed it. check for a content reference element on the scoped component and insert
2566
- // it there
2567
- this.__textContent = value;
2568
- const contentRefElm = this['s-cr'];
2569
- if (contentRefElm) {
2570
- this.insertBefore(contentRefElm, this.firstChild);
2571
- }
2572
- }
2573
- },
2574
- });
2575
- }
2576
- };
2577
- const patchChildSlotNodes = (elm, cmpMeta) => {
2578
- class FakeNodeList extends Array {
2579
- item(n) {
2580
- return this[n];
2581
- }
2582
- }
2583
- if (cmpMeta.$flags$ & 8 /* CMP_FLAGS.needsShadowDomShim */) {
2584
- const childNodesFn = elm.__lookupGetter__('childNodes');
2585
- Object.defineProperty(elm, 'children', {
2586
- get() {
2587
- return this.childNodes.map((n) => n.nodeType === 1);
2588
- },
2589
- });
2590
- Object.defineProperty(elm, 'childElementCount', {
2591
- get() {
2592
- return elm.children.length;
2593
- },
2594
- });
2595
- Object.defineProperty(elm, 'childNodes', {
2596
- get() {
2597
- const childNodes = childNodesFn.call(this);
2598
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0 &&
2599
- getHostRef(this).$flags$ & 2 /* HOST_FLAGS.hasRendered */) {
2600
- const result = new FakeNodeList();
2601
- for (let i = 0; i < childNodes.length; i++) {
2602
- const slot = childNodes[i]['s-nr'];
2603
- if (slot) {
2604
- result.push(slot);
2605
- }
2606
- }
2607
- return result;
2608
- }
2609
- return FakeNodeList.from(childNodes);
2610
- },
2611
- });
2612
- }
2613
- };
2614
- const getSlotName = (node) => node['s-sn'] || (node.nodeType === 1 && node.getAttribute('slot')) || '';
2615
- /**
2616
- * Recursively searches a series of child nodes for a slot with the provided name.
2617
- * @param childNodes the nodes to search for a slot with a specific name.
2618
- * @param slotName the name of the slot to match on.
2619
- * @returns a reference to the slot node that matches the provided name, `null` otherwise
2620
- */
2621
- const getHostSlotNode = (childNodes, slotName) => {
2622
- let i = 0;
2623
- let childNode;
2624
- for (; i < childNodes.length; i++) {
2625
- childNode = childNodes[i];
2626
- if (childNode['s-sr'] && childNode['s-sn'] === slotName) {
2627
- return childNode;
2628
- }
2629
- childNode = getHostSlotNode(childNode.childNodes, slotName);
2630
- if (childNode) {
2631
- return childNode;
2632
- }
2633
- }
2634
- return null;
2635
- };
2636
- const getHostSlotChildNodes = (n, slotName) => {
2637
- const childNodes = [n];
2638
- while ((n = n.nextSibling) && n['s-sn'] === slotName) {
2639
- childNodes.push(n);
2640
- }
2641
- return childNodes;
2642
- };
2643
- const hmrStart = (elm, cmpMeta, hmrVersionId) => {
2644
- // ¯\_(ツ)_/¯
2645
- const hostRef = getHostRef(elm);
2646
- // reset state flags to only have been connected
2647
- hostRef.$flags$ = 1 /* HOST_FLAGS.hasConnected */;
2648
- // TODO
2649
- // detatch any event listeners that may have been added
2650
- // because we're not passing an exact event name it'll
2651
- // remove all of this element's event, which is good
2652
- // create a callback for when this component finishes hmr
2653
- elm['s-hmr-load'] = () => {
2654
- // finished hmr for this element
2655
- delete elm['s-hmr-load'];
2656
- };
2657
- // re-initialize the component
2658
- initializeComponent(elm, hostRef, cmpMeta, hmrVersionId);
2659
- };
2660
- const bootstrapLazy = (lazyBundles, options = {}) => {
2661
- if (BUILD.profile && performance.mark) {
2662
- performance.mark('st:app:start');
2663
- }
2664
- installDevTools();
2665
- const endBootstrap = createTime('bootstrapLazy');
2666
- const cmpTags = [];
2667
- const exclude = options.exclude || [];
2668
- const customElements = win.customElements;
2669
- const head = doc.head;
2670
- const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
2671
- const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
2672
- const deferredConnectedCallbacks = [];
2673
- const styles = /*@__PURE__*/ doc.querySelectorAll(`[${HYDRATED_STYLE_ID}]`);
2674
- let appLoadFallback;
2675
- let isBootstrapping = true;
2676
- let i = 0;
2677
- Object.assign(plt, options);
2678
- plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
2679
- if (BUILD.asyncQueue) {
2680
- if (options.syncQueue) {
2681
- plt.$flags$ |= 4 /* PLATFORM_FLAGS.queueSync */;
2682
- }
2683
- }
2684
- if (BUILD.hydrateClientSide) {
2685
- // If the app is already hydrated there is not point to disable the
2686
- // async queue. This will improve the first input delay
2687
- plt.$flags$ |= 2 /* PLATFORM_FLAGS.appLoaded */;
2688
- }
2689
- if (BUILD.hydrateClientSide && BUILD.shadowDom) {
2690
- for (; i < styles.length; i++) {
2691
- registerStyle(styles[i].getAttribute(HYDRATED_STYLE_ID), convertScopedToShadow(styles[i].innerHTML), true);
2692
- }
2693
- }
2694
- lazyBundles.map((lazyBundle) => {
2695
- lazyBundle[1].map((compactMeta) => {
2696
- const cmpMeta = {
2697
- $flags$: compactMeta[0],
2698
- $tagName$: compactMeta[1],
2699
- $members$: compactMeta[2],
2700
- $listeners$: compactMeta[3],
2701
- };
2702
- if (BUILD.member) {
2703
- cmpMeta.$members$ = compactMeta[2];
2704
- }
2705
- if (BUILD.hostListener) {
2706
- cmpMeta.$listeners$ = compactMeta[3];
2707
- }
2708
- if (BUILD.reflect) {
2709
- cmpMeta.$attrsToReflect$ = [];
2710
- }
2711
- if (BUILD.watchCallback) {
2712
- cmpMeta.$watchers$ = {};
2713
- }
2714
- if (BUILD.shadowDom && !supportsShadow && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2715
- cmpMeta.$flags$ |= 8 /* CMP_FLAGS.needsShadowDomShim */;
2716
- }
2717
- const tagName = BUILD.transformTagName && options.transformTagName
2718
- ? options.transformTagName(cmpMeta.$tagName$)
2719
- : cmpMeta.$tagName$;
2720
- const HostElement = class extends HTMLElement {
2721
- // StencilLazyHost
2722
- constructor(self) {
2723
- // @ts-ignore
2724
- super(self);
2725
- self = this;
2726
- registerHost(self, cmpMeta);
2727
- if (BUILD.shadowDom && cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2728
- // this component is using shadow dom
2729
- // and this browser supports shadow dom
2730
- // add the read-only property "shadowRoot" to the host element
2731
- // adding the shadow root build conditionals to minimize runtime
2732
- if (supportsShadow) {
2733
- if (BUILD.shadowDelegatesFocus) {
2734
- self.attachShadow({
2735
- mode: 'open',
2736
- delegatesFocus: !!(cmpMeta.$flags$ & 16 /* CMP_FLAGS.shadowDelegatesFocus */),
2737
- });
2738
- }
2739
- else {
2740
- self.attachShadow({ mode: 'open' });
2741
- }
2742
- }
2743
- else if (!BUILD.hydrateServerSide && !('shadowRoot' in self)) {
2744
- self.shadowRoot = self;
2745
- }
2746
- }
2747
- if (BUILD.slotChildNodesFix) {
2748
- patchChildSlotNodes(self, cmpMeta);
2749
- }
2750
- }
2751
- connectedCallback() {
2752
- if (appLoadFallback) {
2753
- clearTimeout(appLoadFallback);
2754
- appLoadFallback = null;
2755
- }
2756
- if (isBootstrapping) {
2757
- // connectedCallback will be processed once all components have been registered
2758
- deferredConnectedCallbacks.push(this);
2759
- }
2760
- else {
2761
- plt.jmp(() => connectedCallback(this));
2762
- }
2763
- }
2764
- disconnectedCallback() {
2765
- plt.jmp(() => disconnectedCallback(this));
2766
- }
2767
- componentOnReady() {
2768
- return getHostRef(this).$onReadyPromise$;
2769
- }
2770
- };
2771
- if (BUILD.cloneNodeFix) {
2772
- patchCloneNode(HostElement.prototype);
2773
- }
2774
- if (BUILD.appendChildSlotFix) {
2775
- patchSlotAppendChild(HostElement.prototype);
2776
- }
2777
- if (BUILD.hotModuleReplacement) {
2778
- HostElement.prototype['s-hmr'] = function (hmrVersionId) {
2779
- hmrStart(this, cmpMeta, hmrVersionId);
2780
- };
2781
- }
2782
- if (BUILD.scopedSlotTextContentFix) {
2783
- patchTextContent(HostElement.prototype, cmpMeta);
2784
- }
2785
- cmpMeta.$lazyBundleId$ = lazyBundle[0];
2786
- if (!exclude.includes(tagName) && !customElements.get(tagName)) {
2787
- cmpTags.push(tagName);
2788
- customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
2789
- }
2790
- });
2791
- });
2792
- if (BUILD.invisiblePrehydration && (BUILD.hydratedClass || BUILD.hydratedAttribute)) {
2793
- visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
2794
- visibilityStyle.setAttribute('data-styles', '');
2795
- head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
2796
- }
2797
- // Process deferred connectedCallbacks now all components have been registered
2798
- isBootstrapping = false;
2799
- if (deferredConnectedCallbacks.length) {
2800
- deferredConnectedCallbacks.map((host) => host.connectedCallback());
2801
- }
2802
- else {
2803
- if (BUILD.profile) {
2804
- plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30, 'timeout')));
2805
- }
2806
- else {
2807
- plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
2808
- }
2809
- }
2810
- // Fallback appLoad event
2811
- endBootstrap();
2812
- };
2813
- const getConnect = (_ref, tagName) => {
2814
- const componentOnReady = () => {
2815
- let elm = doc.querySelector(tagName);
2816
- if (!elm) {
2817
- elm = doc.createElement(tagName);
2818
- doc.body.appendChild(elm);
2819
- }
2820
- return typeof elm.componentOnReady === 'function' ? elm.componentOnReady() : Promise.resolve(elm);
2821
- };
2822
- const create = (...args) => {
2823
- return componentOnReady().then((el) => el.create(...args));
2824
- };
2825
- return {
2826
- create,
2827
- componentOnReady,
2828
- };
2829
- };
2830
- const getContext = (_elm, context) => {
2831
- if (context in Context) {
2832
- return Context[context];
2833
- }
2834
- else if (context === 'window') {
2835
- return win;
2836
- }
2837
- else if (context === 'document') {
2838
- return doc;
2839
- }
2840
- else if (context === 'isServer' || context === 'isPrerender') {
2841
- return BUILD.hydrateServerSide ? true : false;
2842
- }
2843
- else if (context === 'isClient') {
2844
- return BUILD.hydrateServerSide ? false : true;
2845
- }
2846
- else if (context === 'resourcesUrl' || context === 'publicPath') {
2847
- return getAssetPath('.');
2848
- }
2849
- else if (context === 'queue') {
2850
- return {
2851
- write: writeTask,
2852
- read: readTask,
2853
- tick: {
2854
- then(cb) {
2855
- return nextTick(cb);
2856
- },
2857
- },
2858
- };
2859
- }
2860
- return undefined;
2861
- };
2862
- const Fragment = (_, children) => children;
2863
- const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
2864
- if (BUILD.hostListener && listeners) {
2865
- // this is called immediately within the element's constructor
2866
- // initialize our event listeners on the host element
2867
- // we do this now so that we can listen to events that may
2868
- // have fired even before the instance is ready
2869
- if (BUILD.hostListenerTargetParent) {
2870
- // this component may have event listeners that should be attached to the parent
2871
- if (attachParentListeners) {
2872
- // this is being ran from within the connectedCallback
2873
- // which is important so that we know the host element actually has a parent element
2874
- // filter out the listeners to only have the ones that ARE being attached to the parent
2875
- listeners = listeners.filter(([flags]) => flags & 32 /* LISTENER_FLAGS.TargetParent */);
2876
- }
2877
- else {
2878
- // this is being ran from within the component constructor
2879
- // everything BUT the parent element listeners should be attached at this time
2880
- // filter out the listeners that are NOT being attached to the parent
2881
- listeners = listeners.filter(([flags]) => !(flags & 32 /* LISTENER_FLAGS.TargetParent */));
2882
- }
2883
- }
2884
- listeners.map(([flags, name, method]) => {
2885
- const target = BUILD.hostListenerTarget ? getHostListenerTarget(elm, flags) : elm;
2886
- const handler = hostListenerProxy(hostRef, method);
2887
- const opts = hostListenerOpts(flags);
2888
- plt.ael(target, name, handler, opts);
2889
- (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
2890
- });
2891
- }
2892
- };
2893
- const hostListenerProxy = (hostRef, methodName) => (ev) => {
2894
- try {
2895
- if (BUILD.lazyLoad) {
2896
- if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
2897
- // instance is ready, let's call it's member method for this event
2898
- hostRef.$lazyInstance$[methodName](ev);
2899
- }
2900
- else {
2901
- (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
2902
- }
2903
- }
2904
- else {
2905
- hostRef.$hostElement$[methodName](ev);
2906
- }
2907
- }
2908
- catch (e) {
2909
- consoleError(e);
2910
- }
2911
- };
2912
- const getHostListenerTarget = (elm, flags) => {
2913
- if (BUILD.hostListenerTargetDocument && flags & 4 /* LISTENER_FLAGS.TargetDocument */)
2914
- return doc;
2915
- if (BUILD.hostListenerTargetWindow && flags & 8 /* LISTENER_FLAGS.TargetWindow */)
2916
- return win;
2917
- if (BUILD.hostListenerTargetBody && flags & 16 /* LISTENER_FLAGS.TargetBody */)
2918
- return doc.body;
2919
- if (BUILD.hostListenerTargetParent && flags & 32 /* LISTENER_FLAGS.TargetParent */)
2920
- return elm.parentElement;
2921
- return elm;
2922
- };
2923
- // prettier-ignore
2924
- const hostListenerOpts = (flags) => supportsListenerOptions
2925
- ? ({
2926
- passive: (flags & 1 /* LISTENER_FLAGS.Passive */) !== 0,
2927
- capture: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0,
2928
- })
2929
- : (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
2930
- const setPlatformOptions = (opts) => Object.assign(plt, opts);
2931
- const insertVdomAnnotations = (doc, staticComponents) => {
2932
- if (doc != null) {
2933
- const docData = {
2934
- hostIds: 0,
2935
- rootLevelIds: 0,
2936
- staticComponents: new Set(staticComponents),
2937
- };
2938
- const orgLocationNodes = [];
2939
- parseVNodeAnnotations(doc, doc.body, docData, orgLocationNodes);
2940
- orgLocationNodes.forEach((orgLocationNode) => {
2941
- if (orgLocationNode != null) {
2942
- const nodeRef = orgLocationNode['s-nr'];
2943
- let hostId = nodeRef['s-host-id'];
2944
- let nodeId = nodeRef['s-node-id'];
2945
- let childId = `${hostId}.${nodeId}`;
2946
- if (hostId == null) {
2947
- hostId = 0;
2948
- docData.rootLevelIds++;
2949
- nodeId = docData.rootLevelIds;
2950
- childId = `${hostId}.${nodeId}`;
2951
- if (nodeRef.nodeType === 1 /* NODE_TYPE.ElementNode */) {
2952
- nodeRef.setAttribute(HYDRATE_CHILD_ID, childId);
2953
- }
2954
- else if (nodeRef.nodeType === 3 /* NODE_TYPE.TextNode */) {
2955
- if (hostId === 0) {
2956
- const textContent = nodeRef.nodeValue.trim();
2957
- if (textContent === '') {
2958
- // useless whitespace node at the document root
2959
- orgLocationNode.remove();
2960
- return;
2961
- }
2962
- }
2963
- const commentBeforeTextNode = doc.createComment(childId);
2964
- commentBeforeTextNode.nodeValue = `${TEXT_NODE_ID}.${childId}`;
2965
- nodeRef.parentNode.insertBefore(commentBeforeTextNode, nodeRef);
2966
- }
2967
- }
2968
- let orgLocationNodeId = `${ORG_LOCATION_ID}.${childId}`;
2969
- const orgLocationParentNode = orgLocationNode.parentElement;
2970
- if (orgLocationParentNode) {
2971
- if (orgLocationParentNode['s-en'] === '') {
2972
- // ending with a "." means that the parent element
2973
- // of this node's original location is a SHADOW dom element
2974
- // and this node is apart of the root level light dom
2975
- orgLocationNodeId += `.`;
2976
- }
2977
- else if (orgLocationParentNode['s-en'] === 'c') {
2978
- // ending with a ".c" means that the parent element
2979
- // of this node's original location is a SCOPED element
2980
- // and this node is apart of the root level light dom
2981
- orgLocationNodeId += `.c`;
2982
- }
2983
- }
2984
- orgLocationNode.nodeValue = orgLocationNodeId;
2985
- }
2986
- });
2987
- }
2988
- };
2989
- const parseVNodeAnnotations = (doc, node, docData, orgLocationNodes) => {
2990
- if (node == null) {
2991
- return;
2992
- }
2993
- if (node['s-nr'] != null) {
2994
- orgLocationNodes.push(node);
2995
- }
2996
- if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
2997
- node.childNodes.forEach((childNode) => {
2998
- const hostRef = getHostRef(childNode);
2999
- if (hostRef != null && !docData.staticComponents.has(childNode.nodeName.toLowerCase())) {
3000
- const cmpData = {
3001
- nodeIds: 0,
3002
- };
3003
- insertVNodeAnnotations(doc, childNode, hostRef.$vnode$, docData, cmpData);
3004
- }
3005
- parseVNodeAnnotations(doc, childNode, docData, orgLocationNodes);
3006
- });
3007
- }
3008
- };
3009
- const insertVNodeAnnotations = (doc, hostElm, vnode, docData, cmpData) => {
3010
- if (vnode != null) {
3011
- const hostId = ++docData.hostIds;
3012
- hostElm.setAttribute(HYDRATE_ID, hostId);
3013
- if (hostElm['s-cr'] != null) {
3014
- hostElm['s-cr'].nodeValue = `${CONTENT_REF_ID}.${hostId}`;
3015
- }
3016
- if (vnode.$children$ != null) {
3017
- const depth = 0;
3018
- vnode.$children$.forEach((vnodeChild, index) => {
3019
- insertChildVNodeAnnotations(doc, vnodeChild, cmpData, hostId, depth, index);
3020
- });
3021
- }
3022
- if (hostElm && vnode && vnode.$elm$ && !hostElm.hasAttribute('c-id')) {
3023
- const parent = hostElm.parentElement;
3024
- if (parent && parent.childNodes) {
3025
- const parentChildNodes = Array.from(parent.childNodes);
3026
- const comment = parentChildNodes.find((node) => node.nodeType === 8 /* NODE_TYPE.CommentNode */ && node['s-sr']);
3027
- if (comment) {
3028
- const index = parentChildNodes.indexOf(hostElm) - 1;
3029
- vnode.$elm$.setAttribute(HYDRATE_CHILD_ID, `${comment['s-host-id']}.${comment['s-node-id']}.0.${index}`);
3030
- }
3031
- }
3032
- }
3033
- }
3034
- };
3035
- const insertChildVNodeAnnotations = (doc, vnodeChild, cmpData, hostId, depth, index) => {
3036
- const childElm = vnodeChild.$elm$;
3037
- if (childElm == null) {
3038
- return;
3039
- }
3040
- const nodeId = cmpData.nodeIds++;
3041
- const childId = `${hostId}.${nodeId}.${depth}.${index}`;
3042
- childElm['s-host-id'] = hostId;
3043
- childElm['s-node-id'] = nodeId;
3044
- if (childElm.nodeType === 1 /* NODE_TYPE.ElementNode */) {
3045
- childElm.setAttribute(HYDRATE_CHILD_ID, childId);
3046
- }
3047
- else if (childElm.nodeType === 3 /* NODE_TYPE.TextNode */) {
3048
- const parentNode = childElm.parentNode;
3049
- const nodeName = parentNode.nodeName;
3050
- if (nodeName !== 'STYLE' && nodeName !== 'SCRIPT') {
3051
- const textNodeId = `${TEXT_NODE_ID}.${childId}`;
3052
- const commentBeforeTextNode = doc.createComment(textNodeId);
3053
- parentNode.insertBefore(commentBeforeTextNode, childElm);
3054
- }
3055
- }
3056
- else if (childElm.nodeType === 8 /* NODE_TYPE.CommentNode */) {
3057
- if (childElm['s-sr']) {
3058
- const slotName = childElm['s-sn'] || '';
3059
- const slotNodeId = `${SLOT_NODE_ID}.${childId}.${slotName}`;
3060
- childElm.nodeValue = slotNodeId;
3061
- }
3062
- }
3063
- if (vnodeChild.$children$ != null) {
3064
- const childDepth = depth + 1;
3065
- vnodeChild.$children$.forEach((vnode, index) => {
3066
- insertChildVNodeAnnotations(doc, vnode, cmpData, hostId, childDepth, index);
3067
- });
3068
- }
3069
- };
3070
- const hostRefs = /*@__PURE__*/ new WeakMap();
3071
- const getHostRef = (ref) => hostRefs.get(ref);
3072
- const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
3073
- const registerHost = (elm, cmpMeta) => {
3074
- const hostRef = {
3075
- $flags$: 0,
3076
- $hostElement$: elm,
3077
- $cmpMeta$: cmpMeta,
3078
- $instanceValues$: new Map(),
3079
- };
3080
- if (BUILD.isDev) {
3081
- hostRef.$renderCount$ = 0;
3082
- }
3083
- if (BUILD.method && BUILD.lazyLoad) {
3084
- hostRef.$onInstancePromise$ = new Promise((r) => (hostRef.$onInstanceResolve$ = r));
3085
- }
3086
- if (BUILD.asyncLoading) {
3087
- hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
3088
- elm['s-p'] = [];
3089
- elm['s-rc'] = [];
3090
- }
3091
- addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
3092
- return hostRefs.set(elm, hostRef);
3093
- };
3094
- const isMemberInElement = (elm, memberName) => memberName in elm;
3095
- const consoleError = (e, el) => (customError || console.error)(e, el);
3096
- const STENCIL_DEV_MODE = BUILD.isTesting
3097
- ? ['STENCIL:'] // E2E testing
3098
- : [
3099
- '%cstencil',
3100
- 'color: white;background:#4c47ff;font-weight: bold; font-size:10px; padding:2px 6px; border-radius: 5px',
3101
- ];
3102
- const consoleDevError = (...m) => console.error(...STENCIL_DEV_MODE, ...m);
3103
- const consoleDevWarn = (...m) => console.warn(...STENCIL_DEV_MODE, ...m);
3104
- const consoleDevInfo = (...m) => console.info(...STENCIL_DEV_MODE, ...m);
3105
- const setErrorHandler = (handler) => (customError = handler);
3106
- const cmpModules = /*@__PURE__*/ new Map();
3107
- const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
3108
- // loadModuleImport
3109
- const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
3110
- const bundleId = cmpMeta.$lazyBundleId$;
3111
- if (BUILD.isDev && typeof bundleId !== 'string') {
3112
- consoleDevError(`Trying to lazily load component <${cmpMeta.$tagName$}> with style mode "${hostRef.$modeName$}", but it does not exist.`);
3113
- return undefined;
3114
- }
3115
- const module = !BUILD.hotModuleReplacement ? cmpModules.get(bundleId) : false;
3116
- if (module) {
3117
- return module[exportName];
3118
- }
3119
- /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
3120
- return import(
3121
- /* @vite-ignore */
3122
- /* webpackInclude: /\.entry\.js$/ */
3123
- /* webpackExclude: /\.system\.entry\.js$/ */
3124
- /* webpackMode: "lazy" */
3125
- `./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : ''}`).then((importedModule) => {
3126
- if (!BUILD.hotModuleReplacement) {
3127
- cmpModules.set(bundleId, importedModule);
3128
- }
3129
- return importedModule[exportName];
3130
- }, consoleError);
3131
- };
3132
- const styles = /*@__PURE__*/ new Map();
3133
- const modeResolutionChain = [];
3134
- const win = typeof window !== 'undefined' ? window : {};
3135
- const CSS = BUILD.cssVarShim ? win.CSS : null;
3136
- const doc = win.document || { head: {} };
3137
- const H = (win.HTMLElement || class {
3138
- });
3139
- const plt = {
3140
- $flags$: 0,
3141
- $resourcesUrl$: '',
3142
- jmp: (h) => h(),
3143
- raf: (h) => requestAnimationFrame(h),
3144
- ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
3145
- rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
3146
- ce: (eventName, opts) => new CustomEvent(eventName, opts),
3147
- };
3148
- const setPlatformHelpers = (helpers) => {
3149
- Object.assign(plt, helpers);
3150
- };
3151
- const supportsShadow = BUILD.shadowDomShim && BUILD.shadowDom
3152
- ? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)()
3153
- : true;
3154
- const supportsListenerOptions = /*@__PURE__*/ (() => {
3155
- let supportsListenerOptions = false;
3156
- try {
3157
- doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
3158
- get() {
3159
- supportsListenerOptions = true;
3160
- },
3161
- }));
3162
- }
3163
- catch (e) { }
3164
- return supportsListenerOptions;
3165
- })();
3166
- const promiseResolve = (v) => Promise.resolve(v);
3167
- const supportsConstructableStylesheets = BUILD.constructableCSS
3168
- ? /*@__PURE__*/ (() => {
3169
- try {
3170
- new CSSStyleSheet();
3171
- return typeof new CSSStyleSheet().replaceSync === 'function';
3172
- }
3173
- catch (e) { }
3174
- return false;
3175
- })()
3176
- : false;
3177
- const queueDomReads = [];
3178
- const queueDomWrites = [];
3179
- const queueDomWritesLow = [];
3180
- const queueTask = (queue, write) => (cb) => {
3181
- queue.push(cb);
3182
- if (!queuePending) {
3183
- queuePending = true;
3184
- if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
3185
- nextTick(flush);
3186
- }
3187
- else {
3188
- plt.raf(flush);
3189
- }
3190
- }
3191
- };
3192
- const consume = (queue) => {
3193
- for (let i = 0; i < queue.length; i++) {
3194
- try {
3195
- queue[i](performance.now());
3196
- }
3197
- catch (e) {
3198
- consoleError(e);
3199
- }
3200
- }
3201
- queue.length = 0;
3202
- };
3203
- const consumeTimeout = (queue, timeout) => {
3204
- let i = 0;
3205
- let ts = 0;
3206
- while (i < queue.length && (ts = performance.now()) < timeout) {
3207
- try {
3208
- queue[i++](ts);
3209
- }
3210
- catch (e) {
3211
- consoleError(e);
3212
- }
3213
- }
3214
- if (i === queue.length) {
3215
- queue.length = 0;
3216
- }
3217
- else if (i !== 0) {
3218
- queue.splice(0, i);
3219
- }
3220
- };
3221
- const flush = () => {
3222
- if (BUILD.asyncQueue) {
3223
- queueCongestion++;
3224
- }
3225
- // always force a bunch of medium callbacks to run, but still have
3226
- // a throttle on how many can run in a certain time
3227
- // DOM READS!!!
3228
- consume(queueDomReads);
3229
- // DOM WRITES!!!
3230
- if (BUILD.asyncQueue) {
3231
- const timeout = (plt.$flags$ & 6 /* PLATFORM_FLAGS.queueMask */) === 2 /* PLATFORM_FLAGS.appLoaded */
3232
- ? performance.now() + 14 * Math.ceil(queueCongestion * (1.0 / 10.0))
3233
- : Infinity;
3234
- consumeTimeout(queueDomWrites, timeout);
3235
- consumeTimeout(queueDomWritesLow, timeout);
3236
- if (queueDomWrites.length > 0) {
3237
- queueDomWritesLow.push(...queueDomWrites);
3238
- queueDomWrites.length = 0;
3239
- }
3240
- if ((queuePending = queueDomReads.length + queueDomWrites.length + queueDomWritesLow.length > 0)) {
3241
- // still more to do yet, but we've run out of time
3242
- // let's let this thing cool off and try again in the next tick
3243
- plt.raf(flush);
3244
- }
3245
- else {
3246
- queueCongestion = 0;
3247
- }
3248
- }
3249
- else {
3250
- consume(queueDomWrites);
3251
- if ((queuePending = queueDomReads.length > 0)) {
3252
- // still more to do yet, but we've run out of time
3253
- // let's let this thing cool off and try again in the next tick
3254
- plt.raf(flush);
3255
- }
3256
- }
3257
- };
3258
- const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
3259
- const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
3260
- const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
3261
-
3262
- export { BUILD as B, CSS as C, H, NAMESPACE as N, promiseResolve as a, bootstrapLazy as b, consoleDevInfo as c, doc as d, createEvent as e, Host as f, getElement as g, h, plt as p, registerInstance as r, win as w };