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