@usecapsule/core-components 3.0.1 → 3.1.0

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