@bquery/bquery 1.4.0 → 1.6.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 (164) hide show
  1. package/README.md +586 -527
  2. package/dist/component/component.d.ts +13 -5
  3. package/dist/component/component.d.ts.map +1 -1
  4. package/dist/component/html.d.ts +40 -3
  5. package/dist/component/html.d.ts.map +1 -1
  6. package/dist/component/index.d.ts +4 -2
  7. package/dist/component/index.d.ts.map +1 -1
  8. package/dist/component/library.d.ts +34 -0
  9. package/dist/component/library.d.ts.map +1 -0
  10. package/dist/component/types.d.ts +132 -13
  11. package/dist/component/types.d.ts.map +1 -1
  12. package/dist/component-BEQgt5hl.js +600 -0
  13. package/dist/component-BEQgt5hl.js.map +1 -0
  14. package/dist/component.es.mjs +7 -184
  15. package/dist/config-DRmZZno3.js +40 -0
  16. package/dist/config-DRmZZno3.js.map +1 -0
  17. package/dist/core-BGQJVw0-.js +35 -0
  18. package/dist/core-BGQJVw0-.js.map +1 -0
  19. package/dist/core-CCEabVHl.js +648 -0
  20. package/dist/core-CCEabVHl.js.map +1 -0
  21. package/dist/core.es.mjs +45 -1261
  22. package/dist/effect-AFRW_Plg.js +84 -0
  23. package/dist/effect-AFRW_Plg.js.map +1 -0
  24. package/dist/full.d.ts +8 -8
  25. package/dist/full.d.ts.map +1 -1
  26. package/dist/full.es.mjs +101 -91
  27. package/dist/full.iife.js +173 -3
  28. package/dist/full.iife.js.map +1 -1
  29. package/dist/full.umd.js +173 -3
  30. package/dist/full.umd.js.map +1 -1
  31. package/dist/index.es.mjs +147 -139
  32. package/dist/motion/transition.d.ts +1 -1
  33. package/dist/motion/transition.d.ts.map +1 -1
  34. package/dist/motion/types.d.ts +11 -1
  35. package/dist/motion/types.d.ts.map +1 -1
  36. package/dist/motion-D9TcHxOF.js +415 -0
  37. package/dist/motion-D9TcHxOF.js.map +1 -0
  38. package/dist/motion.es.mjs +25 -361
  39. package/dist/object-qGpWr6-J.js +38 -0
  40. package/dist/object-qGpWr6-J.js.map +1 -0
  41. package/dist/platform/announcer.d.ts +59 -0
  42. package/dist/platform/announcer.d.ts.map +1 -0
  43. package/dist/platform/config.d.ts +92 -0
  44. package/dist/platform/config.d.ts.map +1 -0
  45. package/dist/platform/cookies.d.ts +45 -0
  46. package/dist/platform/cookies.d.ts.map +1 -0
  47. package/dist/platform/index.d.ts +8 -0
  48. package/dist/platform/index.d.ts.map +1 -1
  49. package/dist/platform/meta.d.ts +62 -0
  50. package/dist/platform/meta.d.ts.map +1 -0
  51. package/dist/platform-Dr9b6fsq.js +362 -0
  52. package/dist/platform-Dr9b6fsq.js.map +1 -0
  53. package/dist/platform.es.mjs +11 -248
  54. package/dist/reactive/async-data.d.ts +114 -0
  55. package/dist/reactive/async-data.d.ts.map +1 -0
  56. package/dist/reactive/index.d.ts +2 -2
  57. package/dist/reactive/index.d.ts.map +1 -1
  58. package/dist/reactive/signal.d.ts +2 -0
  59. package/dist/reactive/signal.d.ts.map +1 -1
  60. package/dist/reactive-DSkct0dO.js +254 -0
  61. package/dist/reactive-DSkct0dO.js.map +1 -0
  62. package/dist/reactive.es.mjs +18 -32
  63. package/dist/router-CbDhl8rS.js +188 -0
  64. package/dist/router-CbDhl8rS.js.map +1 -0
  65. package/dist/router.es.mjs +11 -200
  66. package/dist/sanitize-Bs2dkMby.js +313 -0
  67. package/dist/sanitize-Bs2dkMby.js.map +1 -0
  68. package/dist/security/constants.d.ts.map +1 -1
  69. package/dist/security/index.d.ts +4 -2
  70. package/dist/security/index.d.ts.map +1 -1
  71. package/dist/security/sanitize.d.ts +4 -1
  72. package/dist/security/sanitize.d.ts.map +1 -1
  73. package/dist/security/trusted-html.d.ts +53 -0
  74. package/dist/security/trusted-html.d.ts.map +1 -0
  75. package/dist/security.es.mjs +11 -56
  76. package/dist/store/define-store.d.ts +1 -1
  77. package/dist/store/define-store.d.ts.map +1 -1
  78. package/dist/store/mapping.d.ts +1 -1
  79. package/dist/store/mapping.d.ts.map +1 -1
  80. package/dist/store/persisted.d.ts +1 -1
  81. package/dist/store/persisted.d.ts.map +1 -1
  82. package/dist/store/types.d.ts +2 -2
  83. package/dist/store/types.d.ts.map +1 -1
  84. package/dist/store/watch.d.ts +1 -1
  85. package/dist/store/watch.d.ts.map +1 -1
  86. package/dist/store-BwDvI45q.js +263 -0
  87. package/dist/store-BwDvI45q.js.map +1 -0
  88. package/dist/store.es.mjs +12 -25
  89. package/dist/storybook/index.d.ts +37 -0
  90. package/dist/storybook/index.d.ts.map +1 -0
  91. package/dist/storybook.es.mjs +151 -0
  92. package/dist/storybook.es.mjs.map +1 -0
  93. package/dist/untrack-B0rVscTc.js +7 -0
  94. package/dist/untrack-B0rVscTc.js.map +1 -0
  95. package/dist/view-C70lA3vf.js +397 -0
  96. package/dist/view-C70lA3vf.js.map +1 -0
  97. package/dist/view.es.mjs +11 -430
  98. package/package.json +141 -132
  99. package/src/component/component.ts +524 -289
  100. package/src/component/html.ts +153 -53
  101. package/src/component/index.ts +50 -40
  102. package/src/component/library.ts +518 -0
  103. package/src/component/types.ts +256 -85
  104. package/src/core/collection.ts +628 -628
  105. package/src/core/element.ts +774 -774
  106. package/src/core/index.ts +48 -48
  107. package/src/core/utils/function.ts +151 -151
  108. package/src/full.ts +229 -187
  109. package/src/motion/animate.ts +113 -113
  110. package/src/motion/flip.ts +176 -176
  111. package/src/motion/scroll.ts +57 -57
  112. package/src/motion/spring.ts +150 -150
  113. package/src/motion/timeline.ts +246 -246
  114. package/src/motion/transition.ts +97 -51
  115. package/src/motion/types.ts +11 -1
  116. package/src/platform/announcer.ts +208 -0
  117. package/src/platform/config.ts +163 -0
  118. package/src/platform/cookies.ts +165 -0
  119. package/src/platform/index.ts +21 -0
  120. package/src/platform/meta.ts +168 -0
  121. package/src/platform/storage.ts +215 -215
  122. package/src/reactive/async-data.ts +486 -0
  123. package/src/reactive/core.ts +114 -114
  124. package/src/reactive/effect.ts +54 -54
  125. package/src/reactive/index.ts +15 -1
  126. package/src/reactive/internals.ts +122 -122
  127. package/src/reactive/signal.ts +9 -0
  128. package/src/security/constants.ts +3 -1
  129. package/src/security/index.ts +17 -10
  130. package/src/security/sanitize-core.ts +364 -364
  131. package/src/security/sanitize.ts +70 -66
  132. package/src/security/trusted-html.ts +71 -0
  133. package/src/store/define-store.ts +49 -48
  134. package/src/store/mapping.ts +74 -73
  135. package/src/store/persisted.ts +62 -61
  136. package/src/store/types.ts +92 -94
  137. package/src/store/watch.ts +53 -52
  138. package/src/storybook/index.ts +479 -0
  139. package/src/view/evaluate.ts +290 -290
  140. package/dist/batch-x7b2eZST.js +0 -13
  141. package/dist/batch-x7b2eZST.js.map +0 -1
  142. package/dist/component.es.mjs.map +0 -1
  143. package/dist/core-BhpuvPhy.js +0 -170
  144. package/dist/core-BhpuvPhy.js.map +0 -1
  145. package/dist/core.es.mjs.map +0 -1
  146. package/dist/full.es.mjs.map +0 -1
  147. package/dist/index.es.mjs.map +0 -1
  148. package/dist/motion.es.mjs.map +0 -1
  149. package/dist/persisted-DHoi3uEs.js +0 -278
  150. package/dist/persisted-DHoi3uEs.js.map +0 -1
  151. package/dist/platform.es.mjs.map +0 -1
  152. package/dist/reactive.es.mjs.map +0 -1
  153. package/dist/router.es.mjs.map +0 -1
  154. package/dist/sanitize-Cxvxa-DX.js +0 -283
  155. package/dist/sanitize-Cxvxa-DX.js.map +0 -1
  156. package/dist/security.es.mjs.map +0 -1
  157. package/dist/store.es.mjs.map +0 -1
  158. package/dist/type-guards-BdKlYYlS.js +0 -32
  159. package/dist/type-guards-BdKlYYlS.js.map +0 -1
  160. package/dist/untrack-DNnnqdlR.js +0 -6
  161. package/dist/untrack-DNnnqdlR.js.map +0 -1
  162. package/dist/view.es.mjs.map +0 -1
  163. package/dist/watch-DXXv3iAI.js +0 -58
  164. package/dist/watch-DXXv3iAI.js.map +0 -1
@@ -0,0 +1,479 @@
1
+ /**
2
+ * Storybook template helpers for authoring bQuery component stories.
3
+ *
4
+ * `storyHtml` mirrors bQuery's string-based `html` tag while adding support for
5
+ * Storybook-friendly boolean attribute shorthand (`?disabled=${true}`).
6
+ *
7
+ * @module bquery/storybook
8
+ */
9
+
10
+ import { sanitizeHtml } from '../security/sanitize';
11
+
12
+ type StoryValue = string | number | boolean | null | undefined | StoryValue[] | (() => StoryValue);
13
+
14
+ /**
15
+ * Marks template interpolation boundaries while inferring sanitizer allowlists.
16
+ * Uses the null character because authored HTML/template strings should not
17
+ * contain it, making it a safe internal sentinel during parsing.
18
+ */
19
+ const INTERPOLATION_BOUNDARY_MARKER = '\u0000';
20
+
21
+ const isWhitespace = (value: string): boolean => {
22
+ return value === ' ' || value === '\t' || value === '\n' || value === '\r' || value === '\f';
23
+ };
24
+
25
+ /**
26
+ * Detects interpolation boundaries embedded into joined template string fragments.
27
+ */
28
+ const isInterpolationBoundaryMarker = (value: string): boolean => value === INTERPOLATION_BOUNDARY_MARKER;
29
+
30
+ const isAttributeSeparator = (value: string): boolean => {
31
+ return isWhitespace(value) || isInterpolationBoundaryMarker(value);
32
+ };
33
+
34
+ const isAsciiLetter = (value: string): boolean => {
35
+ const code = value.charCodeAt(0);
36
+
37
+ return (code >= 65 && code <= 90) || (code >= 97 && code <= 122);
38
+ };
39
+
40
+ const isAttributeNameStart = (value: string): boolean => isAsciiLetter(value);
41
+
42
+ const isAttributeNameChar = (value: string): boolean => {
43
+ const code = value.charCodeAt(0);
44
+
45
+ return (
46
+ isAsciiLetter(value) ||
47
+ (code >= 48 && code <= 57) ||
48
+ value === ':' ||
49
+ value === '.' ||
50
+ value === '_' ||
51
+ value === '-'
52
+ );
53
+ };
54
+
55
+ const isQuoteChar = (value: string): boolean => value === '"' || value === "'";
56
+
57
+ const isTagNameChar = (value: string): boolean => {
58
+ const code = value.charCodeAt(0);
59
+
60
+ return (
61
+ isAsciiLetter(value) ||
62
+ (code >= 48 && code <= 57) ||
63
+ value === '.' ||
64
+ value === '_' ||
65
+ value === '-'
66
+ );
67
+ };
68
+
69
+ const hasLineBreak = (value: string): boolean => {
70
+ for (let index = 0; index < value.length; index += 1) {
71
+ if (value[index] === '\n' || value[index] === '\r') {
72
+ return true;
73
+ }
74
+ }
75
+
76
+ return false;
77
+ };
78
+
79
+ const getTagNameEnd = (fragment: string): number => {
80
+ let index = 0;
81
+
82
+ while (
83
+ index < fragment.length &&
84
+ !isAttributeSeparator(fragment[index]) &&
85
+ fragment[index] !== '/' &&
86
+ fragment[index] !== '>'
87
+ ) {
88
+ index += 1;
89
+ }
90
+
91
+ return index;
92
+ };
93
+
94
+ const isCustomElementTagName = (tagName: string): boolean => {
95
+ if (!tagName.includes('-') || !isAsciiLetter(tagName[0])) {
96
+ return false;
97
+ }
98
+
99
+ const last = tagName[tagName.length - 1];
100
+ const code = last.charCodeAt(0);
101
+
102
+ return isAsciiLetter(last) || (code >= 48 && code <= 57) || last === '.' || last === '_';
103
+ };
104
+
105
+ const isAutoAllowedStoryAttribute = (attributeName: string): boolean => {
106
+ return attributeName !== 'style' && !attributeName.startsWith('on');
107
+ };
108
+
109
+ const findBooleanAttributeSuffix = (
110
+ part: string
111
+ ): { attribute: string; basePart: string; spacing: string } | null => {
112
+ let index = part.length - 1;
113
+
114
+ while (index >= 0 && isWhitespace(part[index])) {
115
+ index -= 1;
116
+ }
117
+
118
+ if (index < 0 || part[index] !== '=') {
119
+ return null;
120
+ }
121
+
122
+ index -= 1;
123
+
124
+ while (index >= 0 && isWhitespace(part[index])) {
125
+ index -= 1;
126
+ }
127
+
128
+ const attributeEnd = index;
129
+
130
+ while (
131
+ index >= 0 &&
132
+ !isWhitespace(part[index]) &&
133
+ part[index] !== '?' &&
134
+ part[index] !== '=' &&
135
+ part[index] !== '/' &&
136
+ part[index] !== '>'
137
+ ) {
138
+ index -= 1;
139
+ }
140
+
141
+ const attributeStart = index + 1;
142
+
143
+ if (attributeStart > attributeEnd || part[index] !== '?') {
144
+ return null;
145
+ }
146
+
147
+ const questionMarkIndex = index;
148
+ let spacingStart = questionMarkIndex;
149
+
150
+ while (spacingStart > 0 && isWhitespace(part[spacingStart - 1])) {
151
+ spacingStart -= 1;
152
+ }
153
+
154
+ return {
155
+ attribute: part.slice(attributeStart, attributeEnd + 1),
156
+ basePart: part.slice(0, spacingStart),
157
+ spacing: part.slice(spacingStart, questionMarkIndex),
158
+ };
159
+ };
160
+
161
+ const collectOpeningTagFragments = (template: string): string[] => {
162
+ const fragments: string[] = [];
163
+ let index = 0;
164
+
165
+ while (index < template.length) {
166
+ if (template[index] !== '<') {
167
+ index += 1;
168
+ continue;
169
+ }
170
+
171
+ const next = template[index + 1];
172
+
173
+ if (!next || next === '/' || next === '!' || next === '?') {
174
+ index += 1;
175
+ continue;
176
+ }
177
+
178
+ let cursor = index + 1;
179
+
180
+ if (!isAsciiLetter(template[cursor])) {
181
+ index += 1;
182
+ continue;
183
+ }
184
+
185
+ while (cursor < template.length && isTagNameChar(template[cursor])) {
186
+ cursor += 1;
187
+ }
188
+
189
+ const tagStart = index + 1;
190
+ const tagName = template.slice(tagStart, cursor);
191
+
192
+ if (!tagName) {
193
+ index += 1;
194
+ continue;
195
+ }
196
+
197
+ let inQuote: '"' | "'" | null = null;
198
+ let tagEnd = cursor;
199
+
200
+ while (tagEnd < template.length) {
201
+ const char = template[tagEnd];
202
+
203
+ if (inQuote) {
204
+ if (char === inQuote) {
205
+ inQuote = null;
206
+ }
207
+
208
+ tagEnd += 1;
209
+ continue;
210
+ }
211
+
212
+ if (char === '"' || char === "'") {
213
+ inQuote = char;
214
+ tagEnd += 1;
215
+ continue;
216
+ }
217
+
218
+ if (char === '>') {
219
+ fragments.push(template.slice(index + 1, tagEnd));
220
+ tagEnd += 1;
221
+ break;
222
+ }
223
+
224
+ tagEnd += 1;
225
+ }
226
+
227
+ index = tagEnd;
228
+ }
229
+
230
+ return fragments;
231
+ };
232
+
233
+ /**
234
+ * Consumes a literal HTML attribute value starting at the given index.
235
+ *
236
+ * Returns the position immediately after a quoted or unquoted value. When the
237
+ * current position reaches an interpolation boundary (optionally after
238
+ * whitespace), the returned index advances past the boundary marker so
239
+ * interpolated attributes do not swallow following authored attributes during
240
+ * sanitizer allowlist inference.
241
+ *
242
+ * @param fragment - The opening-tag fragment currently being scanned
243
+ * @param index - The position immediately after the `=` sign
244
+ * @returns The index after the consumed literal value, or just past an
245
+ * interpolation boundary when no literal value should be consumed from the
246
+ * current template fragment.
247
+ */
248
+ const skipAttributeValue = (fragment: string, index: number): number => {
249
+ if (index >= fragment.length) {
250
+ return index;
251
+ }
252
+
253
+ let cursor = index;
254
+
255
+ if (isInterpolationBoundaryMarker(fragment[cursor])) {
256
+ return cursor + 1;
257
+ }
258
+
259
+ while (cursor < fragment.length && isWhitespace(fragment[cursor])) {
260
+ cursor += 1;
261
+ }
262
+
263
+ if (cursor >= fragment.length) {
264
+ return cursor;
265
+ }
266
+
267
+ if (isInterpolationBoundaryMarker(fragment[cursor])) {
268
+ return cursor + 1;
269
+ }
270
+
271
+ const quote = fragment[cursor];
272
+
273
+ if (isQuoteChar(quote)) {
274
+ cursor += 1;
275
+
276
+ while (cursor < fragment.length) {
277
+ if (fragment[cursor] === quote) {
278
+ return cursor + 1;
279
+ }
280
+
281
+ cursor += 1;
282
+ }
283
+
284
+ return cursor;
285
+ }
286
+
287
+ while (
288
+ cursor < fragment.length &&
289
+ !isAttributeSeparator(fragment[cursor]) &&
290
+ fragment[cursor] !== '/' &&
291
+ fragment[cursor] !== '>'
292
+ ) {
293
+ cursor += 1;
294
+ }
295
+
296
+ if (cursor < fragment.length && isInterpolationBoundaryMarker(fragment[cursor])) {
297
+ return cursor + 1;
298
+ }
299
+
300
+ return cursor;
301
+ };
302
+
303
+ const collectAttributesFromTagFragment = (
304
+ fragment: string,
305
+ allowAttributes: Set<string>,
306
+ autoAllowAttributes: boolean
307
+ ): void => {
308
+ let index = 0;
309
+
310
+ while (index < fragment.length && !isAttributeSeparator(fragment[index])) {
311
+ index += 1;
312
+ }
313
+
314
+ while (index < fragment.length) {
315
+ while (index < fragment.length && isAttributeSeparator(fragment[index])) {
316
+ index += 1;
317
+ }
318
+
319
+ if (index >= fragment.length || fragment[index] === '/') {
320
+ return;
321
+ }
322
+
323
+ // Skip standalone colons (e.g. namespace prefixes or framework-specific bindings)
324
+ if (fragment[index] === ':') {
325
+ index += 1;
326
+ continue;
327
+ }
328
+
329
+ const hasBooleanPrefix = fragment[index] === '?';
330
+
331
+ if (hasBooleanPrefix) {
332
+ index += 1;
333
+ }
334
+
335
+ if (index >= fragment.length || !isAttributeNameStart(fragment[index])) {
336
+ // Skip unrecognised character to avoid an infinite loop
337
+ index += 1;
338
+ continue;
339
+ }
340
+
341
+ const nameStart = index;
342
+
343
+ index += 1;
344
+
345
+ while (index < fragment.length && isAttributeNameChar(fragment[index])) {
346
+ index += 1;
347
+ }
348
+
349
+ const attributeName = fragment.slice(nameStart, index).toLowerCase();
350
+
351
+ while (index < fragment.length && isAttributeSeparator(fragment[index])) {
352
+ index += 1;
353
+ }
354
+
355
+ if (index < fragment.length && fragment[index] === '=') {
356
+ if (autoAllowAttributes && isAutoAllowedStoryAttribute(attributeName)) {
357
+ allowAttributes.add(attributeName);
358
+ }
359
+ index = skipAttributeValue(fragment, index + 1);
360
+ continue;
361
+ }
362
+
363
+ if (hasBooleanPrefix && autoAllowAttributes && isAutoAllowedStoryAttribute(attributeName)) {
364
+ allowAttributes.add(attributeName);
365
+ }
366
+ }
367
+ };
368
+
369
+ const collectTemplateSanitizeOptions = (strings: TemplateStringsArray) => {
370
+ const template = strings.join(INTERPOLATION_BOUNDARY_MARKER);
371
+ const allowTags = new Set<string>();
372
+ const allowAttributes = new Set<string>();
373
+
374
+ for (const fragment of collectOpeningTagFragments(template)) {
375
+ const tagName = fragment.slice(0, getTagNameEnd(fragment)).toLowerCase();
376
+ const isCustomElement = isCustomElementTagName(tagName);
377
+
378
+ if (isCustomElement) {
379
+ allowTags.add(tagName);
380
+ }
381
+
382
+ collectAttributesFromTagFragment(fragment, allowAttributes, isCustomElement);
383
+ }
384
+
385
+ return {
386
+ allowTags: Array.from(allowTags),
387
+ allowAttributes: Array.from(allowAttributes),
388
+ };
389
+ };
390
+
391
+ const resolveStoryValue = (value: StoryValue): string => {
392
+ if (value == null) {
393
+ return '';
394
+ }
395
+
396
+ if (Array.isArray(value)) {
397
+ return value.map((item) => resolveStoryValue(item)).join('');
398
+ }
399
+
400
+ if (typeof value === 'function') {
401
+ return resolveStoryValue(value());
402
+ }
403
+
404
+ return String(value);
405
+ };
406
+
407
+ const resolveBooleanStoryValue = (value: StoryValue): boolean => {
408
+ if (value == null) {
409
+ return false;
410
+ }
411
+
412
+ if (typeof value === 'function') {
413
+ return resolveBooleanStoryValue(value());
414
+ }
415
+
416
+ if (Array.isArray(value)) {
417
+ return Boolean(resolveStoryValue(value));
418
+ }
419
+
420
+ if (typeof value === 'boolean') {
421
+ return value;
422
+ }
423
+
424
+ return Boolean(value);
425
+ };
426
+
427
+ /**
428
+ * Tagged template literal for Storybook render functions.
429
+ *
430
+ * Supports boolean attribute shorthand compatible with Storybook's string
431
+ * renderer:
432
+ *
433
+ * ```ts
434
+ * storyHtml`<bq-button ?disabled=${true}>Save</bq-button>`;
435
+ * // => '<bq-button disabled="">Save</bq-button>'
436
+ * ```
437
+ *
438
+ * @param strings - Template literal string parts
439
+ * @param values - Interpolated values
440
+ * @returns HTML string compatible with `@storybook/web-components`
441
+ */
442
+ export const storyHtml = (strings: TemplateStringsArray, ...values: StoryValue[]): string => {
443
+ const rendered = strings.reduce((acc, part, index) => {
444
+ if (index >= values.length) {
445
+ return `${acc}${part}`;
446
+ }
447
+
448
+ const booleanAttributeMatch = findBooleanAttributeSuffix(part);
449
+
450
+ if (booleanAttributeMatch) {
451
+ const { attribute, basePart, spacing } = booleanAttributeMatch;
452
+ const preservedSpacing = hasLineBreak(spacing) ? spacing : '';
453
+ const isEnabled = resolveBooleanStoryValue(values[index]);
454
+
455
+ return `${acc}${basePart}${isEnabled ? `${spacing}${attribute}` : preservedSpacing}`;
456
+ }
457
+
458
+ return `${acc}${part}${resolveStoryValue(values[index])}`;
459
+ }, '');
460
+
461
+ return sanitizeHtml(rendered, collectTemplateSanitizeOptions(strings));
462
+ };
463
+
464
+ /**
465
+ * Conditionally render a value or template fragment.
466
+ *
467
+ * @param condition - Condition that controls rendering
468
+ * @param truthyValue - Value or callback rendered when the condition is truthy
469
+ * @param falsyValue - Optional value or callback rendered when the condition is falsy
470
+ * @returns Rendered string fragment, or an empty string when the condition is
471
+ * falsy and no fallback is provided
472
+ */
473
+ export const when = (
474
+ condition: unknown,
475
+ truthyValue: StoryValue,
476
+ falsyValue?: StoryValue
477
+ ): string => {
478
+ return resolveStoryValue(condition ? truthyValue : falsyValue);
479
+ };