Skip to content

Commit 15353db

Browse files
authored
Merge branch 'sudeep2003:main' into fix/jsx-runtime-warning
2 parents 1537288 + aa54cce commit 15353db

51 files changed

Lines changed: 2485 additions & 1360 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: 📘 Documentation
4-
url: https://astroicon.dev
4+
url: https://astro-iconset.wingflows.com
55
about: Read the official documentation

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,22 @@ jobs:
2727
cache: 'pnpm'
2828
- run: pnpm install
2929
- run: pnpm -r build
30+
31+
test:
32+
name: Unit Tests (${{ matrix.os }})
33+
runs-on: ${{ matrix.os }}
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
# Windows is intentionally included: several path/URL bugs only surface
38+
# when the project path contains spaces or uses backslashes.
39+
os: [ubuntu-latest, windows-latest]
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: pnpm/action-setup@v4
43+
- uses: actions/setup-node@v4
44+
with:
45+
node-version: 22
46+
cache: 'pnpm'
47+
- run: pnpm install
48+
- run: pnpm --filter astro-iconset run test

.gitignore

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,7 @@ dist
137137

138138

139139
.vscode
140-
docs/plan-*
141140
sandbox.config.json
142-
143-
packages/core/*.md
144-
145-
PLAN.md
146141
REFERENCES.md
147-
FRAMEWORKS.md
148-
GAPS.md
149142
TESTING.md
150-
ISSUES.md
151-
152-
tests/
143+
ISSUES.md

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"scripts": {
77
"build": "pnpm --filter astro-iconset --filter site run build",
88
"dev": "pnpm -r run dev",
9+
"test": "pnpm --filter astro-iconset run test",
10+
"test:coverage": "pnpm --filter astro-iconset run test:coverage",
911
"lint": "prettier --check \"**/*.{js,ts,md,json}\"",
1012
"format": "prettier --write \"**/*.{js,ts,md,json}\"",
1113
"version": "changeset version && pnpm install --no-frozen-lockfile --lockfile-only"
@@ -29,6 +31,6 @@
2931
"@changesets/cli": "^2.18.1"
3032
},
3133
"devDependencies": {
32-
"prettier": "^3.1.1"
34+
"prettier": "^3.8.4"
3335
}
3436
}

packages/astro-iconset/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# astro-iconset Changelog
22

3+
## 0.0.6
4+
5+
### Patch
6+
7+
- Resilient icon loading: missing icon directories and un-optimizable SVGs (e.g. embedded raster images) now warn instead of aborting the build.
8+
- Fix: `?icon` imports resolve through Vite, adding support for path aliases including tsconfig `paths` and `resolve.alias`.
9+
- Fix: deduplicate the "Loaded icons from …" dev log across SSR/client module evaluations.
10+
- New `dataAttr` integration option to rename (`dataAttr: "data-astro-icon"`) or disable (`dataAttr: false`) the `data-icon` attribute. Defaults to `data-icon` (backward compatible).
11+
312
## 0.0.5
413

514
### Patch

packages/astro-iconset/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ icon({
223223

224224
To use only `iconDirs` for the default local set, set `iconDirs.local` instead of `iconDir`. Do not set both `iconDir` and `iconDirs.local`.
225225

226+
### `dataAttr`
227+
228+
The data attribute added to each rendered icon for CSS targeting. Defaults to `"data-icon"`. Pass a custom string to rename it, or `false` to remove it entirely.
229+
230+
```js
231+
icon({
232+
dataAttr: "data-astro-icon", // or false to disable
233+
});
234+
```
235+
226236
### `svgoOptions`
227237

228238
Override default SVGO behavior. See [SVGO configuration](https://github.com/svg/svgo#configuration).

packages/astro-iconset/components/Icon.astro

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ let normalizedBody: string;
8686
let viewBox: string | undefined;
8787
let id: string;
8888
89+
const mod = (await import("virtual:astro-iconset")) as {
90+
default: AstroIconCollectionMap;
91+
config: {
92+
include?: Record<string, ["*"] | string[]>;
93+
dataAttr?: string | false;
94+
};
95+
};
96+
97+
const icons = mod.default;
98+
const config = mod.config;
99+
100+
const dataAttrName =
101+
config.dataAttr === false ? undefined : (config.dataAttr ?? "data-icon");
102+
89103
if (icon) {
90104
const renderData = iconToSVG(icon);
91105
id = `ai:${importedCacheKey(icon)}`;
@@ -107,12 +121,6 @@ if (icon) {
107121
delete normalizedProps.viewBox;
108122
}
109123
} else {
110-
const mod = (await import("virtual:astro-iconset")) as {
111-
default: AstroIconCollectionMap;
112-
config: { include?: Record<string, ["*"] | string[]> };
113-
};
114-
const icons = mod.default;
115-
const config = mod.config;
116124
const name = nameProp as string;
117125
const { include = {} } = config;
118126
const sets = Object.keys(include);
@@ -200,9 +208,11 @@ if (icon) {
200208
delete normalizedProps.viewBox;
201209
}
202210
}
211+
212+
const svgDataAttr = dataAttrName != null ? { [dataAttrName]: cacheKey } : {};
203213
---
204214

205-
<svg {...normalizedProps} data-icon={cacheKey}>
215+
<svg {...normalizedProps} {...svgDataAttr}>
206216
{title && <title>{title}</title>}
207217
{desc && <desc>{desc}</desc>}
208218
{

packages/astro-iconset/components/preact/Icon.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type IconProps =
1818

1919
export default function Icon(props: IconProps) {
2020
const { name, icon, size, width, height, title, desc, ...rest } = props;
21-
const { attrs, inner, dataIcon } = resolveIcon(
21+
const { attrs, inner, dataAttr } = resolveIcon(
2222
{ name: name as string | undefined, icon, size, width: width as number | string | undefined, height: height as number | string | undefined, title, desc },
2323
"preact"
2424
);
@@ -27,7 +27,9 @@ export default function Icon(props: IconProps) {
2727
<svg
2828
{...(attrs as JSX.IntrinsicElements["svg"])}
2929
{...rest}
30-
data-icon={dataIcon}
30+
{...(dataAttr
31+
? { [dataAttr.name]: dataAttr.value }
32+
: {})}
3133
dangerouslySetInnerHTML={{ __html: inner }}
3234
/>
3335
);

packages/astro-iconset/components/react/Icon.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type IconProps =
1818

1919
export default function Icon(props: IconProps) {
2020
const { name, icon, size, width, height, title, desc, ...rest } = props;
21-
const { attrs, inner, dataIcon } = resolveIcon(
21+
const { attrs, inner, dataAttr } = resolveIcon(
2222
{ name: name as string | undefined, icon, size, width: width as number | string | undefined, height: height as number | string | undefined, title, desc },
2323
"react"
2424
);
@@ -27,7 +27,9 @@ export default function Icon(props: IconProps) {
2727
<svg
2828
{...(attrs as SVGProps<SVGSVGElement>)}
2929
{...rest}
30-
data-icon={dataIcon}
30+
{...(dataAttr
31+
? { [dataAttr.name]: dataAttr.value }
32+
: {})}
3133
dangerouslySetInnerHTML={{ __html: inner }}
3234
/>
3335
);

packages/astro-iconset/components/shared/core.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import { getIconData, iconToSVG, replaceIDs } from "@iconify/utils";
44
import type { AstroIconCollectionMap } from "../../typings/integration";
55
import type { AstroIconImport } from "../../typings/astro-icon-import";
6-
import collections_mod from "virtual:astro-iconset";
6+
import collections_mod, { config } from "virtual:astro-iconset";
77

88
const _collections = ((collections_mod as any).default ?? collections_mod) as AstroIconCollectionMap;
99

10+
const _config = config ?? {};
11+
1012
export interface ResolveIconInput {
1113
name?: string;
1214
icon?: AstroIconImport;
@@ -20,7 +22,10 @@ export interface ResolveIconInput {
2022
export interface ResolvedIcon {
2123
attrs: Record<string, string>;
2224
inner: string;
23-
dataIcon: string;
25+
dataAttr?: {
26+
name: string;
27+
value: string;
28+
};
2429
}
2530

2631
function escapeHtml(s: string): string {
@@ -79,5 +84,15 @@ export function resolveIcon(input: ResolveIconInput, framework: string): Resolve
7984
(desc ? `<desc>${escapeHtml(desc)}</desc>` : "") +
8085
body;
8186

82-
return { attrs, inner, dataIcon: icon ? "astro-iconset:import" : (name as string) };
87+
const dataIconValue = icon ? "astro-iconset:import" : (name as string);
88+
89+
const dataAttr =
90+
_config.dataAttr === false
91+
? undefined
92+
: {
93+
name: _config.dataAttr ?? "data-icon",
94+
value: dataIconValue,
95+
};
96+
97+
return { attrs, inner, dataAttr };
8398
}

0 commit comments

Comments
 (0)