@dso-toolkit/core 62.21.0 → 62.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/dist/cjs/dso-accordion-section.cjs.entry.js +1 -1
  2. package/dist/cjs/dso-accordion.cjs.entry.js +1 -1
  3. package/dist/cjs/dso-action-list-item.cjs.entry.js +1 -1
  4. package/dist/cjs/dso-action-list.cjs.entry.js +1 -1
  5. package/dist/cjs/dso-advanced-select.cjs.entry.js +1 -1
  6. package/dist/cjs/dso-alert_7.cjs.entry.js +3 -3
  7. package/dist/cjs/dso-annotation-output_3.cjs.entry.js +2 -2
  8. package/dist/cjs/dso-attachments-counter.cjs.entry.js +1 -1
  9. package/dist/cjs/dso-autosuggest.cjs.entry.js +1 -1
  10. package/dist/cjs/dso-banner.cjs.entry.js +1 -1
  11. package/dist/cjs/dso-card-container.cjs.entry.js +1 -1
  12. package/dist/cjs/dso-card.cjs.entry.js +1 -1
  13. package/dist/cjs/dso-date-picker-legacy.cjs.entry.js +1 -1
  14. package/dist/cjs/dso-date-picker.cjs.entry.js +1 -1
  15. package/dist/cjs/dso-dropdown-menu.cjs.entry.js +1 -1
  16. package/dist/cjs/dso-expandable.cjs.entry.js +1 -1
  17. package/dist/cjs/dso-header.cjs.entry.js +1 -1
  18. package/dist/cjs/dso-helpcenter-panel.cjs.entry.js +1 -1
  19. package/dist/cjs/dso-highlight-box.cjs.entry.js +1 -1
  20. package/dist/cjs/dso-icon.cjs.entry.js +1 -1
  21. package/dist/cjs/dso-info-button.cjs.entry.js +1 -1
  22. package/dist/cjs/dso-info_2.cjs.entry.js +3 -3
  23. package/dist/cjs/dso-info_2.cjs.entry.js.map +1 -1
  24. package/dist/cjs/dso-input-range.cjs.entry.js +1 -1
  25. package/dist/cjs/dso-legend-item.cjs.entry.js +1 -1
  26. package/dist/cjs/dso-list-button.cjs.entry.js +1 -1
  27. package/dist/cjs/dso-logo.cjs.entry.js +16 -3
  28. package/dist/cjs/dso-logo.cjs.entry.js.map +1 -1
  29. package/dist/cjs/dso-map-base-layers.cjs.entry.js +2 -2
  30. package/dist/cjs/dso-map-controls.cjs.entry.js +2 -2
  31. package/dist/cjs/dso-map-overlays.cjs.entry.js +2 -2
  32. package/dist/cjs/dso-mark-bar.cjs.entry.js +2 -2
  33. package/dist/cjs/dso-modal.cjs.entry.js +3 -3
  34. package/dist/cjs/dso-pagination.cjs.entry.js +1 -1
  35. package/dist/cjs/dso-progress-bar.cjs.entry.js +2 -2
  36. package/dist/cjs/dso-progress-indicator.cjs.entry.js +2 -2
  37. package/dist/cjs/dso-responsive-element.cjs.entry.js +2 -2
  38. package/dist/cjs/dso-scrollable.cjs.entry.js +3 -3
  39. package/dist/cjs/dso-toggletip.cjs.entry.js +2 -2
  40. package/dist/cjs/dso-toolkit.cjs.js +10 -10
  41. package/dist/cjs/dso-toolkit.cjs.js.map +1 -1
  42. package/dist/cjs/dso-tooltip.cjs.entry.js +2 -2
  43. package/dist/cjs/dso-tree-view.cjs.entry.js +2 -2
  44. package/dist/cjs/dso-viewer-grid.cjs.entry.js +2 -2
  45. package/dist/cjs/dsot-document-component-demo.cjs.entry.js +1 -1
  46. package/dist/cjs/index-15fb3d00.js +1650 -0
  47. package/dist/cjs/index-15fb3d00.js.map +1 -0
  48. package/dist/cjs/loader.cjs.js +2 -2
  49. package/dist/collection/collection-manifest.json +1 -1
  50. package/dist/collection/components/info/info.css +3 -1
  51. package/dist/collection/components/logo/logo.css +40 -0
  52. package/dist/collection/components/logo/logo.interfaces.js +2 -0
  53. package/dist/collection/components/logo/logo.interfaces.js.map +1 -0
  54. package/dist/collection/components/logo/logo.js +93 -3
  55. package/dist/collection/components/logo/logo.js.map +1 -1
  56. package/dist/collection/components/map-base-layers/map-base-layers.js +1 -1
  57. package/dist/collection/components/map-controls/map-controls.js +1 -1
  58. package/dist/collection/components/map-overlays/map-overlays.js +1 -1
  59. package/dist/collection/components/mark-bar/mark-bar.js +1 -1
  60. package/dist/collection/components/modal/modal.js +2 -2
  61. package/dist/collection/components/ozon-content/ozon-content.js +1 -1
  62. package/dist/collection/components/progress-bar/progress-bar.js +1 -1
  63. package/dist/collection/components/progress-indicator/progress-indicator.js +1 -1
  64. package/dist/collection/components/responsive-element/responsive-element.js +1 -1
  65. package/dist/collection/components/scrollable/scrollable.js +2 -2
  66. package/dist/collection/components/selectable/selectable.js +1 -1
  67. package/dist/collection/components/slide-toggle/slide-toggle.js +1 -1
  68. package/dist/collection/components/table/table.js +1 -1
  69. package/dist/collection/components/toggletip/toggletip.js +1 -1
  70. package/dist/collection/components/tooltip/tooltip.js +1 -1
  71. package/dist/collection/components/tree-view/tree-view.js +1 -1
  72. package/dist/collection/components/viewer-grid/viewer-grid.js +1 -1
  73. package/dist/components/dso-logo.js +19 -4
  74. package/dist/components/dso-logo.js.map +1 -1
  75. package/dist/components/dso-map-base-layers.js +1 -1
  76. package/dist/components/dso-map-controls.js +1 -1
  77. package/dist/components/dso-map-overlays.js +1 -1
  78. package/dist/components/dso-mark-bar.js +1 -1
  79. package/dist/components/dso-modal.js +2 -2
  80. package/dist/components/dso-progress-bar.js +1 -1
  81. package/dist/components/dso-tree-view.js +1 -1
  82. package/dist/components/dso-viewer-grid.js +1 -1
  83. package/dist/components/info.js +1 -1
  84. package/dist/components/info.js.map +1 -1
  85. package/dist/components/ozon-content.js +1 -1
  86. package/dist/components/progress-indicator.js +1 -1
  87. package/dist/components/responsive-element.js +1 -1
  88. package/dist/components/scrollable.js +2 -2
  89. package/dist/components/selectable.js +1 -1
  90. package/dist/components/slide-toggle.js +1 -1
  91. package/dist/components/table.js +1 -1
  92. package/dist/components/toggletip.js +1 -1
  93. package/dist/components/tooltip.js +1 -1
  94. package/dist/dso-toolkit/dso-toolkit.esm.js +1 -1
  95. package/dist/dso-toolkit/dso-toolkit.esm.js.map +1 -1
  96. package/dist/dso-toolkit/{p-d75e278f.entry.js → p-04d39919.entry.js} +2 -2
  97. package/dist/dso-toolkit/{p-c22965e0.entry.js → p-0fc86795.entry.js} +2 -2
  98. package/dist/dso-toolkit/{p-0bbdb3e7.entry.js → p-26eb8cbd.entry.js} +2 -2
  99. package/dist/dso-toolkit/{p-7f5b0979.entry.js → p-31d0baad.entry.js} +2 -2
  100. package/dist/dso-toolkit/{p-dd9d670a.entry.js → p-3374b805.entry.js} +2 -2
  101. package/dist/dso-toolkit/{p-4eaf26e3.entry.js → p-383c1a21.entry.js} +2 -2
  102. package/dist/dso-toolkit/{p-e3b54b03.entry.js → p-4af7eed7.entry.js} +2 -2
  103. package/dist/dso-toolkit/{p-62ec675a.entry.js → p-4ca2f894.entry.js} +2 -2
  104. package/dist/dso-toolkit/{p-906ae1e7.entry.js → p-503624b9.entry.js} +2 -2
  105. package/dist/dso-toolkit/{p-0c1b34f6.entry.js → p-549761c7.entry.js} +2 -2
  106. package/dist/dso-toolkit/{p-64d88436.entry.js → p-551af248.entry.js} +2 -2
  107. package/dist/dso-toolkit/{p-bcc19bae.entry.js → p-60ee6373.entry.js} +2 -2
  108. package/dist/dso-toolkit/{p-6e7dcc0e.entry.js → p-65c71684.entry.js} +2 -2
  109. package/dist/dso-toolkit/{p-0142294a.entry.js → p-6be9e2eb.entry.js} +2 -2
  110. package/dist/dso-toolkit/p-6c9208cb.entry.js +2 -0
  111. package/dist/dso-toolkit/p-6c9208cb.entry.js.map +1 -0
  112. package/dist/dso-toolkit/{p-10d464fa.entry.js → p-6d9c9b93.entry.js} +2 -2
  113. package/dist/dso-toolkit/p-70c0fffb.entry.js +2 -0
  114. package/dist/dso-toolkit/{p-0308135a.entry.js.map → p-70c0fffb.entry.js.map} +1 -1
  115. package/dist/dso-toolkit/p-77bd63bb.entry.js +2 -0
  116. package/dist/dso-toolkit/p-77bd63bb.entry.js.map +1 -0
  117. package/dist/dso-toolkit/{p-cef2a4da.entry.js → p-8012e14f.entry.js} +2 -2
  118. package/dist/dso-toolkit/{p-a00fb3ac.entry.js → p-80db6914.entry.js} +2 -2
  119. package/dist/dso-toolkit/{p-88b1db54.entry.js → p-81f3e003.entry.js} +2 -2
  120. package/dist/dso-toolkit/{p-1cb9cd71.entry.js → p-852e6d6a.entry.js} +2 -2
  121. package/dist/dso-toolkit/{p-fbf6613f.entry.js → p-884d85f4.entry.js} +2 -2
  122. package/dist/dso-toolkit/{p-5028d1e1.entry.js → p-89cb24d7.entry.js} +2 -2
  123. package/dist/dso-toolkit/{p-64755e52.entry.js → p-8d838e75.entry.js} +2 -2
  124. package/dist/dso-toolkit/{p-0bb4a95b.entry.js → p-9a5744b5.entry.js} +2 -2
  125. package/dist/dso-toolkit/{p-e8648400.entry.js → p-9ec0f7fa.entry.js} +2 -2
  126. package/dist/dso-toolkit/{p-28de6034.entry.js → p-a139772d.entry.js} +2 -2
  127. package/dist/dso-toolkit/{p-9bf86dbf.entry.js → p-a15e4418.entry.js} +2 -2
  128. package/dist/dso-toolkit/{p-e8ada03b.entry.js → p-a3a53844.entry.js} +2 -2
  129. package/dist/dso-toolkit/{p-bc3c966f.entry.js → p-a759f597.entry.js} +2 -2
  130. package/dist/dso-toolkit/{p-67480a2f.entry.js → p-b4f6836e.entry.js} +2 -2
  131. package/dist/dso-toolkit/{p-9709ff83.entry.js → p-beca66e0.entry.js} +2 -2
  132. package/dist/dso-toolkit/{p-435baefc.entry.js → p-bf698df4.entry.js} +2 -2
  133. package/dist/dso-toolkit/{p-cd466fa3.entry.js → p-c23d96a4.entry.js} +2 -2
  134. package/dist/dso-toolkit/{p-b22757ab.entry.js → p-c9156d64.entry.js} +2 -2
  135. package/dist/dso-toolkit/p-d312d9d2.entry.js +2 -0
  136. package/dist/dso-toolkit/{p-bec5778a.entry.js → p-dcc1111a.entry.js} +2 -2
  137. package/dist/dso-toolkit/{p-1f66a719.entry.js → p-e19d5d76.entry.js} +2 -2
  138. package/dist/dso-toolkit/p-e1b4d45b.js +3 -0
  139. package/dist/dso-toolkit/p-e1b4d45b.js.map +1 -0
  140. package/dist/dso-toolkit/{p-b879c985.entry.js → p-ea580da0.entry.js} +2 -2
  141. package/dist/dso-toolkit/{p-86e80f9c.entry.js → p-ff7b61e7.entry.js} +2 -2
  142. package/dist/esm/dso-accordion-section.entry.js +1 -1
  143. package/dist/esm/dso-accordion.entry.js +1 -1
  144. package/dist/esm/dso-action-list-item.entry.js +1 -1
  145. package/dist/esm/dso-action-list.entry.js +1 -1
  146. package/dist/esm/dso-advanced-select.entry.js +1 -1
  147. package/dist/esm/dso-alert_7.entry.js +3 -3
  148. package/dist/esm/dso-annotation-output_3.entry.js +2 -2
  149. package/dist/esm/dso-attachments-counter.entry.js +1 -1
  150. package/dist/esm/dso-autosuggest.entry.js +1 -1
  151. package/dist/esm/dso-banner.entry.js +1 -1
  152. package/dist/esm/dso-card-container.entry.js +1 -1
  153. package/dist/esm/dso-card.entry.js +1 -1
  154. package/dist/esm/dso-date-picker-legacy.entry.js +1 -1
  155. package/dist/esm/dso-date-picker.entry.js +1 -1
  156. package/dist/esm/dso-dropdown-menu.entry.js +1 -1
  157. package/dist/esm/dso-expandable.entry.js +1 -1
  158. package/dist/esm/dso-header.entry.js +1 -1
  159. package/dist/esm/dso-helpcenter-panel.entry.js +1 -1
  160. package/dist/esm/dso-highlight-box.entry.js +1 -1
  161. package/dist/esm/dso-icon.entry.js +1 -1
  162. package/dist/esm/dso-info-button.entry.js +1 -1
  163. package/dist/esm/dso-info_2.entry.js +3 -3
  164. package/dist/esm/dso-info_2.entry.js.map +1 -1
  165. package/dist/esm/dso-input-range.entry.js +1 -1
  166. package/dist/esm/dso-legend-item.entry.js +1 -1
  167. package/dist/esm/dso-list-button.entry.js +1 -1
  168. package/dist/esm/dso-logo.entry.js +16 -3
  169. package/dist/esm/dso-logo.entry.js.map +1 -1
  170. package/dist/esm/dso-map-base-layers.entry.js +2 -2
  171. package/dist/esm/dso-map-controls.entry.js +2 -2
  172. package/dist/esm/dso-map-overlays.entry.js +2 -2
  173. package/dist/esm/dso-mark-bar.entry.js +2 -2
  174. package/dist/esm/dso-modal.entry.js +3 -3
  175. package/dist/esm/dso-pagination.entry.js +1 -1
  176. package/dist/esm/dso-progress-bar.entry.js +2 -2
  177. package/dist/esm/dso-progress-indicator.entry.js +2 -2
  178. package/dist/esm/dso-responsive-element.entry.js +2 -2
  179. package/dist/esm/dso-scrollable.entry.js +3 -3
  180. package/dist/esm/dso-toggletip.entry.js +2 -2
  181. package/dist/esm/dso-toolkit.js +11 -11
  182. package/dist/esm/dso-toolkit.js.map +1 -1
  183. package/dist/esm/dso-tooltip.entry.js +2 -2
  184. package/dist/esm/dso-tree-view.entry.js +2 -2
  185. package/dist/esm/dso-viewer-grid.entry.js +2 -2
  186. package/dist/esm/dsot-document-component-demo.entry.js +1 -1
  187. package/dist/esm/index-5769f943.js +1618 -0
  188. package/dist/esm/index-5769f943.js.map +1 -0
  189. package/dist/esm/loader.js +3 -3
  190. package/dist/types/components/logo/logo.d.ts +20 -2
  191. package/dist/types/components/logo/logo.interfaces.d.ts +12 -0
  192. package/dist/types/components.d.ts +42 -0
  193. package/package.json +7 -7
  194. package/dist/cjs/index-a58ba49d.js +0 -2584
  195. package/dist/cjs/index-a58ba49d.js.map +0 -1
  196. package/dist/dso-toolkit/p-0308135a.entry.js +0 -2
  197. package/dist/dso-toolkit/p-43bcfb18.entry.js +0 -2
  198. package/dist/dso-toolkit/p-43bcfb18.entry.js.map +0 -1
  199. package/dist/dso-toolkit/p-701648d3.js +0 -3
  200. package/dist/dso-toolkit/p-701648d3.js.map +0 -1
  201. package/dist/dso-toolkit/p-b51c4022.entry.js +0 -2
  202. package/dist/dso-toolkit/p-bc95874a.entry.js +0 -2
  203. package/dist/dso-toolkit/p-bc95874a.entry.js.map +0 -1
  204. package/dist/esm/index-2e1b7388.js +0 -2552
  205. package/dist/esm/index-2e1b7388.js.map +0 -1
  206. /package/dist/dso-toolkit/{p-d75e278f.entry.js.map → p-04d39919.entry.js.map} +0 -0
  207. /package/dist/dso-toolkit/{p-c22965e0.entry.js.map → p-0fc86795.entry.js.map} +0 -0
  208. /package/dist/dso-toolkit/{p-0bbdb3e7.entry.js.map → p-26eb8cbd.entry.js.map} +0 -0
  209. /package/dist/dso-toolkit/{p-7f5b0979.entry.js.map → p-31d0baad.entry.js.map} +0 -0
  210. /package/dist/dso-toolkit/{p-dd9d670a.entry.js.map → p-3374b805.entry.js.map} +0 -0
  211. /package/dist/dso-toolkit/{p-4eaf26e3.entry.js.map → p-383c1a21.entry.js.map} +0 -0
  212. /package/dist/dso-toolkit/{p-e3b54b03.entry.js.map → p-4af7eed7.entry.js.map} +0 -0
  213. /package/dist/dso-toolkit/{p-62ec675a.entry.js.map → p-4ca2f894.entry.js.map} +0 -0
  214. /package/dist/dso-toolkit/{p-906ae1e7.entry.js.map → p-503624b9.entry.js.map} +0 -0
  215. /package/dist/dso-toolkit/{p-0c1b34f6.entry.js.map → p-549761c7.entry.js.map} +0 -0
  216. /package/dist/dso-toolkit/{p-64d88436.entry.js.map → p-551af248.entry.js.map} +0 -0
  217. /package/dist/dso-toolkit/{p-bcc19bae.entry.js.map → p-60ee6373.entry.js.map} +0 -0
  218. /package/dist/dso-toolkit/{p-6e7dcc0e.entry.js.map → p-65c71684.entry.js.map} +0 -0
  219. /package/dist/dso-toolkit/{p-0142294a.entry.js.map → p-6be9e2eb.entry.js.map} +0 -0
  220. /package/dist/dso-toolkit/{p-10d464fa.entry.js.map → p-6d9c9b93.entry.js.map} +0 -0
  221. /package/dist/dso-toolkit/{p-cef2a4da.entry.js.map → p-8012e14f.entry.js.map} +0 -0
  222. /package/dist/dso-toolkit/{p-a00fb3ac.entry.js.map → p-80db6914.entry.js.map} +0 -0
  223. /package/dist/dso-toolkit/{p-88b1db54.entry.js.map → p-81f3e003.entry.js.map} +0 -0
  224. /package/dist/dso-toolkit/{p-1cb9cd71.entry.js.map → p-852e6d6a.entry.js.map} +0 -0
  225. /package/dist/dso-toolkit/{p-fbf6613f.entry.js.map → p-884d85f4.entry.js.map} +0 -0
  226. /package/dist/dso-toolkit/{p-5028d1e1.entry.js.map → p-89cb24d7.entry.js.map} +0 -0
  227. /package/dist/dso-toolkit/{p-64755e52.entry.js.map → p-8d838e75.entry.js.map} +0 -0
  228. /package/dist/dso-toolkit/{p-0bb4a95b.entry.js.map → p-9a5744b5.entry.js.map} +0 -0
  229. /package/dist/dso-toolkit/{p-e8648400.entry.js.map → p-9ec0f7fa.entry.js.map} +0 -0
  230. /package/dist/dso-toolkit/{p-28de6034.entry.js.map → p-a139772d.entry.js.map} +0 -0
  231. /package/dist/dso-toolkit/{p-9bf86dbf.entry.js.map → p-a15e4418.entry.js.map} +0 -0
  232. /package/dist/dso-toolkit/{p-e8ada03b.entry.js.map → p-a3a53844.entry.js.map} +0 -0
  233. /package/dist/dso-toolkit/{p-bc3c966f.entry.js.map → p-a759f597.entry.js.map} +0 -0
  234. /package/dist/dso-toolkit/{p-67480a2f.entry.js.map → p-b4f6836e.entry.js.map} +0 -0
  235. /package/dist/dso-toolkit/{p-9709ff83.entry.js.map → p-beca66e0.entry.js.map} +0 -0
  236. /package/dist/dso-toolkit/{p-435baefc.entry.js.map → p-bf698df4.entry.js.map} +0 -0
  237. /package/dist/dso-toolkit/{p-cd466fa3.entry.js.map → p-c23d96a4.entry.js.map} +0 -0
  238. /package/dist/dso-toolkit/{p-b22757ab.entry.js.map → p-c9156d64.entry.js.map} +0 -0
  239. /package/dist/dso-toolkit/{p-b51c4022.entry.js.map → p-d312d9d2.entry.js.map} +0 -0
  240. /package/dist/dso-toolkit/{p-bec5778a.entry.js.map → p-dcc1111a.entry.js.map} +0 -0
  241. /package/dist/dso-toolkit/{p-1f66a719.entry.js.map → p-e19d5d76.entry.js.map} +0 -0
  242. /package/dist/dso-toolkit/{p-b879c985.entry.js.map → p-ea580da0.entry.js.map} +0 -0
  243. /package/dist/dso-toolkit/{p-86e80f9c.entry.js.map → p-ff7b61e7.entry.js.map} +0 -0
@@ -1,2584 +0,0 @@
1
- 'use strict';
2
-
3
- function _interopNamespace(e) {
4
- if (e && e.__esModule) return e;
5
- var n = Object.create(null);
6
- if (e) {
7
- Object.keys(e).forEach(function (k) {
8
- if (k !== 'default') {
9
- var d = Object.getOwnPropertyDescriptor(e, k);
10
- Object.defineProperty(n, k, d.get ? d : {
11
- enumerable: true,
12
- get: function () {
13
- return e[k];
14
- }
15
- });
16
- }
17
- });
18
- }
19
- n['default'] = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- const NAMESPACE = 'dso-toolkit';
24
- const BUILD = /* dso-toolkit */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: true, cmpDidRender: true, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: true, cmpWillRender: false, cmpWillUpdate: false, connectedCallback: true, constructableCSS: true, cssAnnotations: true, devTools: false, disconnectedCallback: true, element: false, event: true, experimentalScopedSlotChanges: false, experimentalSlotFixes: false, formAssociated: false, hasRenderFn: true, hostListener: true, hostListenerTarget: true, hostListenerTargetBody: false, hostListenerTargetDocument: true, hostListenerTargetParent: false, hostListenerTargetWindow: true, hotModuleReplacement: false, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: false, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: true, mode: false, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: true, propString: true, reflect: true, scoped: true, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, slot: true, slotChildNodesFix: false, slotRelocation: true, state: true, style: true, svg: true, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: true, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: true, vdomText: true, vdomXlink: true, watchCallback: true };
25
-
26
- /**
27
- * Virtual DOM patching algorithm based on Snabbdom by
28
- * Simon Friis Vindum (@paldepind)
29
- * Licensed under the MIT License
30
- * https://github.com/snabbdom/snabbdom/blob/master/LICENSE
31
- *
32
- * Modified for Stencil's renderer and slot projection
33
- */
34
- let scopeId;
35
- let contentRef;
36
- let hostTagName;
37
- let useNativeShadowDom = false;
38
- let checkSlotFallbackVisibility = false;
39
- let checkSlotRelocate = false;
40
- let isSvgMode = false;
41
- let renderingRef = null;
42
- let queuePending = false;
43
- const createTime = (fnName, tagName = '') => {
44
- {
45
- return () => {
46
- return;
47
- };
48
- }
49
- };
50
- const uniqueTime = (key, measureText) => {
51
- {
52
- return () => {
53
- return;
54
- };
55
- }
56
- };
57
- const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
58
- /**
59
- * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
60
- *
61
- * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
62
- * support as of Stencil v4.
63
- */
64
- const SLOT_FB_CSS = 'slot-fb{display:contents}slot-fb[hidden]{display:none}';
65
- const XLINK_NS = 'http://www.w3.org/1999/xlink';
66
- /**
67
- * Default style mode id
68
- */
69
- /**
70
- * Reusable empty obj/array
71
- * Don't add values to these!!
72
- */
73
- const EMPTY_OBJ = {};
74
- /**
75
- * Namespaces
76
- */
77
- const SVG_NS = 'http://www.w3.org/2000/svg';
78
- const HTML_NS = 'http://www.w3.org/1999/xhtml';
79
- const isDef = (v) => v != null;
80
- /**
81
- * Check whether a value is a 'complex type', defined here as an object or a
82
- * function.
83
- *
84
- * @param o the value to check
85
- * @returns whether it's a complex type or not
86
- */
87
- const isComplexType = (o) => {
88
- // https://jsperf.com/typeof-fn-object/5
89
- o = typeof o;
90
- return o === 'object' || o === 'function';
91
- };
92
- /**
93
- * Helper method for querying a `meta` tag that contains a nonce value
94
- * out of a DOM's head.
95
- *
96
- * @param doc The DOM containing the `head` to query against
97
- * @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
98
- * exists or the tag has no content.
99
- */
100
- function queryNonceMetaTagContent(doc) {
101
- var _a, _b, _c;
102
- return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
103
- }
104
- /**
105
- * Production h() function based on Preact by
106
- * Jason Miller (@developit)
107
- * Licensed under the MIT License
108
- * https://github.com/developit/preact/blob/master/LICENSE
109
- *
110
- * Modified for Stencil's compiler and vdom
111
- */
112
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
113
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
114
- const h = (nodeName, vnodeData, ...children) => {
115
- let child = null;
116
- let key = null;
117
- let slotName = null;
118
- let simple = false;
119
- let lastSimple = false;
120
- const vNodeChildren = [];
121
- const walk = (c) => {
122
- for (let i = 0; i < c.length; i++) {
123
- child = c[i];
124
- if (Array.isArray(child)) {
125
- walk(child);
126
- }
127
- else if (child != null && typeof child !== 'boolean') {
128
- if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
129
- child = String(child);
130
- }
131
- if (simple && lastSimple) {
132
- // If the previous child was simple (string), we merge both
133
- vNodeChildren[vNodeChildren.length - 1].$text$ += child;
134
- }
135
- else {
136
- // Append a new vNode, if it's text, we create a text vNode
137
- vNodeChildren.push(simple ? newVNode(null, child) : child);
138
- }
139
- lastSimple = simple;
140
- }
141
- }
142
- };
143
- walk(children);
144
- if (vnodeData) {
145
- if (vnodeData.key) {
146
- key = vnodeData.key;
147
- }
148
- if (vnodeData.name) {
149
- slotName = vnodeData.name;
150
- }
151
- // normalize class / className attributes
152
- {
153
- const classData = vnodeData.className || vnodeData.class;
154
- if (classData) {
155
- vnodeData.class =
156
- typeof classData !== 'object'
157
- ? classData
158
- : Object.keys(classData)
159
- .filter((k) => classData[k])
160
- .join(' ');
161
- }
162
- }
163
- }
164
- if (typeof nodeName === 'function') {
165
- // nodeName is a functional component
166
- return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
167
- }
168
- const vnode = newVNode(nodeName, null);
169
- vnode.$attrs$ = vnodeData;
170
- if (vNodeChildren.length > 0) {
171
- vnode.$children$ = vNodeChildren;
172
- }
173
- {
174
- vnode.$key$ = key;
175
- }
176
- {
177
- vnode.$name$ = slotName;
178
- }
179
- return vnode;
180
- };
181
- /**
182
- * A utility function for creating a virtual DOM node from a tag and some
183
- * possible text content.
184
- *
185
- * @param tag the tag for this element
186
- * @param text possible text content for the node
187
- * @returns a newly-minted virtual DOM node
188
- */
189
- const newVNode = (tag, text) => {
190
- const vnode = {
191
- $flags$: 0,
192
- $tag$: tag,
193
- $text$: text,
194
- $elm$: null,
195
- $children$: null,
196
- };
197
- {
198
- vnode.$attrs$ = null;
199
- }
200
- {
201
- vnode.$key$ = null;
202
- }
203
- {
204
- vnode.$name$ = null;
205
- }
206
- return vnode;
207
- };
208
- const Host = {};
209
- /**
210
- * Check whether a given node is a Host node or not
211
- *
212
- * @param node the virtual DOM node to check
213
- * @returns whether it's a Host node or not
214
- */
215
- const isHost = (node) => node && node.$tag$ === Host;
216
- /**
217
- * Implementation of {@link d.FunctionalUtilities} for Stencil's VDom.
218
- *
219
- * Note that these functions convert from {@link d.VNode} to
220
- * {@link d.ChildNode} to give functional component developers a friendly
221
- * interface.
222
- */
223
- const vdomFnUtils = {
224
- forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
225
- map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
226
- };
227
- /**
228
- * Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
229
- * friendlier public interface (hence, 'convertToPublic').
230
- *
231
- * @param node the virtual DOM node to convert
232
- * @returns a converted child node
233
- */
234
- const convertToPublic = (node) => ({
235
- vattrs: node.$attrs$,
236
- vchildren: node.$children$,
237
- vkey: node.$key$,
238
- vname: node.$name$,
239
- vtag: node.$tag$,
240
- vtext: node.$text$,
241
- });
242
- /**
243
- * Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
244
- * order to use the resulting object in the virtual DOM. The initial object was
245
- * likely created as part of presenting a public API, so converting it back
246
- * involved making it 'private' again (hence, `convertToPrivate`).
247
- *
248
- * @param node the child node to convert
249
- * @returns a converted virtual DOM node
250
- */
251
- const convertToPrivate = (node) => {
252
- if (typeof node.vtag === 'function') {
253
- const vnodeData = Object.assign({}, node.vattrs);
254
- if (node.vkey) {
255
- vnodeData.key = node.vkey;
256
- }
257
- if (node.vname) {
258
- vnodeData.name = node.vname;
259
- }
260
- return h(node.vtag, vnodeData, ...(node.vchildren || []));
261
- }
262
- const vnode = newVNode(node.vtag, node.vtext);
263
- vnode.$attrs$ = node.vattrs;
264
- vnode.$children$ = node.vchildren;
265
- vnode.$key$ = node.vkey;
266
- vnode.$name$ = node.vname;
267
- return vnode;
268
- };
269
- /**
270
- * Parse a new property value for a given property type.
271
- *
272
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
273
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
274
- * 1. `any`, the type given to `propValue` in the function signature
275
- * 2. the type stored from `propType`.
276
- *
277
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
278
- *
279
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
280
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
281
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
282
- * ```tsx
283
- * <my-cmp prop-val={0}></my-cmp>
284
- * ```
285
- *
286
- * HTML prop values on the other hand, will always a string
287
- *
288
- * @param propValue the new value to coerce to some type
289
- * @param propType the type of the prop, expressed as a binary number
290
- * @returns the parsed/coerced value
291
- */
292
- const parsePropertyValue = (propValue, propType) => {
293
- // ensure this value is of the correct prop type
294
- if (propValue != null && !isComplexType(propValue)) {
295
- if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
296
- // per the HTML spec, any string value means it is a boolean true value
297
- // but we'll cheat here and say that the string "false" is the boolean false
298
- return propValue === 'false' ? false : propValue === '' || !!propValue;
299
- }
300
- if (propType & 2 /* MEMBER_FLAGS.Number */) {
301
- // force it to be a number
302
- return parseFloat(propValue);
303
- }
304
- if (propType & 1 /* MEMBER_FLAGS.String */) {
305
- // could have been passed as a number or boolean
306
- // but we still want it as a string
307
- return String(propValue);
308
- }
309
- // redundant return here for better minification
310
- return propValue;
311
- }
312
- // not sure exactly what type we want
313
- // so no need to change to a different type
314
- return propValue;
315
- };
316
- const getElement = (ref) => (getHostRef(ref).$hostElement$ );
317
- const createEvent = (ref, name, flags) => {
318
- const elm = getElement(ref);
319
- return {
320
- emit: (detail) => {
321
- return emitEvent(elm, name, {
322
- bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
323
- composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
324
- cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
325
- detail,
326
- });
327
- },
328
- };
329
- };
330
- /**
331
- * Helper function to create & dispatch a custom Event on a provided target
332
- * @param elm the target of the Event
333
- * @param name the name to give the custom Event
334
- * @param opts options for configuring a custom Event
335
- * @returns the custom Event
336
- */
337
- const emitEvent = (elm, name, opts) => {
338
- const ev = plt.ce(name, opts);
339
- elm.dispatchEvent(ev);
340
- return ev;
341
- };
342
- const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
343
- const registerStyle = (scopeId, cssText, allowCS) => {
344
- let style = styles.get(scopeId);
345
- if (supportsConstructableStylesheets && allowCS) {
346
- style = (style || new CSSStyleSheet());
347
- if (typeof style === 'string') {
348
- style = cssText;
349
- }
350
- else {
351
- style.replaceSync(cssText);
352
- }
353
- }
354
- else {
355
- style = cssText;
356
- }
357
- styles.set(scopeId, style);
358
- };
359
- const addStyle = (styleContainerNode, cmpMeta, mode) => {
360
- var _a;
361
- const scopeId = getScopeId(cmpMeta);
362
- const style = styles.get(scopeId);
363
- // if an element is NOT connected then getRootNode() will return the wrong root node
364
- // so the fallback is to always use the document for the root node in those cases
365
- styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
366
- if (style) {
367
- if (typeof style === 'string') {
368
- styleContainerNode = styleContainerNode.head || styleContainerNode;
369
- let appliedStyles = rootAppliedStyles.get(styleContainerNode);
370
- let styleElm;
371
- if (!appliedStyles) {
372
- rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
373
- }
374
- if (!appliedStyles.has(scopeId)) {
375
- {
376
- styleElm = doc.createElement('style');
377
- styleElm.innerHTML = style;
378
- // Apply CSP nonce to the style tag if it exists
379
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
380
- if (nonce != null) {
381
- styleElm.setAttribute('nonce', nonce);
382
- }
383
- styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
384
- }
385
- // Add styles for `slot-fb` elements if we're using slots outside the Shadow DOM
386
- if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
387
- styleElm.innerHTML += SLOT_FB_CSS;
388
- }
389
- if (appliedStyles) {
390
- appliedStyles.add(scopeId);
391
- }
392
- }
393
- }
394
- else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
395
- styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
396
- }
397
- }
398
- return scopeId;
399
- };
400
- const attachStyles = (hostRef) => {
401
- const cmpMeta = hostRef.$cmpMeta$;
402
- const elm = hostRef.$hostElement$;
403
- const flags = cmpMeta.$flags$;
404
- const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
405
- const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
406
- if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
407
- // only required when we're NOT using native shadow dom (slot)
408
- // or this browser doesn't support native shadow dom
409
- // and this host element was NOT created with SSR
410
- // let's pick out the inner content for slot projection
411
- // create a node to represent where the original
412
- // content was first placed, which is useful later on
413
- // DOM WRITE!!
414
- elm['s-sc'] = scopeId;
415
- elm.classList.add(scopeId + '-h');
416
- if (flags & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
417
- elm.classList.add(scopeId + '-s');
418
- }
419
- }
420
- endAttachStyles();
421
- };
422
- const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
423
- /**
424
- * Production setAccessor() function based on Preact by
425
- * Jason Miller (@developit)
426
- * Licensed under the MIT License
427
- * https://github.com/developit/preact/blob/master/LICENSE
428
- *
429
- * Modified for Stencil's compiler and vdom
430
- */
431
- /**
432
- * When running a VDom render set properties present on a VDom node onto the
433
- * corresponding HTML element.
434
- *
435
- * Note that this function has special functionality for the `class`,
436
- * `style`, `key`, and `ref` attributes, as well as event handlers (like
437
- * `onClick`, etc). All others are just passed through as-is.
438
- *
439
- * @param elm the HTMLElement onto which attributes should be set
440
- * @param memberName the name of the attribute to set
441
- * @param oldValue the old value for the attribute
442
- * @param newValue the new value for the attribute
443
- * @param isSvg whether we're in an svg context or not
444
- * @param flags bitflags for Vdom variables
445
- */
446
- const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
447
- if (oldValue !== newValue) {
448
- let isProp = isMemberInElement(elm, memberName);
449
- let ln = memberName.toLowerCase();
450
- if (memberName === 'class') {
451
- const classList = elm.classList;
452
- const oldClasses = parseClassList(oldValue);
453
- const newClasses = parseClassList(newValue);
454
- classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
455
- classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
456
- }
457
- else if (memberName === 'style') {
458
- // update style attribute, css properties and values
459
- {
460
- for (const prop in oldValue) {
461
- if (!newValue || newValue[prop] == null) {
462
- if (prop.includes('-')) {
463
- elm.style.removeProperty(prop);
464
- }
465
- else {
466
- elm.style[prop] = '';
467
- }
468
- }
469
- }
470
- }
471
- for (const prop in newValue) {
472
- if (!oldValue || newValue[prop] !== oldValue[prop]) {
473
- if (prop.includes('-')) {
474
- elm.style.setProperty(prop, newValue[prop]);
475
- }
476
- else {
477
- elm.style[prop] = newValue[prop];
478
- }
479
- }
480
- }
481
- }
482
- else if (memberName === 'key')
483
- ;
484
- else if (memberName === 'ref') {
485
- // minifier will clean this up
486
- if (newValue) {
487
- newValue(elm);
488
- }
489
- }
490
- else if ((!isProp ) &&
491
- memberName[0] === 'o' &&
492
- memberName[1] === 'n') {
493
- // Event Handlers
494
- // so if the member name starts with "on" and the 3rd characters is
495
- // a capital letter, and it's not already a member on the element,
496
- // then we're assuming it's an event listener
497
- if (memberName[2] === '-') {
498
- // on- prefixed events
499
- // allows to be explicit about the dom event to listen without any magic
500
- // under the hood:
501
- // <my-cmp on-click> // listens for "click"
502
- // <my-cmp on-Click> // listens for "Click"
503
- // <my-cmp on-ionChange> // listens for "ionChange"
504
- // <my-cmp on-EVENTS> // listens for "EVENTS"
505
- memberName = memberName.slice(3);
506
- }
507
- else if (isMemberInElement(win, ln)) {
508
- // standard event
509
- // the JSX attribute could have been "onMouseOver" and the
510
- // member name "onmouseover" is on the window's prototype
511
- // so let's add the listener "mouseover", which is all lowercased
512
- memberName = ln.slice(2);
513
- }
514
- else {
515
- // custom event
516
- // the JSX attribute could have been "onMyCustomEvent"
517
- // so let's trim off the "on" prefix and lowercase the first character
518
- // and add the listener "myCustomEvent"
519
- // except for the first character, we keep the event name case
520
- memberName = ln[2] + memberName.slice(3);
521
- }
522
- if (oldValue || newValue) {
523
- // Need to account for "capture" events.
524
- // If the event name ends with "Capture", we'll update the name to remove
525
- // the "Capture" suffix and make sure the event listener is setup to handle the capture event.
526
- const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
527
- // Make sure we only replace the last instance of "Capture"
528
- memberName = memberName.replace(CAPTURE_EVENT_REGEX, '');
529
- if (oldValue) {
530
- plt.rel(elm, memberName, oldValue, capture);
531
- }
532
- if (newValue) {
533
- plt.ael(elm, memberName, newValue, capture);
534
- }
535
- }
536
- }
537
- else {
538
- // Set property if it exists and it's not a SVG
539
- const isComplex = isComplexType(newValue);
540
- if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
541
- try {
542
- if (!elm.tagName.includes('-')) {
543
- const n = newValue == null ? '' : newValue;
544
- // Workaround for Safari, moving the <input> caret when re-assigning the same valued
545
- if (memberName === 'list') {
546
- isProp = false;
547
- }
548
- else if (oldValue == null || elm[memberName] != n) {
549
- elm[memberName] = n;
550
- }
551
- }
552
- else {
553
- elm[memberName] = newValue;
554
- }
555
- }
556
- catch (e) {
557
- /**
558
- * in case someone tries to set a read-only property, e.g. "namespaceURI", we just ignore it
559
- */
560
- }
561
- }
562
- /**
563
- * Need to manually update attribute if:
564
- * - memberName is not an attribute
565
- * - if we are rendering the host element in order to reflect attribute
566
- * - if it's a SVG, since properties might not work in <svg>
567
- * - if the newValue is null/undefined or 'false'.
568
- */
569
- let xlink = false;
570
- {
571
- if (ln !== (ln = ln.replace(/^xlink\:?/, ''))) {
572
- memberName = ln;
573
- xlink = true;
574
- }
575
- }
576
- if (newValue == null || newValue === false) {
577
- if (newValue !== false || elm.getAttribute(memberName) === '') {
578
- if (xlink) {
579
- elm.removeAttributeNS(XLINK_NS, memberName);
580
- }
581
- else {
582
- elm.removeAttribute(memberName);
583
- }
584
- }
585
- }
586
- else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
587
- newValue = newValue === true ? '' : newValue;
588
- if (xlink) {
589
- elm.setAttributeNS(XLINK_NS, memberName, newValue);
590
- }
591
- else {
592
- elm.setAttribute(memberName, newValue);
593
- }
594
- }
595
- }
596
- }
597
- };
598
- const parseClassListRegex = /\s/;
599
- /**
600
- * Parsed a string of classnames into an array
601
- * @param value className string, e.g. "foo bar baz"
602
- * @returns list of classes, e.g. ["foo", "bar", "baz"]
603
- */
604
- const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
605
- const CAPTURE_EVENT_SUFFIX = 'Capture';
606
- const CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + '$');
607
- const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
608
- // if the element passed in is a shadow root, which is a document fragment
609
- // then we want to be adding attrs/props to the shadow root's "host" element
610
- // if it's not a shadow root, then we add attrs/props to the same element
611
- const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
612
- ? newVnode.$elm$.host
613
- : newVnode.$elm$;
614
- const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
615
- const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
616
- {
617
- // remove attributes no longer present on the vnode by setting them to undefined
618
- for (memberName of sortedAttrNames(Object.keys(oldVnodeAttrs))) {
619
- if (!(memberName in newVnodeAttrs)) {
620
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
621
- }
622
- }
623
- }
624
- // add new & update changed attributes
625
- for (memberName of sortedAttrNames(Object.keys(newVnodeAttrs))) {
626
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
627
- }
628
- };
629
- /**
630
- * Sort a list of attribute names to ensure that all the attribute names which
631
- * are _not_ `"ref"` come before `"ref"`. Preserve the order of the non-ref
632
- * attributes.
633
- *
634
- * **Note**: if the supplied attributes do not include `'ref'` then the same
635
- * (by reference) array will be returned without modification.
636
- *
637
- * @param attrNames attribute names to sort
638
- * @returns a list of attribute names, sorted if they include `"ref"`
639
- */
640
- function sortedAttrNames(attrNames) {
641
- return attrNames.includes('ref')
642
- ? // we need to sort these to ensure that `'ref'` is the last attr
643
- [...attrNames.filter((attr) => attr !== 'ref'), 'ref']
644
- : // no need to sort, return the original array
645
- attrNames;
646
- }
647
- /**
648
- * Create a DOM Node corresponding to one of the children of a given VNode.
649
- *
650
- * @param oldParentVNode the parent VNode from the previous render
651
- * @param newParentVNode the parent VNode from the current render
652
- * @param childIndex the index of the VNode, in the _new_ parent node's
653
- * children, for which we will create a new DOM node
654
- * @param parentElm the parent DOM node which our new node will be a child of
655
- * @returns the newly created node
656
- */
657
- const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
658
- var _a;
659
- // tslint:disable-next-line: prefer-const
660
- const newVNode = newParentVNode.$children$[childIndex];
661
- let i = 0;
662
- let elm;
663
- let childNode;
664
- let oldVNode;
665
- if (!useNativeShadowDom) {
666
- // remember for later we need to check to relocate nodes
667
- checkSlotRelocate = true;
668
- if (newVNode.$tag$ === 'slot') {
669
- if (scopeId) {
670
- // scoped css needs to add its scoped id to the parent element
671
- parentElm.classList.add(scopeId + '-s');
672
- }
673
- newVNode.$flags$ |= newVNode.$children$
674
- ? // slot element has fallback content
675
- 2 /* VNODE_FLAGS.isSlotFallback */
676
- : // slot element does not have fallback content
677
- 1 /* VNODE_FLAGS.isSlotReference */;
678
- }
679
- }
680
- if (newVNode.$text$ !== null) {
681
- // create text node
682
- elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
683
- }
684
- else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
685
- // create a slot reference node
686
- elm = newVNode.$elm$ =
687
- doc.createTextNode('');
688
- }
689
- else {
690
- if (!isSvgMode) {
691
- isSvgMode = newVNode.$tag$ === 'svg';
692
- }
693
- // create element
694
- elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
695
- ? 'slot-fb'
696
- : newVNode.$tag$)
697
- );
698
- if (isSvgMode && newVNode.$tag$ === 'foreignObject') {
699
- isSvgMode = false;
700
- }
701
- // add css classes, attrs, props, listeners, etc.
702
- {
703
- updateElement(null, newVNode, isSvgMode);
704
- }
705
- if (isDef(scopeId) && elm['s-si'] !== scopeId) {
706
- // if there is a scopeId and this is the initial render
707
- // then let's add the scopeId as a css class
708
- elm.classList.add((elm['s-si'] = scopeId));
709
- }
710
- if (newVNode.$children$) {
711
- for (i = 0; i < newVNode.$children$.length; ++i) {
712
- // create the node
713
- childNode = createElm(oldParentVNode, newVNode, i, elm);
714
- // return node could have been null
715
- if (childNode) {
716
- // append our new node
717
- elm.appendChild(childNode);
718
- }
719
- }
720
- }
721
- {
722
- if (newVNode.$tag$ === 'svg') {
723
- // Only reset the SVG context when we're exiting <svg> element
724
- isSvgMode = false;
725
- }
726
- else if (elm.tagName === 'foreignObject') {
727
- // Reenter SVG context when we're exiting <foreignObject> element
728
- isSvgMode = true;
729
- }
730
- }
731
- }
732
- // This needs to always happen so we can hide nodes that are projected
733
- // to another component but don't end up in a slot
734
- elm['s-hn'] = hostTagName;
735
- {
736
- if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
737
- // remember the content reference comment
738
- elm['s-sr'] = true;
739
- // remember the content reference comment
740
- elm['s-cr'] = contentRef;
741
- // remember the slot name, or empty string for default slot
742
- elm['s-sn'] = newVNode.$name$ || '';
743
- // remember the ref callback function
744
- elm['s-rf'] = (_a = newVNode.$attrs$) === null || _a === void 0 ? void 0 : _a.ref;
745
- // check if we've got an old vnode for this slot
746
- oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
747
- if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
748
- {
749
- // we've got an old slot vnode and the wrapper is being replaced
750
- // so let's move the old slot content back to its original location
751
- putBackInOriginalLocation(oldParentVNode.$elm$, false);
752
- }
753
- }
754
- }
755
- }
756
- return elm;
757
- };
758
- const putBackInOriginalLocation = (parentElm, recursive) => {
759
- plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
760
- const oldSlotChildNodes = Array.from(parentElm.childNodes);
761
- if (parentElm['s-sr'] && BUILD.experimentalSlotFixes) {
762
- let node = parentElm;
763
- while ((node = node.nextSibling)) {
764
- if (node && node['s-sn'] === parentElm['s-sn'] && node['s-sh'] === hostTagName) {
765
- oldSlotChildNodes.push(node);
766
- }
767
- }
768
- }
769
- for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
770
- const childNode = oldSlotChildNodes[i];
771
- if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
772
- // and relocate it back to it's original location
773
- parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
774
- // remove the old original location comment entirely
775
- // later on the patch function will know what to do
776
- // and move this to the correct spot if need be
777
- childNode['s-ol'].remove();
778
- childNode['s-ol'] = undefined;
779
- // Reset so we can correctly move the node around again.
780
- childNode['s-sh'] = undefined;
781
- checkSlotRelocate = true;
782
- }
783
- if (recursive) {
784
- putBackInOriginalLocation(childNode, recursive);
785
- }
786
- }
787
- plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
788
- };
789
- /**
790
- * Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
791
- * add them to the DOM in the appropriate place.
792
- *
793
- * @param parentElm the DOM node which should be used as a parent for the new
794
- * DOM nodes
795
- * @param before a child of the `parentElm` which the new children should be
796
- * inserted before (optional)
797
- * @param parentVNode the parent virtual DOM node
798
- * @param vnodes the new child virtual DOM nodes to produce DOM nodes for
799
- * @param startIdx the index in the child virtual DOM nodes at which to start
800
- * creating DOM nodes (inclusive)
801
- * @param endIdx the index in the child virtual DOM nodes at which to stop
802
- * creating DOM nodes (inclusive)
803
- */
804
- const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
805
- let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
806
- let childNode;
807
- if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
808
- containerElm = containerElm.shadowRoot;
809
- }
810
- for (; startIdx <= endIdx; ++startIdx) {
811
- if (vnodes[startIdx]) {
812
- childNode = createElm(null, parentVNode, startIdx, parentElm);
813
- if (childNode) {
814
- vnodes[startIdx].$elm$ = childNode;
815
- containerElm.insertBefore(childNode, referenceNode(before) );
816
- }
817
- }
818
- }
819
- };
820
- /**
821
- * Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
822
- * This can be used to, for instance, clean up after a list of children which
823
- * should no longer be shown.
824
- *
825
- * This function also handles some of Stencil's slot relocation logic.
826
- *
827
- * @param vnodes a list of virtual DOM nodes to remove
828
- * @param startIdx the index at which to start removing nodes (inclusive)
829
- * @param endIdx the index at which to stop removing nodes (inclusive)
830
- */
831
- const removeVnodes = (vnodes, startIdx, endIdx) => {
832
- for (let index = startIdx; index <= endIdx; ++index) {
833
- const vnode = vnodes[index];
834
- if (vnode) {
835
- const elm = vnode.$elm$;
836
- nullifyVNodeRefs(vnode);
837
- if (elm) {
838
- {
839
- // we're removing this element
840
- // so it's possible we need to show slot fallback content now
841
- checkSlotFallbackVisibility = true;
842
- if (elm['s-ol']) {
843
- // remove the original location comment
844
- elm['s-ol'].remove();
845
- }
846
- else {
847
- // it's possible that child nodes of the node
848
- // that's being removed are slot nodes
849
- putBackInOriginalLocation(elm, true);
850
- }
851
- }
852
- // remove the vnode's element from the dom
853
- elm.remove();
854
- }
855
- }
856
- }
857
- };
858
- /**
859
- * Reconcile the children of a new VNode with the children of an old VNode by
860
- * traversing the two collections of children, identifying nodes that are
861
- * conserved or changed, calling out to `patch` to make any necessary
862
- * updates to the DOM, and rearranging DOM nodes as needed.
863
- *
864
- * The algorithm for reconciling children works by analyzing two 'windows' onto
865
- * the two arrays of children (`oldCh` and `newCh`). We keep track of the
866
- * 'windows' by storing start and end indices and references to the
867
- * corresponding array entries. Initially the two 'windows' are basically equal
868
- * to the entire array, but we progressively narrow the windows until there are
869
- * no children left to update by doing the following:
870
- *
871
- * 1. Skip any `null` entries at the beginning or end of the two arrays, so
872
- * that if we have an initial array like the following we'll end up dealing
873
- * only with a window bounded by the highlighted elements:
874
- *
875
- * [null, null, VNode1 , ... , VNode2, null, null]
876
- * ^^^^^^ ^^^^^^
877
- *
878
- * 2. Check to see if the elements at the head and tail positions are equal
879
- * across the windows. This will basically detect elements which haven't
880
- * been added, removed, or changed position, i.e. if you had the following
881
- * VNode elements (represented as HTML):
882
- *
883
- * oldVNode: `<div><p><span>HEY</span></p></div>`
884
- * newVNode: `<div><p><span>THERE</span></p></div>`
885
- *
886
- * Then when comparing the children of the `<div>` tag we check the equality
887
- * of the VNodes corresponding to the `<p>` tags and, since they are the
888
- * same tag in the same position, we'd be able to avoid completely
889
- * re-rendering the subtree under them with a new DOM element and would just
890
- * call out to `patch` to handle reconciling their children and so on.
891
- *
892
- * 3. Check, for both windows, to see if the element at the beginning of the
893
- * window corresponds to the element at the end of the other window. This is
894
- * a heuristic which will let us identify _some_ situations in which
895
- * elements have changed position, for instance it _should_ detect that the
896
- * children nodes themselves have not changed but merely moved in the
897
- * following example:
898
- *
899
- * oldVNode: `<div><element-one /><element-two /></div>`
900
- * newVNode: `<div><element-two /><element-one /></div>`
901
- *
902
- * If we find cases like this then we also need to move the concrete DOM
903
- * elements corresponding to the moved children to write the re-order to the
904
- * DOM.
905
- *
906
- * 4. Finally, if VNodes have the `key` attribute set on them we check for any
907
- * nodes in the old children which have the same key as the first element in
908
- * our window on the new children. If we find such a node we handle calling
909
- * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
910
- * what we find.
911
- *
912
- * Finally, once we've narrowed our 'windows' to the point that either of them
913
- * collapse (i.e. they have length 0) we then handle any remaining VNode
914
- * insertion or deletion that needs to happen to get a DOM state that correctly
915
- * reflects the new child VNodes. If, for instance, after our window on the old
916
- * children has collapsed we still have more nodes on the new children that
917
- * we haven't dealt with yet then we need to add them, or if the new children
918
- * collapse but we still have unhandled _old_ children then we need to make
919
- * sure the corresponding DOM nodes are removed.
920
- *
921
- * @param parentElm the node into which the parent VNode is rendered
922
- * @param oldCh the old children of the parent node
923
- * @param newVNode the new VNode which will replace the parent
924
- * @param newCh the new children of the parent node
925
- * @param isInitialRender whether or not this is the first render of the vdom
926
- */
927
- const updateChildren = (parentElm, oldCh, newVNode, newCh, isInitialRender = false) => {
928
- let oldStartIdx = 0;
929
- let newStartIdx = 0;
930
- let idxInOld = 0;
931
- let i = 0;
932
- let oldEndIdx = oldCh.length - 1;
933
- let oldStartVnode = oldCh[0];
934
- let oldEndVnode = oldCh[oldEndIdx];
935
- let newEndIdx = newCh.length - 1;
936
- let newStartVnode = newCh[0];
937
- let newEndVnode = newCh[newEndIdx];
938
- let node;
939
- let elmToMove;
940
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
941
- if (oldStartVnode == null) {
942
- // VNode might have been moved left
943
- oldStartVnode = oldCh[++oldStartIdx];
944
- }
945
- else if (oldEndVnode == null) {
946
- oldEndVnode = oldCh[--oldEndIdx];
947
- }
948
- else if (newStartVnode == null) {
949
- newStartVnode = newCh[++newStartIdx];
950
- }
951
- else if (newEndVnode == null) {
952
- newEndVnode = newCh[--newEndIdx];
953
- }
954
- else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
955
- // if the start nodes are the same then we should patch the new VNode
956
- // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
957
- // indices to reflect that. We don't need to move any DOM Nodes around
958
- // since things are matched up in order.
959
- patch(oldStartVnode, newStartVnode, isInitialRender);
960
- oldStartVnode = oldCh[++oldStartIdx];
961
- newStartVnode = newCh[++newStartIdx];
962
- }
963
- else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
964
- // likewise, if the end nodes are the same we patch new onto old and
965
- // decrement our end indices, and also likewise in this case we don't
966
- // need to move any DOM Nodes.
967
- patch(oldEndVnode, newEndVnode, isInitialRender);
968
- oldEndVnode = oldCh[--oldEndIdx];
969
- newEndVnode = newCh[--newEndIdx];
970
- }
971
- else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
972
- // case: "Vnode moved right"
973
- //
974
- // We've found that the last node in our window on the new children is
975
- // the same VNode as the _first_ node in our window on the old children
976
- // we're dealing with now. Visually, this is the layout of these two
977
- // nodes:
978
- //
979
- // newCh: [..., newStartVnode , ... , newEndVnode , ...]
980
- // ^^^^^^^^^^^
981
- // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
982
- // ^^^^^^^^^^^^^
983
- //
984
- // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
985
- // and move the DOM element for `oldStartVnode`.
986
- if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
987
- putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
988
- }
989
- patch(oldStartVnode, newEndVnode, isInitialRender);
990
- // We need to move the element for `oldStartVnode` into a position which
991
- // will be appropriate for `newEndVnode`. For this we can use
992
- // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
993
- // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
994
- // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
995
- //
996
- // <old-start-node />
997
- // <some-intervening-node />
998
- // <old-end-node />
999
- // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
1000
- // <next-sibling />
1001
- //
1002
- // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
1003
- // the node for `oldStartVnode` at the end of the children of
1004
- // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
1005
- // aren't any siblings, and passing `null` to `Node.insertBefore` will
1006
- // append it to the children of the parent element.
1007
- parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
1008
- oldStartVnode = oldCh[++oldStartIdx];
1009
- newEndVnode = newCh[--newEndIdx];
1010
- }
1011
- else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
1012
- // case: "Vnode moved left"
1013
- //
1014
- // We've found that the first node in our window on the new children is
1015
- // the same VNode as the _last_ node in our window on the old children.
1016
- // Visually, this is the layout of these two nodes:
1017
- //
1018
- // newCh: [..., newStartVnode , ... , newEndVnode , ...]
1019
- // ^^^^^^^^^^^^^
1020
- // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
1021
- // ^^^^^^^^^^^
1022
- //
1023
- // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
1024
- // (which will handle updating any changed attributes, reconciling their
1025
- // children etc) but we also need to move the DOM node to which
1026
- // `oldEndVnode` corresponds.
1027
- if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
1028
- putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
1029
- }
1030
- patch(oldEndVnode, newStartVnode, isInitialRender);
1031
- // We've already checked above if `oldStartVnode` and `newStartVnode` are
1032
- // the same node, so since we're here we know that they are not. Thus we
1033
- // can move the element for `oldEndVnode` _before_ the element for
1034
- // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
1035
- // future.
1036
- parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
1037
- oldEndVnode = oldCh[--oldEndIdx];
1038
- newStartVnode = newCh[++newStartIdx];
1039
- }
1040
- else {
1041
- // Here we do some checks to match up old and new nodes based on the
1042
- // `$key$` attribute, which is set by putting a `key="my-key"` attribute
1043
- // in the JSX for a DOM element in the implementation of a Stencil
1044
- // component.
1045
- //
1046
- // First we check to see if there are any nodes in the array of old
1047
- // children which have the same key as the first node in the new
1048
- // children.
1049
- idxInOld = -1;
1050
- {
1051
- for (i = oldStartIdx; i <= oldEndIdx; ++i) {
1052
- if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
1053
- idxInOld = i;
1054
- break;
1055
- }
1056
- }
1057
- }
1058
- if (idxInOld >= 0) {
1059
- // We found a node in the old children which matches up with the first
1060
- // node in the new children! So let's deal with that
1061
- elmToMove = oldCh[idxInOld];
1062
- if (elmToMove.$tag$ !== newStartVnode.$tag$) {
1063
- // the tag doesn't match so we'll need a new DOM element
1064
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
1065
- }
1066
- else {
1067
- patch(elmToMove, newStartVnode, isInitialRender);
1068
- // invalidate the matching old node so that we won't try to update it
1069
- // again later on
1070
- oldCh[idxInOld] = undefined;
1071
- node = elmToMove.$elm$;
1072
- }
1073
- newStartVnode = newCh[++newStartIdx];
1074
- }
1075
- else {
1076
- // We either didn't find an element in the old children that matches
1077
- // the key of the first new child OR the build is not using `key`
1078
- // attributes at all. In either case we need to create a new element
1079
- // for the new node.
1080
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
1081
- newStartVnode = newCh[++newStartIdx];
1082
- }
1083
- if (node) {
1084
- // if we created a new node then handle inserting it to the DOM
1085
- {
1086
- parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
1087
- }
1088
- }
1089
- }
1090
- }
1091
- if (oldStartIdx > oldEndIdx) {
1092
- // we have some more new nodes to add which don't match up with old nodes
1093
- addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
1094
- }
1095
- else if (newStartIdx > newEndIdx) {
1096
- // there are nodes in the `oldCh` array which no longer correspond to nodes
1097
- // in the new array, so lets remove them (which entails cleaning up the
1098
- // relevant DOM nodes)
1099
- removeVnodes(oldCh, oldStartIdx, oldEndIdx);
1100
- }
1101
- };
1102
- /**
1103
- * Compare two VNodes to determine if they are the same
1104
- *
1105
- * **NB**: This function is an equality _heuristic_ based on the available
1106
- * information set on the two VNodes and can be misleading under certain
1107
- * circumstances. In particular, if the two nodes do not have `key` attrs
1108
- * (available under `$key$` on VNodes) then the function falls back on merely
1109
- * checking that they have the same tag.
1110
- *
1111
- * So, in other words, if `key` attrs are not set on VNodes which may be
1112
- * changing order within a `children` array or something along those lines then
1113
- * we could obtain a false negative and then have to do needless re-rendering
1114
- * (i.e. we'd say two VNodes aren't equal when in fact they should be).
1115
- *
1116
- * @param leftVNode the first VNode to check
1117
- * @param rightVNode the second VNode to check
1118
- * @param isInitialRender whether or not this is the first render of the vdom
1119
- * @returns whether they're equal or not
1120
- */
1121
- const isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
1122
- // compare if two vnode to see if they're "technically" the same
1123
- // need to have the same element tag, and same key to be the same
1124
- if (leftVNode.$tag$ === rightVNode.$tag$) {
1125
- if (leftVNode.$tag$ === 'slot') {
1126
- return leftVNode.$name$ === rightVNode.$name$;
1127
- }
1128
- // this will be set if JSX tags in the build have `key` attrs set on them
1129
- // we only want to check this if we're not on the first render since on
1130
- // first render `leftVNode.$key$` will always be `null`, so we can be led
1131
- // astray and, for instance, accidentally delete a DOM node that we want to
1132
- // keep around.
1133
- if (!isInitialRender) {
1134
- return leftVNode.$key$ === rightVNode.$key$;
1135
- }
1136
- return true;
1137
- }
1138
- return false;
1139
- };
1140
- const referenceNode = (node) => {
1141
- // this node was relocated to a new location in the dom
1142
- // because of some other component's slot
1143
- // but we still have an html comment in place of where
1144
- // it's original location was according to it's original vdom
1145
- return (node && node['s-ol']) || node;
1146
- };
1147
- const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
1148
- /**
1149
- * Handle reconciling an outdated VNode with a new one which corresponds to
1150
- * it. This function handles flushing updates to the DOM and reconciling the
1151
- * children of the two nodes (if any).
1152
- *
1153
- * @param oldVNode an old VNode whose DOM element and children we want to update
1154
- * @param newVNode a new VNode representing an updated version of the old one
1155
- * @param isInitialRender whether or not this is the first render of the vdom
1156
- */
1157
- const patch = (oldVNode, newVNode, isInitialRender = false) => {
1158
- const elm = (newVNode.$elm$ = oldVNode.$elm$);
1159
- const oldChildren = oldVNode.$children$;
1160
- const newChildren = newVNode.$children$;
1161
- const tag = newVNode.$tag$;
1162
- const text = newVNode.$text$;
1163
- let defaultHolder;
1164
- if (text === null) {
1165
- {
1166
- // test if we're rendering an svg element, or still rendering nodes inside of one
1167
- // only add this to the when the compiler sees we're using an svg somewhere
1168
- isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
1169
- }
1170
- {
1171
- if (tag === 'slot' && !useNativeShadowDom) ;
1172
- else {
1173
- // either this is the first render of an element OR it's an update
1174
- // AND we already know it's possible it could have changed
1175
- // this updates the element's css classes, attrs, props, listeners, etc.
1176
- updateElement(oldVNode, newVNode, isSvgMode);
1177
- }
1178
- }
1179
- if (oldChildren !== null && newChildren !== null) {
1180
- // looks like there's child vnodes for both the old and new vnodes
1181
- // so we need to call `updateChildren` to reconcile them
1182
- updateChildren(elm, oldChildren, newVNode, newChildren, isInitialRender);
1183
- }
1184
- else if (newChildren !== null) {
1185
- // no old child vnodes, but there are new child vnodes to add
1186
- if (oldVNode.$text$ !== null) {
1187
- // the old vnode was text, so be sure to clear it out
1188
- elm.textContent = '';
1189
- }
1190
- // add the new vnode children
1191
- addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
1192
- }
1193
- else if (oldChildren !== null) {
1194
- // no new child vnodes, but there are old child vnodes to remove
1195
- removeVnodes(oldChildren, 0, oldChildren.length - 1);
1196
- }
1197
- if (isSvgMode && tag === 'svg') {
1198
- isSvgMode = false;
1199
- }
1200
- }
1201
- else if ((defaultHolder = elm['s-cr'])) {
1202
- // this element has slotted content
1203
- defaultHolder.parentNode.textContent = text;
1204
- }
1205
- else if (oldVNode.$text$ !== text) {
1206
- // update the text content for the text only vnode
1207
- // and also only if the text is different than before
1208
- elm.data = text;
1209
- }
1210
- };
1211
- /**
1212
- * Adjust the `.hidden` property as-needed on any nodes in a DOM subtree which
1213
- * are slot fallbacks nodes.
1214
- *
1215
- * A slot fallback node should be visible by default. Then, it should be
1216
- * conditionally hidden if:
1217
- *
1218
- * - it has a sibling with a `slot` property set to its slot name or if
1219
- * - it is a default fallback slot node, in which case we hide if it has any
1220
- * content
1221
- *
1222
- * @param elm the element of interest
1223
- */
1224
- const updateFallbackSlotVisibility = (elm) => {
1225
- const childNodes = elm.childNodes;
1226
- for (const childNode of childNodes) {
1227
- if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1228
- if (childNode['s-sr']) {
1229
- // this is a slot fallback node
1230
- // get the slot name for this slot reference node
1231
- const slotName = childNode['s-sn'];
1232
- // by default always show a fallback slot node
1233
- // then hide it if there are other slots in the light dom
1234
- childNode.hidden = false;
1235
- // we need to check all of its sibling nodes in order to see if
1236
- // `childNode` should be hidden
1237
- for (const siblingNode of childNodes) {
1238
- // Don't check the node against itself
1239
- if (siblingNode !== childNode) {
1240
- if (siblingNode['s-hn'] !== childNode['s-hn'] || slotName !== '') {
1241
- // this sibling node is from a different component OR is a named
1242
- // fallback slot node
1243
- if (siblingNode.nodeType === 1 /* NODE_TYPE.ElementNode */ &&
1244
- (slotName === siblingNode.getAttribute('slot') || slotName === siblingNode['s-sn'])) {
1245
- childNode.hidden = true;
1246
- break;
1247
- }
1248
- }
1249
- else {
1250
- // this is a default fallback slot node
1251
- // any element or text node (with content)
1252
- // should hide the default fallback slot node
1253
- if (siblingNode.nodeType === 1 /* NODE_TYPE.ElementNode */ ||
1254
- (siblingNode.nodeType === 3 /* NODE_TYPE.TextNode */ && siblingNode.textContent.trim() !== '')) {
1255
- childNode.hidden = true;
1256
- break;
1257
- }
1258
- }
1259
- }
1260
- }
1261
- }
1262
- // keep drilling down
1263
- updateFallbackSlotVisibility(childNode);
1264
- }
1265
- }
1266
- };
1267
- /**
1268
- * Component-global information about nodes which are either currently being
1269
- * relocated or will be shortly.
1270
- */
1271
- const relocateNodes = [];
1272
- /**
1273
- * Mark the contents of a slot for relocation via adding references to them to
1274
- * the {@link relocateNodes} data structure. The actual work of relocating them
1275
- * will then be handled in {@link renderVdom}.
1276
- *
1277
- * @param elm a render node whose child nodes need to be relocated
1278
- */
1279
- const markSlotContentForRelocation = (elm) => {
1280
- // tslint:disable-next-line: prefer-const
1281
- let node;
1282
- let hostContentNodes;
1283
- let j;
1284
- for (const childNode of elm.childNodes) {
1285
- // we need to find child nodes which are slot references so we can then try
1286
- // to match them up with nodes that need to be relocated
1287
- if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
1288
- // first get the content reference comment node ('s-cr'), then we get
1289
- // its parent, which is where all the host content is now
1290
- hostContentNodes = node.parentNode.childNodes;
1291
- const slotName = childNode['s-sn'];
1292
- // iterate through all the nodes under the location where the host was
1293
- // originally rendered
1294
- for (j = hostContentNodes.length - 1; j >= 0; j--) {
1295
- node = hostContentNodes[j];
1296
- // check that the node is not a content reference node or a node
1297
- // reference and then check that the host name does not match that of
1298
- // childNode.
1299
- // In addition, check that the slot either has not already been relocated, or
1300
- // that its current location's host is not childNode's host. This is essentially
1301
- // a check so that we don't try to relocate (and then hide) a node that is already
1302
- // where it should be.
1303
- if (!node['s-cn'] &&
1304
- !node['s-nr'] &&
1305
- node['s-hn'] !== childNode['s-hn'] &&
1306
- (!BUILD.experimentalSlotFixes )) {
1307
- // if `node` is located in the slot that `childNode` refers to (via the
1308
- // `'s-sn'` property) then we need to relocate it from it's current spot
1309
- // (under the host element parent) to the right slot location
1310
- if (isNodeLocatedInSlot(node, slotName)) {
1311
- // it's possible we've already decided to relocate this node
1312
- let relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1313
- // made some changes to slots
1314
- // let's make sure we also double check
1315
- // fallbacks are correctly hidden or shown
1316
- checkSlotFallbackVisibility = true;
1317
- // ensure that the slot-name attr is correct
1318
- node['s-sn'] = node['s-sn'] || slotName;
1319
- if (relocateNodeData) {
1320
- relocateNodeData.$nodeToRelocate$['s-sh'] = childNode['s-hn'];
1321
- // we marked this node for relocation previously but didn't find
1322
- // out the slot reference node to which it needs to be relocated
1323
- // so write it down now!
1324
- relocateNodeData.$slotRefNode$ = childNode;
1325
- }
1326
- else {
1327
- node['s-sh'] = childNode['s-hn'];
1328
- // add to our list of nodes to relocate
1329
- relocateNodes.push({
1330
- $slotRefNode$: childNode,
1331
- $nodeToRelocate$: node,
1332
- });
1333
- }
1334
- if (node['s-sr']) {
1335
- relocateNodes.map((relocateNode) => {
1336
- if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
1337
- relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
1338
- if (relocateNodeData && !relocateNode.$slotRefNode$) {
1339
- relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1340
- }
1341
- }
1342
- });
1343
- }
1344
- }
1345
- else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
1346
- // the node is not found within the slot (`childNode`) that we're
1347
- // currently looking at, so we stick it into `relocateNodes` to
1348
- // handle later. If we never find a home for this element then
1349
- // we'll need to hide it
1350
- relocateNodes.push({
1351
- $nodeToRelocate$: node,
1352
- });
1353
- }
1354
- }
1355
- }
1356
- }
1357
- // if we're dealing with any type of element (capable of itself being a
1358
- // slot reference or containing one) then we recur
1359
- if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1360
- markSlotContentForRelocation(childNode);
1361
- }
1362
- }
1363
- };
1364
- /**
1365
- * Check whether a node is located in a given named slot.
1366
- *
1367
- * @param nodeToRelocate the node of interest
1368
- * @param slotName the slot name to check
1369
- * @returns whether the node is located in the slot or not
1370
- */
1371
- const isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
1372
- if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1373
- if (nodeToRelocate.getAttribute('slot') === null && slotName === '') {
1374
- // if the node doesn't have a slot attribute, and the slot we're checking
1375
- // is not a named slot, then we assume the node should be within the slot
1376
- return true;
1377
- }
1378
- if (nodeToRelocate.getAttribute('slot') === slotName) {
1379
- return true;
1380
- }
1381
- return false;
1382
- }
1383
- if (nodeToRelocate['s-sn'] === slotName) {
1384
- return true;
1385
- }
1386
- return slotName === '';
1387
- };
1388
- /**
1389
- * 'Nullify' any VDom `ref` callbacks on a VDom node or its children by calling
1390
- * them with `null`. This signals that the DOM element corresponding to the VDom
1391
- * node has been removed from the DOM.
1392
- *
1393
- * @param vNode a virtual DOM node
1394
- */
1395
- const nullifyVNodeRefs = (vNode) => {
1396
- {
1397
- vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
1398
- vNode.$children$ && vNode.$children$.map(nullifyVNodeRefs);
1399
- }
1400
- };
1401
- /**
1402
- * The main entry point for Stencil's virtual DOM-based rendering engine
1403
- *
1404
- * Given a {@link d.HostRef} container and some virtual DOM nodes, this
1405
- * function will handle creating a virtual DOM tree with a single root, patching
1406
- * the current virtual DOM tree onto an old one (if any), dealing with slot
1407
- * relocation, and reflecting attributes.
1408
- *
1409
- * @param hostRef data needed to root and render the virtual DOM tree, such as
1410
- * the DOM node into which it should be rendered.
1411
- * @param renderFnResults the virtual DOM nodes to be rendered
1412
- * @param isInitialLoad whether or not this is the first call after page load
1413
- */
1414
- const renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
1415
- var _a, _b, _c, _d;
1416
- const hostElm = hostRef.$hostElement$;
1417
- const cmpMeta = hostRef.$cmpMeta$;
1418
- const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1419
- // if `renderFnResults` is a Host node then we can use it directly. If not,
1420
- // we need to call `h` again to wrap the children of our component in a
1421
- // 'dummy' Host node (well, an empty vnode) since `renderVdom` assumes
1422
- // implicitly that the top-level vdom node is 1) an only child and 2)
1423
- // contains attrs that need to be set on the host element.
1424
- const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1425
- hostTagName = hostElm.tagName;
1426
- if (cmpMeta.$attrsToReflect$) {
1427
- rootVnode.$attrs$ = rootVnode.$attrs$ || {};
1428
- cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
1429
- }
1430
- // On the first render and *only* on the first render we want to check for
1431
- // any attributes set on the host element which are also set on the vdom
1432
- // node. If we find them, we override the value on the VDom node attrs with
1433
- // the value from the host element, which allows developers building apps
1434
- // with Stencil components to override e.g. the `role` attribute on a
1435
- // component even if it's already set on the `Host`.
1436
- if (isInitialLoad && rootVnode.$attrs$) {
1437
- for (const key of Object.keys(rootVnode.$attrs$)) {
1438
- // We have a special implementation in `setAccessor` for `style` and
1439
- // `class` which reconciles values coming from the VDom with values
1440
- // already present on the DOM element, so we don't want to override those
1441
- // attributes on the VDom tree with values from the host element if they
1442
- // are present.
1443
- //
1444
- // Likewise, `ref` and `key` are special internal values for the Stencil
1445
- // runtime and we don't want to override those either.
1446
- if (hostElm.hasAttribute(key) && !['key', 'ref', 'style', 'class'].includes(key)) {
1447
- rootVnode.$attrs$[key] = hostElm[key];
1448
- }
1449
- }
1450
- }
1451
- rootVnode.$tag$ = null;
1452
- rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
1453
- hostRef.$vnode$ = rootVnode;
1454
- rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
1455
- {
1456
- scopeId = hostElm['s-sc'];
1457
- }
1458
- useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1459
- {
1460
- contentRef = hostElm['s-cr'];
1461
- // always reset
1462
- checkSlotFallbackVisibility = false;
1463
- }
1464
- // synchronous patch
1465
- patch(oldVNode, rootVnode, isInitialLoad);
1466
- {
1467
- // while we're moving nodes around existing nodes, temporarily disable
1468
- // the disconnectCallback from working
1469
- plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1470
- if (checkSlotRelocate) {
1471
- markSlotContentForRelocation(rootVnode.$elm$);
1472
- for (const relocateData of relocateNodes) {
1473
- const nodeToRelocate = relocateData.$nodeToRelocate$;
1474
- if (!nodeToRelocate['s-ol']) {
1475
- // add a reference node marking this node's original location
1476
- // keep a reference to this node for later lookups
1477
- const orgLocationNode = doc.createTextNode('');
1478
- orgLocationNode['s-nr'] = nodeToRelocate;
1479
- nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1480
- }
1481
- }
1482
- for (const relocateData of relocateNodes) {
1483
- const nodeToRelocate = relocateData.$nodeToRelocate$;
1484
- const slotRefNode = relocateData.$slotRefNode$;
1485
- if (slotRefNode) {
1486
- const parentNodeRef = slotRefNode.parentNode;
1487
- // When determining where to insert content, the most simple case would be
1488
- // to relocate the node immediately following the slot reference node. We do this
1489
- // by getting a reference to the node immediately following the slot reference node
1490
- // since we will use `insertBefore` to manipulate the DOM.
1491
- //
1492
- // If there is no node immediately following the slot reference node, then we will just
1493
- // end up appending the node as the last child of the parent.
1494
- let insertBeforeNode = slotRefNode.nextSibling;
1495
- // If the node we're currently planning on inserting the new node before is an element,
1496
- // we need to do some additional checks to make sure we're inserting the node in the correct order.
1497
- // The use case here would be that we have multiple nodes being relocated to the same slot. So, we want
1498
- // to make sure they get inserted into their new home in the same order they were declared in their original location.
1499
- //
1500
- // TODO(STENCIL-914): Remove `experimentalSlotFixes` check
1501
- {
1502
- let orgLocationNode = (_a = nodeToRelocate['s-ol']) === null || _a === void 0 ? void 0 : _a.previousSibling;
1503
- while (orgLocationNode) {
1504
- let refNode = (_b = orgLocationNode['s-nr']) !== null && _b !== void 0 ? _b : null;
1505
- if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1506
- refNode = refNode.nextSibling;
1507
- // If the refNode is the same node to be relocated or another element's slot reference, keep searching to find the
1508
- // correct relocation target
1509
- while (refNode === nodeToRelocate || (refNode === null || refNode === void 0 ? void 0 : refNode['s-sr'])) {
1510
- refNode = refNode === null || refNode === void 0 ? void 0 : refNode.nextSibling;
1511
- }
1512
- if (!refNode || !refNode['s-nr']) {
1513
- insertBeforeNode = refNode;
1514
- break;
1515
- }
1516
- }
1517
- orgLocationNode = orgLocationNode.previousSibling;
1518
- }
1519
- }
1520
- if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
1521
- nodeToRelocate.nextSibling !== insertBeforeNode) {
1522
- // we've checked that it's worth while to relocate
1523
- // since that the node to relocate
1524
- // has a different next sibling or parent relocated
1525
- if (nodeToRelocate !== insertBeforeNode) {
1526
- if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1527
- // probably a component in the index.html that doesn't have its hostname set
1528
- nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1529
- }
1530
- // Add it back to the dom but in its new home
1531
- // If we get to this point and `insertBeforeNode` is `null`, that means
1532
- // we're just going to append the node as the last child of the parent. Passing
1533
- // `null` as the second arg here will trigger that behavior.
1534
- parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1535
- // Reset the `hidden` value back to what it was defined as originally
1536
- // This solves a problem where a `slot` is dynamically rendered and `hidden` may have
1537
- // been set on content originally, but now it has a slot to go to so it should have
1538
- // the value it was defined as having in the DOM, not what we overrode it to.
1539
- if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1540
- nodeToRelocate.hidden = (_c = nodeToRelocate['s-ih']) !== null && _c !== void 0 ? _c : false;
1541
- }
1542
- }
1543
- }
1544
- nodeToRelocate && typeof slotRefNode['s-rf'] === 'function' && slotRefNode['s-rf'](nodeToRelocate);
1545
- }
1546
- else {
1547
- // this node doesn't have a slot home to go to, so let's hide it
1548
- if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1549
- // Store the initial value of `hidden` so we can reset it later when
1550
- // moving nodes around.
1551
- if (isInitialLoad) {
1552
- nodeToRelocate['s-ih'] = (_d = nodeToRelocate.hidden) !== null && _d !== void 0 ? _d : false;
1553
- }
1554
- nodeToRelocate.hidden = true;
1555
- }
1556
- }
1557
- }
1558
- }
1559
- if (checkSlotFallbackVisibility) {
1560
- updateFallbackSlotVisibility(rootVnode.$elm$);
1561
- }
1562
- // done moving nodes around
1563
- // allow the disconnect callback to work again
1564
- plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1565
- // always reset
1566
- relocateNodes.length = 0;
1567
- }
1568
- // Clear the content ref so we don't create a memory leak
1569
- contentRef = undefined;
1570
- };
1571
- const attachToAncestor = (hostRef, ancestorComponent) => {
1572
- if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
1573
- ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
1574
- }
1575
- };
1576
- const scheduleUpdate = (hostRef, isInitialLoad) => {
1577
- {
1578
- hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
1579
- }
1580
- if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
1581
- hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
1582
- return;
1583
- }
1584
- attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1585
- // there is no ancestor component or the ancestor component
1586
- // has already fired off its lifecycle update then
1587
- // fire off the initial update
1588
- const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1589
- return writeTask(dispatch) ;
1590
- };
1591
- /**
1592
- * Dispatch initial-render and update lifecycle hooks, enqueuing calls to
1593
- * component lifecycle methods like `componentWillLoad` as well as
1594
- * {@link updateComponent}, which will kick off the virtual DOM re-render.
1595
- *
1596
- * @param hostRef a reference to a host DOM node
1597
- * @param isInitialLoad whether we're on the initial load or not
1598
- * @returns an empty Promise which is used to enqueue a series of operations for
1599
- * the component
1600
- */
1601
- const dispatchHooks = (hostRef, isInitialLoad) => {
1602
- const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1603
- const instance = hostRef.$lazyInstance$ ;
1604
- // We're going to use this variable together with `enqueue` to implement a
1605
- // little promise-based queue. We start out with it `undefined`. When we add
1606
- // the first function to the queue we'll set this variable to be that
1607
- // function's return value. When we attempt to add subsequent values to the
1608
- // queue we'll check that value and, if it was a `Promise`, we'll then chain
1609
- // the new function off of that `Promise` using `.then()`. This will give our
1610
- // queue two nice properties:
1611
- //
1612
- // 1. If all functions added to the queue are synchronous they'll be called
1613
- // synchronously right away.
1614
- // 2. If all functions added to the queue are asynchronous they'll all be
1615
- // called in order after `dispatchHooks` exits.
1616
- let maybePromise;
1617
- if (isInitialLoad) {
1618
- {
1619
- hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
1620
- if (hostRef.$queuedListeners$) {
1621
- hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
1622
- hostRef.$queuedListeners$ = undefined;
1623
- }
1624
- }
1625
- {
1626
- // If `componentWillLoad` returns a `Promise` then we want to wait on
1627
- // whatever's going on in that `Promise` before we launch into
1628
- // rendering the component, doing other lifecycle stuff, etc. So
1629
- // in that case we assign the returned promise to the variable we
1630
- // declared above to hold a possible 'queueing' Promise
1631
- maybePromise = safeCall(instance, 'componentWillLoad');
1632
- }
1633
- }
1634
- endSchedule();
1635
- return enqueue(maybePromise, () => updateComponent(hostRef, instance, isInitialLoad));
1636
- };
1637
- /**
1638
- * This function uses a Promise to implement a simple first-in, first-out queue
1639
- * of functions to be called.
1640
- *
1641
- * The queue is ordered on the basis of the first argument. If it's
1642
- * `undefined`, then nothing is on the queue yet, so the provided function can
1643
- * be called synchronously (although note that this function may return a
1644
- * `Promise`). The idea is that then the return value of that enqueueing
1645
- * operation is kept around, so that if it was a `Promise` then subsequent
1646
- * functions can be enqueued by calling this function again with that `Promise`
1647
- * as the first argument.
1648
- *
1649
- * @param maybePromise either a `Promise` which should resolve before the next function is called or an 'empty' sentinel
1650
- * @param fn a function to enqueue
1651
- * @returns either a `Promise` or the return value of the provided function
1652
- */
1653
- const enqueue = (maybePromise, fn) => isPromisey(maybePromise) ? maybePromise.then(fn) : fn();
1654
- /**
1655
- * Check that a value is a `Promise`. To check, we first see if the value is an
1656
- * instance of the `Promise` global. In a few circumstances, in particular if
1657
- * the global has been overwritten, this is could be misleading, so we also do
1658
- * a little 'duck typing' check to see if the `.then` property of the value is
1659
- * defined and a function.
1660
- *
1661
- * @param maybePromise it might be a promise!
1662
- * @returns whether it is or not
1663
- */
1664
- const isPromisey = (maybePromise) => maybePromise instanceof Promise ||
1665
- (maybePromise && maybePromise.then && typeof maybePromise.then === 'function');
1666
- /**
1667
- * Update a component given reference to its host elements and so on.
1668
- *
1669
- * @param hostRef an object containing references to the element's host node,
1670
- * VDom nodes, and other metadata
1671
- * @param instance a reference to the underlying host element where it will be
1672
- * rendered
1673
- * @param isInitialLoad whether or not this function is being called as part of
1674
- * the first render cycle
1675
- */
1676
- const updateComponent = async (hostRef, instance, isInitialLoad) => {
1677
- var _a;
1678
- const elm = hostRef.$hostElement$;
1679
- const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1680
- const rc = elm['s-rc'];
1681
- if (isInitialLoad) {
1682
- // DOM WRITE!
1683
- attachStyles(hostRef);
1684
- }
1685
- const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1686
- {
1687
- callRender(hostRef, instance, elm, isInitialLoad);
1688
- }
1689
- if (rc) {
1690
- // ok, so turns out there are some child host elements
1691
- // waiting on this parent element to load
1692
- // let's fire off all update callbacks waiting
1693
- rc.map((cb) => cb());
1694
- elm['s-rc'] = undefined;
1695
- }
1696
- endRender();
1697
- endUpdate();
1698
- {
1699
- const childrenPromises = (_a = elm['s-p']) !== null && _a !== void 0 ? _a : [];
1700
- const postUpdate = () => postUpdateComponent(hostRef);
1701
- if (childrenPromises.length === 0) {
1702
- postUpdate();
1703
- }
1704
- else {
1705
- Promise.all(childrenPromises).then(postUpdate);
1706
- hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1707
- childrenPromises.length = 0;
1708
- }
1709
- }
1710
- };
1711
- /**
1712
- * Handle making the call to the VDom renderer with the proper context given
1713
- * various build variables
1714
- *
1715
- * @param hostRef an object containing references to the element's host node,
1716
- * VDom nodes, and other metadata
1717
- * @param instance a reference to the underlying host element where it will be
1718
- * rendered
1719
- * @param elm the Host element for the component
1720
- * @param isInitialLoad whether or not this function is being called as part of
1721
- * @returns an empty promise
1722
- */
1723
- const callRender = (hostRef, instance, elm, isInitialLoad) => {
1724
- try {
1725
- renderingRef = instance;
1726
- /**
1727
- * minification optimization: `allRenderFn` is `true` if all components have a `render`
1728
- * method, so we can call the method immediately. If not, check before calling it.
1729
- */
1730
- instance = instance.render() ;
1731
- {
1732
- hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1733
- }
1734
- {
1735
- hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1736
- }
1737
- {
1738
- {
1739
- // looks like we've got child nodes to render into this host element
1740
- // or we need to update the css class/attrs on the host element
1741
- // DOM WRITE!
1742
- {
1743
- renderVdom(hostRef, instance, isInitialLoad);
1744
- }
1745
- }
1746
- }
1747
- }
1748
- catch (e) {
1749
- consoleError(e, hostRef.$hostElement$);
1750
- }
1751
- renderingRef = null;
1752
- return null;
1753
- };
1754
- const getRenderingRef = () => renderingRef;
1755
- const postUpdateComponent = (hostRef) => {
1756
- const tagName = hostRef.$cmpMeta$.$tagName$;
1757
- const elm = hostRef.$hostElement$;
1758
- const endPostUpdate = createTime('postUpdate', tagName);
1759
- const instance = hostRef.$lazyInstance$ ;
1760
- const ancestorComponent = hostRef.$ancestorComponent$;
1761
- {
1762
- safeCall(instance, 'componentDidRender');
1763
- }
1764
- if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1765
- hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1766
- {
1767
- // DOM WRITE!
1768
- addHydratedFlag(elm);
1769
- }
1770
- {
1771
- safeCall(instance, 'componentDidLoad');
1772
- }
1773
- endPostUpdate();
1774
- {
1775
- hostRef.$onReadyResolve$(elm);
1776
- if (!ancestorComponent) {
1777
- appDidLoad();
1778
- }
1779
- }
1780
- }
1781
- else {
1782
- endPostUpdate();
1783
- }
1784
- {
1785
- hostRef.$onInstanceResolve$(elm);
1786
- }
1787
- // load events fire from bottom to top
1788
- // the deepest elements load first then bubbles up
1789
- {
1790
- if (hostRef.$onRenderResolve$) {
1791
- hostRef.$onRenderResolve$();
1792
- hostRef.$onRenderResolve$ = undefined;
1793
- }
1794
- if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
1795
- nextTick(() => scheduleUpdate(hostRef, false));
1796
- }
1797
- hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
1798
- }
1799
- // ( •_•)
1800
- // ( •_•)>⌐■-■
1801
- // (⌐■_■)
1802
- };
1803
- const forceUpdate = (ref) => {
1804
- {
1805
- const hostRef = getHostRef(ref);
1806
- const isConnected = hostRef.$hostElement$.isConnected;
1807
- if (isConnected &&
1808
- (hostRef.$flags$ & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1809
- scheduleUpdate(hostRef, false);
1810
- }
1811
- // Returns "true" when the forced update was successfully scheduled
1812
- return isConnected;
1813
- }
1814
- };
1815
- const appDidLoad = (who) => {
1816
- // on appload
1817
- // we have finish the first big initial render
1818
- {
1819
- addHydratedFlag(doc.documentElement);
1820
- }
1821
- nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1822
- };
1823
- /**
1824
- * Allows to safely call a method, e.g. `componentDidLoad`, on an instance,
1825
- * e.g. custom element node. If a build figures out that e.g. no component
1826
- * has a `componentDidLoad` method, the instance method gets removed from the
1827
- * output bundle and this function returns `undefined`.
1828
- * @param instance any object that may or may not contain methods
1829
- * @param method method name
1830
- * @param arg single arbitrary argument
1831
- * @returns result of method call if it exists, otherwise `undefined`
1832
- */
1833
- const safeCall = (instance, method, arg) => {
1834
- if (instance && instance[method]) {
1835
- try {
1836
- return instance[method](arg);
1837
- }
1838
- catch (e) {
1839
- consoleError(e);
1840
- }
1841
- }
1842
- return undefined;
1843
- };
1844
- const addHydratedFlag = (elm) => elm.classList.add('hydrated')
1845
- ;
1846
- const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1847
- const setValue = (ref, propName, newVal, cmpMeta) => {
1848
- // check our new property value against our internal value
1849
- const hostRef = getHostRef(ref);
1850
- const elm = hostRef.$hostElement$ ;
1851
- const oldVal = hostRef.$instanceValues$.get(propName);
1852
- const flags = hostRef.$flags$;
1853
- const instance = hostRef.$lazyInstance$ ;
1854
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1855
- // explicitly check for NaN on both sides, as `NaN === NaN` is always false
1856
- const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
1857
- const didValueChange = newVal !== oldVal && !areBothNaN;
1858
- if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1859
- // gadzooks! the property's value has changed!!
1860
- // set our new value!
1861
- hostRef.$instanceValues$.set(propName, newVal);
1862
- if (instance) {
1863
- // get an array of method names of watch functions to call
1864
- if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
1865
- const watchMethods = cmpMeta.$watchers$[propName];
1866
- if (watchMethods) {
1867
- // this instance is watching for when this property changed
1868
- watchMethods.map((watchMethodName) => {
1869
- try {
1870
- // fire off each of the watch methods that are watching this property
1871
- instance[watchMethodName](newVal, oldVal, propName);
1872
- }
1873
- catch (e) {
1874
- consoleError(e, elm);
1875
- }
1876
- });
1877
- }
1878
- }
1879
- if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1880
- // looks like this value actually changed, so we've got work to do!
1881
- // but only if we've already rendered, otherwise just chill out
1882
- // queue that we need to do an update, but don't worry about queuing
1883
- // up millions cuz this function ensures it only runs once
1884
- scheduleUpdate(hostRef, false);
1885
- }
1886
- }
1887
- }
1888
- };
1889
- /**
1890
- * Attach a series of runtime constructs to a compiled Stencil component
1891
- * constructor, including getters and setters for the `@Prop` and `@State`
1892
- * decorators, callbacks for when attributes change, and so on.
1893
- *
1894
- * @param Cstr the constructor for a component that we need to process
1895
- * @param cmpMeta metadata collected previously about the component
1896
- * @param flags a number used to store a series of bit flags
1897
- * @returns a reference to the same constructor passed in (but now mutated)
1898
- */
1899
- const proxyComponent = (Cstr, cmpMeta, flags) => {
1900
- var _a;
1901
- const prototype = Cstr.prototype;
1902
- if (cmpMeta.$members$) {
1903
- if (Cstr.watchers) {
1904
- cmpMeta.$watchers$ = Cstr.watchers;
1905
- }
1906
- // It's better to have a const than two Object.entries()
1907
- const members = Object.entries(cmpMeta.$members$);
1908
- members.map(([memberName, [memberFlags]]) => {
1909
- if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
1910
- ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
1911
- // proxyComponent - prop
1912
- Object.defineProperty(prototype, memberName, {
1913
- get() {
1914
- // proxyComponent, get value
1915
- return getValue(this, memberName);
1916
- },
1917
- set(newValue) {
1918
- // proxyComponent, set value
1919
- setValue(this, memberName, newValue, cmpMeta);
1920
- },
1921
- configurable: true,
1922
- enumerable: true,
1923
- });
1924
- }
1925
- else if (flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
1926
- memberFlags & 64 /* MEMBER_FLAGS.Method */) {
1927
- // proxyComponent - method
1928
- Object.defineProperty(prototype, memberName, {
1929
- value(...args) {
1930
- var _a;
1931
- const ref = getHostRef(this);
1932
- return (_a = ref === null || ref === void 0 ? void 0 : ref.$onInstancePromise$) === null || _a === void 0 ? void 0 : _a.then(() => { var _a; return (_a = ref.$lazyInstance$) === null || _a === void 0 ? void 0 : _a[memberName](...args); });
1933
- },
1934
- });
1935
- }
1936
- });
1937
- if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1938
- const attrNameToPropName = new Map();
1939
- prototype.attributeChangedCallback = function (attrName, oldValue, newValue) {
1940
- plt.jmp(() => {
1941
- var _a;
1942
- const propName = attrNameToPropName.get(attrName);
1943
- // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
1944
- // in the case where an attribute was set inline.
1945
- // ```html
1946
- // <my-component some-attribute="some-value"></my-component>
1947
- // ```
1948
- //
1949
- // There is an edge case where a developer sets the attribute inline on a custom element and then
1950
- // programmatically changes it before it has been upgraded as shown below:
1951
- //
1952
- // ```html
1953
- // <!-- this component has _not_ been upgraded yet -->
1954
- // <my-component id="test" some-attribute="some-value"></my-component>
1955
- // <script>
1956
- // // grab non-upgraded component
1957
- // el = document.querySelector("#test");
1958
- // el.someAttribute = "another-value";
1959
- // // upgrade component
1960
- // customElements.define('my-component', MyComponent);
1961
- // </script>
1962
- // ```
1963
- // In this case if we do not un-shadow here and use the value of the shadowing property, attributeChangedCallback
1964
- // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
1965
- // to the value that was set inline i.e. "some-value" from above example. When
1966
- // the connectedCallback attempts to un-shadow it will use "some-value" as the initial value rather than "another-value"
1967
- //
1968
- // The case where the attribute was NOT set inline but was not set programmatically shall be handled/un-shadowed
1969
- // by connectedCallback as this attributeChangedCallback will not fire.
1970
- //
1971
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1972
- //
1973
- // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
1974
- // properties here given that this goes against best practices outlined here
1975
- // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
1976
- if (this.hasOwnProperty(propName)) {
1977
- newValue = this[propName];
1978
- delete this[propName];
1979
- }
1980
- else if (prototype.hasOwnProperty(propName) &&
1981
- typeof this[propName] === 'number' &&
1982
- this[propName] == newValue) {
1983
- // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
1984
- // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
1985
- // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
1986
- return;
1987
- }
1988
- else if (propName == null) {
1989
- // At this point we should know this is not a "member", so we can treat it like watching an attribute
1990
- // on a vanilla web component
1991
- const hostRef = getHostRef(this);
1992
- const flags = hostRef === null || hostRef === void 0 ? void 0 : hostRef.$flags$;
1993
- // We only want to trigger the callback(s) if:
1994
- // 1. The instance is ready
1995
- // 2. The watchers are ready
1996
- // 3. The value has changed
1997
- if (flags &&
1998
- !(flags & 8 /* HOST_FLAGS.isConstructingInstance */) &&
1999
- flags & 128 /* HOST_FLAGS.isWatchReady */ &&
2000
- newValue !== oldValue) {
2001
- const instance = hostRef.$lazyInstance$ ;
2002
- const entry = (_a = cmpMeta.$watchers$) === null || _a === void 0 ? void 0 : _a[attrName];
2003
- entry === null || entry === void 0 ? void 0 : entry.forEach((callbackName) => {
2004
- if (instance[callbackName] != null) {
2005
- instance[callbackName].call(instance, newValue, oldValue, attrName);
2006
- }
2007
- });
2008
- }
2009
- return;
2010
- }
2011
- this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
2012
- });
2013
- };
2014
- // Create an array of attributes to observe
2015
- // This list in comprised of all strings used within a `@Watch()` decorator
2016
- // on a component as well as any Stencil-specific "members" (`@Prop()`s and `@State()`s).
2017
- // As such, there is no way to guarantee type-safety here that a user hasn't entered
2018
- // an invalid attribute.
2019
- Cstr.observedAttributes = Array.from(new Set([
2020
- ...Object.keys((_a = cmpMeta.$watchers$) !== null && _a !== void 0 ? _a : {}),
2021
- ...members
2022
- .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */)
2023
- .map(([propName, m]) => {
2024
- var _a;
2025
- const attrName = m[1] || propName;
2026
- attrNameToPropName.set(attrName, propName);
2027
- if (m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
2028
- (_a = cmpMeta.$attrsToReflect$) === null || _a === void 0 ? void 0 : _a.push([propName, attrName]);
2029
- }
2030
- return attrName;
2031
- }),
2032
- ]));
2033
- }
2034
- }
2035
- return Cstr;
2036
- };
2037
- /**
2038
- * Initialize a Stencil component given a reference to its host element, its
2039
- * runtime bookkeeping data structure, runtime metadata about the component,
2040
- * and (optionally) an HMR version ID.
2041
- *
2042
- * @param elm a host element
2043
- * @param hostRef the element's runtime bookkeeping object
2044
- * @param cmpMeta runtime metadata for the Stencil component
2045
- * @param hmrVersionId an (optional) HMR version ID
2046
- */
2047
- const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
2048
- let Cstr;
2049
- // initializeComponent
2050
- if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
2051
- // Let the runtime know that the component has been initialized
2052
- hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
2053
- const bundleId = cmpMeta.$lazyBundleId$;
2054
- if (bundleId) {
2055
- // lazy loaded components
2056
- // request the component's implementation to be
2057
- // wired up with the host element
2058
- Cstr = loadModule(cmpMeta);
2059
- if (Cstr.then) {
2060
- // Await creates a micro-task avoid if possible
2061
- const endLoad = uniqueTime();
2062
- Cstr = await Cstr;
2063
- endLoad();
2064
- }
2065
- if (!Cstr.isProxied) {
2066
- // we've never proxied this Constructor before
2067
- // let's add the getters/setters to its prototype before
2068
- // the first time we create an instance of the implementation
2069
- {
2070
- cmpMeta.$watchers$ = Cstr.watchers;
2071
- }
2072
- proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
2073
- Cstr.isProxied = true;
2074
- }
2075
- const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
2076
- // ok, time to construct the instance
2077
- // but let's keep track of when we start and stop
2078
- // so that the getters/setters don't incorrectly step on data
2079
- {
2080
- hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
2081
- }
2082
- // construct the lazy-loaded component implementation
2083
- // passing the hostRef is very important during
2084
- // construction in order to directly wire together the
2085
- // host element and the lazy-loaded instance
2086
- try {
2087
- new Cstr(hostRef);
2088
- }
2089
- catch (e) {
2090
- consoleError(e);
2091
- }
2092
- {
2093
- hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
2094
- }
2095
- {
2096
- hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
2097
- }
2098
- endNewInstance();
2099
- fireConnectedCallback(hostRef.$lazyInstance$);
2100
- }
2101
- else {
2102
- // sync constructor component
2103
- Cstr = elm.constructor;
2104
- // wait for the CustomElementRegistry to mark the component as ready before setting `isWatchReady`. Otherwise,
2105
- // watchers may fire prematurely if `customElements.get()`/`customElements.whenDefined()` resolves _before_
2106
- // Stencil has completed instantiating the component.
2107
- customElements.whenDefined(cmpMeta.$tagName$).then(() => (hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */));
2108
- }
2109
- if (Cstr.style) {
2110
- // this component has styles but we haven't registered them yet
2111
- let style = Cstr.style;
2112
- const scopeId = getScopeId(cmpMeta);
2113
- if (!styles.has(scopeId)) {
2114
- const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
2115
- registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
2116
- endRegisterStyles();
2117
- }
2118
- }
2119
- }
2120
- // we've successfully created a lazy instance
2121
- const ancestorComponent = hostRef.$ancestorComponent$;
2122
- const schedule = () => scheduleUpdate(hostRef, true);
2123
- if (ancestorComponent && ancestorComponent['s-rc']) {
2124
- // this is the initial load and this component it has an ancestor component
2125
- // but the ancestor component has NOT fired its will update lifecycle yet
2126
- // so let's just cool our jets and wait for the ancestor to continue first
2127
- // this will get fired off when the ancestor component
2128
- // finally gets around to rendering its lazy self
2129
- // fire off the initial update
2130
- ancestorComponent['s-rc'].push(schedule);
2131
- }
2132
- else {
2133
- schedule();
2134
- }
2135
- };
2136
- const fireConnectedCallback = (instance) => {
2137
- {
2138
- safeCall(instance, 'connectedCallback');
2139
- }
2140
- };
2141
- const connectedCallback = (elm) => {
2142
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
2143
- const hostRef = getHostRef(elm);
2144
- const cmpMeta = hostRef.$cmpMeta$;
2145
- const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
2146
- if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
2147
- // first time this component has connected
2148
- hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
2149
- {
2150
- // initUpdate
2151
- // if the slot polyfill is required we'll need to put some nodes
2152
- // in here to act as original content anchors as we move nodes around
2153
- // host element has been connected to the DOM
2154
- if ((// TODO(STENCIL-854): Remove code related to legacy shadowDomShim field
2155
- cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
2156
- setContentReference(elm);
2157
- }
2158
- }
2159
- {
2160
- // find the first ancestor component (if there is one) and register
2161
- // this component as one of the actively loading child components for its ancestor
2162
- let ancestorComponent = elm;
2163
- while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
2164
- // climb up the ancestors looking for the first
2165
- // component that hasn't finished its lifecycle update yet
2166
- if (ancestorComponent['s-p']) {
2167
- // we found this components first ancestor component
2168
- // keep a reference to this component's ancestor component
2169
- attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
2170
- break;
2171
- }
2172
- }
2173
- }
2174
- // Lazy properties
2175
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
2176
- if (cmpMeta.$members$) {
2177
- Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
2178
- if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
2179
- const value = elm[memberName];
2180
- delete elm[memberName];
2181
- elm[memberName] = value;
2182
- }
2183
- });
2184
- }
2185
- {
2186
- initializeComponent(elm, hostRef, cmpMeta);
2187
- }
2188
- }
2189
- else {
2190
- // not the first time this has connected
2191
- // reattach any event listeners to the host
2192
- // since they would have been removed when disconnected
2193
- addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
2194
- // fire off connectedCallback() on component instance
2195
- if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) {
2196
- fireConnectedCallback(hostRef.$lazyInstance$);
2197
- }
2198
- else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
2199
- hostRef.$onReadyPromise$.then(() => fireConnectedCallback(hostRef.$lazyInstance$));
2200
- }
2201
- }
2202
- endConnected();
2203
- }
2204
- };
2205
- const setContentReference = (elm) => {
2206
- // only required when we're NOT using native shadow dom (slot)
2207
- // or this browser doesn't support native shadow dom
2208
- // and this host element was NOT created with SSR
2209
- // let's pick out the inner content for slot projection
2210
- // create a node to represent where the original
2211
- // content was first placed, which is useful later on
2212
- const contentRefElm = (elm['s-cr'] = doc.createComment(''));
2213
- contentRefElm['s-cn'] = true;
2214
- elm.insertBefore(contentRefElm, elm.firstChild);
2215
- };
2216
- const disconnectInstance = (instance) => {
2217
- {
2218
- safeCall(instance, 'disconnectedCallback');
2219
- }
2220
- };
2221
- const disconnectedCallback = async (elm) => {
2222
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
2223
- const hostRef = getHostRef(elm);
2224
- {
2225
- if (hostRef.$rmListeners$) {
2226
- hostRef.$rmListeners$.map((rmListener) => rmListener());
2227
- hostRef.$rmListeners$ = undefined;
2228
- }
2229
- }
2230
- if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$lazyInstance$) {
2231
- disconnectInstance(hostRef.$lazyInstance$);
2232
- }
2233
- else if (hostRef === null || hostRef === void 0 ? void 0 : hostRef.$onReadyPromise$) {
2234
- hostRef.$onReadyPromise$.then(() => disconnectInstance(hostRef.$lazyInstance$));
2235
- }
2236
- }
2237
- };
2238
- const bootstrapLazy = (lazyBundles, options = {}) => {
2239
- var _a;
2240
- const endBootstrap = createTime();
2241
- const cmpTags = [];
2242
- const exclude = options.exclude || [];
2243
- const customElements = win.customElements;
2244
- const head = doc.head;
2245
- const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
2246
- const dataStyles = /*@__PURE__*/ doc.createElement('style');
2247
- const deferredConnectedCallbacks = [];
2248
- let appLoadFallback;
2249
- let isBootstrapping = true;
2250
- Object.assign(plt, options);
2251
- plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
2252
- let hasSlotRelocation = false;
2253
- lazyBundles.map((lazyBundle) => {
2254
- lazyBundle[1].map((compactMeta) => {
2255
- var _a;
2256
- const cmpMeta = {
2257
- $flags$: compactMeta[0],
2258
- $tagName$: compactMeta[1],
2259
- $members$: compactMeta[2],
2260
- $listeners$: compactMeta[3],
2261
- };
2262
- // Check if we are using slots outside the shadow DOM in this component.
2263
- // We'll use this information later to add styles for `slot-fb` elements
2264
- if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
2265
- hasSlotRelocation = true;
2266
- }
2267
- {
2268
- cmpMeta.$members$ = compactMeta[2];
2269
- }
2270
- {
2271
- cmpMeta.$listeners$ = compactMeta[3];
2272
- }
2273
- {
2274
- cmpMeta.$attrsToReflect$ = [];
2275
- }
2276
- {
2277
- cmpMeta.$watchers$ = (_a = compactMeta[4]) !== null && _a !== void 0 ? _a : {};
2278
- }
2279
- const tagName = cmpMeta.$tagName$;
2280
- const HostElement = class extends HTMLElement {
2281
- // StencilLazyHost
2282
- constructor(self) {
2283
- // @ts-ignore
2284
- super(self);
2285
- self = this;
2286
- registerHost(self, cmpMeta);
2287
- if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
2288
- // this component is using shadow dom
2289
- // and this browser supports shadow dom
2290
- // add the read-only property "shadowRoot" to the host element
2291
- // adding the shadow root build conditionals to minimize runtime
2292
- {
2293
- {
2294
- self.attachShadow({ mode: 'open' });
2295
- }
2296
- }
2297
- }
2298
- }
2299
- connectedCallback() {
2300
- if (appLoadFallback) {
2301
- clearTimeout(appLoadFallback);
2302
- appLoadFallback = null;
2303
- }
2304
- if (isBootstrapping) {
2305
- // connectedCallback will be processed once all components have been registered
2306
- deferredConnectedCallbacks.push(this);
2307
- }
2308
- else {
2309
- plt.jmp(() => connectedCallback(this));
2310
- }
2311
- }
2312
- disconnectedCallback() {
2313
- plt.jmp(() => disconnectedCallback(this));
2314
- }
2315
- componentOnReady() {
2316
- return getHostRef(this).$onReadyPromise$;
2317
- }
2318
- };
2319
- cmpMeta.$lazyBundleId$ = lazyBundle[0];
2320
- if (!exclude.includes(tagName) && !customElements.get(tagName)) {
2321
- cmpTags.push(tagName);
2322
- customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
2323
- }
2324
- });
2325
- });
2326
- // Only bother generating CSS if we have components
2327
- // TODO(STENCIL-1118): Add test cases for CSS content based on conditionals
2328
- if (cmpTags.length > 0) {
2329
- // Add styles for `slot-fb` elements if any of our components are using slots outside the Shadow DOM
2330
- if (hasSlotRelocation) {
2331
- dataStyles.textContent += SLOT_FB_CSS;
2332
- }
2333
- // Add hydration styles
2334
- {
2335
- dataStyles.textContent += cmpTags + HYDRATED_CSS;
2336
- }
2337
- // If we have styles, add them to the DOM
2338
- if (dataStyles.innerHTML.length) {
2339
- dataStyles.setAttribute('data-styles', '');
2340
- // Apply CSP nonce to the style tag if it exists
2341
- const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
2342
- if (nonce != null) {
2343
- dataStyles.setAttribute('nonce', nonce);
2344
- }
2345
- // Insert the styles into the document head
2346
- // NOTE: this _needs_ to happen last so we can ensure the nonce (and other attributes) are applied
2347
- head.insertBefore(dataStyles, metaCharset ? metaCharset.nextSibling : head.firstChild);
2348
- }
2349
- }
2350
- // Process deferred connectedCallbacks now all components have been registered
2351
- isBootstrapping = false;
2352
- if (deferredConnectedCallbacks.length) {
2353
- deferredConnectedCallbacks.map((host) => host.connectedCallback());
2354
- }
2355
- else {
2356
- {
2357
- plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
2358
- }
2359
- }
2360
- // Fallback appLoad event
2361
- endBootstrap();
2362
- };
2363
- const Fragment = (_, children) => children;
2364
- const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
2365
- if (listeners) {
2366
- listeners.map(([flags, name, method]) => {
2367
- const target = getHostListenerTarget(elm, flags) ;
2368
- const handler = hostListenerProxy(hostRef, method);
2369
- const opts = hostListenerOpts(flags);
2370
- plt.ael(target, name, handler, opts);
2371
- (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
2372
- });
2373
- }
2374
- };
2375
- const hostListenerProxy = (hostRef, methodName) => (ev) => {
2376
- try {
2377
- {
2378
- if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
2379
- // instance is ready, let's call it's member method for this event
2380
- hostRef.$lazyInstance$[methodName](ev);
2381
- }
2382
- else {
2383
- (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
2384
- }
2385
- }
2386
- }
2387
- catch (e) {
2388
- consoleError(e);
2389
- }
2390
- };
2391
- const getHostListenerTarget = (elm, flags) => {
2392
- if (flags & 4 /* LISTENER_FLAGS.TargetDocument */)
2393
- return doc;
2394
- if (flags & 8 /* LISTENER_FLAGS.TargetWindow */)
2395
- return win;
2396
- return elm;
2397
- };
2398
- // prettier-ignore
2399
- const hostListenerOpts = (flags) => supportsListenerOptions
2400
- ? ({
2401
- passive: (flags & 1 /* LISTENER_FLAGS.Passive */) !== 0,
2402
- capture: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0,
2403
- })
2404
- : (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
2405
- /**
2406
- * Assigns the given value to the nonce property on the runtime platform object.
2407
- * During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
2408
- * @param nonce The value to be assigned to the platform nonce property.
2409
- * @returns void
2410
- */
2411
- const setNonce = (nonce) => (plt.$nonce$ = nonce);
2412
- /**
2413
- * A WeakMap mapping runtime component references to their corresponding host reference
2414
- * instances.
2415
- *
2416
- * **Note**: If we're in an HMR context we need to store a reference to this
2417
- * value on `window` in order to maintain the mapping of {@link d.RuntimeRef}
2418
- * to {@link d.HostRef} across HMR updates.
2419
- *
2420
- * This is necessary because when HMR updates for a component are processed by
2421
- * the browser-side dev server client the JS bundle for that component is
2422
- * re-fetched. Since the module containing {@link hostRefs} is included in
2423
- * that bundle, if we do not store a reference to it the new iteration of the
2424
- * component will not have access to the previous hostRef map, leading to a
2425
- * bug where the new version of the component cannot properly initialize.
2426
- */
2427
- const hostRefs = new WeakMap();
2428
- /**
2429
- * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
2430
- *
2431
- * @param ref the runtime ref of interest
2432
- * @returns the Host reference (if found) or undefined
2433
- */
2434
- const getHostRef = (ref) => hostRefs.get(ref);
2435
- /**
2436
- * Register a lazy instance with the {@link hostRefs} object so it's
2437
- * corresponding {@link d.HostRef} can be retrieved later.
2438
- *
2439
- * @param lazyInstance the lazy instance of interest
2440
- * @param hostRef that instances `HostRef` object
2441
- * @returns a reference to the host ref WeakMap
2442
- */
2443
- const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
2444
- /**
2445
- * Register a host element for a Stencil component, setting up various metadata
2446
- * and callbacks based on {@link BUILD} flags as well as the component's runtime
2447
- * metadata.
2448
- *
2449
- * @param hostElement the host element to register
2450
- * @param cmpMeta runtime metadata for that component
2451
- * @returns a reference to the host ref WeakMap
2452
- */
2453
- const registerHost = (hostElement, cmpMeta) => {
2454
- const hostRef = {
2455
- $flags$: 0,
2456
- $hostElement$: hostElement,
2457
- $cmpMeta$: cmpMeta,
2458
- $instanceValues$: new Map(),
2459
- };
2460
- {
2461
- hostRef.$onInstancePromise$ = new Promise((r) => (hostRef.$onInstanceResolve$ = r));
2462
- }
2463
- {
2464
- hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
2465
- hostElement['s-p'] = [];
2466
- hostElement['s-rc'] = [];
2467
- }
2468
- addHostEventListeners(hostElement, hostRef, cmpMeta.$listeners$);
2469
- return hostRefs.set(hostElement, hostRef);
2470
- };
2471
- const isMemberInElement = (elm, memberName) => memberName in elm;
2472
- const consoleError = (e, el) => (0, console.error)(e, el);
2473
- const cmpModules = /*@__PURE__*/ new Map();
2474
- const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
2475
- // loadModuleImport
2476
- const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
2477
- const bundleId = cmpMeta.$lazyBundleId$;
2478
- const module = cmpModules.get(bundleId) ;
2479
- if (module) {
2480
- return module[exportName];
2481
- }
2482
- /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
2483
- return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(
2484
- /* @vite-ignore */
2485
- /* webpackInclude: /\.entry\.js$/ */
2486
- /* webpackExclude: /\.system\.entry\.js$/ */
2487
- /* webpackMode: "lazy" */
2488
- `./${bundleId}.entry.js${''}`)); }).then((importedModule) => {
2489
- {
2490
- cmpModules.set(bundleId, importedModule);
2491
- }
2492
- return importedModule[exportName];
2493
- }, consoleError);
2494
- };
2495
- const styles = /*@__PURE__*/ new Map();
2496
- const win = typeof window !== 'undefined' ? window : {};
2497
- const doc = win.document || { head: {} };
2498
- const plt = {
2499
- $flags$: 0,
2500
- $resourcesUrl$: '',
2501
- jmp: (h) => h(),
2502
- raf: (h) => requestAnimationFrame(h),
2503
- ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
2504
- rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
2505
- ce: (eventName, opts) => new CustomEvent(eventName, opts),
2506
- };
2507
- const supportsListenerOptions = /*@__PURE__*/ (() => {
2508
- let supportsListenerOptions = false;
2509
- try {
2510
- doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
2511
- get() {
2512
- supportsListenerOptions = true;
2513
- },
2514
- }));
2515
- }
2516
- catch (e) { }
2517
- return supportsListenerOptions;
2518
- })();
2519
- const promiseResolve = (v) => Promise.resolve(v);
2520
- const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
2521
- try {
2522
- new CSSStyleSheet();
2523
- return typeof new CSSStyleSheet().replaceSync === 'function';
2524
- }
2525
- catch (e) { }
2526
- return false;
2527
- })()
2528
- ;
2529
- const queueDomReads = [];
2530
- const queueDomWrites = [];
2531
- const queueTask = (queue, write) => (cb) => {
2532
- queue.push(cb);
2533
- if (!queuePending) {
2534
- queuePending = true;
2535
- if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
2536
- nextTick(flush);
2537
- }
2538
- else {
2539
- plt.raf(flush);
2540
- }
2541
- }
2542
- };
2543
- const consume = (queue) => {
2544
- for (let i = 0; i < queue.length; i++) {
2545
- try {
2546
- queue[i](performance.now());
2547
- }
2548
- catch (e) {
2549
- consoleError(e);
2550
- }
2551
- }
2552
- queue.length = 0;
2553
- };
2554
- const flush = () => {
2555
- // always force a bunch of medium callbacks to run, but still have
2556
- // a throttle on how many can run in a certain time
2557
- // DOM READS!!!
2558
- consume(queueDomReads);
2559
- // DOM WRITES!!!
2560
- {
2561
- consume(queueDomWrites);
2562
- if ((queuePending = queueDomReads.length > 0)) {
2563
- // still more to do yet, but we've run out of time
2564
- // let's let this thing cool off and try again in the next tick
2565
- plt.raf(flush);
2566
- }
2567
- }
2568
- };
2569
- const nextTick = (cb) => promiseResolve().then(cb);
2570
- const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
2571
-
2572
- exports.Fragment = Fragment;
2573
- exports.Host = Host;
2574
- exports.bootstrapLazy = bootstrapLazy;
2575
- exports.createEvent = createEvent;
2576
- exports.forceUpdate = forceUpdate;
2577
- exports.getElement = getElement;
2578
- exports.getRenderingRef = getRenderingRef;
2579
- exports.h = h;
2580
- exports.promiseResolve = promiseResolve;
2581
- exports.registerInstance = registerInstance;
2582
- exports.setNonce = setNonce;
2583
-
2584
- //# sourceMappingURL=index-a58ba49d.js.map