index-1c5c47b4.js 67 KB

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