index-5c65e149.js 68 KB

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