index.js 129 KB

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