@swisspost/design-system-components 2.1.0 → 7.1.0

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