@jumpgroup/jump-design-system 0.3.18 → 0.3.20

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