vira 31.24.1 → 31.24.2

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.
@@ -414,6 +414,13 @@ export const ViraTabs = defineViraElement()({
414
414
  const isSelected = routeHasPaths(inputs.currentRoute, tab.paths, {
415
415
  exactMatch: tab.exactMatch,
416
416
  });
417
+ const iconTemplate = tab.icon
418
+ ? html `
419
+ <${ViraIcon.assign({
420
+ icon: tab.icon,
421
+ })}></${ViraIcon}>
422
+ `
423
+ : nothing;
417
424
  return {
418
425
  content: html `
419
426
  <${ViraLink.assign({
@@ -425,8 +432,15 @@ export const ViraTabs = defineViraElement()({
425
432
  scrollToTop: true,
426
433
  },
427
434
  disableLinkStyles: true,
435
+ stylePassthrough: {
436
+ a: css `
437
+ display: flex;
438
+ align-items: center;
439
+ gap: 8px;
440
+ `,
441
+ },
428
442
  })}>
429
- ${tab.label}
443
+ ${iconTemplate} ${tab.label}
430
444
  </${ViraLink}>
431
445
  `,
432
446
  selected: isSelected,
@@ -4,7 +4,7 @@ import { viraIconCssVars } from './icon-css-vars.js';
4
4
  import { type ViraIconSvg } from './icon-svg.js';
5
5
  /**
6
6
  * Wraps an existing icon with a specific color and outputs another icon that can be used anywhere
7
- * the original icon can be used.
7
+ * the original icon can be used. Results are cached per source icon and color combination.
8
8
  *
9
9
  * @category Icon
10
10
  */
@@ -1,11 +1,17 @@
1
1
  import { check } from '@augment-vir/assert';
2
- import { getObjectTypedKeys } from '@augment-vir/common';
2
+ import { getObjectTypedKeys, getOrSetFromMap } from '@augment-vir/common';
3
3
  import { css, html, unsafeCSS } from 'element-vir';
4
4
  import { viraIconCssVars } from './icon-css-vars.js';
5
5
  import { defineIcon } from './icon-svg.js';
6
+ /**
7
+ * Caches colored icons keyed first by the source icon and then by the generated color styles. The
8
+ * outer `WeakMap` lets the entire cache for a given icon be garbage collected once that icon is no
9
+ * longer referenced, preventing a memory leak from unbounded icon definitions.
10
+ */
11
+ const coloredIconCache = new WeakMap();
6
12
  /**
7
13
  * Wraps an existing icon with a specific color and outputs another icon that can be used anywhere
8
- * the original icon can be used.
14
+ * the original icon can be used. Results are cached per source icon and color combination.
9
15
  *
10
16
  * @category Icon
11
17
  */
@@ -21,15 +27,18 @@ export function createColoredIcon(icon, colors) {
21
27
  })
22
28
  .filter(check.isTruthy)
23
29
  .join(' ');
24
- const styles = css `
25
- ${unsafeCSS(colorStyles)}
26
- display: inline-flex;
27
- vertical-align: middle;
28
- `;
29
- return defineIcon({
30
- name: icon.name,
31
- svgTemplate: html `
32
- <div style=${styles}>${icon.svgTemplate}</div>
33
- `,
30
+ const iconCache = getOrSetFromMap(coloredIconCache, icon, () => new Map());
31
+ return getOrSetFromMap(iconCache, colorStyles, () => {
32
+ const styles = css `
33
+ ${unsafeCSS(colorStyles)}
34
+ display: inline-flex;
35
+ vertical-align: middle;
36
+ `;
37
+ return defineIcon({
38
+ name: icon.name,
39
+ svgTemplate: html `
40
+ <div style=${styles}>${icon.svgTemplate}</div>
41
+ `,
42
+ });
34
43
  });
35
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vira",
3
- "version": "31.24.1",
3
+ "version": "31.24.2",
4
4
  "description": "A simple and highly versatile design system using element-vir.",
5
5
  "keywords": [
6
6
  "design",