index-4b66db81.js 71 KB

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