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