index-b72adede.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  1. const NAMESPACE = 'ionicons';
  2. /**
  3. * Virtual DOM patching algorithm based on Snabbdom by
  4. * Simon Friis Vindum (@paldepind)
  5. * Licensed under the MIT License
  6. * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
  7. *
  8. * Modified for Stencil's renderer and slot projection
  9. */
  10. let scopeId;
  11. let hostTagName;
  12. let isSvgMode = false;
  13. let queuePending = false;
  14. const getAssetPath = (path) => {
  15. const assetUrl = new URL(path, plt.$resourcesUrl$);
  16. return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
  17. };
  18. const setAssetPath = (path) => (plt.$resourcesUrl$ = path);
  19. const createTime = (fnName, tagName = '') => {
  20. {
  21. return () => {
  22. return;
  23. };
  24. }
  25. };
  26. const uniqueTime = (key, measureText) => {
  27. {
  28. return () => {
  29. return;
  30. };
  31. }
  32. };
  33. const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
  34. const XLINK_NS = 'http://www.w3.org/1999/xlink';
  35. /**
  36. * Default style mode id
  37. */
  38. /**
  39. * Reusable empty obj/array
  40. * Don't add values to these!!
  41. */
  42. const EMPTY_OBJ = {};
  43. const isDef = (v) => v != null;
  44. /**
  45. * Check whether a value is a 'complex type', defined here as an object or a
  46. * function.
  47. *
  48. * @param o the value to check
  49. * @returns whether it's a complex type or not
  50. */
  51. const isComplexType = (o) => {
  52. // https://jsperf.com/typeof-fn-object/5
  53. o = typeof o;
  54. return o === 'object' || o === 'function';
  55. };
  56. /**
  57. * Helper method for querying a `meta` tag that contains a nonce value
  58. * out of a DOM's head.
  59. *
  60. * @param doc The DOM containing the `head` to query against
  61. * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
  62. * exists or the tag has no content.
  63. */
  64. function queryNonceMetaTagContent(doc) {
  65. var _a, _b, _c;
  66. return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
  67. }
  68. /**
  69. * Production h() function based on Preact by
  70. * Jason Miller (@developit)
  71. * Licensed under the MIT License
  72. * https://github.com/developit/preact/blob/master/LICENSE
  73. *
  74. * Modified for Stencil's compiler and vdom
  75. */
  76. // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
  77. // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
  78. const h = (nodeName, vnodeData, ...children) => {
  79. let child = null;
  80. let key = null;
  81. let simple = false;
  82. let lastSimple = false;
  83. const vNodeChildren = [];
  84. const walk = (c) => {
  85. for (let i = 0; i < c.length; i++) {
  86. child = c[i];
  87. if (Array.isArray(child)) {
  88. walk(child);
  89. }
  90. else if (child != null && typeof child !== 'boolean') {
  91. if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
  92. child = String(child);
  93. }
  94. if (simple && lastSimple) {
  95. // If the previous child was simple (string), we merge both
  96. vNodeChildren[vNodeChildren.length - 1].$text$ += child;
  97. }
  98. else {
  99. // Append a new vNode, if it's text, we create a text vNode
  100. vNodeChildren.push(simple ? newVNode(null, child) : child);
  101. }
  102. lastSimple = simple;
  103. }
  104. }
  105. };
  106. walk(children);
  107. if (vnodeData) {
  108. // normalize class / classname attributes
  109. if (vnodeData.key) {
  110. key = vnodeData.key;
  111. }
  112. {
  113. const classData = vnodeData.className || vnodeData.class;
  114. if (classData) {
  115. vnodeData.class =
  116. typeof classData !== 'object'
  117. ? classData
  118. : Object.keys(classData)
  119. .filter((k) => classData[k])
  120. .join(' ');
  121. }
  122. }
  123. }
  124. const vnode = newVNode(nodeName, null);
  125. vnode.$attrs$ = vnodeData;
  126. if (vNodeChildren.length > 0) {
  127. vnode.$children$ = vNodeChildren;
  128. }
  129. {
  130. vnode.$key$ = key;
  131. }
  132. return vnode;
  133. };
  134. /**
  135. * A utility function for creating a virtual DOM node from a tag and some
  136. * possible text content.
  137. *
  138. * @param tag the tag for this element
  139. * @param text possible text content for the node
  140. * @returns a newly-minted virtual DOM node
  141. */
  142. const newVNode = (tag, text) => {
  143. const vnode = {
  144. $flags$: 0,
  145. $tag$: tag,
  146. $text$: text,
  147. $elm$: null,
  148. $children$: null,
  149. };
  150. {
  151. vnode.$attrs$ = null;
  152. }
  153. {
  154. vnode.$key$ = null;
  155. }
  156. return vnode;
  157. };
  158. const Host = {};
  159. /**
  160. * Check whether a given node is a Host node or not
  161. *
  162. * @param node the virtual DOM node to check
  163. * @returns whether it's a Host node or not
  164. */
  165. const isHost = (node) => node && node.$tag$ === Host;
  166. /**
  167. * Parse a new property value for a given property type.
  168. *
  169. * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
  170. * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
  171. * 1. `any`, the type given to `propValue` in the function signature
  172. * 2. the type stored from `propType`.
  173. *
  174. * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
  175. *
  176. * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
  177. * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
  178. * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
  179. * ```tsx
  180. * <my-cmp prop-val={0}></my-cmp>
  181. * ```
  182. *
  183. * HTML prop values on the other hand, will always a string
  184. *
  185. * @param propValue the new value to coerce to some type
  186. * @param propType the type of the prop, expressed as a binary number
  187. * @returns the parsed/coerced value
  188. */
  189. const parsePropertyValue = (propValue, propType) => {
  190. // ensure this value is of the correct prop type
  191. if (propValue != null && !isComplexType(propValue)) {
  192. if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
  193. // per the HTML spec, any string value means it is a boolean true value
  194. // but we'll cheat here and say that the string "false" is the boolean false
  195. return propValue === 'false' ? false : propValue === '' || !!propValue;
  196. }
  197. if (propType & 1 /* MEMBER_FLAGS.String */) {
  198. // could have been passed as a number or boolean
  199. // but we still want it as a string
  200. return String(propValue);
  201. }
  202. // redundant return here for better minification
  203. return propValue;
  204. }
  205. // not sure exactly what type we want
  206. // so no need to change to a different type
  207. return propValue;
  208. };
  209. const getElement = (ref) => (getHostRef(ref).$hostElement$ );
  210. /**
  211. * Helper function to create & dispatch a custom Event on a provided target
  212. * @param elm the target of the Event
  213. * @param name the name to give the custom Event
  214. * @param opts options for configuring a custom Event
  215. * @returns the custom Event
  216. */
  217. const emitEvent = (elm, name, opts) => {
  218. const ev = plt.ce(name, opts);
  219. elm.dispatchEvent(ev);
  220. return ev;
  221. };
  222. const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
  223. const registerStyle = (scopeId, cssText, allowCS) => {
  224. let style = styles.get(scopeId);
  225. if (supportsConstructableStylesheets && allowCS) {
  226. style = (style || new CSSStyleSheet());
  227. if (typeof style === 'string') {
  228. style = cssText;
  229. }
  230. else {
  231. style.replaceSync(cssText);
  232. }
  233. }
  234. else {
  235. style = cssText;
  236. }
  237. styles.set(scopeId, style);
  238. };
  239. const addStyle = (styleContainerNode, cmpMeta, mode) => {
  240. var _a;
  241. const scopeId = getScopeId(cmpMeta);
  242. const style = styles.get(scopeId);
  243. // if an element is NOT connected then getRootNode() will return the wrong root node
  244. // so the fallback is to always use the document for the root node in those cases
  245. styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
  246. if (style) {
  247. if (typeof style === 'string') {
  248. styleContainerNode = styleContainerNode.head || styleContainerNode;
  249. let appliedStyles = rootAppliedStyles.get(styleContainerNode);
  250. let styleElm;
  251. if (!appliedStyles) {
  252. rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
  253. }
  254. if (!appliedStyles.has(scopeId)) {
  255. {
  256. styleElm = doc.createElement('style');
  257. styleElm.innerHTML = style;
  258. // Apply CSP nonce to the style tag if it exists
  259. const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
  260. if (nonce != null) {
  261. styleElm.setAttribute('nonce', nonce);
  262. }
  263. styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
  264. }
  265. if (appliedStyles) {
  266. appliedStyles.add(scopeId);
  267. }
  268. }
  269. }
  270. else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
  271. styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
  272. }
  273. }
  274. return scopeId;
  275. };
  276. const attachStyles = (hostRef) => {
  277. const cmpMeta = hostRef.$cmpMeta$;
  278. const elm = hostRef.$hostElement$;
  279. const flags = cmpMeta.$flags$;
  280. const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
  281. const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
  282. if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
  283. // only required when we're NOT using native shadow dom (slot)
  284. // or this browser doesn't support native shadow dom
  285. // and this host element was NOT created with SSR
  286. // let's pick out the inner content for slot projection
  287. // create a node to represent where the original
  288. // content was first placed, which is useful later on
  289. // DOM WRITE!!
  290. elm['s-sc'] = scopeId;
  291. elm.classList.add(scopeId + '-h');
  292. }
  293. endAttachStyles();
  294. };
  295. const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
  296. /**
  297. * Production setAccessor() function based on Preact by
  298. * Jason Miller (@developit)
  299. * Licensed under the MIT License
  300. * https://github.com/developit/preact/blob/master/LICENSE
  301. *
  302. * Modified for Stencil's compiler and vdom
  303. */
  304. /**
  305. * When running a VDom render set properties present on a VDom node onto the
  306. * corresponding HTML element.
  307. *
  308. * Note that this function has special functionality for the `class`,
  309. * `style`, `key`, and `ref` attributes, as well as event handlers (like
  310. * `onClick`, etc). All others are just passed through as-is.
  311. *
  312. * @param elm the HTMLElement onto which attributes should be set
  313. * @param memberName the name of the attribute to set
  314. * @param oldValue the old value for the attribute
  315. * @param newValue the new value for the attribute
  316. * @param isSvg whether we're in an svg context or not
  317. * @param flags bitflags for Vdom variables
  318. */
  319. const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
  320. if (oldValue !== newValue) {
  321. let isProp = isMemberInElement(elm, memberName);
  322. let ln = memberName.toLowerCase();
  323. if (memberName === 'class') {
  324. const classList = elm.classList;
  325. const oldClasses = parseClassList(oldValue);
  326. const newClasses = parseClassList(newValue);
  327. classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
  328. classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
  329. }
  330. else if (memberName === 'style') {
  331. // update style attribute, css properties and values
  332. {
  333. for (const prop in oldValue) {
  334. if (!newValue || newValue[prop] == null) {
  335. if (prop.includes('-')) {
  336. elm.style.removeProperty(prop);
  337. }
  338. else {
  339. elm.style[prop] = '';
  340. }
  341. }
  342. }
  343. }
  344. for (const prop in newValue) {
  345. if (!oldValue || newValue[prop] !== oldValue[prop]) {
  346. if (prop.includes('-')) {
  347. elm.style.setProperty(prop, newValue[prop]);
  348. }
  349. else {
  350. elm.style[prop] = newValue[prop];
  351. }
  352. }
  353. }
  354. }
  355. else if (memberName === 'key')
  356. ;
  357. else if (memberName === 'ref') {
  358. // minifier will clean this up
  359. if (newValue) {
  360. newValue(elm);
  361. }
  362. }
  363. else if ((!isProp ) &&
  364. memberName[0] === 'o' &&
  365. memberName[1] === 'n') {
  366. // Event Handlers
  367. // so if the member name starts with "on" and the 3rd characters is
  368. // a capital letter, and it's not already a member on the element,
  369. // then we're assuming it's an event listener
  370. if (memberName[2] === '-') {
  371. // on- prefixed events
  372. // allows to be explicit about the dom event to listen without any magic
  373. // under the hood:
  374. // <my-cmp on-click> // listens for "click"
  375. // <my-cmp on-Click> // listens for "Click"
  376. // <my-cmp on-ionChange> // listens for "ionChange"
  377. // <my-cmp on-EVENTS> // listens for "EVENTS"
  378. memberName = memberName.slice(3);
  379. }
  380. else if (isMemberInElement(win, ln)) {
  381. // standard event
  382. // the JSX attribute could have been "onMouseOver" and the
  383. // member name "onmouseover" is on the window's prototype
  384. // so let's add the listener "mouseover", which is all lowercased
  385. memberName = ln.slice(2);
  386. }
  387. else {
  388. // custom event
  389. // the JSX attribute could have been "onMyCustomEvent"
  390. // so let's trim off the "on" prefix and lowercase the first character
  391. // and add the listener "myCustomEvent"
  392. // except for the first character, we keep the event name case
  393. memberName = ln[2] + memberName.slice(3);
  394. }
  395. if (oldValue) {
  396. plt.rel(elm, memberName, oldValue, false);
  397. }
  398. if (newValue) {
  399. plt.ael(elm, memberName, newValue, false);
  400. }
  401. }
  402. else {
  403. // Set property if it exists and it's not a SVG
  404. const isComplex = isComplexType(newValue);
  405. if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
  406. try {
  407. if (!elm.tagName.includes('-')) {
  408. const n = newValue == null ? '' : newValue;
  409. // Workaround for Safari, moving the <input> caret when re-assigning the same valued
  410. if (memberName === 'list') {
  411. isProp = false;
  412. }
  413. else if (oldValue == null || elm[memberName] != n) {
  414. elm[memberName] = n;
  415. }
  416. }
  417. else {
  418. elm[memberName] = newValue;
  419. }
  420. }
  421. catch (e) { }
  422. }
  423. /**
  424. * Need to manually update attribute if:
  425. * - memberName is not an attribute
  426. * - if we are rendering the host element in order to reflect attribute
  427. * - if it's a SVG, since properties might not work in <svg>
  428. * - if the newValue is null/undefined or 'false'.
  429. */
  430. let xlink = false;
  431. {
  432. if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
  433. memberName = ln;
  434. xlink = true;
  435. }
  436. }
  437. if (newValue == null || newValue === false) {
  438. if (newValue !== false || elm.getAttribute(memberName) === '') {
  439. if (xlink) {
  440. elm.removeAttributeNS(XLINK_NS, memberName);
  441. }
  442. else {
  443. elm.removeAttribute(memberName);
  444. }
  445. }
  446. }
  447. else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
  448. newValue = newValue === true ? '' : newValue;
  449. if (xlink) {
  450. elm.setAttributeNS(XLINK_NS, memberName, newValue);
  451. }
  452. else {
  453. elm.setAttribute(memberName, newValue);
  454. }
  455. }
  456. }
  457. }
  458. };
  459. const parseClassListRegex = /\s/;
  460. const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
  461. const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
  462. // if the element passed in is a shadow root, which is a document fragment
  463. // then we want to be adding attrs/props to the shadow root's "host" element
  464. // if it's not a shadow root, then we add attrs/props to the same element
  465. const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
  466. ? newVnode.$elm$.host
  467. : newVnode.$elm$;
  468. const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
  469. const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
  470. {
  471. // remove attributes no longer present on the vnode by setting them to undefined
  472. for (memberName in oldVnodeAttrs) {
  473. if (!(memberName in newVnodeAttrs)) {
  474. setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
  475. }
  476. }
  477. }
  478. // add new & update changed attributes
  479. for (memberName in newVnodeAttrs) {
  480. setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
  481. }
  482. };
  483. /**
  484. * Create a DOM Node corresponding to one of the children of a given VNode.
  485. *
  486. * @param oldParentVNode the parent VNode from the previous render
  487. * @param newParentVNode the parent VNode from the current render
  488. * @param childIndex the index of the VNode, in the _new_ parent node's
  489. * children, for which we will create a new DOM node
  490. * @param parentElm the parent DOM node which our new node will be a child of
  491. * @returns the newly created node
  492. */
  493. const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
  494. // tslint:disable-next-line: prefer-const
  495. const newVNode = newParentVNode.$children$[childIndex];
  496. let i = 0;
  497. let elm;
  498. let childNode;
  499. if (newVNode.$text$ !== null) {
  500. // create text node
  501. elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
  502. }
  503. else {
  504. // create element
  505. elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
  506. // add css classes, attrs, props, listeners, etc.
  507. {
  508. updateElement(null, newVNode, isSvgMode);
  509. }
  510. if (isDef(scopeId) && elm['s-si'] !== scopeId) {
  511. // if there is a scopeId and this is the initial render
  512. // then let's add the scopeId as a css class
  513. elm.classList.add((elm['s-si'] = scopeId));
  514. }
  515. if (newVNode.$children$) {
  516. for (i = 0; i < newVNode.$children$.length; ++i) {
  517. // create the node
  518. childNode = createElm(oldParentVNode, newVNode, i);
  519. // return node could have been null
  520. if (childNode) {
  521. // append our new node
  522. elm.appendChild(childNode);
  523. }
  524. }
  525. }
  526. }
  527. return elm;
  528. };
  529. /**
  530. * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
  531. * add them to the DOM in the appropriate place.
  532. *
  533. * @param parentElm the DOM node which should be used as a parent for the new
  534. * DOM nodes
  535. * @param before a child of the `parentElm` which the new children should be
  536. * inserted before (optional)
  537. * @param parentVNode the parent virtual DOM node
  538. * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
  539. * @param startIdx the index in the child virtual DOM nodes at which to start
  540. * creating DOM nodes (inclusive)
  541. * @param endIdx the index in the child virtual DOM nodes at which to stop
  542. * creating DOM nodes (inclusive)
  543. */
  544. const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
  545. let containerElm = (parentElm);
  546. let childNode;
  547. if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
  548. containerElm = containerElm.shadowRoot;
  549. }
  550. for (; startIdx <= endIdx; ++startIdx) {
  551. if (vnodes[startIdx]) {
  552. childNode = createElm(null, parentVNode, startIdx);
  553. if (childNode) {
  554. vnodes[startIdx].$elm$ = childNode;
  555. containerElm.insertBefore(childNode, before);
  556. }
  557. }
  558. }
  559. };
  560. /**
  561. * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
  562. * This can be used to, for instance, clean up after a list of children which
  563. * should no longer be shown.
  564. *
  565. * This function also handles some of Stencil's slot relocation logic.
  566. *
  567. * @param vnodes a list of virtual DOM nodes to remove
  568. * @param startIdx the index at which to start removing nodes (inclusive)
  569. * @param endIdx the index at which to stop removing nodes (inclusive)
  570. */
  571. const removeVnodes = (vnodes, startIdx, endIdx) => {
  572. for (let index = startIdx; index <= endIdx; ++index) {
  573. const vnode = vnodes[index];
  574. if (vnode) {
  575. const elm = vnode.$elm$;
  576. nullifyVNodeRefs(vnode);
  577. if (elm) {
  578. // remove the vnode's element from the dom
  579. elm.remove();
  580. }
  581. }
  582. }
  583. };
  584. /**
  585. * Reconcile the children of a new VNode with the children of an old VNode by
  586. * traversing the two collections of children, identifying nodes that are
  587. * conserved or changed, calling out to `patch` to make any necessary
  588. * updates to the DOM, and rearranging DOM nodes as needed.
  589. *
  590. * The algorithm for reconciling children works by analyzing two 'windows' onto
  591. * the two arrays of children (`oldCh` and `newCh`). We keep track of the
  592. * 'windows' by storing start and end indices and references to the
  593. * corresponding array entries. Initially the two 'windows' are basically equal
  594. * to the entire array, but we progressively narrow the windows until there are
  595. * no children left to update by doing the following:
  596. *
  597. * 1. Skip any `null` entries at the beginning or end of the two arrays, so
  598. * that if we have an initial array like the following we'll end up dealing
  599. * only with a window bounded by the highlighted elements:
  600. *
  601. * [null, null, VNode1 , ... , VNode2, null, null]
  602. * ^^^^^^ ^^^^^^
  603. *
  604. * 2. Check to see if the elements at the head and tail positions are equal
  605. * across the windows. This will basically detect elements which haven't
  606. * been added, removed, or changed position, i.e. if you had the following
  607. * VNode elements (represented as HTML):
  608. *
  609. * oldVNode: `<div><p><span>HEY</span></p></div>`
  610. * newVNode: `<div><p><span>THERE</span></p></div>`
  611. *
  612. * Then when comparing the children of the `<div>` tag we check the equality
  613. * of the VNodes corresponding to the `<p>` tags and, since they are the
  614. * same tag in the same position, we'd be able to avoid completely
  615. * re-rendering the subtree under them with a new DOM element and would just
  616. * call out to `patch` to handle reconciling their children and so on.
  617. *
  618. * 3. Check, for both windows, to see if the element at the beginning of the
  619. * window corresponds to the element at the end of the other window. This is
  620. * a heuristic which will let us identify _some_ situations in which
  621. * elements have changed position, for instance it _should_ detect that the
  622. * children nodes themselves have not changed but merely moved in the
  623. * following example:
  624. *
  625. * oldVNode: `<div><element-one /><element-two /></div>`
  626. * newVNode: `<div><element-two /><element-one /></div>`
  627. *
  628. * If we find cases like this then we also need to move the concrete DOM
  629. * elements corresponding to the moved children to write the re-order to the
  630. * DOM.
  631. *
  632. * 4. Finally, if VNodes have the `key` attribute set on them we check for any
  633. * nodes in the old children which have the same key as the first element in
  634. * our window on the new children. If we find such a node we handle calling
  635. * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
  636. * what we find.
  637. *
  638. * Finally, once we've narrowed our 'windows' to the point that either of them
  639. * collapse (i.e. they have length 0) we then handle any remaining VNode
  640. * insertion or deletion that needs to happen to get a DOM state that correctly
  641. * reflects the new child VNodes. If, for instance, after our window on the old
  642. * children has collapsed we still have more nodes on the new children that
  643. * we haven't dealt with yet then we need to add them, or if the new children
  644. * collapse but we still have unhandled _old_ children then we need to make
  645. * sure the corresponding DOM nodes are removed.
  646. *
  647. * @param parentElm the node into which the parent VNode is rendered
  648. * @param oldCh the old children of the parent node
  649. * @param newVNode the new VNode which will replace the parent
  650. * @param newCh the new children of the parent node
  651. */
  652. const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
  653. let oldStartIdx = 0;
  654. let newStartIdx = 0;
  655. let idxInOld = 0;
  656. let i = 0;
  657. let oldEndIdx = oldCh.length - 1;
  658. let oldStartVnode = oldCh[0];
  659. let oldEndVnode = oldCh[oldEndIdx];
  660. let newEndIdx = newCh.length - 1;
  661. let newStartVnode = newCh[0];
  662. let newEndVnode = newCh[newEndIdx];
  663. let node;
  664. let elmToMove;
  665. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  666. if (oldStartVnode == null) {
  667. // VNode might have been moved left
  668. oldStartVnode = oldCh[++oldStartIdx];
  669. }
  670. else if (oldEndVnode == null) {
  671. oldEndVnode = oldCh[--oldEndIdx];
  672. }
  673. else if (newStartVnode == null) {
  674. newStartVnode = newCh[++newStartIdx];
  675. }
  676. else if (newEndVnode == null) {
  677. newEndVnode = newCh[--newEndIdx];
  678. }
  679. else if (isSameVnode(oldStartVnode, newStartVnode)) {
  680. // if the start nodes are the same then we should patch the new VNode
  681. // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
  682. // indices to reflect that. We don't need to move any DOM Nodes around
  683. // since things are matched up in order.
  684. patch(oldStartVnode, newStartVnode);
  685. oldStartVnode = oldCh[++oldStartIdx];
  686. newStartVnode = newCh[++newStartIdx];
  687. }
  688. else if (isSameVnode(oldEndVnode, newEndVnode)) {
  689. // likewise, if the end nodes are the same we patch new onto old and
  690. // decrement our end indices, and also likewise in this case we don't
  691. // need to move any DOM Nodes.
  692. patch(oldEndVnode, newEndVnode);
  693. oldEndVnode = oldCh[--oldEndIdx];
  694. newEndVnode = newCh[--newEndIdx];
  695. }
  696. else if (isSameVnode(oldStartVnode, newEndVnode)) {
  697. patch(oldStartVnode, newEndVnode);
  698. // We need to move the element for `oldStartVnode` into a position which
  699. // will be appropriate for `newEndVnode`. For this we can use
  700. // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
  701. // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
  702. // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
  703. //
  704. // <old-start-node />
  705. // <some-intervening-node />
  706. // <old-end-node />
  707. // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
  708. // <next-sibling />
  709. //
  710. // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
  711. // the node for `oldStartVnode` at the end of the children of
  712. // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
  713. // aren't any siblings, and passing `null` to `Node.insertBefore` will
  714. // append it to the children of the parent element.
  715. parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
  716. oldStartVnode = oldCh[++oldStartIdx];
  717. newEndVnode = newCh[--newEndIdx];
  718. }
  719. else if (isSameVnode(oldEndVnode, newStartVnode)) {
  720. patch(oldEndVnode, newStartVnode);
  721. // We've already checked above if `oldStartVnode` and `newStartVnode` are
  722. // the same node, so since we're here we know that they are not. Thus we
  723. // can move the element for `oldEndVnode` _before_ the element for
  724. // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
  725. // future.
  726. parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
  727. oldEndVnode = oldCh[--oldEndIdx];
  728. newStartVnode = newCh[++newStartIdx];
  729. }
  730. else {
  731. // Here we do some checks to match up old and new nodes based on the
  732. // `$key$` attribute, which is set by putting a `key="my-key"` attribute
  733. // in the JSX for a DOM element in the implementation of a Stencil
  734. // component.
  735. //
  736. // First we check to see if there are any nodes in the array of old
  737. // children which have the same key as the first node in the new
  738. // children.
  739. idxInOld = -1;
  740. {
  741. for (i = oldStartIdx; i <= oldEndIdx; ++i) {
  742. if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
  743. idxInOld = i;
  744. break;
  745. }
  746. }
  747. }
  748. if (idxInOld >= 0) {
  749. // We found a node in the old children which matches up with the first
  750. // node in the new children! So let's deal with that
  751. elmToMove = oldCh[idxInOld];
  752. if (elmToMove.$tag$ !== newStartVnode.$tag$) {
  753. // the tag doesn't match so we'll need a new DOM element
  754. node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
  755. }
  756. else {
  757. patch(elmToMove, newStartVnode);
  758. // invalidate the matching old node so that we won't try to update it
  759. // again later on
  760. oldCh[idxInOld] = undefined;
  761. node = elmToMove.$elm$;
  762. }
  763. newStartVnode = newCh[++newStartIdx];
  764. }
  765. else {
  766. // We either didn't find an element in the old children that matches
  767. // the key of the first new child OR the build is not using `key`
  768. // attributes at all. In either case we need to create a new element
  769. // for the new node.
  770. node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
  771. newStartVnode = newCh[++newStartIdx];
  772. }
  773. if (node) {
  774. // if we created a new node then handle inserting it to the DOM
  775. {
  776. oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
  777. }
  778. }
  779. }
  780. }
  781. if (oldStartIdx > oldEndIdx) {
  782. // we have some more new nodes to add which don't match up with old nodes
  783. addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
  784. }
  785. else if (newStartIdx > newEndIdx) {
  786. // there are nodes in the `oldCh` array which no longer correspond to nodes
  787. // in the new array, so lets remove them (which entails cleaning up the
  788. // relevant DOM nodes)
  789. removeVnodes(oldCh, oldStartIdx, oldEndIdx);
  790. }
  791. };
  792. /**
  793. * Compare two VNodes to determine if they are the same
  794. *
  795. * **NB**: This function is an equality _heuristic_ based on the available
  796. * information set on the two VNodes and can be misleading under certain
  797. * circumstances. In particular, if the two nodes do not have `key` attrs
  798. * (available under `$key$` on VNodes) then the function falls back on merely
  799. * checking that they have the same tag.
  800. *
  801. * So, in other words, if `key` attrs are not set on VNodes which may be
  802. * changing order within a `children` array or something along those lines then
  803. * we could obtain a false negative and then have to do needless re-rendering
  804. * (i.e. we'd say two VNodes aren't equal when in fact they should be).
  805. *
  806. * @param leftVNode the first VNode to check
  807. * @param rightVNode the second VNode to check
  808. * @returns whether they're equal or not
  809. */
  810. const isSameVnode = (leftVNode, rightVNode) => {
  811. // compare if two vnode to see if they're "technically" the same
  812. // need to have the same element tag, and same key to be the same
  813. if (leftVNode.$tag$ === rightVNode.$tag$) {
  814. // this will be set if components in the build have `key` attrs set on them
  815. {
  816. return leftVNode.$key$ === rightVNode.$key$;
  817. }
  818. }
  819. return false;
  820. };
  821. /**
  822. * Handle reconciling an outdated VNode with a new one which corresponds to
  823. * it. This function handles flushing updates to the DOM and reconciling the
  824. * children of the two nodes (if any).
  825. *
  826. * @param oldVNode an old VNode whose DOM element and children we want to update
  827. * @param newVNode a new VNode representing an updated version of the old one
  828. */
  829. const patch = (oldVNode, newVNode) => {
  830. const elm = (newVNode.$elm$ = oldVNode.$elm$);
  831. const oldChildren = oldVNode.$children$;
  832. const newChildren = newVNode.$children$;
  833. const text = newVNode.$text$;
  834. if (text === null) {
  835. {
  836. {
  837. // either this is the first render of an element OR it's an update
  838. // AND we already know it's possible it could have changed
  839. // this updates the element's css classes, attrs, props, listeners, etc.
  840. updateElement(oldVNode, newVNode, isSvgMode);
  841. }
  842. }
  843. if (oldChildren !== null && newChildren !== null) {
  844. // looks like there's child vnodes for both the old and new vnodes
  845. // so we need to call `updateChildren` to reconcile them
  846. updateChildren(elm, oldChildren, newVNode, newChildren);
  847. }
  848. else if (newChildren !== null) {
  849. // no old child vnodes, but there are new child vnodes to add
  850. if (oldVNode.$text$ !== null) {
  851. // the old vnode was text, so be sure to clear it out
  852. elm.textContent = '';
  853. }
  854. // add the new vnode children
  855. addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
  856. }
  857. else if (oldChildren !== null) {
  858. // no new child vnodes, but there are old child vnodes to remove
  859. removeVnodes(oldChildren, 0, oldChildren.length - 1);
  860. }
  861. }
  862. else if (oldVNode.$text$ !== text) {
  863. // update the text content for the text only vnode
  864. // and also only if the text is different than before
  865. elm.data = text;
  866. }
  867. };
  868. /**
  869. * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by
  870. * calling them with `null`. This signals that the DOM element corresponding to
  871. * the VDom node has been removed from the DOM.
  872. *
  873. * @param vNode a virtual DOM node
  874. */
  875. const nullifyVNodeRefs = (vNode) => {
  876. {
  877. vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
  878. vNode.$children$ && vNode.$children$.map(nullifyVNodeRefs);
  879. }
  880. };
  881. /**
  882. * The main entry point for Stencil's virtual DOM-based rendering engine
  883. *
  884. * Given a {@link d.HostRef} container and some virtual DOM nodes, this
  885. * function will handle creating a virtual DOM tree with a single root, patching
  886. * the current virtual DOM tree onto an old one (if any), dealing with slot
  887. * relocation, and reflecting attributes.
  888. *
  889. * @param hostRef data needed to root and render the virtual DOM tree, such as
  890. * the DOM node into which it should be rendered.
  891. * @param renderFnResults the virtual DOM nodes to be rendered
  892. * @param isInitialLoad whether or not this is the first call after page load
  893. */
  894. const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
  895. const hostElm = hostRef.$hostElement$;
  896. const cmpMeta = hostRef.$cmpMeta$;
  897. const oldVNode = hostRef.$vnode$ || newVNode(null, null);
  898. // if `renderFnResults` is a Host node then we can use it directly. If not,
  899. // we need to call `h` again to wrap the children of our component in a
  900. // 'dummy' Host node (well, an empty vnode) since `renderVdom` assumes
  901. // implicitly that the top-level vdom node is 1) an only child and 2)
  902. // contains attrs that need to be set on the host element.
  903. const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
  904. hostTagName = hostElm.tagName;
  905. if (cmpMeta.$attrsToReflect$) {
  906. rootVnode.$attrs$ = rootVnode.$attrs$ || {};
  907. cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
  908. }
  909. // On the first render and *only* on the first render we want to check for
  910. // any attributes set on the host element which are also set on the vdom
  911. // node. If we find them, we override the value on the VDom node attrs with
  912. // the value from the host element, which allows developers building apps
  913. // with Stencil components to override e.g. the `role` attribute on a
  914. // component even if it's already set on the `Host`.
  915. if (isInitialLoad && rootVnode.$attrs$) {
  916. for (const key of Object.keys(rootVnode.$attrs$)) {
  917. // We have a special implementation in `setAccessor` for `style` and
  918. // `class` which reconciles values coming from the VDom with values
  919. // already present on the DOM element, so we don't want to override those
  920. // attributes on the VDom tree with values from the host element if they
  921. // are present.
  922. //
  923. // Likewise, `ref` and `key` are special internal values for the Stencil
  924. // runtime and we don't want to override those either.
  925. if (hostElm.hasAttribute(key) && !['key', 'ref', 'style', 'class'].includes(key)) {
  926. rootVnode.$attrs$[key] = hostElm[key];
  927. }
  928. }
  929. }
  930. rootVnode.$tag$ = null;
  931. rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
  932. hostRef.$vnode$ = rootVnode;
  933. rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
  934. {
  935. scopeId = hostElm['s-sc'];
  936. }
  937. // synchronous patch
  938. patch(oldVNode, rootVnode);
  939. };
  940. const attachToAncestor = (hostRef, ancestorComponent) => {
  941. if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
  942. ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
  943. }
  944. };
  945. const scheduleUpdate = (hostRef, isInitialLoad) => {
  946. {
  947. hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
  948. }
  949. if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
  950. hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
  951. return;
  952. }
  953. attachToAncestor(hostRef, hostRef.$ancestorComponent$);
  954. // there is no ancestor component or the ancestor component
  955. // has already fired off its lifecycle update then
  956. // fire off the initial update
  957. const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
  958. return writeTask(dispatch) ;
  959. };
  960. /**
  961. * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
  962. * component lifecycle methods like `componentWillLoad` as well as
  963. * {@link updateComponent}, which will kick off the virtual DOM re-render.
  964. *
  965. * @param hostRef a reference to a host DOM node
  966. * @param isInitialLoad whether we're on the initial load or not
  967. * @returns an empty Promise which is used to enqueue a series of operations for
  968. * the component
  969. */
  970. const dispatchHooks = (hostRef, isInitialLoad) => {
  971. const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
  972. const instance = hostRef.$lazyInstance$ ;
  973. // We're going to use this variable together with `enqueue` to implement a
  974. // little promise-based queue. We start out with it `undefined`. When we add
  975. // the first function to the queue we'll set this variable to be that
  976. // function's return value. When we attempt to add subsequent values to the
  977. // queue we'll check that value and, if it was a `Promise`, we'll then chain
  978. // the new function off of that `Promise` using `.then()`. This will give our
  979. // queue two nice properties:
  980. //
  981. // 1. If all functions added to the queue are synchronous they'll be called
  982. // synchronously right away.
  983. // 2. If all functions added to the queue are asynchronous they'll all be
  984. // called in order after `dispatchHooks` exits.
  985. let maybePromise;
  986. if (isInitialLoad) {
  987. {
  988. // If `componentWillLoad` returns a `Promise` then we want to wait on
  989. // whatever's going on in that `Promise` before we launch into
  990. // rendering the component, doing other lifecycle stuff, etc. So
  991. // in that case we assign the returned promise to the variable we
  992. // declared above to hold a possible 'queueing' Promise
  993. maybePromise = safeCall(instance, 'componentWillLoad');
  994. }
  995. }
  996. endSchedule();
  997. return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
  998. };
  999. /**
  1000. * This function uses a Promise to implement a simple first-in, first-out queue
  1001. * of functions to be called.
  1002. *
  1003. * The queue is ordered on the basis of the first argument. If it's
  1004. * `undefined`, then nothing is on the queue yet, so the provided function can
  1005. * be called synchronously (although note that this function may return a
  1006. * `Promise`). The idea is that then the return value of that enqueueing
  1007. * operation is kept around, so that if it was a `Promise` then subsequent
  1008. * functions can be enqueued by calling this function again with that `Promise`
  1009. * as the first argument.
  1010. *
  1011. * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
  1012. * @param fn a function to enqueue
  1013. * @returns either a `Promise` or the return value of the provided function
  1014. */
  1015. const enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
  1016. /**
  1017. * Check that a value is a `Promise`. To check, we first see if the value is an
  1018. * instance of the `Promise` global. In a few circumstances, in particular if
  1019. * the global has been overwritten, this is could be misleading, so we also do
  1020. * a little 'duck typing' check to see if the `.then` property of the value is
  1021. * defined and a function.
  1022. *
  1023. * @param maybePromise it might be a promise!
  1024. * @returns whether it is or not
  1025. */
  1026. const isPromisey = (maybePromise) => maybePromise instanceof Promise ||
  1027. (maybePromise && maybePromise.then && typeof maybePromise.then === 'function');
  1028. /**
  1029. * Update a component given reference to its host elements and so on.
  1030. *
  1031. * @param hostRef an object containing references to the element's host node,
  1032. * VDom nodes, and other metadata
  1033. * @param instance a reference to the underlying host element where it will be
  1034. * rendered
  1035. * @param isInitialLoad whether or not this function is being called as part of
  1036. * the first render cycle
  1037. */
  1038. const updateComponent = async (hostRef, instance, isInitialLoad) => {
  1039. var _a;
  1040. const elm = hostRef.$hostElement$;
  1041. const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
  1042. const rc = elm['s-rc'];
  1043. if (isInitialLoad) {
  1044. // DOM WRITE!
  1045. attachStyles(hostRef);
  1046. }
  1047. const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
  1048. {
  1049. callRender(hostRef, instance, elm, isInitialLoad);
  1050. }
  1051. if (rc) {
  1052. // ok, so turns out there are some child host elements
  1053. // waiting on this parent element to load
  1054. // let's fire off all update callbacks waiting
  1055. rc.map((cb) => cb());
  1056. elm['s-rc'] = undefined;
  1057. }
  1058. endRender();
  1059. endUpdate();
  1060. {
  1061. const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
  1062. const postUpdate = () => postUpdateComponent(hostRef);
  1063. if (childrenPromises.length === 0) {
  1064. postUpdate();
  1065. }
  1066. else {
  1067. Promise.all(childrenPromises).then(postUpdate);
  1068. hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
  1069. childrenPromises.length = 0;
  1070. }
  1071. }
  1072. };
  1073. /**
  1074. * Handle making the call to the VDom renderer with the proper context given
  1075. * various build variables
  1076. *
  1077. * @param hostRef an object containing references to the element's host node,
  1078. * VDom nodes, and other metadata
  1079. * @param instance a reference to the underlying host element where it will be
  1080. * rendered
  1081. * @param elm the Host element for the component
  1082. * @param isInitialLoad whether or not this function is being called as part of
  1083. * @returns an empty promise
  1084. */
  1085. const callRender = (hostRef, instance, elm, isInitialLoad) => {
  1086. try {
  1087. instance = instance.render() ;
  1088. {
  1089. hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
  1090. }
  1091. {
  1092. hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
  1093. }
  1094. {
  1095. {
  1096. // looks like we've got child nodes to render into this host element
  1097. // or we need to update the css class/attrs on the host element
  1098. // DOM WRITE!
  1099. {
  1100. renderVdom(hostRef, instance, isInitialLoad);
  1101. }
  1102. }
  1103. }
  1104. }
  1105. catch (e) {
  1106. consoleError(e, hostRef.$hostElement$);
  1107. }
  1108. return null;
  1109. };
  1110. const postUpdateComponent = (hostRef) => {
  1111. const tagName = hostRef.$cmpMeta$.$tagName$;
  1112. const elm = hostRef.$hostElement$;
  1113. const endPostUpdate = createTime('postUpdate', tagName);
  1114. const instance = hostRef.$lazyInstance$ ;
  1115. const ancestorComponent = hostRef.$ancestorComponent$;
  1116. if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
  1117. hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
  1118. {
  1119. // DOM WRITE!
  1120. addHydratedFlag(elm);
  1121. }
  1122. {
  1123. safeCall(instance, 'componentDidLoad');
  1124. }
  1125. endPostUpdate();
  1126. {
  1127. hostRef.$onReadyResolve$(elm);
  1128. if (!ancestorComponent) {
  1129. appDidLoad();
  1130. }
  1131. }
  1132. }
  1133. else {
  1134. endPostUpdate();
  1135. }
  1136. // load events fire from bottom to top
  1137. // the deepest elements load first then bubbles up
  1138. {
  1139. if (hostRef.$onRenderResolve$) {
  1140. hostRef.$onRenderResolve$();
  1141. hostRef.$onRenderResolve$ = undefined;
  1142. }
  1143. if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
  1144. nextTick(() => scheduleUpdate(hostRef, false));
  1145. }
  1146. hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
  1147. }
  1148. // ( •_•)
  1149. // ( •_•)>⌐■-■
  1150. // (⌐■_■)
  1151. };
  1152. const appDidLoad = (who) => {
  1153. // on appload
  1154. // we have finish the first big initial render
  1155. {
  1156. addHydratedFlag(doc.documentElement);
  1157. }
  1158. nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
  1159. };
  1160. const safeCall = (instance, method, arg) => {
  1161. if (instance && instance[method]) {
  1162. try {
  1163. return instance[method](arg);
  1164. }
  1165. catch (e) {
  1166. consoleError(e);
  1167. }
  1168. }
  1169. return undefined;
  1170. };
  1171. const addHydratedFlag = (elm) => elm.classList.add('hydrated')
  1172. ;
  1173. const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
  1174. const setValue = (ref, propName, newVal, cmpMeta) => {
  1175. // check our new property value against our internal value
  1176. const hostRef = getHostRef(ref);
  1177. const elm = hostRef.$hostElement$ ;
  1178. const oldVal = hostRef.$instanceValues$.get(propName);
  1179. const flags = hostRef.$flags$;
  1180. const instance = hostRef.$lazyInstance$ ;
  1181. newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
  1182. // explicitly check for NaN on both sides, as `NaN === NaN` is always false
  1183. const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
  1184. const didValueChange = newVal !== oldVal && !areBothNaN;
  1185. if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
  1186. // gadzooks! the property's value has changed!!
  1187. // set our new value!
  1188. hostRef.$instanceValues$.set(propName, newVal);
  1189. if (instance) {
  1190. // get an array of method names of watch functions to call
  1191. if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
  1192. const watchMethods = cmpMeta.$watchers$[propName];
  1193. if (watchMethods) {
  1194. // this instance is watching for when this property changed
  1195. watchMethods.map((watchMethodName) => {
  1196. try {
  1197. // fire off each of the watch methods that are watching this property
  1198. instance[watchMethodName](newVal, oldVal, propName);
  1199. }
  1200. catch (e) {
  1201. consoleError(e, elm);
  1202. }
  1203. });
  1204. }
  1205. }
  1206. if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
  1207. // looks like this value actually changed, so we've got work to do!
  1208. // but only if we've already rendered, otherwise just chill out
  1209. // queue that we need to do an update, but don't worry about queuing
  1210. // up millions cuz this function ensures it only runs once
  1211. scheduleUpdate(hostRef, false);
  1212. }
  1213. }
  1214. }
  1215. };
  1216. /**
  1217. * Attach a series of runtime constructs to a compiled Stencil component
  1218. * constructor, including getters and setters for the `@Prop` and `@State`
  1219. * decorators, callbacks for when attributes change, and so on.
  1220. *
  1221. * @param Cstr the constructor for a component that we need to process
  1222. * @param cmpMeta metadata collected previously about the component
  1223. * @param flags a number used to store a series of bit flags
  1224. * @returns a reference to the same constructor passed in (but now mutated)
  1225. */
  1226. const proxyComponent = (Cstr, cmpMeta, flags) => {
  1227. if (cmpMeta.$members$) {
  1228. if (Cstr.watchers) {
  1229. cmpMeta.$watchers$ = Cstr.watchers;
  1230. }
  1231. // It's better to have a const than two Object.entries()
  1232. const members = Object.entries(cmpMeta.$members$);
  1233. const prototype = Cstr.prototype;
  1234. members.map(([memberName, [memberFlags]]) => {
  1235. if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
  1236. ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
  1237. // proxyComponent - prop
  1238. Object.defineProperty(prototype, memberName, {
  1239. get() {
  1240. // proxyComponent, get value
  1241. return getValue(this, memberName);
  1242. },
  1243. set(newValue) {
  1244. // proxyComponent, set value
  1245. setValue(this, memberName, newValue, cmpMeta);
  1246. },
  1247. configurable: true,
  1248. enumerable: true,
  1249. });
  1250. }
  1251. });
  1252. if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
  1253. const attrNameToPropName = new Map();
  1254. prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
  1255. plt.jmp(() => {
  1256. const propName = attrNameToPropName.get(attrName);
  1257. // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
  1258. // in the case where an attribute was set inline.
  1259. // ```html
  1260. // <my-component some-attribute="some-value"></my-component>
  1261. // ```
  1262. //
  1263. // There is an edge case where a developer sets the attribute inline on a custom element and then
  1264. // programmatically changes it before it has been upgraded as shown below:
  1265. //
  1266. // ```html
  1267. // <!-- this component has _not_ been upgraded yet -->
  1268. // <my-component id="test" some-attribute="some-value"></my-component>
  1269. // <script>
  1270. // // grab non-upgraded component
  1271. // el = document.querySelector("#test");
  1272. // el.someAttribute = "another-value";
  1273. // // upgrade component
  1274. // customElements.define('my-component', MyComponent);
  1275. // </script>
  1276. // ```
  1277. // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
  1278. // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
  1279. // to the value that was set inline i.e. "some-value" from above example. When
  1280. // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
  1281. //
  1282. // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
  1283. // by connectedCallback as this attributeChangedCallback will not fire.
  1284. //
  1285. // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
  1286. //
  1287. // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
  1288. // properties here given that this goes against best practices outlined here
  1289. // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
  1290. if (this.hasOwnProperty(propName)) {
  1291. newValue = this[propName];
  1292. delete this[propName];
  1293. }
  1294. else if (prototype.hasOwnProperty(propName) &&
  1295. typeof this[propName] === 'number' &&
  1296. this[propName] == newValue) {
  1297. // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
  1298. // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
  1299. // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
  1300. return;
  1301. }
  1302. this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
  1303. });
  1304. };
  1305. // create an array of attributes to observe
  1306. // and also create a map of html attribute name to js property name
  1307. Cstr.observedAttributes = members
  1308. .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
  1309. .map(([propName, m]) => {
  1310. const attrName = m[1] || propName;
  1311. attrNameToPropName.set(attrName, propName);
  1312. if (m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
  1313. cmpMeta.$attrsToReflect$.push([propName, attrName]);
  1314. }
  1315. return attrName;
  1316. });
  1317. }
  1318. }
  1319. return Cstr;
  1320. };
  1321. const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
  1322. // initializeComponent
  1323. if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
  1324. // Let the runtime know that the component has been initialized
  1325. hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
  1326. {
  1327. // lazy loaded components
  1328. // request the component's implementation to be
  1329. // wired up with the host element
  1330. Cstr = loadModule(cmpMeta);
  1331. if (Cstr.then) {
  1332. // Await creates a micro-task avoid if possible
  1333. const endLoad = uniqueTime();
  1334. Cstr = await Cstr;
  1335. endLoad();
  1336. }
  1337. if (!Cstr.isProxied) {
  1338. // we've never proxied this Constructor before
  1339. // let's add the getters/setters to its prototype before
  1340. // the first time we create an instance of the implementation
  1341. {
  1342. cmpMeta.$watchers$ = Cstr.watchers;
  1343. }
  1344. proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
  1345. Cstr.isProxied = true;
  1346. }
  1347. const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
  1348. // ok, time to construct the instance
  1349. // but let's keep track of when we start and stop
  1350. // so that the getters/setters don't incorrectly step on data
  1351. {
  1352. hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
  1353. }
  1354. // construct the lazy-loaded component implementation
  1355. // passing the hostRef is very important during
  1356. // construction in order to directly wire together the
  1357. // host element and the lazy-loaded instance
  1358. try {
  1359. new Cstr(hostRef);
  1360. }
  1361. catch (e) {
  1362. consoleError(e);
  1363. }
  1364. {
  1365. hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
  1366. }
  1367. {
  1368. hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
  1369. }
  1370. endNewInstance();
  1371. fireConnectedCallback(hostRef.$lazyInstance$);
  1372. }
  1373. if (Cstr.style) {
  1374. // this component has styles but we haven't registered them yet
  1375. let style = Cstr.style;
  1376. const scopeId = getScopeId(cmpMeta);
  1377. if (!styles.has(scopeId)) {
  1378. const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
  1379. registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
  1380. endRegisterStyles();
  1381. }
  1382. }
  1383. }
  1384. // we've successfully created a lazy instance
  1385. const ancestorComponent = hostRef.$ancestorComponent$;
  1386. const schedule = () => scheduleUpdate(hostRef, true);
  1387. if (ancestorComponent && ancestorComponent['s-rc']) {
  1388. // this is the initial load and this component it has an ancestor component
  1389. // but the ancestor component has NOT fired its will update lifecycle yet
  1390. // so let's just cool our jets and wait for the ancestor to continue first
  1391. // this will get fired off when the ancestor component
  1392. // finally gets around to rendering its lazy self
  1393. // fire off the initial update
  1394. ancestorComponent['s-rc'].push(schedule);
  1395. }
  1396. else {
  1397. schedule();
  1398. }
  1399. };
  1400. const fireConnectedCallback = (instance) => {
  1401. {
  1402. safeCall(instance, 'connectedCallback');
  1403. }
  1404. };
  1405. const connectedCallback = (elm) => {
  1406. if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
  1407. const hostRef = getHostRef(elm);
  1408. const cmpMeta = hostRef.$cmpMeta$;
  1409. const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
  1410. if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
  1411. // first time this component has connected
  1412. hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
  1413. {
  1414. // find the first ancestor component (if there is one) and register
  1415. // this component as one of the actively loading child components for its ancestor
  1416. let ancestorComponent = elm;
  1417. while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
  1418. // climb up the ancestors looking for the first
  1419. // component that hasn't finished its lifecycle update yet
  1420. if (ancestorComponent['s-p']) {
  1421. // we found this components first ancestor component
  1422. // keep a reference to this component's ancestor component
  1423. attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
  1424. break;
  1425. }
  1426. }
  1427. }
  1428. // Lazy properties
  1429. // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
  1430. if (cmpMeta.$members$) {
  1431. Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
  1432. if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
  1433. const value = elm[memberName];
  1434. delete elm[memberName];
  1435. elm[memberName] = value;
  1436. }
  1437. });
  1438. }
  1439. {
  1440. initializeComponent(elm, hostRef, cmpMeta);
  1441. }
  1442. }
  1443. else {
  1444. // fire off connectedCallback() on component instance
  1445. if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) {
  1446. fireConnectedCallback(hostRef.$lazyInstance$);
  1447. }
  1448. else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
  1449. hostRef.$onReadyPromise$.then(() => fireConnectedCallback(hostRef.$lazyInstance$));
  1450. }
  1451. }
  1452. endConnected();
  1453. }
  1454. };
  1455. const disconnectInstance = (instance) => {
  1456. {
  1457. safeCall(instance, 'disconnectedCallback');
  1458. }
  1459. };
  1460. const disconnectedCallback = async (elm) => {
  1461. if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
  1462. const hostRef = getHostRef(elm);
  1463. if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) {
  1464. disconnectInstance(hostRef.$lazyInstance$);
  1465. }
  1466. else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
  1467. hostRef.$onReadyPromise$.then(() => disconnectInstance(hostRef.$lazyInstance$));
  1468. }
  1469. }
  1470. };
  1471. const bootstrapLazy = (lazyBundles, options = {}) => {
  1472. var _a;
  1473. const endBootstrap = createTime();
  1474. const cmpTags = [];
  1475. const exclude = options.exclude || [];
  1476. const customElements = win.customElements;
  1477. const head = doc.head;
  1478. const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
  1479. const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
  1480. const deferredConnectedCallbacks = [];
  1481. let appLoadFallback;
  1482. let isBootstrapping = true;
  1483. Object.assign(plt, options);
  1484. plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
  1485. lazyBundles.map((lazyBundle) => {
  1486. lazyBundle[1].map((compactMeta) => {
  1487. const cmpMeta = {
  1488. $flags$: compactMeta[0],
  1489. $tagName$: compactMeta[1],
  1490. $members$: compactMeta[2],
  1491. $listeners$: compactMeta[3],
  1492. };
  1493. {
  1494. cmpMeta.$members$ = compactMeta[2];
  1495. }
  1496. {
  1497. cmpMeta.$attrsToReflect$ = [];
  1498. }
  1499. {
  1500. cmpMeta.$watchers$ = {};
  1501. }
  1502. const tagName = cmpMeta.$tagName$;
  1503. const HostElement = class extends HTMLElement {
  1504. // StencilLazyHost
  1505. constructor(self) {
  1506. // @ts-ignore
  1507. super(self);
  1508. self = this;
  1509. registerHost(self, cmpMeta);
  1510. if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
  1511. // this component is using shadow dom
  1512. // and this browser supports shadow dom
  1513. // add the read-only property "shadowRoot" to the host element
  1514. // adding the shadow root build conditionals to minimize runtime
  1515. {
  1516. {
  1517. self.attachShadow({ mode: 'open' });
  1518. }
  1519. }
  1520. }
  1521. }
  1522. connectedCallback() {
  1523. if (appLoadFallback) {
  1524. clearTimeout(appLoadFallback);
  1525. appLoadFallback = null;
  1526. }
  1527. if (isBootstrapping) {
  1528. // connectedCallback will be processed once all components have been registered
  1529. deferredConnectedCallbacks.push(this);
  1530. }
  1531. else {
  1532. plt.jmp(() => connectedCallback(this));
  1533. }
  1534. }
  1535. disconnectedCallback() {
  1536. plt.jmp(() => disconnectedCallback(this));
  1537. }
  1538. componentOnReady() {
  1539. return getHostRef(this).$onReadyPromise$;
  1540. }
  1541. };
  1542. cmpMeta.$lazyBundleId$ = lazyBundle[0];
  1543. if (!exclude.includes(tagName) && !customElements.get(tagName)) {
  1544. cmpTags.push(tagName);
  1545. customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
  1546. }
  1547. });
  1548. });
  1549. {
  1550. visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
  1551. visibilityStyle.setAttribute('data-styles', '');
  1552. // Apply CSP nonce to the style tag if it exists
  1553. const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
  1554. if (nonce != null) {
  1555. visibilityStyle.setAttribute('nonce', nonce);
  1556. }
  1557. head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
  1558. }
  1559. // Process deferred connectedCallbacks now all components have been registered
  1560. isBootstrapping = false;
  1561. if (deferredConnectedCallbacks.length) {
  1562. deferredConnectedCallbacks.map((host) => host.connectedCallback());
  1563. }
  1564. else {
  1565. {
  1566. plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
  1567. }
  1568. }
  1569. // Fallback appLoad event
  1570. endBootstrap();
  1571. };
  1572. /**
  1573. * Assigns the given value to the nonce property on the runtime platform object.
  1574. * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
  1575. * @param nonce The value to be assigned to the platform nonce property.
  1576. * @returns void
  1577. */
  1578. const setNonce = (nonce) => (plt.$nonce$ = nonce);
  1579. const hostRefs = /*@__PURE__*/ new WeakMap();
  1580. const getHostRef = (ref) => hostRefs.get(ref);
  1581. const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
  1582. const registerHost = (elm, cmpMeta) => {
  1583. const hostRef = {
  1584. $flags$: 0,
  1585. $hostElement$: elm,
  1586. $cmpMeta$: cmpMeta,
  1587. $instanceValues$: new Map(),
  1588. };
  1589. {
  1590. hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
  1591. elm['s-p'] = [];
  1592. elm['s-rc'] = [];
  1593. }
  1594. return hostRefs.set(elm, hostRef);
  1595. };
  1596. const isMemberInElement = (elm, memberName) => memberName in elm;
  1597. const consoleError = (e, el) => (0, console.error)(e, el);
  1598. const cmpModules = /*@__PURE__*/ new Map();
  1599. const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
  1600. // loadModuleImport
  1601. const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
  1602. const bundleId = cmpMeta.$lazyBundleId$;
  1603. const module = cmpModules.get(bundleId) ;
  1604. if (module) {
  1605. return module[exportName];
  1606. }
  1607. /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
  1608. return import(
  1609. /* @vite-ignore */
  1610. /* webpackInclude: /\.entry\.js$/ */
  1611. /* webpackExclude: /\.system\.entry\.js$/ */
  1612. /* webpackMode: "lazy" */
  1613. `./${bundleId}.entry.js${''}`).then((importedModule) => {
  1614. {
  1615. cmpModules.set(bundleId, importedModule);
  1616. }
  1617. return importedModule[exportName];
  1618. }, consoleError);
  1619. };
  1620. const styles = /*@__PURE__*/ new Map();
  1621. const win = typeof window !== 'undefined' ? window : {};
  1622. const doc = win.document || { head: {} };
  1623. const plt = {
  1624. $flags$: 0,
  1625. $resourcesUrl$: '',
  1626. jmp: (h) => h(),
  1627. raf: (h) => requestAnimationFrame(h),
  1628. ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
  1629. rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
  1630. ce: (eventName, opts) => new CustomEvent(eventName, opts),
  1631. };
  1632. const promiseResolve = (v) => Promise.resolve(v);
  1633. const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
  1634. try {
  1635. new CSSStyleSheet();
  1636. return typeof new CSSStyleSheet().replaceSync === 'function';
  1637. }
  1638. catch (e) { }
  1639. return false;
  1640. })()
  1641. ;
  1642. const queueDomReads = [];
  1643. const queueDomWrites = [];
  1644. const queueTask = (queue, write) => (cb) => {
  1645. queue.push(cb);
  1646. if (!queuePending) {
  1647. queuePending = true;
  1648. if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
  1649. nextTick(flush);
  1650. }
  1651. else {
  1652. plt.raf(flush);
  1653. }
  1654. }
  1655. };
  1656. const consume = (queue) => {
  1657. for (let i = 0; i < queue.length; i++) {
  1658. try {
  1659. queue[i](performance.now());
  1660. }
  1661. catch (e) {
  1662. consoleError(e);
  1663. }
  1664. }
  1665. queue.length = 0;
  1666. };
  1667. const flush = () => {
  1668. // always force a bunch of medium callbacks to run, but still have
  1669. // a throttle on how many can run in a certain time
  1670. // DOM READS!!!
  1671. consume(queueDomReads);
  1672. // DOM WRITES!!!
  1673. {
  1674. consume(queueDomWrites);
  1675. if ((queuePending = queueDomReads.length > 0)) {
  1676. // still more to do yet, but we've run out of time
  1677. // let's let this thing cool off and try again in the next tick
  1678. plt.raf(flush);
  1679. }
  1680. }
  1681. };
  1682. const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
  1683. const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
  1684. export { Host as H, setAssetPath as a, bootstrapLazy as b, getElement as c, getAssetPath as g, h, promiseResolve as p, registerInstance as r, setNonce as s };