index-8ece2564.js 67 KB

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