vadivam 0.0.80 → 0.0.82

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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ Tree-shakeable 24px outline and solid SVG icons for JavaScript, with raw assets
8
8
  [![downloads](https://img.shields.io/npm/dw/vadivam?style=flat-square&color=666)](https://www.npmjs.com/package/vadivam)
9
9
  [![license](https://img.shields.io/npm/l/vadivam?style=flat-square&color=111)](https://github.com/praveenjuge/vadivam/blob/main/LICENSE)
10
10
 
11
- ![All Vadivam icons](https://raw.githubusercontent.com/praveenjuge/vadivam/main/apps/docs/public/preview.png?v=0.0.80)
11
+ ![All Vadivam icons](https://raw.githubusercontent.com/praveenjuge/vadivam/main/apps/docs/public/preview.png?v=0.0.82)
12
12
 
13
13
  ```sh
14
14
  npm install vadivam
@@ -46,6 +46,8 @@ Every icon also has a solid twin with the same name in `vadivam/solid`, with its
46
46
  import { Activity, createElement } from "vadivam/solid";
47
47
  ```
48
48
 
49
- Package family: [React](https://www.npmjs.com/package/vadivam-react) · [React Native](https://www.npmjs.com/package/vadivam-react-native) · [Vue](https://www.npmjs.com/package/vadivam-vue) · [Svelte](https://www.npmjs.com/package/vadivam-svelte) · [Solid](https://www.npmjs.com/package/vadivam-solid) · [Angular](https://www.npmjs.com/package/vadivam-angular) · [Astro](https://www.npmjs.com/package/vadivam-astro) · [Preact](https://www.npmjs.com/package/vadivam-preact) · [Qwik](https://www.npmjs.com/package/vadivam-qwik) · [Lit](https://www.npmjs.com/package/vadivam-lit) · [Flutter](https://pub.dev/packages/vadivam) · [Jetpack Compose](https://central.sonatype.com/artifact/com.praveenjuge/vadivam-compose) · [MCP server](https://www.npmjs.com/package/vadivam-mcp)
49
+ <!-- vadivam-packages:start -->
50
+ Package family: [React](https://www.npmjs.com/package/vadivam-react) · [React Native](https://www.npmjs.com/package/vadivam-react-native) · [Vue](https://www.npmjs.com/package/vadivam-vue) · [Svelte](https://www.npmjs.com/package/vadivam-svelte) · [Solid](https://www.npmjs.com/package/vadivam-solid) · [Preact](https://www.npmjs.com/package/vadivam-preact) · [Astro](https://www.npmjs.com/package/vadivam-astro) · [Angular](https://www.npmjs.com/package/vadivam-angular) · [Qwik](https://www.npmjs.com/package/vadivam-qwik) · [Lit](https://www.npmjs.com/package/vadivam-lit) · [Flutter](https://pub.dev/packages/vadivam) · [Compose](https://central.sonatype.com/artifact/com.praveenjuge/vadivam-compose) · [MCP server](https://www.npmjs.com/package/vadivam-mcp)
51
+ <!-- vadivam-packages:end -->
50
52
 
51
53
  [Issues](https://github.com/praveenjuge/vadivam/issues)
@@ -1,16 +1,12 @@
1
1
  import createElement from "./createElement.js";
2
2
  import defaultAttributes from "./defaultAttributes.js";
3
+ import { sanitizeRootAttributes } from "./runtimePolicy.js";
3
4
 
4
5
  function attributes(element) {
5
6
  return Object.fromEntries(Array.from(element.attributes, ({ name, value }) => [name, value]));
6
7
  }
7
- function classes(value) {
8
- if (Array.isArray(value)) return value;
9
- return typeof value === "string" ? value.split(/\s+/).filter(Boolean) : [];
10
- }
11
- function hasAccessibleName(attrs) {
12
- return Object.keys(attrs).some((name) => name.startsWith("aria-") || name === "role" || name === "title");
13
- }
8
+ function mergeClasses(...values) { return values.flatMap((value) => typeof value === "string" ? value.split(/\s+/) : []).filter((value, index, all) => value && all.indexOf(value) === index).join(" "); }
9
+ function isLabelled(title, attributeNames) { return Boolean(title) || attributeNames.some((name) => name.startsWith("aria-") || name === "role" || name === "title"); }
14
10
  function replaceElement(element, { nameAttr, icons, attrs }) {
15
11
  const name = element.getAttribute(nameAttr);
16
12
  if (!name) return;
@@ -21,8 +17,8 @@ function replaceElement(element, { nameAttr, icons, attrs }) {
21
17
  return;
22
18
  }
23
19
  const elementAttrs = attributes(element);
24
- const iconAttrs = { ...defaultAttributes, [nameAttr]: name, ...(hasAccessibleName(elementAttrs) ? {} : { "aria-hidden": "true" }), ...attrs, ...elementAttrs };
25
- iconAttrs.class = ["vadivam", `vadivam-${name}`, ...classes(elementAttrs.class), ...classes(attrs.class)].filter((value, index, all) => value && all.indexOf(value) === index).join(" ");
20
+ const iconAttrs = { ...defaultAttributes, [nameAttr]: name, ...(isLabelled(null, Object.keys(sanitizeRootAttributes({ ...attrs, ...elementAttrs }))) ? {} : { "aria-hidden": "true" }), ...attrs, ...elementAttrs };
21
+ iconAttrs.class = mergeClasses("vadivam", `vadivam-${name}`, elementAttrs.class, ...[attrs.class].flat());
26
22
  element.parentNode?.replaceChild(createElement(iconNode, iconAttrs), element);
27
23
  }
28
24
 
@@ -30,7 +26,8 @@ export function createIcons({ icons = {}, nameAttr = "data-vadivam", attrs = {},
30
26
  if (!Object.keys(icons).length) throw new Error("Please provide an icons object to createIcons().");
31
27
  if (!root) throw new Error("createIcons() only works in a browser environment.");
32
28
  if (!/^[A-Za-z_:][A-Za-z0-9_.:-]*$/.test(nameAttr)) throw new Error("createIcons() received an invalid nameAttr.");
33
- for (const element of root.querySelectorAll(`[${nameAttr}]`)) replaceElement(element, { nameAttr, icons, attrs });
29
+ // A valid attribute name may hold "." or ":", which a selector must escape.
30
+ for (const element of root.querySelectorAll(`[${nameAttr.replace(/[.:]/g, "\\$&")}]`)) replaceElement(element, { nameAttr, icons, attrs });
34
31
  if (inTemplates) {
35
32
  for (const template of root.querySelectorAll("template")) createIcons({ icons, nameAttr, attrs, root: template.content, inTemplates });
36
33
  }