index-d7f36e37.js 68 KB

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