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