@mgdis/core-ui-helpers 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/.turbo/turbo-build.log +52 -0
  2. package/CHANGELOG.md +12 -0
  3. package/LICENSE +29 -0
  4. package/README.md +95 -0
  5. package/dist/angular/index.cjs +27 -0
  6. package/dist/angular/index.cjs.map +1 -0
  7. package/dist/angular/index.d.ts +21 -0
  8. package/dist/angular/index.js +25 -0
  9. package/dist/angular/index.js.map +1 -0
  10. package/dist/angular/index.umd.js +33 -0
  11. package/dist/angular/index.umd.js.map +1 -0
  12. package/dist/locale/index.cjs +164 -0
  13. package/dist/locale/index.cjs.map +1 -0
  14. package/dist/locale/index.d.ts +103 -0
  15. package/dist/locale/index.js +156 -0
  16. package/dist/locale/index.js.map +1 -0
  17. package/dist/locale/index.umd.js +170 -0
  18. package/dist/locale/index.umd.js.map +1 -0
  19. package/dist/playwright/index.cjs +124 -0
  20. package/dist/playwright/index.cjs.map +1 -0
  21. package/dist/playwright/index.d.ts +35 -0
  22. package/dist/playwright/index.js +120 -0
  23. package/dist/playwright/index.js.map +1 -0
  24. package/dist/playwright/index.umd.js +130 -0
  25. package/dist/playwright/index.umd.js.map +1 -0
  26. package/dist/stencil/index.cjs +281 -0
  27. package/dist/stencil/index.cjs.map +1 -0
  28. package/dist/stencil/index.d.ts +111 -0
  29. package/dist/stencil/index.js +277 -0
  30. package/dist/stencil/index.js.map +1 -0
  31. package/dist/stencil/index.umd.js +287 -0
  32. package/dist/stencil/index.umd.js.map +1 -0
  33. package/dist/storybook/index.cjs +2109 -0
  34. package/dist/storybook/index.cjs.map +1 -0
  35. package/dist/storybook/index.d.ts +85 -0
  36. package/dist/storybook/index.js +2103 -0
  37. package/dist/storybook/index.js.map +1 -0
  38. package/dist/storybook/index.umd.js +2115 -0
  39. package/dist/storybook/index.umd.js.map +1 -0
  40. package/dist/tests/index.cjs +166 -0
  41. package/dist/tests/index.cjs.map +1 -0
  42. package/dist/tests/index.d.ts +91 -0
  43. package/dist/tests/index.js +161 -0
  44. package/dist/tests/index.js.map +1 -0
  45. package/dist/tests/index.umd.js +172 -0
  46. package/dist/tests/index.umd.js.map +1 -0
  47. package/dist/utils/index.cjs +433 -0
  48. package/dist/utils/index.cjs.map +1 -0
  49. package/dist/utils/index.d.ts +265 -0
  50. package/dist/utils/index.js +409 -0
  51. package/dist/utils/index.js.map +1 -0
  52. package/dist/utils/index.umd.js +439 -0
  53. package/dist/utils/index.umd.js.map +1 -0
  54. package/dist/vue/index.cjs +1934 -0
  55. package/dist/vue/index.cjs.map +1 -0
  56. package/dist/vue/index.d.ts +35 -0
  57. package/dist/vue/index.js +1932 -0
  58. package/dist/vue/index.js.map +1 -0
  59. package/dist/vue/index.umd.js +1940 -0
  60. package/dist/vue/index.umd.js.map +1 -0
  61. package/json-doc.test.json +253 -0
  62. package/package.json +80 -0
  63. package/rollup.config.mjs +61 -0
  64. package/src/angular/index.spec.ts +8 -0
  65. package/src/angular/index.ts +1 -0
  66. package/src/angular/mg-angular-logger/index.ts +1 -0
  67. package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +3 -0
  68. package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +40 -0
  69. package/src/angular/mg-angular-logger/mg-angular-logger.ts +23 -0
  70. package/src/locale/index.spec.ts +14 -0
  71. package/src/locale/index.ts +1 -0
  72. package/src/locale/locale.spec.ts +173 -0
  73. package/src/locale/locale.ts +166 -0
  74. package/src/playwright/config/index.ts +43 -0
  75. package/src/playwright/index.spec.ts +16 -0
  76. package/src/playwright/index.ts +4 -0
  77. package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +48 -0
  78. package/src/playwright/utils/index.ts +1 -0
  79. package/src/playwright/utils/utils.spec.ts +43 -0
  80. package/src/playwright/utils/utils.ts +64 -0
  81. package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +527 -0
  82. package/src/stencil/ide/ide.spec.ts +25 -0
  83. package/src/stencil/ide/ide.ts +214 -0
  84. package/src/stencil/ide/index.ts +1 -0
  85. package/src/stencil/index.spec.ts +12 -0
  86. package/src/stencil/index.ts +1 -0
  87. package/src/storybook/index.spec.ts +15 -0
  88. package/src/storybook/index.ts +1 -0
  89. package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +329 -0
  90. package/src/storybook/stencil/index.ts +1 -0
  91. package/src/storybook/stencil/stencil-shim.d.ts +1 -0
  92. package/src/storybook/stencil/stencil.conf.ts +4 -0
  93. package/src/storybook/stencil/stencil.spec.ts +142 -0
  94. package/src/storybook/stencil/stencil.ts +366 -0
  95. package/src/tests/index.spec.ts +13 -0
  96. package/src/tests/index.ts +1 -0
  97. package/src/tests/unit/__snapshots__/unit.spec.ts.snap +52 -0
  98. package/src/tests/unit/index.ts +1 -0
  99. package/src/tests/unit/unit.conf.ts +9 -0
  100. package/src/tests/unit/unit.spec.ts +44 -0
  101. package/src/tests/unit/unit.ts +171 -0
  102. package/src/utils/attributes/class-list/class-list.spec.ts +36 -0
  103. package/src/utils/attributes/class-list/class-list.ts +51 -0
  104. package/src/utils/attributes/class-list/index.ts +1 -0
  105. package/src/utils/attributes/id/id.spec.ts +51 -0
  106. package/src/utils/attributes/id/id.ts +46 -0
  107. package/src/utils/attributes/id/index.ts +1 -0
  108. package/src/utils/attributes/index.ts +3 -0
  109. package/src/utils/attributes/to-kebab-case/index.ts +1 -0
  110. package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +29 -0
  111. package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +23 -0
  112. package/src/utils/components/__snapshots__/components.spec.ts.snap +313 -0
  113. package/src/utils/components/components.conf.ts +11 -0
  114. package/src/utils/components/components.spec.ts +192 -0
  115. package/src/utils/components/components.ts +138 -0
  116. package/src/utils/components/index.ts +2 -0
  117. package/src/utils/date/date.spec.ts +12 -0
  118. package/src/utils/date/date.ts +20 -0
  119. package/src/utils/date/index.ts +1 -0
  120. package/src/utils/elements/elements.spec.ts +17 -0
  121. package/src/utils/elements/elements.ts +16 -0
  122. package/src/utils/elements/index.ts +1 -0
  123. package/src/utils/index.spec.ts +84 -0
  124. package/src/utils/index.ts +8 -0
  125. package/src/utils/number/index.ts +1 -0
  126. package/src/utils/number/number.spec.ts +14 -0
  127. package/src/utils/number/number.ts +6 -0
  128. package/src/utils/object/index.ts +2 -0
  129. package/src/utils/object/object.conf.ts +4 -0
  130. package/src/utils/object/object.spec.ts +98 -0
  131. package/src/utils/object/object.ts +26 -0
  132. package/src/utils/string/index.ts +1 -0
  133. package/src/utils/string/string.spec.ts +47 -0
  134. package/src/utils/string/string.ts +38 -0
  135. package/src/utils/windows/index.ts +1 -0
  136. package/src/utils/windows/windows.spec.ts +65 -0
  137. package/src/utils/windows/windows.ts +50 -0
  138. package/src/vue/index.spec.ts +8 -0
  139. package/src/vue/index.ts +1 -0
  140. package/src/vue/mg-model/index.ts +1 -0
  141. package/src/vue/mg-model/mg-model.conf.ts +6 -0
  142. package/src/vue/mg-model/mg-model.spec.ts +50 -0
  143. package/src/vue/mg-model/mg-model.ts +50 -0
  144. package/tsconfig.json +17 -0
  145. package/typedoc.json +14 -0
  146. package/vitest.config.mts +13 -0
@@ -0,0 +1,2103 @@
1
+ // src/app-data/index.ts
2
+ var BUILD = {
3
+ updatable: true,
4
+ slotRelocation: true,
5
+ // TODO(STENCIL-914): remove this option when `experimentalSlotFixes` is the default behavior
6
+ experimentalSlotFixes: false
7
+ };
8
+
9
+ /*
10
+ Stencil Client Platform v4.28.2 | MIT Licensed | https://stenciljs.com
11
+ */
12
+ var __defProp = Object.defineProperty;
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
17
+
18
+ // src/utils/constants.ts
19
+ var SVG_NS = "http://www.w3.org/2000/svg";
20
+ var HTML_NS = "http://www.w3.org/1999/xhtml";
21
+ var isMemberInElement = (elm, memberName) => memberName in elm;
22
+ var XLINK_NS = "http://www.w3.org/1999/xlink";
23
+ var win = typeof window !== "undefined" ? window : {};
24
+ var plt = {
25
+ $flags$: 0,
26
+ $resourcesUrl$: "",
27
+ jmp: (h2) => h2(),
28
+ raf: (h2) => requestAnimationFrame(h2),
29
+ ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
30
+ rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
31
+ ce: (eventName, opts) => new CustomEvent(eventName, opts)
32
+ };
33
+
34
+ // src/utils/helpers.ts
35
+ var isDef = (v) => v != null && v !== void 0;
36
+ var isComplexType = (o) => {
37
+ o = typeof o;
38
+ return o === "object" || o === "function";
39
+ };
40
+
41
+ // src/utils/result.ts
42
+ var result_exports = {};
43
+ __export(result_exports, {
44
+ err: () => err,
45
+ map: () => map,
46
+ ok: () => ok,
47
+ unwrap: () => unwrap,
48
+ unwrapErr: () => unwrapErr
49
+ });
50
+ var ok = (value) => ({
51
+ isOk: true,
52
+ isErr: false,
53
+ value
54
+ });
55
+ var err = (value) => ({
56
+ isOk: false,
57
+ isErr: true,
58
+ value
59
+ });
60
+ function map(result, fn) {
61
+ if (result.isOk) {
62
+ const val = fn(result.value);
63
+ if (val instanceof Promise) {
64
+ return val.then((newVal) => ok(newVal));
65
+ } else {
66
+ return ok(val);
67
+ }
68
+ }
69
+ if (result.isErr) {
70
+ const value = result.value;
71
+ return err(value);
72
+ }
73
+ throw "should never get here";
74
+ }
75
+ var unwrap = (result) => {
76
+ if (result.isOk) {
77
+ return result.value;
78
+ } else {
79
+ throw result.value;
80
+ }
81
+ };
82
+ var unwrapErr = (result) => {
83
+ if (result.isErr) {
84
+ return result.value;
85
+ } else {
86
+ throw result.value;
87
+ }
88
+ };
89
+ var updateFallbackSlotVisibility = (elm) => {
90
+ const childNodes = internalCall(elm, "childNodes");
91
+ if (elm.tagName && elm.tagName.includes("-") && elm["s-cr"] && elm.tagName !== "SLOT-FB") {
92
+ getHostSlotNodes(childNodes, elm.tagName).forEach((slotNode) => {
93
+ if (slotNode.nodeType === 1 /* ElementNode */ && slotNode.tagName === "SLOT-FB") {
94
+ if (getSlotChildSiblings(slotNode, getSlotName(slotNode), false).length) {
95
+ slotNode.hidden = true;
96
+ } else {
97
+ slotNode.hidden = false;
98
+ }
99
+ }
100
+ });
101
+ }
102
+ let i2 = 0;
103
+ for (i2 = 0; i2 < childNodes.length; i2++) {
104
+ const childNode = childNodes[i2];
105
+ if (childNode.nodeType === 1 /* ElementNode */ && internalCall(childNode, "childNodes").length) {
106
+ updateFallbackSlotVisibility(childNode);
107
+ }
108
+ }
109
+ };
110
+ var getSlottedChildNodes = (childNodes) => {
111
+ const result = [];
112
+ for (let i2 = 0; i2 < childNodes.length; i2++) {
113
+ const slottedNode = childNodes[i2]["s-nr"] || void 0;
114
+ if (slottedNode && slottedNode.isConnected) {
115
+ result.push(slottedNode);
116
+ }
117
+ }
118
+ return result;
119
+ };
120
+ function getHostSlotNodes(childNodes, hostName, slotName) {
121
+ let i2 = 0;
122
+ let slottedNodes = [];
123
+ let childNode;
124
+ for (; i2 < childNodes.length; i2++) {
125
+ childNode = childNodes[i2];
126
+ if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0)) {
127
+ slottedNodes.push(childNode);
128
+ }
129
+ slottedNodes = [...slottedNodes, ...getHostSlotNodes(childNode.childNodes, hostName, slotName)];
130
+ }
131
+ return slottedNodes;
132
+ }
133
+ var getSlotChildSiblings = (slot, slotName, includeSlot = true) => {
134
+ const childNodes = [];
135
+ if (includeSlot && slot["s-sr"] || !slot["s-sr"]) childNodes.push(slot);
136
+ let node = slot;
137
+ while (node = node.nextSibling) {
138
+ if (getSlotName(node) === slotName && (includeSlot || !node["s-sr"])) childNodes.push(node);
139
+ }
140
+ return childNodes;
141
+ };
142
+ var isNodeLocatedInSlot = (nodeToRelocate, slotName) => {
143
+ if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
144
+ if (nodeToRelocate.getAttribute("slot") === null && slotName === "") {
145
+ return true;
146
+ }
147
+ if (nodeToRelocate.getAttribute("slot") === slotName) {
148
+ return true;
149
+ }
150
+ return false;
151
+ }
152
+ if (nodeToRelocate["s-sn"] === slotName) {
153
+ return true;
154
+ }
155
+ return slotName === "";
156
+ };
157
+ var getSlotName = (node) => typeof node["s-sn"] === "string" ? node["s-sn"] : node.nodeType === 1 && node.getAttribute("slot") || void 0;
158
+ function patchSlotNode(node) {
159
+ if (node.assignedElements || node.assignedNodes || !node["s-sr"]) return;
160
+ const assignedFactory = (elementsOnly) => (function(opts) {
161
+ const toReturn = [];
162
+ const slotName = this["s-sn"];
163
+ if (opts == null ? void 0 : opts.flatten) {
164
+ console.error(`
165
+ Flattening is not supported for Stencil non-shadow slots.
166
+ You can use \`.childNodes\` to nested slot fallback content.
167
+ If you have a particular use case, please open an issue on the Stencil repo.
168
+ `);
169
+ }
170
+ const parent = this["s-cr"].parentElement;
171
+ const slottedNodes = parent.__childNodes ? parent.childNodes : getSlottedChildNodes(parent.childNodes);
172
+ slottedNodes.forEach((n) => {
173
+ if (slotName === getSlotName(n)) {
174
+ toReturn.push(n);
175
+ }
176
+ });
177
+ if (elementsOnly) {
178
+ return toReturn.filter((n) => n.nodeType === 1 /* ElementNode */);
179
+ }
180
+ return toReturn;
181
+ }).bind(node);
182
+ node.assignedElements = assignedFactory(true);
183
+ node.assignedNodes = assignedFactory(false);
184
+ }
185
+ function internalCall(node, method) {
186
+ if ("__" + method in node) {
187
+ const toReturn = node["__" + method];
188
+ if (typeof toReturn !== "function") return toReturn;
189
+ return toReturn.bind(node);
190
+ } else {
191
+ if (typeof node[method] !== "function") return node[method];
192
+ return node[method].bind(node);
193
+ }
194
+ }
195
+ var h = (nodeName, vnodeData, ...children) => {
196
+ let child = null;
197
+ let key = null;
198
+ let slotName = null;
199
+ let simple = false;
200
+ let lastSimple = false;
201
+ const vNodeChildren = [];
202
+ const walk = (c) => {
203
+ for (let i2 = 0; i2 < c.length; i2++) {
204
+ child = c[i2];
205
+ if (Array.isArray(child)) {
206
+ walk(child);
207
+ } else if (child != null && typeof child !== "boolean") {
208
+ if (simple = !isComplexType(child)) {
209
+ child = String(child);
210
+ }
211
+ if (simple && lastSimple) {
212
+ vNodeChildren[vNodeChildren.length - 1].$text$ += child;
213
+ } else {
214
+ vNodeChildren.push(simple ? newVNode(null, child) : child);
215
+ }
216
+ lastSimple = simple;
217
+ }
218
+ }
219
+ };
220
+ walk(children);
221
+ const vnode = newVNode(nodeName, null);
222
+ vnode.$attrs$ = vnodeData;
223
+ if (vNodeChildren.length > 0) {
224
+ vnode.$children$ = vNodeChildren;
225
+ }
226
+ {
227
+ vnode.$key$ = key;
228
+ }
229
+ {
230
+ vnode.$name$ = slotName;
231
+ }
232
+ return vnode;
233
+ };
234
+ var newVNode = (tag, text) => {
235
+ const vnode = {
236
+ $flags$: 0,
237
+ $tag$: tag,
238
+ $text$: text,
239
+ $elm$: null,
240
+ $children$: null
241
+ };
242
+ {
243
+ vnode.$attrs$ = null;
244
+ }
245
+ {
246
+ vnode.$key$ = null;
247
+ }
248
+ {
249
+ vnode.$name$ = null;
250
+ }
251
+ return vnode;
252
+ };
253
+ var Host = {};
254
+ var isHost = (node) => node && node.$tag$ === Host;
255
+ var setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialRender) => {
256
+ if (oldValue === newValue) {
257
+ return;
258
+ }
259
+ let isProp = isMemberInElement(elm, memberName);
260
+ let ln = memberName.toLowerCase();
261
+ if (memberName === "class") {
262
+ const classList = elm.classList;
263
+ const oldClasses = parseClassList(oldValue);
264
+ let newClasses = parseClassList(newValue);
265
+ {
266
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
267
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
268
+ }
269
+ } else if (memberName === "style") {
270
+ {
271
+ for (const prop in oldValue) {
272
+ if (!newValue || newValue[prop] == null) {
273
+ if (prop.includes("-")) {
274
+ elm.style.removeProperty(prop);
275
+ } else {
276
+ elm.style[prop] = "";
277
+ }
278
+ }
279
+ }
280
+ }
281
+ for (const prop in newValue) {
282
+ if (!oldValue || newValue[prop] !== oldValue[prop]) {
283
+ if (prop.includes("-")) {
284
+ elm.style.setProperty(prop, newValue[prop]);
285
+ } else {
286
+ elm.style[prop] = newValue[prop];
287
+ }
288
+ }
289
+ }
290
+ } else if (memberName === "key") ; else if (memberName === "ref") {
291
+ if (newValue) {
292
+ newValue(elm);
293
+ }
294
+ } else if ((!elm.__lookupSetter__(memberName)) && memberName[0] === "o" && memberName[1] === "n") {
295
+ if (memberName[2] === "-") {
296
+ memberName = memberName.slice(3);
297
+ } else if (isMemberInElement(win, ln)) {
298
+ memberName = ln.slice(2);
299
+ } else {
300
+ memberName = ln[2] + memberName.slice(3);
301
+ }
302
+ if (oldValue || newValue) {
303
+ const capture = memberName.endsWith(CAPTURE_EVENT_SUFFIX);
304
+ memberName = memberName.replace(CAPTURE_EVENT_REGEX, "");
305
+ if (oldValue) {
306
+ plt.rel(elm, memberName, oldValue, capture);
307
+ }
308
+ if (newValue) {
309
+ plt.ael(elm, memberName, newValue, capture);
310
+ }
311
+ }
312
+ } else {
313
+ const isComplex = isComplexType(newValue);
314
+ if ((isProp || isComplex && newValue !== null) && !isSvg) {
315
+ try {
316
+ if (!elm.tagName.includes("-")) {
317
+ const n = newValue == null ? "" : newValue;
318
+ if (memberName === "list") {
319
+ isProp = false;
320
+ } else if (oldValue == null || elm[memberName] != n) {
321
+ if (typeof elm.__lookupSetter__(memberName) === "function") {
322
+ elm[memberName] = n;
323
+ } else {
324
+ elm.setAttribute(memberName, n);
325
+ }
326
+ }
327
+ } else if (elm[memberName] !== newValue) {
328
+ elm[memberName] = newValue;
329
+ }
330
+ } catch (e) {
331
+ }
332
+ }
333
+ let xlink = false;
334
+ {
335
+ if (ln !== (ln = ln.replace(/^xlink\:?/, ""))) {
336
+ memberName = ln;
337
+ xlink = true;
338
+ }
339
+ }
340
+ if (newValue == null || newValue === false) {
341
+ if (newValue !== false || elm.getAttribute(memberName) === "") {
342
+ if (xlink) {
343
+ elm.removeAttributeNS(XLINK_NS, memberName);
344
+ } else {
345
+ elm.removeAttribute(memberName);
346
+ }
347
+ }
348
+ } else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex && elm.nodeType === 1 /* ElementNode */) {
349
+ newValue = newValue === true ? "" : newValue;
350
+ if (xlink) {
351
+ elm.setAttributeNS(XLINK_NS, memberName, newValue);
352
+ } else {
353
+ elm.setAttribute(memberName, newValue);
354
+ }
355
+ }
356
+ }
357
+ };
358
+ var parseClassListRegex = /\s/;
359
+ var parseClassList = (value) => {
360
+ if (typeof value === "object" && value && "baseVal" in value) {
361
+ value = value.baseVal;
362
+ }
363
+ if (!value || typeof value !== "string") {
364
+ return [];
365
+ }
366
+ return value.split(parseClassListRegex);
367
+ };
368
+ var CAPTURE_EVENT_SUFFIX = "Capture";
369
+ var CAPTURE_EVENT_REGEX = new RegExp(CAPTURE_EVENT_SUFFIX + "$");
370
+
371
+ // src/runtime/vdom/update-element.ts
372
+ var updateElement = (oldVnode, newVnode, isSvgMode2, isInitialRender) => {
373
+ const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host ? newVnode.$elm$.host : newVnode.$elm$;
374
+ const oldVnodeAttrs = oldVnode && oldVnode.$attrs$ || {};
375
+ const newVnodeAttrs = newVnode.$attrs$ || {};
376
+ {
377
+ for (const memberName of sortedAttrNames(Object.keys(oldVnodeAttrs))) {
378
+ if (!(memberName in newVnodeAttrs)) {
379
+ setAccessor(
380
+ elm,
381
+ memberName,
382
+ oldVnodeAttrs[memberName],
383
+ void 0,
384
+ isSvgMode2,
385
+ newVnode.$flags$);
386
+ }
387
+ }
388
+ }
389
+ for (const memberName of sortedAttrNames(Object.keys(newVnodeAttrs))) {
390
+ setAccessor(
391
+ elm,
392
+ memberName,
393
+ oldVnodeAttrs[memberName],
394
+ newVnodeAttrs[memberName],
395
+ isSvgMode2,
396
+ newVnode.$flags$);
397
+ }
398
+ };
399
+ function sortedAttrNames(attrNames) {
400
+ return attrNames.includes("ref") ? (
401
+ // we need to sort these to ensure that `'ref'` is the last attr
402
+ [...attrNames.filter((attr) => attr !== "ref"), "ref"]
403
+ ) : (
404
+ // no need to sort, return the original array
405
+ attrNames
406
+ );
407
+ }
408
+
409
+ // src/runtime/vdom/vdom-render.ts
410
+ var scopeId;
411
+ var contentRef;
412
+ var hostTagName;
413
+ var useNativeShadowDom = false;
414
+ var checkSlotFallbackVisibility = false;
415
+ var checkSlotRelocate = false;
416
+ var isSvgMode = false;
417
+ var createElm = (oldParentVNode, newParentVNode, childIndex) => {
418
+ var _a;
419
+ const newVNode2 = newParentVNode.$children$[childIndex];
420
+ let i2 = 0;
421
+ let elm;
422
+ let childNode;
423
+ let oldVNode;
424
+ if (!useNativeShadowDom) {
425
+ checkSlotRelocate = true;
426
+ if (newVNode2.$tag$ === "slot") {
427
+ newVNode2.$flags$ |= newVNode2.$children$ ? (
428
+ // slot element has fallback content
429
+ // still create an element that "mocks" the slot element
430
+ 2 /* isSlotFallback */
431
+ ) : (
432
+ // slot element does not have fallback content
433
+ // create an html comment we'll use to always reference
434
+ // where actual slot content should sit next to
435
+ 1 /* isSlotReference */
436
+ );
437
+ }
438
+ }
439
+ if (newVNode2.$text$ !== null) {
440
+ elm = newVNode2.$elm$ = win.document.createTextNode(newVNode2.$text$);
441
+ } else if (newVNode2.$flags$ & 1 /* isSlotReference */) {
442
+ elm = newVNode2.$elm$ = win.document.createTextNode("");
443
+ {
444
+ updateElement(null, newVNode2, isSvgMode);
445
+ }
446
+ } else {
447
+ if (!isSvgMode) {
448
+ isSvgMode = newVNode2.$tag$ === "svg";
449
+ }
450
+ if (!win.document) {
451
+ throw new Error(
452
+ "You are trying to render a Stencil component in an environment that doesn't support the DOM. Make sure to populate the [`window`](https://developer.mozilla.org/en-US/docs/Web/API/Window/window) object before rendering a component."
453
+ );
454
+ }
455
+ elm = newVNode2.$elm$ = win.document.createElementNS(
456
+ isSvgMode ? SVG_NS : HTML_NS,
457
+ !useNativeShadowDom && BUILD.slotRelocation && newVNode2.$flags$ & 2 /* isSlotFallback */ ? "slot-fb" : newVNode2.$tag$
458
+ ) ;
459
+ if (isSvgMode && newVNode2.$tag$ === "foreignObject") {
460
+ isSvgMode = false;
461
+ }
462
+ {
463
+ updateElement(null, newVNode2, isSvgMode);
464
+ }
465
+ if (isDef(scopeId) && elm["s-si"] !== scopeId) {
466
+ elm.classList.add(elm["s-si"] = scopeId);
467
+ }
468
+ if (newVNode2.$children$) {
469
+ for (i2 = 0; i2 < newVNode2.$children$.length; ++i2) {
470
+ childNode = createElm(oldParentVNode, newVNode2, i2);
471
+ if (childNode) {
472
+ elm.appendChild(childNode);
473
+ }
474
+ }
475
+ }
476
+ {
477
+ if (newVNode2.$tag$ === "svg") {
478
+ isSvgMode = false;
479
+ } else if (elm.tagName === "foreignObject") {
480
+ isSvgMode = true;
481
+ }
482
+ }
483
+ }
484
+ elm["s-hn"] = hostTagName;
485
+ {
486
+ if (newVNode2.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
487
+ elm["s-sr"] = true;
488
+ elm["s-cr"] = contentRef;
489
+ elm["s-sn"] = newVNode2.$name$ || "";
490
+ elm["s-rf"] = (_a = newVNode2.$attrs$) == null ? void 0 : _a.ref;
491
+ patchSlotNode(elm);
492
+ oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
493
+ if (oldVNode && oldVNode.$tag$ === newVNode2.$tag$ && oldParentVNode.$elm$) {
494
+ {
495
+ putBackInOriginalLocation(oldParentVNode.$elm$, false);
496
+ }
497
+ }
498
+ {
499
+ addRemoveSlotScopedClass(contentRef, elm, newParentVNode.$elm$, oldParentVNode == null ? void 0 : oldParentVNode.$elm$);
500
+ }
501
+ }
502
+ }
503
+ return elm;
504
+ };
505
+ var putBackInOriginalLocation = (parentElm, recursive) => {
506
+ plt.$flags$ |= 1 /* isTmpDisconnected */;
507
+ const oldSlotChildNodes = Array.from(parentElm.__childNodes || parentElm.childNodes);
508
+ if (parentElm["s-sr"] && BUILD.experimentalSlotFixes) ;
509
+ for (let i2 = oldSlotChildNodes.length - 1; i2 >= 0; i2--) {
510
+ const childNode = oldSlotChildNodes[i2];
511
+ if (childNode["s-hn"] !== hostTagName && childNode["s-ol"]) {
512
+ insertBefore(referenceNode(childNode).parentNode, childNode, referenceNode(childNode));
513
+ childNode["s-ol"].remove();
514
+ childNode["s-ol"] = void 0;
515
+ childNode["s-sh"] = void 0;
516
+ checkSlotRelocate = true;
517
+ }
518
+ if (recursive) {
519
+ putBackInOriginalLocation(childNode, recursive);
520
+ }
521
+ }
522
+ plt.$flags$ &= -2 /* isTmpDisconnected */;
523
+ };
524
+ var addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
525
+ let containerElm = parentElm["s-cr"] && parentElm["s-cr"].parentNode || parentElm;
526
+ let childNode;
527
+ if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
528
+ containerElm = containerElm.shadowRoot;
529
+ }
530
+ for (; startIdx <= endIdx; ++startIdx) {
531
+ if (vnodes[startIdx]) {
532
+ childNode = createElm(null, parentVNode, startIdx);
533
+ if (childNode) {
534
+ vnodes[startIdx].$elm$ = childNode;
535
+ insertBefore(containerElm, childNode, referenceNode(before) );
536
+ }
537
+ }
538
+ }
539
+ };
540
+ var removeVnodes = (vnodes, startIdx, endIdx) => {
541
+ for (let index = startIdx; index <= endIdx; ++index) {
542
+ const vnode = vnodes[index];
543
+ if (vnode) {
544
+ const elm = vnode.$elm$;
545
+ nullifyVNodeRefs(vnode);
546
+ if (elm) {
547
+ {
548
+ checkSlotFallbackVisibility = true;
549
+ if (elm["s-ol"]) {
550
+ elm["s-ol"].remove();
551
+ } else {
552
+ putBackInOriginalLocation(elm, true);
553
+ }
554
+ }
555
+ elm.remove();
556
+ }
557
+ }
558
+ }
559
+ };
560
+ var updateChildren = (parentElm, oldCh, newVNode2, newCh, isInitialRender = false) => {
561
+ let oldStartIdx = 0;
562
+ let newStartIdx = 0;
563
+ let idxInOld = 0;
564
+ let i2 = 0;
565
+ let oldEndIdx = oldCh.length - 1;
566
+ let oldStartVnode = oldCh[0];
567
+ let oldEndVnode = oldCh[oldEndIdx];
568
+ let newEndIdx = newCh.length - 1;
569
+ let newStartVnode = newCh[0];
570
+ let newEndVnode = newCh[newEndIdx];
571
+ let node;
572
+ let elmToMove;
573
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
574
+ if (oldStartVnode == null) {
575
+ oldStartVnode = oldCh[++oldStartIdx];
576
+ } else if (oldEndVnode == null) {
577
+ oldEndVnode = oldCh[--oldEndIdx];
578
+ } else if (newStartVnode == null) {
579
+ newStartVnode = newCh[++newStartIdx];
580
+ } else if (newEndVnode == null) {
581
+ newEndVnode = newCh[--newEndIdx];
582
+ } else if (isSameVnode(oldStartVnode, newStartVnode, isInitialRender)) {
583
+ patch(oldStartVnode, newStartVnode, isInitialRender);
584
+ oldStartVnode = oldCh[++oldStartIdx];
585
+ newStartVnode = newCh[++newStartIdx];
586
+ } else if (isSameVnode(oldEndVnode, newEndVnode, isInitialRender)) {
587
+ patch(oldEndVnode, newEndVnode, isInitialRender);
588
+ oldEndVnode = oldCh[--oldEndIdx];
589
+ newEndVnode = newCh[--newEndIdx];
590
+ } else if (isSameVnode(oldStartVnode, newEndVnode, isInitialRender)) {
591
+ if ((oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) {
592
+ putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
593
+ }
594
+ patch(oldStartVnode, newEndVnode, isInitialRender);
595
+ insertBefore(parentElm, oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
596
+ oldStartVnode = oldCh[++oldStartIdx];
597
+ newEndVnode = newCh[--newEndIdx];
598
+ } else if (isSameVnode(oldEndVnode, newStartVnode, isInitialRender)) {
599
+ if ((oldStartVnode.$tag$ === "slot" || newEndVnode.$tag$ === "slot")) {
600
+ putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
601
+ }
602
+ patch(oldEndVnode, newStartVnode, isInitialRender);
603
+ insertBefore(parentElm, oldEndVnode.$elm$, oldStartVnode.$elm$);
604
+ oldEndVnode = oldCh[--oldEndIdx];
605
+ newStartVnode = newCh[++newStartIdx];
606
+ } else {
607
+ idxInOld = -1;
608
+ {
609
+ for (i2 = oldStartIdx; i2 <= oldEndIdx; ++i2) {
610
+ if (oldCh[i2] && oldCh[i2].$key$ !== null && oldCh[i2].$key$ === newStartVnode.$key$) {
611
+ idxInOld = i2;
612
+ break;
613
+ }
614
+ }
615
+ }
616
+ if (idxInOld >= 0) {
617
+ elmToMove = oldCh[idxInOld];
618
+ if (elmToMove.$tag$ !== newStartVnode.$tag$) {
619
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode2, idxInOld);
620
+ } else {
621
+ patch(elmToMove, newStartVnode, isInitialRender);
622
+ oldCh[idxInOld] = void 0;
623
+ node = elmToMove.$elm$;
624
+ }
625
+ newStartVnode = newCh[++newStartIdx];
626
+ } else {
627
+ node = createElm(oldCh && oldCh[newStartIdx], newVNode2, newStartIdx);
628
+ newStartVnode = newCh[++newStartIdx];
629
+ }
630
+ if (node) {
631
+ {
632
+ insertBefore(
633
+ referenceNode(oldStartVnode.$elm$).parentNode,
634
+ node,
635
+ referenceNode(oldStartVnode.$elm$)
636
+ );
637
+ }
638
+ }
639
+ }
640
+ }
641
+ if (oldStartIdx > oldEndIdx) {
642
+ addVnodes(
643
+ parentElm,
644
+ newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$,
645
+ newVNode2,
646
+ newCh,
647
+ newStartIdx,
648
+ newEndIdx
649
+ );
650
+ } else if (newStartIdx > newEndIdx) {
651
+ removeVnodes(oldCh, oldStartIdx, oldEndIdx);
652
+ }
653
+ };
654
+ var isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
655
+ if (leftVNode.$tag$ === rightVNode.$tag$) {
656
+ if (leftVNode.$tag$ === "slot") {
657
+ return leftVNode.$name$ === rightVNode.$name$;
658
+ }
659
+ if (!isInitialRender) {
660
+ return leftVNode.$key$ === rightVNode.$key$;
661
+ }
662
+ if (isInitialRender && !leftVNode.$key$ && rightVNode.$key$) {
663
+ leftVNode.$key$ = rightVNode.$key$;
664
+ }
665
+ return true;
666
+ }
667
+ return false;
668
+ };
669
+ var referenceNode = (node) => node && node["s-ol"] || node;
670
+ var patch = (oldVNode, newVNode2, isInitialRender = false) => {
671
+ const elm = newVNode2.$elm$ = oldVNode.$elm$;
672
+ const oldChildren = oldVNode.$children$;
673
+ const newChildren = newVNode2.$children$;
674
+ const tag = newVNode2.$tag$;
675
+ const text = newVNode2.$text$;
676
+ let defaultHolder;
677
+ if (text === null) {
678
+ {
679
+ isSvgMode = tag === "svg" ? true : tag === "foreignObject" ? false : isSvgMode;
680
+ }
681
+ {
682
+ updateElement(oldVNode, newVNode2, isSvgMode);
683
+ }
684
+ if (oldChildren !== null && newChildren !== null) {
685
+ updateChildren(elm, oldChildren, newVNode2, newChildren, isInitialRender);
686
+ } else if (newChildren !== null) {
687
+ if (oldVNode.$text$ !== null) {
688
+ elm.textContent = "";
689
+ }
690
+ addVnodes(elm, null, newVNode2, newChildren, 0, newChildren.length - 1);
691
+ } else if (
692
+ // don't do this on initial render as it can cause non-hydrated content to be removed
693
+ !isInitialRender && BUILD.updatable && oldChildren !== null
694
+ ) {
695
+ removeVnodes(oldChildren, 0, oldChildren.length - 1);
696
+ }
697
+ if (isSvgMode && tag === "svg") {
698
+ isSvgMode = false;
699
+ }
700
+ } else if ((defaultHolder = elm["s-cr"])) {
701
+ defaultHolder.parentNode.textContent = text;
702
+ } else if (oldVNode.$text$ !== text) {
703
+ elm.data = text;
704
+ }
705
+ };
706
+ var relocateNodes = [];
707
+ var markSlotContentForRelocation = (elm) => {
708
+ let node;
709
+ let hostContentNodes;
710
+ let j;
711
+ const children = elm.__childNodes || elm.childNodes;
712
+ for (const childNode of children) {
713
+ if (childNode["s-sr"] && (node = childNode["s-cr"]) && node.parentNode) {
714
+ hostContentNodes = node.parentNode.__childNodes || node.parentNode.childNodes;
715
+ const slotName = childNode["s-sn"];
716
+ for (j = hostContentNodes.length - 1; j >= 0; j--) {
717
+ node = hostContentNodes[j];
718
+ if (!node["s-cn"] && !node["s-nr"] && node["s-hn"] !== childNode["s-hn"] && (true)) {
719
+ if (isNodeLocatedInSlot(node, slotName)) {
720
+ let relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
721
+ checkSlotFallbackVisibility = true;
722
+ node["s-sn"] = node["s-sn"] || slotName;
723
+ if (relocateNodeData) {
724
+ relocateNodeData.$nodeToRelocate$["s-sh"] = childNode["s-hn"];
725
+ relocateNodeData.$slotRefNode$ = childNode;
726
+ } else {
727
+ node["s-sh"] = childNode["s-hn"];
728
+ relocateNodes.push({
729
+ $slotRefNode$: childNode,
730
+ $nodeToRelocate$: node
731
+ });
732
+ }
733
+ if (node["s-sr"]) {
734
+ relocateNodes.map((relocateNode) => {
735
+ if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node["s-sn"])) {
736
+ relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
737
+ if (relocateNodeData && !relocateNode.$slotRefNode$) {
738
+ relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
739
+ }
740
+ }
741
+ });
742
+ }
743
+ } else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
744
+ relocateNodes.push({
745
+ $nodeToRelocate$: node
746
+ });
747
+ }
748
+ }
749
+ }
750
+ }
751
+ if (childNode.nodeType === 1 /* ElementNode */) {
752
+ markSlotContentForRelocation(childNode);
753
+ }
754
+ }
755
+ };
756
+ var nullifyVNodeRefs = (vNode) => {
757
+ {
758
+ vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
759
+ vNode.$children$ && vNode.$children$.map(nullifyVNodeRefs);
760
+ }
761
+ };
762
+ var insertBefore = (parent, newNode, reference) => {
763
+ if (typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) {
764
+ addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
765
+ }
766
+ {
767
+ return parent == null ? void 0 : parent.insertBefore(newNode, reference);
768
+ }
769
+ };
770
+ function addRemoveSlotScopedClass(reference, slotNode, newParent, oldParent) {
771
+ var _a, _b;
772
+ let scopeId2;
773
+ if (reference && typeof slotNode["s-sn"] === "string" && !!slotNode["s-sr"] && reference.parentNode && reference.parentNode["s-sc"] && (scopeId2 = slotNode["s-si"] || reference.parentNode["s-sc"])) {
774
+ const scopeName = slotNode["s-sn"];
775
+ const hostName = slotNode["s-hn"];
776
+ (_a = newParent.classList) == null ? void 0 : _a.add(scopeId2 + "-s");
777
+ if (oldParent && ((_b = oldParent.classList) == null ? void 0 : _b.contains(scopeId2 + "-s"))) {
778
+ let child = (oldParent.__childNodes || oldParent.childNodes)[0];
779
+ let found = false;
780
+ while (child) {
781
+ if (child["s-sn"] !== scopeName && child["s-hn"] === hostName && !!child["s-sr"]) {
782
+ found = true;
783
+ break;
784
+ }
785
+ child = child.nextSibling;
786
+ }
787
+ if (!found) oldParent.classList.remove(scopeId2 + "-s");
788
+ }
789
+ }
790
+ }
791
+ var renderVdom = (hostRef, renderFnResults, isInitialLoad = false) => {
792
+ var _a, _b, _c, _d, _e;
793
+ const hostElm = hostRef.$hostElement$;
794
+ const cmpMeta = hostRef.$cmpMeta$;
795
+ const oldVNode = hostRef.$vnode$ || newVNode(null, null);
796
+ const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
797
+ hostTagName = hostElm.tagName;
798
+ if (cmpMeta.$attrsToReflect$) {
799
+ rootVnode.$attrs$ = rootVnode.$attrs$ || {};
800
+ cmpMeta.$attrsToReflect$.map(
801
+ ([propName, attribute]) => rootVnode.$attrs$[attribute] = hostElm[propName]
802
+ );
803
+ }
804
+ if (isInitialLoad && rootVnode.$attrs$) {
805
+ for (const key of Object.keys(rootVnode.$attrs$)) {
806
+ if (hostElm.hasAttribute(key) && !["key", "ref", "style", "class"].includes(key)) {
807
+ rootVnode.$attrs$[key] = hostElm[key];
808
+ }
809
+ }
810
+ }
811
+ rootVnode.$tag$ = null;
812
+ rootVnode.$flags$ |= 4 /* isHost */;
813
+ hostRef.$vnode$ = rootVnode;
814
+ rootVnode.$elm$ = oldVNode.$elm$ = hostElm.shadowRoot || hostElm ;
815
+ {
816
+ scopeId = hostElm["s-sc"];
817
+ }
818
+ useNativeShadowDom = !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) && !(cmpMeta.$flags$ & 128 /* shadowNeedsScopedCss */);
819
+ {
820
+ contentRef = hostElm["s-cr"];
821
+ checkSlotFallbackVisibility = false;
822
+ }
823
+ patch(oldVNode, rootVnode, isInitialLoad);
824
+ {
825
+ plt.$flags$ |= 1 /* isTmpDisconnected */;
826
+ if (checkSlotRelocate) {
827
+ markSlotContentForRelocation(rootVnode.$elm$);
828
+ for (const relocateData of relocateNodes) {
829
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
830
+ if (!nodeToRelocate["s-ol"] && win.document) {
831
+ const orgLocationNode = win.document.createTextNode("");
832
+ orgLocationNode["s-nr"] = nodeToRelocate;
833
+ insertBefore(nodeToRelocate.parentNode, nodeToRelocate["s-ol"] = orgLocationNode, nodeToRelocate);
834
+ }
835
+ }
836
+ for (const relocateData of relocateNodes) {
837
+ const nodeToRelocate = relocateData.$nodeToRelocate$;
838
+ const slotRefNode = relocateData.$slotRefNode$;
839
+ if (slotRefNode) {
840
+ const parentNodeRef = slotRefNode.parentNode;
841
+ let insertBeforeNode = slotRefNode.nextSibling;
842
+ {
843
+ let orgLocationNode = (_a = nodeToRelocate["s-ol"]) == null ? void 0 : _a.previousSibling;
844
+ while (orgLocationNode) {
845
+ let refNode = (_b = orgLocationNode["s-nr"]) != null ? _b : null;
846
+ if (refNode && refNode["s-sn"] === nodeToRelocate["s-sn"] && parentNodeRef === (refNode.__parentNode || refNode.parentNode)) {
847
+ refNode = refNode.nextSibling;
848
+ while (refNode === nodeToRelocate || (refNode == null ? void 0 : refNode["s-sr"])) {
849
+ refNode = refNode == null ? void 0 : refNode.nextSibling;
850
+ }
851
+ if (!refNode || !refNode["s-nr"]) {
852
+ insertBeforeNode = refNode;
853
+ break;
854
+ }
855
+ }
856
+ orgLocationNode = orgLocationNode.previousSibling;
857
+ }
858
+ }
859
+ const parent = nodeToRelocate.__parentNode || nodeToRelocate.parentNode;
860
+ const nextSibling = nodeToRelocate.__nextSibling || nodeToRelocate.nextSibling;
861
+ if (!insertBeforeNode && parentNodeRef !== parent || nextSibling !== insertBeforeNode) {
862
+ if (nodeToRelocate !== insertBeforeNode) {
863
+ if (!nodeToRelocate["s-hn"] && nodeToRelocate["s-ol"]) {
864
+ nodeToRelocate["s-hn"] = nodeToRelocate["s-ol"].parentNode.nodeName;
865
+ }
866
+ insertBefore(parentNodeRef, nodeToRelocate, insertBeforeNode);
867
+ if (nodeToRelocate.nodeType === 1 /* ElementNode */ && nodeToRelocate.tagName !== "SLOT-FB") {
868
+ nodeToRelocate.hidden = (_c = nodeToRelocate["s-ih"]) != null ? _c : false;
869
+ }
870
+ }
871
+ }
872
+ nodeToRelocate && typeof slotRefNode["s-rf"] === "function" && slotRefNode["s-rf"](slotRefNode);
873
+ } else {
874
+ if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
875
+ if (isInitialLoad) {
876
+ nodeToRelocate["s-ih"] = (_d = nodeToRelocate.hidden) != null ? _d : false;
877
+ }
878
+ nodeToRelocate.hidden = true;
879
+ }
880
+ }
881
+ }
882
+ }
883
+ if (checkSlotFallbackVisibility) {
884
+ updateFallbackSlotVisibility(rootVnode.$elm$);
885
+ }
886
+ plt.$flags$ &= -2 /* isTmpDisconnected */;
887
+ relocateNodes.length = 0;
888
+ }
889
+ if (BUILD.experimentalScopedSlotChanges && cmpMeta.$flags$ & 2 /* scopedCssEncapsulation */) {
890
+ const children = rootVnode.$elm$.__childNodes || rootVnode.$elm$.childNodes;
891
+ for (const childNode of children) {
892
+ if (childNode["s-hn"] !== hostTagName && !childNode["s-sh"]) {
893
+ if (isInitialLoad && childNode["s-ih"] == null) {
894
+ childNode["s-ih"] = (_e = childNode.hidden) != null ? _e : false;
895
+ }
896
+ childNode.hidden = true;
897
+ }
898
+ }
899
+ }
900
+ contentRef = void 0;
901
+ };
902
+
903
+ /**
904
+ * @type {import('htmlfy').Config}
905
+ */
906
+ const CONFIG = {
907
+ content_wrap: 0,
908
+ ignore: [],
909
+ ignore_with: '_!i-£___£%_',
910
+ strict: false,
911
+ tab_size: 2,
912
+ tag_wrap: 0,
913
+ tag_wrap_width: 80,
914
+ trim: []
915
+ };
916
+
917
+ const CONTENT_IGNORE_STRING = '__!i-£___£%__';
918
+ const IGNORE_STRING = '!i-£___£%_';
919
+
920
+ const VOID_ELEMENTS = [
921
+ 'area', 'base', 'br', 'col', 'embed', 'hr',
922
+ 'img', 'input', 'link', 'meta',
923
+ 'param', 'source', 'track', 'wbr'
924
+ ];
925
+
926
+ /**
927
+ * Checks if content contains at least one HTML element or custom HTML element.
928
+ *
929
+ * The first regex matches void and self-closing elements.
930
+ * The second regex matches normal HTML elements, plus they can have a namespace.
931
+ * The third regex matches custom HTML elemtns, plus they can have a namespace.
932
+ *
933
+ * HTML elements should begin with a letter, and can end with a letter or number.
934
+ *
935
+ * Custom elements must begin with a letter, and can end with a letter, number,
936
+ * hyphen, underscore, or period. However, all letters must be lowercase.
937
+ * They must have at least one hyphen, and can only have periods and underscores if there is a hyphen.
938
+ *
939
+ * These regexes are based on
940
+ * https://w3c.github.io/html-reference/syntax.html#tag-name
941
+ * and
942
+ * https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
943
+ * respectively.
944
+ *
945
+ * @param {string} content Content to evaluate.
946
+ * @returns {boolean} A boolean.
947
+ */
948
+ const isHtml = (content) =>
949
+ /<(?:[A-Za-z]+[A-Za-z0-9]*)(?:\s+.*?)*?\/{0,1}>/.test(content) ||
950
+ /<(?<Element>(?:[A-Za-z]+[A-Za-z0-9]*:)?(?:[A-Za-z]+[A-Za-z0-9]*))(?:\s+.*?)*?>(?:.|\n)*?<\/{1}\k<Element>>/.test(content) ||
951
+ /<(?<Element>(?:[a-z][a-z0-9._]*:)?[a-z][a-z0-9._]*-[a-z0-9._-]+)(?:\s+.*?)*?>(?:.|\n)*?<\/{1}\k<Element>>/.test(content);
952
+
953
+ /**
954
+ * Generic utility which merges two objects.
955
+ *
956
+ * @param {any} current Original object.
957
+ * @param {any} updates Object to merge with original.
958
+ * @returns {any}
959
+ */
960
+ const mergeObjects = (current, updates) => {
961
+ if (!current || !updates)
962
+ throw new Error("Both 'current' and 'updates' must be passed-in to mergeObjects()")
963
+
964
+ /**
965
+ * @type {any}
966
+ */
967
+ let merged;
968
+
969
+ if (Array.isArray(current)) {
970
+ merged = structuredClone(current).concat(updates);
971
+ } else if (typeof current === 'object') {
972
+ merged = { ...current };
973
+ for (let key of Object.keys(updates)) {
974
+ if (typeof updates[key] !== 'object') {
975
+ merged[key] = updates[key];
976
+ } else {
977
+ /* key is an object, run mergeObjects again. */
978
+ merged[key] = mergeObjects(merged[key] || {}, updates[key]);
979
+ }
980
+ }
981
+ }
982
+
983
+ return merged
984
+ };
985
+
986
+ /**
987
+ * Merge a user config with the default config.
988
+ *
989
+ * @param {import('htmlfy').Config} dconfig The default config.
990
+ * @param {import('htmlfy').UserConfig} config The user config.
991
+ * @returns {import('htmlfy').Config}
992
+ */
993
+ const mergeConfig = (dconfig, config) => {
994
+ /**
995
+ * We need to make a deep copy of `dconfig`,
996
+ * otherwise we end up altering the original `CONFIG` because `dconfig` is a reference to it.
997
+ */
998
+ return mergeObjects(structuredClone(dconfig), config)
999
+ };
1000
+
1001
+ /**
1002
+ *
1003
+ * @param {string} html
1004
+ */
1005
+ const protectAttributes = (html) => {
1006
+ html = html.replace(/<[\w:\-]+([^>]*[^\/])>/g, (/** @type {string} */match, /** @type {any} */capture) => {
1007
+ return match.replace(capture, (match) => {
1008
+ return match
1009
+ .replace(/\n/g, IGNORE_STRING + 'nl!')
1010
+ .replace(/\r/g, IGNORE_STRING + 'cr!')
1011
+ .replace(/\s/g, IGNORE_STRING + 'ws!')
1012
+ })
1013
+ });
1014
+
1015
+ return html
1016
+ };
1017
+
1018
+ /**
1019
+ *
1020
+ * @param {string} html
1021
+ */
1022
+ const protectContent = (html) => {
1023
+ return html
1024
+ .replace(/\n/g, CONTENT_IGNORE_STRING + 'nl!')
1025
+ .replace(/\r/g, CONTENT_IGNORE_STRING + 'cr!')
1026
+ .replace(/\s/g, CONTENT_IGNORE_STRING + 'ws!')
1027
+ };
1028
+
1029
+ /**
1030
+ *
1031
+ * @param {string} html
1032
+ */
1033
+ const finalProtectContent = (html) => {
1034
+ const regex = /\s*<([a-zA-Z0-9:-]+)[^>]*>\n\s*<\/\1>(?=\n[ ]*[^\n]*__!i-£___£%__[^\n]*\n)(\n[ ]*\S[^\n]*\n)|<([a-zA-Z0-9:-]+)[^>]*>(?=\n[ ]*[^\n]*__!i-£___£%__[^\n]*\n)(\n[ ]*\S[^\n]*\n\s*)<\/\3>/g;
1035
+ return html
1036
+ .replace(regex, (/** @type {string} */match, p1, p2, p3, p4) => {
1037
+ const text_to_protect = p2 || p4;
1038
+
1039
+ if (!text_to_protect)
1040
+ return match
1041
+
1042
+ const protected_text = text_to_protect
1043
+ .replace(/\n/g, CONTENT_IGNORE_STRING + 'nl!')
1044
+ .replace(/\r/g, CONTENT_IGNORE_STRING + 'cr!')
1045
+ .replace(/\s/g, CONTENT_IGNORE_STRING + "ws!");
1046
+
1047
+ return match.replace(text_to_protect, protected_text)
1048
+ })
1049
+ };
1050
+
1051
+ /**
1052
+ * Replace html brackets with ignore string.
1053
+ *
1054
+ * @param {string} html
1055
+ * @returns {string}
1056
+ */
1057
+ const setIgnoreAttribute = (html) => {
1058
+ const regex = /<([A-Za-z][A-Za-z0-9]*|[a-z][a-z0-9._]*-[a-z0-9._-]+)((?:\s+[A-Za-z0-9_-]+="[^"]*"|\s*[a-z]*)*)>/g;
1059
+
1060
+ html = html.replace(regex, (/** @type {string} */match, p1, p2) => {
1061
+ return match.replace(p2, (match) => {
1062
+ return match
1063
+ .replace(/</g, IGNORE_STRING + 'lt!')
1064
+ .replace(/>/g, IGNORE_STRING + 'gt!')
1065
+ })
1066
+ });
1067
+
1068
+ return html
1069
+ };
1070
+
1071
+ /**
1072
+ * @typedef {"<" | ">" | "\n" | "\r" | " " | "\t"} ReplacementKey
1073
+ * Defines the possible keys for the replacements object.
1074
+ */
1075
+
1076
+ /**
1077
+ * Replace entities with ignore string.
1078
+ *
1079
+ * @param {string} html
1080
+ * @param {import('htmlfy').Config} config
1081
+ * @returns {string}
1082
+ */
1083
+ const setIgnoreElement = (html, config) => {
1084
+ const ignore = config.ignore;
1085
+ const ignore_string = config.ignore_with;
1086
+
1087
+ /* Pre-create replacement map for faster lookup. */
1088
+ const replacements = {
1089
+ "<": "-" + ignore_string + "lt-",
1090
+ ">": "-" + ignore_string + "gt-",
1091
+ "\n": "-" + ignore_string + "nl-",
1092
+ "\r": "-" + ignore_string + "cr-",
1093
+ " ": "-" + ignore_string + "ws-", // Use space ' ' as key
1094
+ "\t": "-" + ignore_string + "tab-", // Use tab '\t' as key (add placeholder if needed)
1095
+ // Add other specific whitespace chars like \v, \f if necessary
1096
+ };
1097
+ /* Regex to match any character we need to replace inside the ignored content. */
1098
+ const charReplaceRegex = /[<>\n\r \t]/g;
1099
+
1100
+ for (let e = 0; e < ignore.length; e++) {
1101
+ const tagName = ignore[e].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
1102
+ const regex = new RegExp(
1103
+ `<${tagName}[^>]*>(.*?)<\/${tagName}>`,
1104
+ "gs" // Use 'g' (global) and 's' (dotAll) flags
1105
+ );
1106
+
1107
+ html = html.replace(
1108
+ regex,
1109
+ (/** @type {string} */ fullMatch, /** @type {string} */ capture) => {
1110
+ const processedCapture = capture.replace(
1111
+ charReplaceRegex,
1112
+ (/** @type {string} */ char) => {
1113
+ return replacements[/** @type {ReplacementKey} */ (char)] // Return the placeholder
1114
+ // Or safer if map might be incomplete: return replacements[char] || char
1115
+ }
1116
+ );
1117
+
1118
+ /* Reconstruct the string using original tags and processed content. */
1119
+ const openingTagEnd = fullMatch.indexOf(">") + 1;
1120
+ const closingTagStart = fullMatch.lastIndexOf(`</${tagName}>`);
1121
+
1122
+ /* Check if tags were found (basic sanity check). */
1123
+ if (openingTagEnd > 0 && closingTagStart > 0) {
1124
+ const openingTag = fullMatch.substring(0, openingTagEnd);
1125
+ const closingTag = fullMatch.substring(closingTagStart);
1126
+ return openingTag + processedCapture + closingTag
1127
+ } else {
1128
+ // Should not happen with valid HTML and correct regex
1129
+ // Return original match to avoid breaking things further
1130
+ return fullMatch
1131
+ }
1132
+ }
1133
+ );
1134
+ }
1135
+ return html
1136
+ };
1137
+
1138
+ /**
1139
+ * Trim leading and trailing whitespace characters.
1140
+ *
1141
+ * @param {string} html
1142
+ * @param {string[]} trim
1143
+ * @returns {string}
1144
+ */
1145
+ const trimify = (html, trim) => {
1146
+ for (let e = 0; e < trim.length; e++) {
1147
+ /* Whitespace character must be escaped with '\' or RegExp() won't include it. */
1148
+ const leading_whitespace = new RegExp(`(<${trim[e]}[^>]*>)\\s+`, "g");
1149
+ const trailing_whitespace = new RegExp(`\\s+(</${trim[e]}>)`, "g");
1150
+
1151
+ html = html
1152
+ .replace(leading_whitespace, '$1')
1153
+ .replace(trailing_whitespace, '$1');
1154
+ }
1155
+
1156
+ return html
1157
+ };
1158
+
1159
+ /**
1160
+ *
1161
+ * @param {string} html
1162
+ */
1163
+ const unprotectAttributes = (html) => {
1164
+ html = html.replace(/<[\w:\-]+([^>]*[^\/])>/g, (/** @type {string} */match, /** @type {any} */capture) => {
1165
+ return match.replace(capture, (match) => {
1166
+ return match
1167
+ .replace(new RegExp(IGNORE_STRING + 'nl!', "g"), '\n')
1168
+ .replace(new RegExp(IGNORE_STRING + 'cr!', "g"), '\r')
1169
+ .replace(new RegExp(IGNORE_STRING + 'ws!', "g"), ' ')
1170
+ })
1171
+ });
1172
+
1173
+ return html
1174
+ };
1175
+
1176
+ /**
1177
+ *
1178
+ * @param {string} html
1179
+ */
1180
+ const unprotectContent = (html) => {
1181
+ html = html.replace(/.*__!i-£___£%__[a-z]{2}!.*/g, (/** @type {string} */match) => {
1182
+ return match.replace(/__!i-£___£%__[a-z]{2}!/g, (match) => {
1183
+ return match
1184
+ .replace(new RegExp(CONTENT_IGNORE_STRING + 'nl!', "g"), '\n')
1185
+ .replace(new RegExp(CONTENT_IGNORE_STRING + 'cr!', "g"), '\r')
1186
+ .replace(new RegExp(CONTENT_IGNORE_STRING + 'ws!', "g"), ' ')
1187
+ })
1188
+ });
1189
+
1190
+ return html
1191
+ };
1192
+
1193
+ const escapedIgnoreString = IGNORE_STRING.replace(
1194
+ /[-\/\\^$*+?.()|[\]{}]/g,
1195
+ "\\$&"
1196
+ );
1197
+ const ltPlaceholderRegex = new RegExp(escapedIgnoreString + "lt!", "g");
1198
+ const gtPlaceholderRegex = new RegExp(escapedIgnoreString + "gt!", "g");
1199
+
1200
+ /**
1201
+ * Replace ignore string with html brackets.
1202
+ *
1203
+ * @param {string} html
1204
+ * @returns {string}
1205
+ */
1206
+ const unsetIgnoreAttribute = (html) => {
1207
+ /* Regex to find opening tags and capture their attributes. */
1208
+ const tagRegex = /<([\w:\-]+)([^>]*)>/g;
1209
+
1210
+ return html.replace(
1211
+ tagRegex,
1212
+ (
1213
+ /** @type {string} */ fullMatch,
1214
+ /** @type {string} */ tagName,
1215
+ /** @type {string} */ attributesCapture
1216
+ ) => {
1217
+ const processedAttributes = attributesCapture
1218
+ .replace(ltPlaceholderRegex, "<")
1219
+ .replace(gtPlaceholderRegex, ">");
1220
+
1221
+ /* Reconstruct the tag. */
1222
+ return `<${tagName}${processedAttributes}>`
1223
+ }
1224
+ )
1225
+ };
1226
+
1227
+ /**
1228
+ * Replace ignore string with entities.
1229
+ *
1230
+ * @param {string} html
1231
+ * @param {import('htmlfy').Config} config
1232
+ * @returns {string}
1233
+ */
1234
+ const unsetIgnoreElement = (html, config) => {
1235
+ const ignore = config.ignore;
1236
+ const ignore_string = config.ignore_with;
1237
+
1238
+ for (let e = 0; e < ignore.length; e++) {
1239
+ const regex = new RegExp(`<${ignore[e]}[^>]*>((.|\n)*?)<\/${ignore[e]}>`, "g");
1240
+
1241
+ html = html.replace(regex, (/** @type {string} */match, /** @type {any} */capture) => {
1242
+ return match.replace(capture, (match) => {
1243
+ return match
1244
+ .replace(new RegExp('-' + ignore_string + 'lt-', "g"), '<')
1245
+ .replace(new RegExp('-' + ignore_string + 'gt-', "g"), '>')
1246
+ .replace(new RegExp('-' + ignore_string + 'nl-', "g"), '\n')
1247
+ .replace(new RegExp('-' + ignore_string + 'cr-', "g"), '\r')
1248
+ .replace(new RegExp('-' + ignore_string + 'ws-', "g"), ' ')
1249
+ })
1250
+ });
1251
+ }
1252
+ return html
1253
+ };
1254
+
1255
+ /**
1256
+ * Validate any passed-in config options and merge with CONFIG.
1257
+ *
1258
+ * @param {import('htmlfy').UserConfig} config A user config.
1259
+ * @returns {import('htmlfy').Config} A validated config.
1260
+ */
1261
+ const validateConfig = (config) => {
1262
+ if (typeof config !== 'object') throw new Error('Config must be an object.')
1263
+
1264
+ const config_empty = !(
1265
+ Object.hasOwn(config, 'content_wrap') ||
1266
+ Object.hasOwn(config, 'ignore') ||
1267
+ Object.hasOwn(config, 'ignore_with') ||
1268
+ Object.hasOwn(config, 'strict') ||
1269
+ Object.hasOwn(config, 'tab_size') ||
1270
+ Object.hasOwn(config, 'tag_wrap') ||
1271
+ Object.hasOwn(config, 'tag_wrap_width') ||
1272
+ Object.hasOwn(config, 'trim')
1273
+ );
1274
+
1275
+ if (config_empty) return CONFIG
1276
+
1277
+ let tab_size = config.tab_size;
1278
+
1279
+ if (tab_size) {
1280
+ if (typeof tab_size !== 'number') throw new Error(`tab_size must be a number, not ${typeof config.tab_size}.`)
1281
+
1282
+ const safe = Number.isSafeInteger(tab_size);
1283
+ if (!safe) throw new Error(`Tab size ${tab_size} is not safe. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger for more info.`)
1284
+
1285
+ /**
1286
+ * Round down, just in case a safe floating point,
1287
+ * like 4.0, was passed.
1288
+ */
1289
+ tab_size = Math.floor(tab_size);
1290
+ if (tab_size < 1 || tab_size > 16) throw new Error('Tab size out of range. Expecting 1 to 16.')
1291
+
1292
+ config.tab_size = tab_size;
1293
+ }
1294
+
1295
+ if (Object.hasOwn(config, 'content_wrap') && typeof config.content_wrap !== 'number')
1296
+ throw new Error(`content_wrap config must be a number, not ${typeof config.tag_wrap_width}.`)
1297
+
1298
+ if (Object.hasOwn(config, 'ignore') && (!Array.isArray(config.ignore) || !config.ignore?.every((e) => typeof e === 'string')))
1299
+ throw new Error('Ignore config must be an array of strings.')
1300
+
1301
+ if (Object.hasOwn(config, 'ignore_with') && typeof config.ignore_with !== 'string')
1302
+ throw new Error(`Ignore_with config must be a string, not ${typeof config.ignore_with}.`)
1303
+
1304
+ if (Object.hasOwn(config, 'strict') && typeof config.strict !== 'boolean')
1305
+ throw new Error(`Strict config must be a boolean, not ${typeof config.strict}.`)
1306
+
1307
+ /* TODO remove in v0.9.0 */
1308
+ if (Object.hasOwn(config, 'tag_wrap') && typeof config.tag_wrap === 'boolean') {
1309
+ console.warn('tag_wrap as a boolean is deprecated, and will not be supported in v0.9.0+. Use `tag_wrap: <number>` instead; where <number> is the max character width acceptable before wrapping attributes.');
1310
+ if (config.tag_wrap_width)
1311
+ config.tag_wrap = config.tag_wrap_width;
1312
+ else
1313
+ config.tag_wrap = CONFIG.tag_wrap_width;
1314
+ }
1315
+
1316
+ if (Object.hasOwn(config, 'tag_wrap') && typeof config.tag_wrap !== 'number')
1317
+ throw new Error(`tag_wrap config must be a number, not ${typeof config.tag_wrap}.`)
1318
+
1319
+ /* TODO remove in v0.9.0 */
1320
+ if (Object.hasOwn(config, 'tag_wrap_width'))
1321
+ console.warn('tag_wrap_width is deprecated, and will not be supported in v0.9.0+. Use `tag_wrap: <number>` instead; where <number> is the max character width acceptable before wrapping attributes.');
1322
+
1323
+ /* TODO remove in v0.9.0 */
1324
+ if (Object.hasOwn(config, 'tag_wrap_width') && typeof config.tag_wrap_width !== 'number')
1325
+ throw new Error(`tag_wrap_width config must be a number, not ${typeof config.tag_wrap_width}.`)
1326
+
1327
+ if (Object.hasOwn(config, 'trim') && (!Array.isArray(config.trim) || !config.trim?.every((e) => typeof e === 'string')))
1328
+ throw new Error('Trim config must be an array of strings.')
1329
+
1330
+ return mergeConfig(CONFIG, config)
1331
+
1332
+ };
1333
+
1334
+ /**
1335
+ *
1336
+ * @param {string} text
1337
+ * @param {number} width
1338
+ * @param {string} indent
1339
+ */
1340
+ const wordWrap = (text, width, indent) => {
1341
+ const words = text.trim().split(/\s+/);
1342
+
1343
+ if (words.length === 0 || (words.length === 1 && words[0] === ''))
1344
+ return ""
1345
+
1346
+ const lines = [];
1347
+ let current_line = "";
1348
+ const padding_string = indent;
1349
+
1350
+ words.forEach((word) => {
1351
+ if (word === "") return
1352
+
1353
+ if (word.length >= width) {
1354
+ /* If there's content on the current line, push it first with correct padding. */
1355
+ if (current_line !== "")
1356
+ lines.push(lines.length === 0 ? indent + current_line : padding_string + current_line);
1357
+
1358
+ /* Push a long word on its own line with correct padding. */
1359
+ lines.push(lines.length === 0 ? indent + word : padding_string + word);
1360
+ current_line = ""; // Reset current line
1361
+ return // Move to the next word
1362
+ }
1363
+
1364
+ /* Check if adding the next word exceeds the wrap width. */
1365
+ const test_line = current_line === "" ? word : current_line + " " + word;
1366
+
1367
+ if (test_line.length <= width) {
1368
+ current_line = test_line;
1369
+ } else {
1370
+ /* Word doesn't fit, finish the current line and push it. */
1371
+ if (current_line !== "") {
1372
+ /* Add padding based on whether it's the first line added or not. */
1373
+ lines.push(lines.length === 0 ? indent + current_line : padding_string + current_line);
1374
+ }
1375
+ /* Start a new line with the current word. */
1376
+ current_line = word;
1377
+ }
1378
+ });
1379
+
1380
+ /* Add the last remaining line with appropriate padding. */
1381
+ if (current_line !== "")
1382
+ lines.push(lines.length === 0 ? indent + current_line : padding_string + current_line);
1383
+
1384
+ const result = lines.join("\n");
1385
+
1386
+ return protectContent(result)
1387
+ };
1388
+
1389
+ /**
1390
+ * Ensure void elements are "self-closing".
1391
+ *
1392
+ * @param {string} html The HTML string to evaluate.
1393
+ * @param {boolean} check_html Check to see if the content contains any HTML, before processing.
1394
+ * @returns {string}
1395
+ * @example <br> => <br />
1396
+ */
1397
+ const closify = (html, check_html = true) => {
1398
+ if (check_html && !isHtml(html)) return html
1399
+
1400
+ return html.replace(/<([a-zA-Z\-0-9:]+)[^>]*>/g, (match, name) => {
1401
+ if (VOID_ELEMENTS.indexOf(name) > -1)
1402
+ return (`${match.substring(0, match.length - 1)} />`).replace(/\/\s\//g, '/')
1403
+
1404
+ return match.replace(/[\s]?\/>/g, `></${name}>`)
1405
+ })
1406
+ };
1407
+
1408
+ /**
1409
+ * Enforce entity characters for textarea content.
1410
+ * To also minifiy, pass `minify` as `true`.
1411
+ *
1412
+ * @param {string} html The HTML string to evaluate.
1413
+ * @param {boolean} [minify] Fully minifies the content of textarea elements.
1414
+ * Defaults to `false`. We recommend a value of `true` if you're running `entify()`
1415
+ * as a standalone function.
1416
+ * @returns {string}
1417
+ * @example <textarea>3 > 2</textarea> => <textarea>3 &gt; 2</textarea>
1418
+ */
1419
+ const entify = (html, minify = false) => {
1420
+ /**
1421
+ * Use entities inside textarea content.
1422
+ */
1423
+ html = html.replace(/<textarea[^>]*>((.|\n)*?)<\/textarea>/g, (match, capture) => {
1424
+ return match.replace(capture, (match) => {
1425
+ return match
1426
+ .replace(/</g, '&lt;')
1427
+ .replace(/>/g, '&gt;')
1428
+ .replace(/"/g, '&quot;')
1429
+ .replace(/'/g, '&apos;')
1430
+ .replace(/\n/g, '&#10;')
1431
+ .replace(/\r/g, '&#13;')
1432
+ .replace(/\s/g, '&nbsp;')
1433
+ })
1434
+ });
1435
+
1436
+ /* Typical minification, but only for textareas. */
1437
+ if (minify) {
1438
+ html = html.replace(/<textarea[^>]*>((.|\n)*?)<\/textarea>/g, (match, capture) => {
1439
+ /* Replace things inside the textarea content. */
1440
+ match = match.replace(capture, (match) => {
1441
+ return match
1442
+ .replace(/\n|\t/g, '')
1443
+ .replace(/[a-z]+="\s*"/ig, '')
1444
+ .replace(/>\s+</g, '><')
1445
+ .replace(/\s+/g, ' ')
1446
+ });
1447
+
1448
+ /* Replace things in the entire element */
1449
+ match = match
1450
+ .replace(/\s+/g, ' ')
1451
+ .replace(/\s>/g, '>')
1452
+ .replace(/>\s/g, '>')
1453
+ .replace(/\s</g, '<')
1454
+ .replace(/class=["']\s/g, (match) => match.replace(/\s/g, ''))
1455
+ .replace(/(class=.*)\s(["'])/g, '$1'+'$2');
1456
+ return match
1457
+ });
1458
+ }
1459
+
1460
+ return html
1461
+ };
1462
+
1463
+ /**
1464
+ * Creates a single-line HTML string
1465
+ * by removing line returns, tabs, and relevant spaces.
1466
+ *
1467
+ * @param {string} html The HTML string to minify.
1468
+ * @param {boolean} check_html Check to see if the content contains any HTML, before processing.
1469
+ * @returns {string} A minified HTML string.
1470
+ */
1471
+ const minify = (html, check_html = true) => {
1472
+ if (check_html && !isHtml(html)) return html
1473
+
1474
+ /**
1475
+ * Ensure textarea content is specially minified and protected
1476
+ * before general minification.
1477
+ */
1478
+ html = entify(html);
1479
+
1480
+ /* All other minification. */
1481
+ // Remove ALL newlines and tabs explicitly.
1482
+ html = html.replace(/\n|\t/g, '');
1483
+
1484
+ // Remove whitespace ONLY between tags.
1485
+ html = html.replace(/>\s+</g, "><");
1486
+
1487
+ // Collapse any remaining multiple spaces to single spaces.
1488
+ html = html.replace(/ {2,}/g, ' ');
1489
+
1490
+ // Remove specific single spaces OR whitespace within closing tags.
1491
+ html = html.replace(/ >/g, ">"); // <tag > -> <tag>
1492
+ html = html.replace(/ </g, "<"); // Text < -> Text< (Also handles leading space before tag)
1493
+ html = html.replace(/> /g, ">"); // > Text -> >Text
1494
+ html = html.replace(/<\s*\//g, '</'); // < /tag -> </tag>
1495
+
1496
+ // Trim spaces around equals signs in attributes (run before value trim)
1497
+ // This handles `attr = "value"` -> `attr="value"`
1498
+ html = html.replace(/ = /g, "=");
1499
+ // Consider safer alternatives if needed (e.g., / = "/g, '="')
1500
+
1501
+ // Trim whitespace inside attribute values
1502
+ html = html.replace(
1503
+ /([a-zA-Z0-9_-]+)=(['"])(.*?)\2/g,
1504
+ (match, attr_name, quote, value) => {
1505
+ // value.trim() handles both leading/trailing spaces
1506
+ // and cases where the value is only whitespace (becomes empty string)
1507
+ const trimmed_value = value.trim();
1508
+ return `${attr_name}=${quote}${trimmed_value}${quote}`
1509
+ }
1510
+ );
1511
+
1512
+ // Final trim for the whole string
1513
+ html = html.trim();
1514
+
1515
+ return html
1516
+ };
1517
+
1518
+ /**
1519
+ * @type {boolean}
1520
+ */
1521
+ let strict;
1522
+
1523
+ /**
1524
+ * @type {string[]}
1525
+ */
1526
+ let trim;
1527
+
1528
+ /**
1529
+ * @type {{ line: Record<string,string>[] }}
1530
+ */
1531
+ const convert = {
1532
+ line: []
1533
+ };
1534
+
1535
+ /**
1536
+ * Isolate tags, content, and comments.
1537
+ *
1538
+ * @param {string} html The HTML string to evaluate.
1539
+ * @returns {string}
1540
+ * @example <div>Hello World!</div> =>
1541
+ * [#-# : 0 : <div> : #-#]
1542
+ * Hello World!
1543
+ * [#-# : 1 : </div> : #-#]
1544
+ */
1545
+ const enqueue = (html) => {
1546
+ convert.line = [];
1547
+ let i = -1;
1548
+ /* Regex to find tags OR text content between tags. */
1549
+ const regex = /(<[^>]+>)|([^<]+)/g;
1550
+
1551
+ html = html.replace(regex, (match, c1, c2) => {
1552
+ if (c1) {
1553
+ convert.line.push({ type: "tag", value: match });
1554
+ } else if (c2 && c2.trim().length > 0) {
1555
+ /* It's text content (and not just whitespace). */
1556
+ convert.line.push({ type: "text", value: match });
1557
+ }
1558
+
1559
+ i++;
1560
+ return `\n[#-# : ${i} : ${match} : #-#]\n`
1561
+ });
1562
+
1563
+ return html
1564
+ };
1565
+
1566
+ /**
1567
+ * Preprocess the HTML.
1568
+ *
1569
+ * @param {string} html The HTML string to preprocess.
1570
+ * @returns {string}
1571
+ */
1572
+ const preprocess = (html) => {
1573
+ html = closify(html, false);
1574
+
1575
+ if (trim.length > 0) html = trimify(html, trim);
1576
+
1577
+ html = minify(html, false);
1578
+ html = enqueue(html);
1579
+
1580
+ return html
1581
+ };
1582
+
1583
+ /**
1584
+ *
1585
+ * @param {string} html The HTML string to process.
1586
+ * @param {import('htmlfy').Config} config
1587
+ * @returns {string}
1588
+ */
1589
+ const process = (html, config) => {
1590
+ const step = " ".repeat(config.tab_size);
1591
+ const tag_wrap = config.tag_wrap;
1592
+ const content_wrap = config.content_wrap;
1593
+ const ignore_with = config.ignore_with;
1594
+ const placeholder_template = `-${ignore_with}`;
1595
+
1596
+ /* Track current number of indentations needed. */
1597
+ let indents = '';
1598
+
1599
+ /** @type string[] */
1600
+ const output_lines = [];
1601
+ const tag_regex = /<[A-Za-z]+\b[^>]*(?:.|\n)*?\/?>/g; /* Is opening tag or void element. */
1602
+ const attribute_regex = /\s{1}[A-Za-z-]+(?:=".*?")?/g; /* Matches all tag/element attributes. */
1603
+
1604
+ /* Process lines and indent. */
1605
+ convert.line.forEach((source, index) => {
1606
+ let current_line_value = source.value;
1607
+
1608
+ const is_ignored_content =
1609
+ current_line_value.startsWith(placeholder_template + "lt--") ||
1610
+ current_line_value.startsWith(placeholder_template + "gt--") ||
1611
+ current_line_value.startsWith(placeholder_template + "nl--") ||
1612
+ current_line_value.startsWith(placeholder_template + "cr--") ||
1613
+ current_line_value.startsWith(placeholder_template + "ws--") ||
1614
+ current_line_value.startsWith(placeholder_template + "tab--");
1615
+
1616
+ let subtrahend = 0;
1617
+ const prev_line_data = convert.line[index - 1];
1618
+ const prev_line_value = prev_line_data?.value ?? ""; // Use empty string if no prev line
1619
+
1620
+ /**
1621
+ * Arbitratry character, to keep track of the string's length.
1622
+ */
1623
+ indents += '0';
1624
+
1625
+ if (index === 0) subtrahend++;
1626
+ /* We're processing a closing tag. */
1627
+ if (current_line_value.trim().startsWith("</")) subtrahend++;
1628
+ /* prevLine is a doctype declaration. */
1629
+ if (prev_line_value.trim().startsWith("<!doctype")) subtrahend++;
1630
+ /* prevLine is a comment. */
1631
+ if (prev_line_value.trim().startsWith("<!--")) subtrahend++;
1632
+ /* prevLine is a self-closing tag. */
1633
+ if (prev_line_value.trim().endsWith("/>")) subtrahend++;
1634
+ /* prevLine is a closing tag. */
1635
+ if (prev_line_value.trim().startsWith("</")) subtrahend++;
1636
+ /* prevLine is text. */
1637
+ if (prev_line_data?.type === "text") subtrahend++;
1638
+
1639
+ /* Determine offset for line indentation. */
1640
+ const offset = Math.max(0, indents.length - subtrahend);
1641
+ /* Correct indent level for *this* line's content */
1642
+ const current_indent_level = offset; // Store the level for this line
1643
+
1644
+ indents = indents.substring(0, current_indent_level); // Adjust for *next* round
1645
+ const padding = step.repeat(current_indent_level);
1646
+
1647
+ if (is_ignored_content) {
1648
+ /* Stop processing this line, as it's set to be ignored. */
1649
+ output_lines.push(current_line_value);
1650
+ } else {
1651
+ /* Remove comment. */
1652
+ if (strict && current_line_value.trim().startsWith("<!--"))
1653
+ return
1654
+
1655
+ let result = current_line_value;
1656
+
1657
+ if (
1658
+ source.type === 'text' &&
1659
+ content_wrap > 0 &&
1660
+ result.length >= content_wrap
1661
+ ) {
1662
+ result = wordWrap(result, content_wrap, padding);
1663
+ }
1664
+ /* Wrap the attributes of open tags and void elements. */
1665
+ else if (
1666
+ tag_wrap > 0 &&
1667
+ result.length > tag_wrap &&
1668
+ tag_regex.test(result)
1669
+ ) {
1670
+ tag_regex.lastIndex = 0; // Reset stateful regex
1671
+ attribute_regex.lastIndex = 0; // Reset stateful regex
1672
+
1673
+ const tag_parts = result.split(attribute_regex).filter(Boolean);
1674
+
1675
+ if (tag_parts.length >= 2) {
1676
+ const attributes = result.matchAll(attribute_regex);
1677
+ const inner_padding = padding + step;
1678
+ let wrapped_tag = padding + tag_parts[0] + "\n";
1679
+
1680
+ for (const a of attributes) {
1681
+ const attribute_string = a[0].trim();
1682
+ wrapped_tag += inner_padding + attribute_string + "\n";
1683
+ }
1684
+
1685
+ const tag_name_match = tag_parts[0].match(/<([A-Za-z_:-]+)/);
1686
+ const tag_name = tag_name_match ? tag_name_match[1] : "";
1687
+ const is_void = VOID_ELEMENTS.includes(tag_name);
1688
+ const closing_part = tag_parts[1].trim();
1689
+ const closing_padding = padding + (strict && is_void ? " " : ""); // Add space if void/strict
1690
+
1691
+ wrapped_tag += closing_padding + closing_part;
1692
+
1693
+ result = wrapped_tag; // Assign the fully wrapped string
1694
+ } else {
1695
+ result = padding + result;
1696
+ }
1697
+ } else {
1698
+ /* Apply simple indentation (if no wrapping occurred) */
1699
+ result = padding + result;
1700
+ }
1701
+
1702
+ /* Add the processed line (or lines if wordWrap creates them) to the output */
1703
+ output_lines.push(result);
1704
+ }
1705
+ });
1706
+
1707
+ /* Join all processed lines into the final HTML string */
1708
+ let final_html = output_lines.join("\n");
1709
+
1710
+ /* Preserve wrapped attributes. */
1711
+ if (tag_wrap > 0) final_html = protectAttributes(final_html);
1712
+
1713
+ /* Extra preserve wrapped content. */
1714
+ if (content_wrap > 0 && /\n[ ]*[^\n]*__!i-£___£%__[^\n]*\n/.test(final_html))
1715
+ final_html = finalProtectContent(final_html);
1716
+
1717
+ /* Remove line returns, tabs, and consecutive spaces within html elements or their content. */
1718
+ final_html = final_html.replace(
1719
+ /<(?<Element>.+).*>[^<]*?[^><\/\s][^<]*?<\/{1}\k<Element>|<script[^>]*>\s+<\/script>|<(\w+)>\s+<\/(\w+)|<(?:([\w:\._-]+)|([\w:\._-]+)[^>]*[^\/])>\s+<\/([\w:\._-]+)>/g,
1720
+ match => match.replace(/\n|\t|\s{2,}/g, '')
1721
+ );
1722
+
1723
+ /* Revert wrapped content. */
1724
+ if (content_wrap > 0) final_html = unprotectContent(final_html);
1725
+
1726
+ /* Revert wrapped attributes. */
1727
+ if (tag_wrap > 0) final_html = unprotectAttributes(final_html);
1728
+
1729
+ /* Remove self-closing nature of void elements. */
1730
+ if (strict) final_html = final_html.replace(/\s\/>|\/>/g, '>');
1731
+
1732
+ /* Trim leading and/or trailing line returns. */
1733
+ if (final_html.startsWith("\n")) final_html = final_html.substring(1);
1734
+ if (final_html.endsWith("\n")) final_html = final_html.substring(0, final_html.length - 1);
1735
+
1736
+ return final_html
1737
+ };
1738
+
1739
+ /**
1740
+ * Format HTML with line returns and indentations.
1741
+ *
1742
+ * @param {string} html The HTML string to prettify.
1743
+ * @param {import('htmlfy').UserConfig} [config] A user configuration object.
1744
+ * @returns {string} A well-formed HTML string.
1745
+ */
1746
+ const prettify = (html, config) => {
1747
+ /* Return content as-is if it does not contain any HTML elements. */
1748
+ if (!isHtml(html)) return html
1749
+
1750
+ const validated_config = config ? validateConfig(config) : CONFIG;
1751
+ strict = validated_config.strict;
1752
+
1753
+ const ignore = validated_config.ignore.length > 0;
1754
+ trim = validated_config.trim;
1755
+
1756
+ /* Preserve ignored elements. */
1757
+ if (ignore) html = setIgnoreElement(html, validated_config);
1758
+
1759
+ /* Preserve html text within attribute values. */
1760
+ html = setIgnoreAttribute(html);
1761
+
1762
+ html = preprocess(html);
1763
+ html = process(html, validated_config);
1764
+
1765
+ /* Revert html text within attribute values. */
1766
+ html = unsetIgnoreAttribute(html);
1767
+
1768
+ /* Revert ignored elements. */
1769
+ if (ignore) html = unsetIgnoreElement(html, validated_config);
1770
+
1771
+ return html
1772
+ };
1773
+
1774
+ /**
1775
+ * Render attribute on the given element
1776
+ * @param element - targeted to render attribute
1777
+ * @param name - of the attribute
1778
+ * @param value - of the attribute
1779
+ */
1780
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1781
+ const renderAttribute = (element, name, value) => {
1782
+ if ([null, undefined, '', false].includes(value) || ['innerHTML', 'style', ''].includes(name)) {
1783
+ return;
1784
+ }
1785
+ element.setAttribute(name, !['object', 'function'].includes(typeof value) ? value : `⚠️ Property must be set through a script or a framework-specific syntax.`);
1786
+ };
1787
+ /**
1788
+ * Render new element in parent element
1789
+ * @param parentNode - HTML element
1790
+ * @param tagName - of the new element
1791
+ * @param attributes - of the new element
1792
+ * @param children - of the new element
1793
+ * @param text - of the new element
1794
+ */
1795
+ const renderElement = (parentNode, tagName, attributes, children, text) => {
1796
+ // render HTML
1797
+ if (tagName && typeof tagName === 'string') {
1798
+ const element = document.createElement(tagName);
1799
+ Object.keys(attributes || {}).forEach(attr => {
1800
+ renderAttribute(element, attr, attributes[attr]);
1801
+ });
1802
+ children?.forEach(child => {
1803
+ renderElement(element, child.$tag$, child.$attrs$, child.$children$, child.$text$);
1804
+ });
1805
+ if (attributes?.innerHTML)
1806
+ element.innerHTML = attributes.innerHTML;
1807
+ parentNode.appendChild(element);
1808
+ }
1809
+ // render text
1810
+ if (text) {
1811
+ parentNode.innerHTML = text;
1812
+ }
1813
+ };
1814
+ /**
1815
+ * Filter default argument on component argument to prevent them to be rendered
1816
+ * @param args - all possible args with custom values
1817
+ * @param defaultValues - component default args values
1818
+ * @param slots - slots
1819
+ * @returns filtres args
1820
+ * @example
1821
+ * ```ts
1822
+ * import { filterArgs } from '@mgdis/core-ui-helpers/dist/storybook';
1823
+ * const Template = (args: MgBadgeType): HTMLElement => <mg-badge {...filterArgs(args, { variant: 'info' }, ['actions'])}></mg-badge>;
1824
+ * ```
1825
+ */
1826
+ const filterArgs = (args, defaultValues, slots = []) => {
1827
+ const filteredArgs = {};
1828
+ if (typeof args !== 'object') {
1829
+ throw new Error("filterArgs - args isn't an object.");
1830
+ }
1831
+ for (const k in args) {
1832
+ if (!slots.includes(k)) {
1833
+ const arg = args[k];
1834
+ // Change camelCase k to kebab-case
1835
+ const key = k.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
1836
+ if (!defaultValues || !Object.keys(defaultValues).includes(k) || defaultValues[k] !== arg) {
1837
+ filteredArgs[key] = arg;
1838
+ }
1839
+ }
1840
+ }
1841
+ return filteredArgs;
1842
+ };
1843
+ /**
1844
+ * Storybook stencil wrapper. Used to target element with `storybook-root` id and render virtual DOM inside.
1845
+ * @param storyFn - storybook render function
1846
+ * @param context - storybook context
1847
+ * @returns rendered element
1848
+ * @example
1849
+ * ```ts
1850
+ * // .storybook/preview.ts
1851
+ * import { stencilWrapper } from '@mgdis/core-ui-helpers/dist/storybook';
1852
+ * export const decorators: Preview['decorators'] = [stencilWrapper];
1853
+ * ```
1854
+ */
1855
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1856
+ const stencilWrapper = (storyFn, context) => {
1857
+ const host = document.getElementById('storybook-root');
1858
+ if (host === null)
1859
+ return;
1860
+ // update local switcher based on context variable
1861
+ document.querySelector('[lang]')?.setAttribute('lang', context.globals?.locale || 'en');
1862
+ renderVdom({
1863
+ $cmpMeta$: {
1864
+ $flags$: 0,
1865
+ $tagName$: host.tagName,
1866
+ },
1867
+ $hostElement$: host,
1868
+ }, storyFn(context));
1869
+ return host.children[host.children.length - 1];
1870
+ };
1871
+ /**
1872
+ * Get story HTML from virtual DOM.
1873
+ * Mainly used to render, component code exemple in stories.
1874
+ * @param vitualNode - story virtual DOM
1875
+ * @returns stringified rendered HTML
1876
+ * @example
1877
+ * ```ts
1878
+ * // .storybook/preview.ts
1879
+ * import { getStoryHTML } from '@mgdis/core-ui-helpers/dist/storybook';
1880
+ *
1881
+ * export const parameters: Preview['parameters'] = {
1882
+ * docs: {
1883
+ * source: {
1884
+ * transform: (_, ctx) => getStoryHTML(ctx.originalStoryFn(ctx.args)),
1885
+ * }
1886
+ * },
1887
+ * };
1888
+ * ```
1889
+ */
1890
+ const getStoryHTML = ({ $tag$, $attrs$, $children$, $text$ }) => {
1891
+ const host = document.createElement('div');
1892
+ renderElement(host, $tag$, $attrs$, $children$, $text$);
1893
+ return prettify(host.innerHTML, {
1894
+ tag_wrap: 40,
1895
+ content_wrap: 120,
1896
+ }).replace(/="true"/g, '');
1897
+ };
1898
+ /**
1899
+ * Retrieve Component Storybook URL from file path
1900
+ * @param storybookBaseUrl - Storybook Base URL
1901
+ * @param filePath - Component file path
1902
+ * @returns Component Storybook URL
1903
+ */
1904
+ const getStorybookUrl = (storybookBaseUrl, filePath) => {
1905
+ if (!filePath) {
1906
+ return;
1907
+ }
1908
+ const split = filePath.split('/');
1909
+ return `${storybookBaseUrl}${split.slice(2, split.length - 1).join('-')}--docs`;
1910
+ };
1911
+ class StorybookPreview {
1912
+ /**
1913
+ * JsonDocs
1914
+ */
1915
+ jsonDoc;
1916
+ constructor(jsonDoc) {
1917
+ this.jsonDoc = jsonDoc;
1918
+ }
1919
+ /**
1920
+ * Get component data from the jsonDoc
1921
+ * @param tagName - tag name we want to get the data from
1922
+ * @returns component data
1923
+ */
1924
+ #getComponentData = (tagName) => {
1925
+ return this.jsonDoc.components.find(component => component.tag === tagName);
1926
+ };
1927
+ /**
1928
+ * Get the control for the given prop
1929
+ * Based on https://storybook.js.org/docs/api/arg-types#controltype
1930
+ * @param prop - prop to get control for
1931
+ * @returns control type and options if applicable
1932
+ */
1933
+ #getPropControl = (prop) => {
1934
+ // Get types
1935
+ const types = prop.type
1936
+ .replace(/"([^"]+)"/g, '$1') // Remove quotes
1937
+ .replace(/\s/g, '') // Remove all whitespace for simplicity
1938
+ .replace(/\(.*?\)/g, match => match.replace(/\|/g, ' OR ')) // Replace '|' inside parentheses
1939
+ .split('|')
1940
+ .map(type => type.trim().replace(/ OR /g, '|')); // Revert ' OR ' back to '|'
1941
+ // Return control and options
1942
+ if (prop.type === 'string') {
1943
+ return { control: { type: 'text' } };
1944
+ }
1945
+ else if (prop.type === 'number') {
1946
+ return { control: { type: 'number' } };
1947
+ }
1948
+ else if (prop.type === 'boolean') {
1949
+ return { control: { type: 'boolean' } };
1950
+ }
1951
+ else if (prop.type.startsWith('{') && prop.type.endsWith('}')) {
1952
+ return { control: { type: 'object' } };
1953
+ }
1954
+ else if (types.length > 1) {
1955
+ // Manage case when multiple types are possible
1956
+ if (types.includes('string')) {
1957
+ return { control: { type: 'text' } };
1958
+ }
1959
+ else if (types.every(type => type?.includes('[]'))) {
1960
+ return { control: { type: 'object' } };
1961
+ }
1962
+ else {
1963
+ // Add the posibility to set undefined
1964
+ types.unshift(undefined);
1965
+ return { control: { type: 'select' }, options: types };
1966
+ }
1967
+ }
1968
+ else
1969
+ return { control: { type: 'object' } };
1970
+ };
1971
+ /**
1972
+ * Extract component arg types from the component data
1973
+ * @param tagName - tag name we want to extract the arg types from
1974
+ * @returns component arg types
1975
+ */
1976
+ extractArgTypes = (tagName) => {
1977
+ const componentData = this.#getComponentData(tagName);
1978
+ // Extract props arg types
1979
+ const componentPropsArgTypes = componentData?.props.reduce((acc, prop) => {
1980
+ // Get Controls
1981
+ const { control, options } = this.#getPropControl(prop);
1982
+ // Set Component ArgTypes
1983
+ return {
1984
+ ...acc,
1985
+ [prop.name]: {
1986
+ name: prop.attr || prop.name,
1987
+ description: prop.docs,
1988
+ type: { required: prop.required },
1989
+ table: {
1990
+ category: 'props',
1991
+ type: { summary: prop.type },
1992
+ defaultValue: { summary: prop.default },
1993
+ },
1994
+ control,
1995
+ options,
1996
+ },
1997
+ };
1998
+ }, {});
1999
+ // Extract events arg types
2000
+ const componentEventsArgTypes = componentData?.events.reduce((acc, event) => ({
2001
+ ...acc,
2002
+ [event.event]: {
2003
+ name: event.event,
2004
+ description: event.docs,
2005
+ table: {
2006
+ category: 'events',
2007
+ type: { summary: event.detail },
2008
+ },
2009
+ },
2010
+ }), {});
2011
+ // Extracts Methods arg types
2012
+ const componentMethodsArgTypes = componentData?.methods.reduce((acc, method) => ({
2013
+ ...acc,
2014
+ [method.name]: {
2015
+ name: method.name,
2016
+ description: method.docs,
2017
+ table: {
2018
+ category: 'methods',
2019
+ type: { summary: method.signature },
2020
+ },
2021
+ },
2022
+ }), {});
2023
+ // Extracts Slots arg types
2024
+ const componentSlotsArgTypes = componentData?.slots.reduce((acc, slot) => ({
2025
+ ...acc,
2026
+ [slot.name]: {
2027
+ name: slot.name !== '' ? slot.name : 'default', // default slot are unnamed
2028
+ description: slot.docs,
2029
+ table: {
2030
+ category: 'slots',
2031
+ type: { summary: undefined },
2032
+ },
2033
+ },
2034
+ }), {});
2035
+ // Extracts CSS Properties arg types
2036
+ const componentCSSPropArgTypes = componentData?.styles.reduce((acc, style) => ({
2037
+ ...acc,
2038
+ [style.name]: {
2039
+ name: style.name,
2040
+ description: style.docs,
2041
+ table: {
2042
+ category: 'custom properties',
2043
+ type: { summary: undefined },
2044
+ },
2045
+ },
2046
+ }), {});
2047
+ // Extract component dependencies
2048
+ const componentDependencies = componentData?.dependencies.reduce((acc, dependency) => {
2049
+ const dependencyData = this.#getComponentData(dependency);
2050
+ if (!dependencyData)
2051
+ return acc; // Prevents from adding internal dependency
2052
+ return {
2053
+ ...acc,
2054
+ [dependency]: {
2055
+ name: dependency,
2056
+ description: `<a href="./?path=/docs/${getStorybookUrl('', dependencyData?.filePath)}">View Component Documentation</a>`,
2057
+ table: {
2058
+ category: 'depends on',
2059
+ type: { summary: undefined },
2060
+ },
2061
+ },
2062
+ };
2063
+ }, {});
2064
+ // Extract dependents components
2065
+ const componentDependents = componentData?.dependents.reduce((acc, dependent) => {
2066
+ const dependentData = this.#getComponentData(dependent);
2067
+ if (!dependentData)
2068
+ return acc; // Prevents from adding internal dependent
2069
+ return {
2070
+ ...acc,
2071
+ [dependent]: {
2072
+ name: dependent,
2073
+ description: `<a href="./?path=/docs/${getStorybookUrl('', dependentData?.filePath)}">View Component Documentation</a>`,
2074
+ table: {
2075
+ category: 'used by',
2076
+ type: { summary: undefined },
2077
+ },
2078
+ },
2079
+ };
2080
+ }, {});
2081
+ return {
2082
+ ...componentPropsArgTypes,
2083
+ ...componentEventsArgTypes,
2084
+ ...componentMethodsArgTypes,
2085
+ ...componentSlotsArgTypes,
2086
+ ...componentCSSPropArgTypes,
2087
+ ...componentDependencies,
2088
+ ...componentDependents,
2089
+ };
2090
+ };
2091
+ /**
2092
+ * Extract component description from the component data
2093
+ * @param tagName - tag name we want to extract the description from
2094
+ * @returns component description
2095
+ */
2096
+ extractComponentDescription = (tagName) => {
2097
+ const componentData = this.#getComponentData(tagName);
2098
+ return componentData?.readme || componentData?.docs;
2099
+ };
2100
+ }
2101
+
2102
+ export { StorybookPreview, filterArgs, getStoryHTML, getStorybookUrl, stencilWrapper };
2103
+ //# sourceMappingURL=index.js.map