vira 29.5.3 → 29.5.5
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.
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
|
+
import { type CSSResult } from 'element-vir';
|
|
3
|
+
import { viraIconCssVars } from './icon-css-vars.js';
|
|
4
|
+
import { type ViraIconSvg } from './icon-svg.js';
|
|
5
|
+
/**
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* @category Icon
|
|
10
|
+
*/
|
|
11
|
+
export declare function createColoredIcon(icon: ViraIconSvg, colors: PartialWithUndefined<Record<keyof typeof viraIconCssVars, string | CSSResult>>): ViraIconSvg;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { getObjectTypedKeys } from '@augment-vir/common';
|
|
3
|
+
import { css, html, unsafeCSS } from 'element-vir';
|
|
4
|
+
import { viraIconCssVars } from './icon-css-vars.js';
|
|
5
|
+
import { defineIcon } from './icon-svg.js';
|
|
6
|
+
/**
|
|
7
|
+
* Wraps an existing icon with a specific color and outputs another icon that can be used anywhere
|
|
8
|
+
* the original icon can be used.
|
|
9
|
+
*
|
|
10
|
+
* @category Icon
|
|
11
|
+
*/
|
|
12
|
+
export function createColoredIcon(icon, colors) {
|
|
13
|
+
const colorStyles = getObjectTypedKeys(colors)
|
|
14
|
+
.map((cssVarName) => {
|
|
15
|
+
if (colors[cssVarName]) {
|
|
16
|
+
return `${viraIconCssVars[cssVarName].name}: ${String(colors[cssVarName])};`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
.filter(check.isTruthy)
|
|
23
|
+
.join(' ');
|
|
24
|
+
const styles = css `
|
|
25
|
+
${unsafeCSS(colorStyles)}
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
`;
|
|
28
|
+
return defineIcon({
|
|
29
|
+
name: icon.name,
|
|
30
|
+
svgTemplate: html `
|
|
31
|
+
<div style=${styles}>${icon.svgTemplate}</div>
|
|
32
|
+
`,
|
|
33
|
+
});
|
|
34
|
+
}
|
package/dist/icons/icon-svg.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type TemplateResult } from 'element-vir';
|
|
2
|
-
import { viraIconCssVars } from './icon-css-vars.js';
|
|
3
2
|
/**
|
|
4
3
|
* An individual Vira icon SVG definition.
|
|
5
4
|
*
|
|
@@ -18,10 +17,3 @@ export declare function defineIcon({ name, svgTemplate, }: {
|
|
|
18
17
|
name: string;
|
|
19
18
|
svgTemplate: TemplateResult;
|
|
20
19
|
}): ViraIconSvg;
|
|
21
|
-
/**
|
|
22
|
-
* Wraps an existing icon with a specific color and outputs another icon that can be used anywhere
|
|
23
|
-
* the original icon can be used.
|
|
24
|
-
*
|
|
25
|
-
* @category Icon
|
|
26
|
-
*/
|
|
27
|
-
export declare function createColoredIcon(icon: ViraIconSvg, colors: Partial<Record<keyof typeof viraIconCssVars, string>>): ViraIconSvg;
|
package/dist/icons/icon-svg.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { getObjectTypedKeys, stringify } from '@augment-vir/common';
|
|
2
|
-
import Color from 'colorjs.io';
|
|
3
|
-
import { html } from 'element-vir';
|
|
4
|
-
import { viraIconCssVars } from './icon-css-vars.js';
|
|
5
1
|
/**
|
|
6
2
|
* A function used to define an individual Vira icon SVG.
|
|
7
3
|
*
|
|
@@ -14,35 +10,3 @@ export function defineIcon({ name, svgTemplate, }) {
|
|
|
14
10
|
};
|
|
15
11
|
return iconSvg;
|
|
16
12
|
}
|
|
17
|
-
function getAssertedValidColor(input) {
|
|
18
|
-
try {
|
|
19
|
-
if (!input) {
|
|
20
|
-
throw new Error('invalid empty color');
|
|
21
|
-
}
|
|
22
|
-
return new Color(input);
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
throw new Error(`Invalid color: ${stringify(input)}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Wraps an existing icon with a specific color and outputs another icon that can be used anywhere
|
|
30
|
-
* the original icon can be used.
|
|
31
|
-
*
|
|
32
|
-
* @category Icon
|
|
33
|
-
*/
|
|
34
|
-
export function createColoredIcon(icon, colors) {
|
|
35
|
-
const colorStyles = getObjectTypedKeys(colors)
|
|
36
|
-
.map((cssVarName) => {
|
|
37
|
-
const colorValue = colors[cssVarName];
|
|
38
|
-
const color = getAssertedValidColor(colorValue);
|
|
39
|
-
return `${viraIconCssVars[cssVarName].name}: ${color.toString()};`;
|
|
40
|
-
})
|
|
41
|
-
.join(' ');
|
|
42
|
-
return defineIcon({
|
|
43
|
-
name: icon.name,
|
|
44
|
-
svgTemplate: html `
|
|
45
|
-
<div style=${colorStyles}>${icon.svgTemplate}</div>
|
|
46
|
-
`,
|
|
47
|
-
});
|
|
48
|
-
}
|
package/dist/icons/index.d.ts
CHANGED
package/dist/icons/index.js
CHANGED
|
@@ -45,6 +45,7 @@ import { StatusWarning24Icon } from './icon-svgs/status-warning-24.icon.js';
|
|
|
45
45
|
import { Sun24Icon } from './icon-svgs/sun-24.icon.js';
|
|
46
46
|
import { Upload24Icon } from './icon-svgs/upload-24.icon.js';
|
|
47
47
|
import { X24Icon } from './icon-svgs/x-24.icon.js';
|
|
48
|
+
export * from './colored-icon.js';
|
|
48
49
|
export * from './icon-css-vars.js';
|
|
49
50
|
export * from './icon-svg.js';
|
|
50
51
|
export * from './icon-svgs/arrow-up-24.icon.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vira",
|
|
3
|
-
"version": "29.5.
|
|
3
|
+
"version": "29.5.5",
|
|
4
4
|
"description": "A simple and highly versatile design system using element-vir.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"@augment-vir/assert": "^31.59.3",
|
|
42
42
|
"@augment-vir/common": "^31.59.3",
|
|
43
43
|
"@augment-vir/web": "^31.59.3",
|
|
44
|
-
"colorjs.io": "^0.6.1",
|
|
45
44
|
"date-vir": "^8.1.1",
|
|
46
45
|
"device-navigation": "^4.5.5",
|
|
47
46
|
"lit-css-vars": "^3.5.0",
|