@stillwind/plugin-iconify 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +254 -2
- package/dist/index.d.ts +108 -0
- package/dist/index.js +539 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Stillwind contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,255 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stillwind/plugin-iconify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stillwind compiles Tailwind CSS v4 utilities into component props and static CSS.
|
|
4
|
+
|
|
5
|
+
`@stillwind/plugin-iconify` adds Iconify icons as Stillwind utilities. Only the icons
|
|
6
|
+
you use are included in your CSS.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
Install the plugin and the icon sets that the project uses:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
vp i -D @stillwind/plugin-iconify @iconify-json/mdi
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Load the plugin in the project stylesheet:
|
|
17
|
+
|
|
18
|
+
```css
|
|
19
|
+
@import "stillwind";
|
|
20
|
+
@plugin "@stillwind/plugin-iconify";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Set up the stylesheet and build integration with the
|
|
24
|
+
[Getting started](https://stillwind.dev/docs) guide.
|
|
25
|
+
|
|
26
|
+
Use `icon-<set>--<icon>` or `icon-[<set>--<icon>]` to select an icon. Variants apply as
|
|
27
|
+
usual. The `prefer-canonical-utilities` lint suggests the named spelling:
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
<span {...style("icon-mdi--close", "hover:icon-[mdi--close-circle]")} />
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Sizes
|
|
34
|
+
|
|
35
|
+
An icon is `1em` high by default, and its width keeps the icon's aspect ratio. A size utility
|
|
36
|
+
sets the height of the icon on the same element:
|
|
37
|
+
|
|
38
|
+
- `icon-<name>` uses the `--icon-size-<name>` theme token.
|
|
39
|
+
- `icon-full` uses `100%` of the parent's height.
|
|
40
|
+
- `icon-[<length>]`, `icon-[<percentage>]`, and `icon-(<custom-property>)` use the given value.
|
|
41
|
+
|
|
42
|
+
```css
|
|
43
|
+
@theme {
|
|
44
|
+
--icon-size-lg: 1.5rem;
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
<span {...style("icon-mdi--close icon-lg")} />
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`icon-full` needs a parent with a definite height. In a parent whose height depends on its
|
|
53
|
+
content, the icon is 0 high. To size an icon by its width instead, override the height:
|
|
54
|
+
`icon-mdi--close w-full h-auto` fills the parent's width and keeps the icon's aspect ratio.
|
|
55
|
+
When other utilities, such as `size-full` or `max-w-full`, change the box, the SVG keeps its
|
|
56
|
+
aspect ratio and stays centered in the box.
|
|
57
|
+
|
|
58
|
+
The size does not reach descendants or the element's `::before` and `::after` boxes. Apply the
|
|
59
|
+
size with the same variant as the icon, such as `before:icon-mdi--close before:icon-lg`.
|
|
60
|
+
Use lengths or percentages for `--icon-size-*` values. These property names stay the
|
|
61
|
+
same when you customize the utility `prefix`.
|
|
62
|
+
|
|
63
|
+
Size values follow lint policies configured for `height`. For example,
|
|
64
|
+
`no-restricted-length-units` with `properties: ["height"]` checks their units, and
|
|
65
|
+
`no-arbitrary-spacing` with `properties: ["height"]` reports arbitrary sizes. Named
|
|
66
|
+
sizes such as `icon-lg` remain theme-token selections.
|
|
67
|
+
|
|
68
|
+
## Icon sets
|
|
69
|
+
|
|
70
|
+
The plugin finds a set in this order:
|
|
71
|
+
|
|
72
|
+
1. The `collections` option of a configured instance.
|
|
73
|
+
2. The `@iconify-json/<set>` package.
|
|
74
|
+
3. The `@iconify/json` package, which contains every Iconify set.
|
|
75
|
+
|
|
76
|
+
Install icon set packages in the project that contains your stylesheet. Changes to a
|
|
77
|
+
set's JSON file update its icons automatically. Editors complete the icons of configured sets
|
|
78
|
+
and of the `@iconify-json/*` packages listed in the project's `package.json` dependencies.
|
|
79
|
+
When `@iconify/json` is installed, editors also complete its set names, such as `icon-mdi--`,
|
|
80
|
+
and list the icons of a set after the input names it.
|
|
81
|
+
|
|
82
|
+
### License notices
|
|
83
|
+
|
|
84
|
+
The CSS output starts with a license notice for each icon set whose icons it contains, such as
|
|
85
|
+
`/*! Material Design Icons | Pictogrammers | Apache 2.0 | ... */`. The notice contains the set's
|
|
86
|
+
name, author, and license from the set's metadata. A `@iconify-json/<set>` package supplies the
|
|
87
|
+
metadata in its `info.json` file. The `@iconify/json` package and custom JSON sets supply it in
|
|
88
|
+
their `info` field.
|
|
89
|
+
|
|
90
|
+
A custom set without metadata adds no notice. It does not use the metadata of an installed set
|
|
91
|
+
with the same name. Pass the `info` option to `svgDirectory()` to add a notice for a set of SVG
|
|
92
|
+
files.
|
|
93
|
+
|
|
94
|
+
## Options
|
|
95
|
+
|
|
96
|
+
The options block of the statement sets these options:
|
|
97
|
+
|
|
98
|
+
```css
|
|
99
|
+
@plugin "@stillwind/plugin-iconify" {
|
|
100
|
+
prefix: i;
|
|
101
|
+
syntax: bracket;
|
|
102
|
+
scale: 1.2;
|
|
103
|
+
mode: mask;
|
|
104
|
+
hash-length: 4;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- `prefix`: utility prefix without the trailing hyphen, such as `icon` or `i`. Defaults to `icon`.
|
|
109
|
+
- `syntax`: spellings that select an icon. `named` accepts `icon-mdi--close`, `bracket` accepts
|
|
110
|
+
`icon-[mdi--close]`, and `both`, the default, accepts both.
|
|
111
|
+
- `scale`: icon height in `em` when no size utility applies. Defaults to `1`.
|
|
112
|
+
- `mode`: `mask` paints the text color through the icon's shape, and `background` paints the
|
|
113
|
+
icon's own colors. `auto`, the default, selects `mask` for icons whose SVG uses
|
|
114
|
+
`currentColor`.
|
|
115
|
+
- `hash-length`: base36 hash length in generated CSS variable names. Accepts integers
|
|
116
|
+
from `1` to `7` and defaults to `4`. Increase it when using many icons to reduce collisions.
|
|
117
|
+
|
|
118
|
+
For custom icon sets or TypeScript options, add `iconify(...)` to your project's
|
|
119
|
+
`plugins` list. Icon sets can be data, absolute JSON file paths, functions that
|
|
120
|
+
return data, or SVG directories. Keep `@plugin "@stillwind/plugin-iconify";` in your stylesheet:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { iconify } from "@stillwind/plugin-iconify";
|
|
124
|
+
import { defineConfig } from "stillwind/config";
|
|
125
|
+
|
|
126
|
+
export default defineConfig({
|
|
127
|
+
projects: [
|
|
128
|
+
{
|
|
129
|
+
css: "src/stillwind.css",
|
|
130
|
+
files: ["src/**/*.{ts,tsx}"],
|
|
131
|
+
plugins: [
|
|
132
|
+
iconify({
|
|
133
|
+
collections: {
|
|
134
|
+
brand: "/abs/path/brand.json",
|
|
135
|
+
},
|
|
136
|
+
}),
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
> [!NOTE]
|
|
144
|
+
> Options in the stylesheet's `@plugin` block override the TypeScript options. Use
|
|
145
|
+
> `hashLength` for the `hash-length` option in TypeScript, such as `iconify({ hashLength: 6 })`.
|
|
146
|
+
> The stylesheet cannot set `collections` or `svgo` (described below).
|
|
147
|
+
|
|
148
|
+
### Custom icon set format
|
|
149
|
+
|
|
150
|
+
A custom icon set uses the Iconify JSON format, which the `IconifyJSON` type of
|
|
151
|
+
`@iconify/types` describes. This is the same format as the `icons.json` file of an
|
|
152
|
+
`@iconify-json/*` package:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"prefix": "brand",
|
|
157
|
+
"width": 24,
|
|
158
|
+
"height": 24,
|
|
159
|
+
"icons": {
|
|
160
|
+
"logo": {
|
|
161
|
+
"body": "<path fill=\"currentColor\" d=\"M4 4h16v16H4z\"/>"
|
|
162
|
+
},
|
|
163
|
+
"badge": {
|
|
164
|
+
"body": "<circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"#e11d48\"/>",
|
|
165
|
+
"width": 32,
|
|
166
|
+
"height": 32
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
"aliases": {
|
|
170
|
+
"logo-flipped": {
|
|
171
|
+
"parent": "logo",
|
|
172
|
+
"hFlip": true
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
- `icons` maps each icon name to its SVG content. `body` contains the elements inside the
|
|
179
|
+
`<svg>` element, without the `<svg>` element itself.
|
|
180
|
+
- `left`, `top`, `width`, and `height` define the icon's `viewBox`. An icon can set them, and
|
|
181
|
+
the top level sets the default values for every icon. Missing values default to `0`, `0`,
|
|
182
|
+
`16`, and `16`.
|
|
183
|
+
- `aliases` maps additional names to an existing icon in `parent`. An alias can override the
|
|
184
|
+
`viewBox` values and add `rotate` (quarter turns), `hFlip`, and `vFlip` transformations.
|
|
185
|
+
- The key in `collections` sets the set name in utilities, such as `icon-brand--logo`. The
|
|
186
|
+
plugin does not use the `prefix` field to find the set.
|
|
187
|
+
|
|
188
|
+
Set names and icon names must consist of lowercase letters and digits, separated by single
|
|
189
|
+
hyphens. Utilities cannot select other names, such as `Logo` or `logo_dark`.
|
|
190
|
+
|
|
191
|
+
With the default `mode: auto`, an icon whose `body` contains `currentColor` paints the text
|
|
192
|
+
color, and the other icons keep their own colors. In the example, `logo` follows the text
|
|
193
|
+
color and `badge` stays red.
|
|
194
|
+
|
|
195
|
+
The plugin does not validate the data. A JSON file must contain valid JSON, but the plugin
|
|
196
|
+
treats an icon that it cannot find in the data as an unknown utility.
|
|
197
|
+
|
|
198
|
+
### Icon sets from SVG files
|
|
199
|
+
|
|
200
|
+
`svgDirectory()` creates an icon set from the SVG files in a directory. Each file becomes one
|
|
201
|
+
icon, and the file name without `.svg` becomes the icon name:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { iconify, svgDirectory } from "@stillwind/plugin-iconify";
|
|
205
|
+
|
|
206
|
+
iconify({
|
|
207
|
+
collections: {
|
|
208
|
+
brand: svgDirectory("src/icons/brand"),
|
|
209
|
+
ui: svgDirectory("src/icons/ui", {
|
|
210
|
+
recursive: true,
|
|
211
|
+
transform: (svg) => svg.replaceAll('fill="#000"', 'fill="currentColor"'),
|
|
212
|
+
}),
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The directory can be an absolute path or a path relative to the project directory. Each file
|
|
218
|
+
must contain an `<svg>` element with a `viewBox` attribute, which sets the icon's dimensions.
|
|
219
|
+
The plugin keeps the `style` attribute of the `<svg>` element and its attributes whose names
|
|
220
|
+
start with `fill` or `stroke`, such as `fill-rule`. It drops the other attributes of the
|
|
221
|
+
`<svg>` element.
|
|
222
|
+
|
|
223
|
+
- `recursive`: reads subdirectories. The default icon name joins the path segments with `-`,
|
|
224
|
+
such as `arrows-left` for `arrows/left.svg`. Defaults to `false`.
|
|
225
|
+
- `name`: maps the file path relative to the directory, without `.svg` and with `/` separators,
|
|
226
|
+
to an icon name. Returning `undefined` skips the file.
|
|
227
|
+
- `transform`: rewrites the SVG text of each file before the plugin parses it.
|
|
228
|
+
- `info`: the set's name, author, and license in the format of the Iconify `info` field. The
|
|
229
|
+
plugin uses it for the [license notice](#license-notices).
|
|
230
|
+
|
|
231
|
+
Loading fails when an icon name is invalid, two files have the same icon name, or a file has
|
|
232
|
+
no `viewBox`. The error names the file. Adding, removing, or editing an SVG file reloads the
|
|
233
|
+
icons while a development server or build watcher runs.
|
|
234
|
+
|
|
235
|
+
A function in `collections` receives the set name and the host's `read`, `list`, and `watch`
|
|
236
|
+
operations, so you can write similar loaders. Watch each file and directory that the function
|
|
237
|
+
reads, such as `context.watch(file)` and `context.watch(directory, "directory")`.
|
|
238
|
+
|
|
239
|
+
### SVG minification
|
|
240
|
+
|
|
241
|
+
The plugin minifies the SVG of each icon with [SVGO](https://svgo.dev/) before it embeds the
|
|
242
|
+
SVG in CSS. The `svgo` TypeScript option controls this:
|
|
243
|
+
|
|
244
|
+
- `true`, the default, uses `preset-default` with `multipass` enabled.
|
|
245
|
+
- An SVGO configuration object replaces that default configuration.
|
|
246
|
+
- `false` embeds the SVG without minification.
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
iconify({
|
|
250
|
+
svgo: {
|
|
251
|
+
multipass: true,
|
|
252
|
+
plugins: ["preset-default", "removeDimensions"],
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Config } from "svgo/browser";
|
|
2
|
+
import { IconifyInfo, IconifyJSON } from "@iconify/types";
|
|
3
|
+
import { PluginContext, StillwindPlugin } from "@stillwind/config";
|
|
4
|
+
/**
|
|
5
|
+
* A custom icon set: Iconify data, an absolute JSON file path, or a function that
|
|
6
|
+
* returns Iconify data synchronously or asynchronously.
|
|
7
|
+
*/
|
|
8
|
+
type CollectionSource = IconifyJSON | string | ((context: CollectionLoadContext) => IconifyJSON | Promise<IconifyJSON>);
|
|
9
|
+
/**
|
|
10
|
+
* Set name and host operations that a function source receives. A function source watches
|
|
11
|
+
* each file and directory that it reads, so that a change reloads the design system.
|
|
12
|
+
*/
|
|
13
|
+
interface CollectionLoadContext extends Pick<PluginContext, "root" | "watch" | "read" | "list"> {
|
|
14
|
+
/** Set name that selects the source in `collections`, such as `brand`. */
|
|
15
|
+
readonly prefix: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options of {@link svgDirectory}.
|
|
19
|
+
*/
|
|
20
|
+
interface SvgDirectoryOptions {
|
|
21
|
+
/** Set information used for the CSS attribution notice. */
|
|
22
|
+
readonly info?: IconifyInfo;
|
|
23
|
+
/**
|
|
24
|
+
* Reads SVG files in subdirectories. The default icon name joins the path segments with `-`,
|
|
25
|
+
* such as `arrows-left` for `arrows/left.svg`. Defaults to `false`.
|
|
26
|
+
*/
|
|
27
|
+
readonly recursive?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Maps a file to an icon name. The function receives the file path relative to the directory,
|
|
30
|
+
* with `/` separators and without the `.svg` extension, such as `arrows/left`. Returning
|
|
31
|
+
* undefined skips the file. By default, the path segments are joined with `-`.
|
|
32
|
+
*/
|
|
33
|
+
readonly name?: (path: string) => string | undefined;
|
|
34
|
+
/** Rewrites the SVG text of each file before the plugin parses it. */
|
|
35
|
+
readonly transform?: (svg: string, name: string) => string | Promise<string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates an icon set from the SVG files in a directory. Each file becomes one icon, and its
|
|
39
|
+
* `viewBox` sets the icon's dimensions. The set watches the directory and its files, so adding,
|
|
40
|
+
* removing, or editing an SVG file reloads the design system.
|
|
41
|
+
*
|
|
42
|
+
* @param directory - Absolute directory path, or a path relative to the project directory.
|
|
43
|
+
* @param options - Settings for reading SVGs and describing the set.
|
|
44
|
+
* @returns A source for the `collections` option of `iconify`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function svgDirectory(directory: string, options?: SvgDirectoryOptions): CollectionSource;
|
|
47
|
+
/**
|
|
48
|
+
* How an icon utility paints the icon. `mask` paints the element's text color through the icon's
|
|
49
|
+
* shape, and `background` paints the icon's own colors. `auto` selects `mask` for icons whose SVG
|
|
50
|
+
* uses `currentColor`, and `background` for the others.
|
|
51
|
+
*/
|
|
52
|
+
type IconMode = "auto" | "mask" | "background";
|
|
53
|
+
/** SVGO configuration that minifies the SVG of each icon. */
|
|
54
|
+
type SvgoConfig = Config;
|
|
55
|
+
/**
|
|
56
|
+
* Icon name formats. `named` accepts `icon-mdi--close`, `bracket` accepts
|
|
57
|
+
* `icon-[mdi--close]`, and `both` accepts either format.
|
|
58
|
+
*/
|
|
59
|
+
type IconSyntax = "both" | "named" | "bracket";
|
|
60
|
+
/**
|
|
61
|
+
* Options of {@link iconify}. The stylesheet's `@plugin` block overrides `prefix`,
|
|
62
|
+
* `syntax`, `scale`, `mode`, and `hashLength` from these options.
|
|
63
|
+
*/
|
|
64
|
+
interface IconifyOptions {
|
|
65
|
+
/**
|
|
66
|
+
* Utility prefix made of lowercase letters, digits, and single hyphens, starting
|
|
67
|
+
* with a letter. Defaults to `icon`.
|
|
68
|
+
*/
|
|
69
|
+
readonly prefix?: string;
|
|
70
|
+
/** Spellings that select an icon. Defaults to `both`. */
|
|
71
|
+
readonly syntax?: IconSyntax;
|
|
72
|
+
/** Positive, finite icon height in `em` when no size utility applies. Defaults to `1`. */
|
|
73
|
+
readonly scale?: number;
|
|
74
|
+
/** Paint method of the icons. Defaults to `auto`. */
|
|
75
|
+
readonly mode?: IconMode;
|
|
76
|
+
/**
|
|
77
|
+
* Base36 hash length in generated CSS variable names. Accepts integers from 1 to 7.
|
|
78
|
+
* Defaults to `4`.
|
|
79
|
+
* Set `hash-length` in the stylesheet's `@plugin` block.
|
|
80
|
+
*/
|
|
81
|
+
readonly hashLength?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Custom icon sets keyed by set prefix, such as `brand`. Accepts data, absolute JSON
|
|
84
|
+
* file paths, or functions that return data, such as the result of `svgDirectory`. These
|
|
85
|
+
* sets override installed packages.
|
|
86
|
+
*/
|
|
87
|
+
readonly collections?: Readonly<Record<string, CollectionSource>>;
|
|
88
|
+
/**
|
|
89
|
+
* SVGO minification of each icon's SVG. `true` selects a multipass `preset-default`
|
|
90
|
+
* configuration, an object replaces that configuration, and `false` keeps the SVG that
|
|
91
|
+
* Iconify builds. Defaults to `true`.
|
|
92
|
+
*/
|
|
93
|
+
readonly svgo?: boolean | SvgoConfig;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Creates an Iconify plugin with custom defaults or icon sets.
|
|
97
|
+
*
|
|
98
|
+
* Enable it in your stylesheet with `@plugin "@stillwind/plugin-iconify";`.
|
|
99
|
+
*
|
|
100
|
+
* @param options - Default settings and configured icon sets.
|
|
101
|
+
* @returns The plugin to add to your project's `plugins` list.
|
|
102
|
+
* @throws If `prefix`, `syntax`, `scale`, `mode`, `hashLength`, or `svgo` is invalid.
|
|
103
|
+
*/
|
|
104
|
+
export declare function iconify(options?: IconifyOptions): StillwindPlugin;
|
|
105
|
+
/** The plugin with default options, which `@plugin "@stillwind/plugin-iconify";` loads. */
|
|
106
|
+
declare const defaultPlugin: StillwindPlugin;
|
|
107
|
+
export { type CollectionLoadContext, type CollectionSource, type IconMode, type IconSyntax, type IconifyOptions, type SvgDirectoryOptions, type SvgoConfig, defaultPlugin as default };
|
|
108
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import { convertParsedSVG, parseSVGContent } from "@iconify/utils/lib/svg/parse";
|
|
2
|
+
import { getIconData } from "@iconify/utils/lib/icon-set/get-icon";
|
|
3
|
+
import { iconToSVG } from "@iconify/utils/lib/svg/build";
|
|
4
|
+
import { iconToHTML } from "@iconify/utils/lib/svg/html";
|
|
5
|
+
import { svgToURL } from "@iconify/utils/lib/svg/url";
|
|
6
|
+
import { optimize } from "svgo/browser";
|
|
7
|
+
// src/collections.ts
|
|
8
|
+
/**
|
|
9
|
+
* Parsed icon sets keyed by file path, with the text that they were parsed from. Statements of
|
|
10
|
+
* later loads reuse the data while the text is unchanged, because large sets take long to parse.
|
|
11
|
+
*/
|
|
12
|
+
const parsed = /* @__PURE__ */ new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Finds and caches the icon sets of one loaded `@plugin` statement.
|
|
15
|
+
*
|
|
16
|
+
* A set comes from the first source that provides it: the configured sources, then the
|
|
17
|
+
* `@iconify-json/<set>` package, then the `@iconify/json` package. Packages are resolved by the
|
|
18
|
+
* host from the stylesheet that contains the statement. Each lookup registers the set's file with
|
|
19
|
+
* the host, so a changed file reloads the design system, and the new statement context reads the
|
|
20
|
+
* file again.
|
|
21
|
+
*/
|
|
22
|
+
var Collections = class {
|
|
23
|
+
#sources;
|
|
24
|
+
#context;
|
|
25
|
+
#loaded = /* @__PURE__ */ new Map();
|
|
26
|
+
#bundled;
|
|
27
|
+
/**
|
|
28
|
+
* @param sources - Configured icon sets keyed by set prefix.
|
|
29
|
+
* @param context - Project directory and host file operations.
|
|
30
|
+
*/
|
|
31
|
+
constructor(sources, context) {
|
|
32
|
+
this.#sources = sources;
|
|
33
|
+
this.#context = context;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns one icon set.
|
|
37
|
+
*
|
|
38
|
+
* @param prefix - Icon set prefix, such as `mdi`.
|
|
39
|
+
* @returns The icon set data, or undefined when no source provides the set.
|
|
40
|
+
* @throws If a configured source fails or a JSON file cannot be read or parsed.
|
|
41
|
+
*/
|
|
42
|
+
async get(prefix) {
|
|
43
|
+
let loaded = this.#loaded.get(prefix);
|
|
44
|
+
if (!loaded) {
|
|
45
|
+
loaded = this.#load(prefix);
|
|
46
|
+
this.#loaded.set(prefix, loaded);
|
|
47
|
+
}
|
|
48
|
+
const { data, file, infoFile } = await loaded;
|
|
49
|
+
if (infoFile) this.#context.watch(infoFile);
|
|
50
|
+
if (file) this.#context.watch(file);
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Lists the set prefixes whose icons editors always complete: the configured sets and the
|
|
55
|
+
* `@iconify-json/*` packages in the dependencies of the project's `package.json`. The sets of the
|
|
56
|
+
* `@iconify/json` package are omitted, because that package contains every Iconify set.
|
|
57
|
+
*
|
|
58
|
+
* @returns Set prefixes without duplicates.
|
|
59
|
+
*/
|
|
60
|
+
async prefixes() {
|
|
61
|
+
const prefixes = new Set(Object.keys(this.#sources));
|
|
62
|
+
const manifest = `${this.#context.root.replace(/[\\/]$/, "")}/package.json`;
|
|
63
|
+
this.#context.watch(manifest);
|
|
64
|
+
let json;
|
|
65
|
+
try {
|
|
66
|
+
json = JSON.parse(await this.#context.read(manifest));
|
|
67
|
+
} catch {
|
|
68
|
+
return [...prefixes];
|
|
69
|
+
}
|
|
70
|
+
for (const field of [
|
|
71
|
+
"dependencies",
|
|
72
|
+
"devDependencies",
|
|
73
|
+
"optionalDependencies"
|
|
74
|
+
]) for (const name of Object.keys(json[field] ?? {})) if (name.startsWith("@iconify-json/")) prefixes.add(name.slice(14));
|
|
75
|
+
return [...prefixes];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Lists the set prefixes of the `@iconify/json` package from its `collections.json` file, and
|
|
79
|
+
* registers that file with the host.
|
|
80
|
+
*
|
|
81
|
+
* @returns Set prefixes, or an empty array when the package is not installed or its file cannot
|
|
82
|
+
* be read.
|
|
83
|
+
*/
|
|
84
|
+
bundledPrefixes() {
|
|
85
|
+
this.#bundled ??= (async () => {
|
|
86
|
+
const file = await this.#context.resolve("@iconify/json/collections.json");
|
|
87
|
+
if (!file) return [];
|
|
88
|
+
this.#context.watch(file);
|
|
89
|
+
try {
|
|
90
|
+
return Object.keys(JSON.parse(await this.#context.read(file)));
|
|
91
|
+
} catch {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
return this.#bundled;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Loads one icon set from the first source that provides it.
|
|
99
|
+
*
|
|
100
|
+
* @param prefix - Icon set prefix.
|
|
101
|
+
* @returns The icon set and its file, or an empty result when no source provides the set.
|
|
102
|
+
* @throws If a configured source fails or a JSON file cannot be read or parsed.
|
|
103
|
+
*/
|
|
104
|
+
async #load(prefix) {
|
|
105
|
+
const source = Object.hasOwn(this.#sources, prefix) ? this.#sources[prefix] : void 0;
|
|
106
|
+
if (typeof source === "function") {
|
|
107
|
+
const context = this.#context;
|
|
108
|
+
return { data: await source({
|
|
109
|
+
prefix,
|
|
110
|
+
root: context.root,
|
|
111
|
+
watch: (path, kind) => context.watch(path, kind),
|
|
112
|
+
read: (path) => context.read(path),
|
|
113
|
+
list: (path) => context.list(path)
|
|
114
|
+
}) };
|
|
115
|
+
}
|
|
116
|
+
if (typeof source === "string") return {
|
|
117
|
+
data: await this.#read(source),
|
|
118
|
+
file: source
|
|
119
|
+
};
|
|
120
|
+
if (source) return { data: source };
|
|
121
|
+
if (/[/\\]|^\.*$/.test(prefix)) return {};
|
|
122
|
+
for (const request of [`@iconify-json/${prefix}/icons.json`, `@iconify/json/json/${prefix}.json`]) {
|
|
123
|
+
const file = await this.#context.resolve(request);
|
|
124
|
+
if (file) {
|
|
125
|
+
const data = await this.#read(file);
|
|
126
|
+
const infoFile = request.startsWith("@iconify-json/") ? await this.#context.resolve(`@iconify-json/${prefix}/info.json`) : void 0;
|
|
127
|
+
const info = infoFile ? JSON.parse(await this.#context.read(infoFile)) : data.info;
|
|
128
|
+
return {
|
|
129
|
+
data: info ? {
|
|
130
|
+
...data,
|
|
131
|
+
info
|
|
132
|
+
} : data,
|
|
133
|
+
file,
|
|
134
|
+
infoFile
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Reads and parses an icon set JSON file, reusing earlier data for unchanged text.
|
|
142
|
+
*
|
|
143
|
+
* @param file - Absolute file path.
|
|
144
|
+
* @returns The parsed icon set.
|
|
145
|
+
* @throws If reading or parsing fails.
|
|
146
|
+
*/
|
|
147
|
+
async #read(file) {
|
|
148
|
+
const text = await this.#context.read(file);
|
|
149
|
+
const cached = parsed.get(file);
|
|
150
|
+
if (cached?.text === text) return cached.data;
|
|
151
|
+
const data = JSON.parse(text);
|
|
152
|
+
parsed.set(file, {
|
|
153
|
+
text,
|
|
154
|
+
data
|
|
155
|
+
});
|
|
156
|
+
return data;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
// src/license.ts
|
|
160
|
+
/**
|
|
161
|
+
* Formats the supplied set information as a preserved CSS notice.
|
|
162
|
+
*
|
|
163
|
+
* @param info - Metadata of the same source that supplied the SVG, or undefined.
|
|
164
|
+
* @returns A banner declaration, or an empty string when no information was provided.
|
|
165
|
+
* @throws If supplied metadata lacks a set name, author, or license title.
|
|
166
|
+
*/
|
|
167
|
+
function iconLicense(info) {
|
|
168
|
+
if (!info) return "";
|
|
169
|
+
if (typeof info.name !== "string" || !info.name.trim() || typeof info.author?.name !== "string" || !info.author.name.trim() || typeof info.license?.title !== "string" || !info.license.title.trim()) throw new Error("Iconify metadata requires a set name, author, and license title");
|
|
170
|
+
const { author, license } = info;
|
|
171
|
+
for (const value of [
|
|
172
|
+
author.url,
|
|
173
|
+
license.spdx,
|
|
174
|
+
license.url
|
|
175
|
+
]) if (value !== void 0 && typeof value !== "string") throw new Error("Iconify author and license metadata must contain strings");
|
|
176
|
+
return ` @stillwind-banner { /*! ${[
|
|
177
|
+
info.name,
|
|
178
|
+
author.name,
|
|
179
|
+
author.url,
|
|
180
|
+
license.title,
|
|
181
|
+
license.spdx && license.spdx !== license.title ? license.spdx : void 0,
|
|
182
|
+
license.url
|
|
183
|
+
].filter((value) => Boolean(value)).join(" | ").replaceAll("*/", "* /")} */ }`;
|
|
184
|
+
}
|
|
185
|
+
// src/icons.ts
|
|
186
|
+
/**
|
|
187
|
+
* Custom property that sets the height of an icon box. Size utilities set it, and icon
|
|
188
|
+
* utilities fall back to {@link IconStyle["scale"]} when it has no value.
|
|
189
|
+
*/
|
|
190
|
+
const ICON_SIZE = "--sw-icon-size";
|
|
191
|
+
/** SVGO configuration that the `svgo` option selects when it is true or omitted. */
|
|
192
|
+
const DEFAULT_SVGO = { multipass: true };
|
|
193
|
+
/**
|
|
194
|
+
* Generates the Stillwind CSS of one icon utility.
|
|
195
|
+
*
|
|
196
|
+
* @param utility - Utility name, such as `icon-mdi--close` or `icon-[mdi--close]`.
|
|
197
|
+
* @param collection - Icon set that contains the icon.
|
|
198
|
+
* @param name - Icon name or alias in the set.
|
|
199
|
+
* @param style - Size, paint method, and SVG minification.
|
|
200
|
+
* @returns CSS for the icon and its resources, or undefined when the set has no such icon.
|
|
201
|
+
* @throws If SVGO fails to optimize the icon's SVG.
|
|
202
|
+
*/
|
|
203
|
+
function iconCss(utility, collection, name, style) {
|
|
204
|
+
const data = getIconData(collection, name);
|
|
205
|
+
if (!data) return;
|
|
206
|
+
const svg = iconToSVG(data, { height: "auto" });
|
|
207
|
+
const [, , width, height] = svg.viewBox;
|
|
208
|
+
const html = iconToHTML(svg.body, svg.attributes);
|
|
209
|
+
const url = svgToURL(style.svgo ? optimize(html, style.svgo).data : html);
|
|
210
|
+
const notice = iconLicense(collection.info);
|
|
211
|
+
const asset = assetName(notice ? `${url}\0${notice}` : url, style.hashLength);
|
|
212
|
+
const paint = style.mode === "mask" || style.mode === "auto" && svg.body.includes("currentColor") ? [
|
|
213
|
+
"background-color: currentColor;",
|
|
214
|
+
"background-image: none;",
|
|
215
|
+
`mask-image: var(${asset});`,
|
|
216
|
+
"mask-size: 100% 100%;",
|
|
217
|
+
"mask-repeat: no-repeat;"
|
|
218
|
+
] : [
|
|
219
|
+
"background-color: transparent;",
|
|
220
|
+
`background-image: var(${asset});`,
|
|
221
|
+
"background-size: 100% 100%;",
|
|
222
|
+
"background-repeat: no-repeat;",
|
|
223
|
+
"mask-image: none;"
|
|
224
|
+
];
|
|
225
|
+
return [
|
|
226
|
+
`@theme default asset {`,
|
|
227
|
+
...notice ? [notice] : [],
|
|
228
|
+
` ${asset}: ${url};`,
|
|
229
|
+
`}`,
|
|
230
|
+
`@utility ${utility} (implementation) {`,
|
|
231
|
+
` display: inline-block;`,
|
|
232
|
+
` width: max-content;`,
|
|
233
|
+
` height: var(${ICON_SIZE}, ${em(style.scale)});`,
|
|
234
|
+
` aspect-ratio: ${decimal(width)} / ${decimal(height)};`,
|
|
235
|
+
...paint.map((declaration) => ` ${declaration}`),
|
|
236
|
+
`}`,
|
|
237
|
+
``
|
|
238
|
+
].join("\n");
|
|
239
|
+
}
|
|
240
|
+
function assetName(content, length) {
|
|
241
|
+
let hash = 2166136261;
|
|
242
|
+
for (let index = 0; index < content.length; index++) hash = Math.imul(hash ^ content.charCodeAt(index), 16777619);
|
|
243
|
+
return `--sw-icon-svg-${(hash >>> 0).toString(36).padStart(length, "0").slice(-length)}`;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Formats a length in `em` with at most four fractional digits.
|
|
247
|
+
*
|
|
248
|
+
* @param value - Finite length.
|
|
249
|
+
* @returns CSS length text.
|
|
250
|
+
*/
|
|
251
|
+
function em(value) {
|
|
252
|
+
return `${decimal(value)}em`;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Formats a number with at most four fractional digits.
|
|
256
|
+
*
|
|
257
|
+
* @param value - Finite number.
|
|
258
|
+
* @returns CSS number text.
|
|
259
|
+
*/
|
|
260
|
+
function decimal(value) {
|
|
261
|
+
return `${Math.round(value * 1e4) / 1e4}`;
|
|
262
|
+
}
|
|
263
|
+
// src/plugin.ts
|
|
264
|
+
/** Iconify set prefixes and icon names: lowercase words joined by single hyphens. */
|
|
265
|
+
const ICONIFY_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
266
|
+
/** Utility prefixes, which must start a CSS identifier and must not contain `--`. */
|
|
267
|
+
const PREFIX = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
268
|
+
const SYNTAXES = [
|
|
269
|
+
"both",
|
|
270
|
+
"named",
|
|
271
|
+
"bracket"
|
|
272
|
+
];
|
|
273
|
+
const MODES = [
|
|
274
|
+
"auto",
|
|
275
|
+
"mask",
|
|
276
|
+
"background"
|
|
277
|
+
];
|
|
278
|
+
/**
|
|
279
|
+
* CSS that every statement shares. The registration keeps an element's icon size from
|
|
280
|
+
* reaching its descendants and its `::before` and `::after` boxes, so each icon box sets
|
|
281
|
+
* its own size.
|
|
282
|
+
*/
|
|
283
|
+
const SIZE_CSS = [
|
|
284
|
+
"@stillwind-theme-namespace --icon-size-* [length] [percentage];",
|
|
285
|
+
`@stillwind-property ${ICON_SIZE} {`,
|
|
286
|
+
" activation: declared;",
|
|
287
|
+
" value-for: height;",
|
|
288
|
+
" syntax: \"*\";",
|
|
289
|
+
" inherits: false;",
|
|
290
|
+
"}"
|
|
291
|
+
].join("\n");
|
|
292
|
+
/**
|
|
293
|
+
* Creates an Iconify plugin with custom defaults or icon sets.
|
|
294
|
+
*
|
|
295
|
+
* Enable it in your stylesheet with `@plugin "@stillwind/plugin-iconify";`.
|
|
296
|
+
*
|
|
297
|
+
* @param options - Default settings and configured icon sets.
|
|
298
|
+
* @returns The plugin to add to your project's `plugins` list.
|
|
299
|
+
* @throws If `prefix`, `syntax`, `scale`, `mode`, `hashLength`, or `svgo` is invalid.
|
|
300
|
+
*/
|
|
301
|
+
function iconify(options = {}) {
|
|
302
|
+
const defaults = settings(options);
|
|
303
|
+
const statements = /* @__PURE__ */ new WeakMap();
|
|
304
|
+
/**
|
|
305
|
+
* Returns the icon sets of one statement.
|
|
306
|
+
* @param context - Statement context. The host keeps it for the lifetime of the loaded statement.
|
|
307
|
+
* @returns The statement's icon set cache.
|
|
308
|
+
*/
|
|
309
|
+
const collections = (context) => {
|
|
310
|
+
let found = statements.get(context);
|
|
311
|
+
if (!found) {
|
|
312
|
+
found = new Collections(options.collections ?? {}, context);
|
|
313
|
+
statements.set(context, found);
|
|
314
|
+
}
|
|
315
|
+
return found;
|
|
316
|
+
};
|
|
317
|
+
return {
|
|
318
|
+
name: "@stillwind/plugin-iconify",
|
|
319
|
+
css(context) {
|
|
320
|
+
const { prefix, syntax } = statementSettings(defaults, context);
|
|
321
|
+
return [
|
|
322
|
+
SIZE_CSS,
|
|
323
|
+
`@utility ${prefix}-full {`,
|
|
324
|
+
` ${ICON_SIZE}: 100%;`,
|
|
325
|
+
`}`,
|
|
326
|
+
`@utility ${prefix}-* {`,
|
|
327
|
+
` ${ICON_SIZE}: --value(--icon-size-*, [length], [percentage]);`,
|
|
328
|
+
`}`,
|
|
329
|
+
...syntax !== "bracket" ? [`@stillwind-dynamic ${prefix}-*;`] : [],
|
|
330
|
+
...syntax !== "named" ? [`@stillwind-dynamic ${prefix}-[*];`] : [],
|
|
331
|
+
""
|
|
332
|
+
].join("\n");
|
|
333
|
+
},
|
|
334
|
+
async resolve(candidates, context) {
|
|
335
|
+
const current = statementSettings(defaults, context);
|
|
336
|
+
return (await Promise.all(candidates.map(async (candidate) => {
|
|
337
|
+
const icon = parseCandidate(candidate, current);
|
|
338
|
+
const collection = icon && await collections(context).get(icon.set);
|
|
339
|
+
return collection ? iconCss(candidate, collection, icon.name, current) : void 0;
|
|
340
|
+
}))).filter((rule) => rule !== void 0).join("");
|
|
341
|
+
},
|
|
342
|
+
async catalog(context, input = "") {
|
|
343
|
+
const { prefix, syntax } = statementSettings(defaults, context);
|
|
344
|
+
const store = collections(context);
|
|
345
|
+
const bracket = syntax === "bracket" || syntax === "both" && input.startsWith(`${prefix}-[`);
|
|
346
|
+
const spell = (set, name) => bracket ? `${prefix}-[${set}--${name}]` : `${prefix}-${set}--${name}`;
|
|
347
|
+
const listed = await store.prefixes();
|
|
348
|
+
const sets = new Set(listed);
|
|
349
|
+
const typed = typedSet(input, prefix);
|
|
350
|
+
if (typed && !sets.has(typed) && await store.get(typed)) sets.add(typed);
|
|
351
|
+
const names = (await Promise.all([...sets].map(async (set) => {
|
|
352
|
+
const collection = await store.get(set);
|
|
353
|
+
return collection ? [...Object.keys(collection.icons), ...Object.keys(collection.aliases ?? {})].map((name) => spell(set, name)) : [];
|
|
354
|
+
}))).flat();
|
|
355
|
+
if (!typed && input && (`${prefix}-`.startsWith(input) || input.startsWith(`${prefix}-`))) {
|
|
356
|
+
for (const set of await store.bundledPrefixes()) if (!sets.has(set)) names.push(bracket ? `${prefix}-[${set}--` : `${prefix}-${set}--`);
|
|
357
|
+
}
|
|
358
|
+
return names;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Returns the icon set that an editor input names.
|
|
364
|
+
*
|
|
365
|
+
* @param input - Utility text before the cursor, such as `icon-mdi--cl` or `icon-[mdi--`.
|
|
366
|
+
* @param prefix - Utility prefix without the trailing hyphen.
|
|
367
|
+
* @returns The set prefix, or undefined when the input does not contain `<prefix>-<set>--`.
|
|
368
|
+
*/
|
|
369
|
+
function typedSet(input, prefix) {
|
|
370
|
+
if (!input.startsWith(`${prefix}-`)) return;
|
|
371
|
+
let rest = input.slice(prefix.length + 1);
|
|
372
|
+
if (rest.startsWith("[")) rest = rest.slice(1);
|
|
373
|
+
const separator = rest.indexOf("--");
|
|
374
|
+
const set = rest.slice(0, separator);
|
|
375
|
+
return separator > 0 && ICONIFY_NAME.test(set) ? set : void 0;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Splits a candidate into its icon set and icon name.
|
|
379
|
+
*
|
|
380
|
+
* @param candidate - Utility name, such as `icon-mdi--close` or `icon-[mdi--close]`.
|
|
381
|
+
* @param settings - Prefix and the spellings that select an icon.
|
|
382
|
+
* @returns The set and icon names, or undefined when the candidate does not name an icon in
|
|
383
|
+
* an accepted spelling.
|
|
384
|
+
*/
|
|
385
|
+
function parseCandidate(candidate, { prefix, syntax }) {
|
|
386
|
+
if (!candidate.startsWith(`${prefix}-`)) return;
|
|
387
|
+
let rest = candidate.slice(prefix.length + 1);
|
|
388
|
+
const bracket = rest.startsWith("[") && rest.endsWith("]");
|
|
389
|
+
if (bracket ? syntax === "named" : syntax === "bracket") return;
|
|
390
|
+
if (bracket) rest = rest.slice(1, -1);
|
|
391
|
+
const separator = rest.indexOf("--");
|
|
392
|
+
const set = rest.slice(0, separator);
|
|
393
|
+
const name = rest.slice(separator + 2);
|
|
394
|
+
return separator > 0 && ICONIFY_NAME.test(set) && ICONIFY_NAME.test(name) ? {
|
|
395
|
+
set,
|
|
396
|
+
name
|
|
397
|
+
} : void 0;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Applies a statement's options block to the plugin's defaults.
|
|
401
|
+
*
|
|
402
|
+
* @param defaults - Settings of the plugin instance.
|
|
403
|
+
* @param context - Statement whose options replace the defaults.
|
|
404
|
+
* @returns The settings of the statement.
|
|
405
|
+
* @throws If an option value is invalid.
|
|
406
|
+
*/
|
|
407
|
+
function statementSettings(defaults, context) {
|
|
408
|
+
const { prefix, syntax, scale, mode } = context.options;
|
|
409
|
+
const hashLength = context.options["hash-length"];
|
|
410
|
+
return settings({
|
|
411
|
+
prefix: prefix ?? defaults.prefix,
|
|
412
|
+
syntax: syntax ?? defaults.syntax,
|
|
413
|
+
scale: scale === void 0 ? defaults.scale : Number(scale),
|
|
414
|
+
mode: mode ?? defaults.mode,
|
|
415
|
+
hashLength: hashLength === void 0 ? defaults.hashLength : Number(hashLength),
|
|
416
|
+
svgo: defaults.svgo
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Validates options and fills in defaults.
|
|
421
|
+
*
|
|
422
|
+
* @param options - Options that may omit settings.
|
|
423
|
+
* @returns Complete settings.
|
|
424
|
+
* @throws If the prefix is not a lowercase identifier, the syntax or mode is unknown, or the
|
|
425
|
+
* scale is not a positive finite number, the hash length is not an integer from 1 to 7, or
|
|
426
|
+
* `svgo` is neither a boolean nor an object.
|
|
427
|
+
*/
|
|
428
|
+
function settings(options) {
|
|
429
|
+
const { prefix = "icon", syntax = "both", scale = 1, mode = "auto", hashLength = 4, svgo = true } = options;
|
|
430
|
+
if (!PREFIX.test(prefix)) throw new Error(`Invalid Iconify utility prefix: ${prefix}`);
|
|
431
|
+
if (!SYNTAXES.includes(syntax)) throw new Error(`Iconify syntax must be one of ${SYNTAXES.join(", ")}: ${syntax}`);
|
|
432
|
+
if (!Number.isFinite(scale) || scale <= 0) throw new Error(`Iconify scale must be a positive number: ${scale}`);
|
|
433
|
+
if (!MODES.includes(mode)) throw new Error(`Iconify mode must be one of ${MODES.join(", ")}: ${mode}`);
|
|
434
|
+
if (!Number.isInteger(hashLength) || hashLength < 1 || hashLength > 7) throw new Error(`Iconify hash length must be an integer from 1 to 7: ${hashLength}`);
|
|
435
|
+
if (typeof svgo !== "boolean" && (typeof svgo !== "object" || svgo === null)) throw new Error(`Iconify svgo must be a boolean or an SVGO configuration: ${String(svgo)}`);
|
|
436
|
+
return {
|
|
437
|
+
prefix,
|
|
438
|
+
syntax,
|
|
439
|
+
scale,
|
|
440
|
+
mode,
|
|
441
|
+
hashLength,
|
|
442
|
+
svgo: svgo === true ? DEFAULT_SVGO : svgo
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
/** The plugin with default options, which `@plugin "@stillwind/plugin-iconify";` loads. */
|
|
446
|
+
const defaultPlugin = iconify();
|
|
447
|
+
// src/directory.ts
|
|
448
|
+
/**
|
|
449
|
+
* Creates an icon set from the SVG files in a directory. Each file becomes one icon, and its
|
|
450
|
+
* `viewBox` sets the icon's dimensions. The set watches the directory and its files, so adding,
|
|
451
|
+
* removing, or editing an SVG file reloads the design system.
|
|
452
|
+
*
|
|
453
|
+
* @param directory - Absolute directory path, or a path relative to the project directory.
|
|
454
|
+
* @param options - Settings for reading SVGs and describing the set.
|
|
455
|
+
* @returns A source for the `collections` option of `iconify`.
|
|
456
|
+
*/
|
|
457
|
+
function svgDirectory(directory, options = {}) {
|
|
458
|
+
return async (context) => {
|
|
459
|
+
const files = await svgFiles(context, absolute(context.root, directory), "", options);
|
|
460
|
+
const icons = {};
|
|
461
|
+
const owners = /* @__PURE__ */ new Map();
|
|
462
|
+
for (const { file, path } of files) {
|
|
463
|
+
const name = options.name ? options.name(path) : path.replaceAll("/", "-");
|
|
464
|
+
if (name === void 0) continue;
|
|
465
|
+
if (!ICONIFY_NAME.test(name)) throw new Error(`SVG icon ${file} has the invalid icon name "${name}". Icon names must consist of lowercase letters and digits separated by single hyphens. Use the name option to rename the file's icon.`);
|
|
466
|
+
const owner = owners.get(name);
|
|
467
|
+
if (owner !== void 0) throw new Error(`SVG icons ${owner} and ${file} have the same icon name "${name}"`);
|
|
468
|
+
owners.set(name, file);
|
|
469
|
+
context.watch(file);
|
|
470
|
+
let svg = await context.read(file);
|
|
471
|
+
if (options.transform) svg = await options.transform(svg, name);
|
|
472
|
+
const parsed = parseSVGContent(svg);
|
|
473
|
+
const icon = parsed && convertParsedSVG(parsed);
|
|
474
|
+
if (!icon) throw new Error(`SVG icon ${file} must be an <svg> element with a viewBox attribute`);
|
|
475
|
+
icons[name] = icon;
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
prefix: context.prefix,
|
|
479
|
+
icons,
|
|
480
|
+
...options.info ? { info: options.info } : {}
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Lists the SVG files of a directory and watches each directory that it lists.
|
|
486
|
+
*
|
|
487
|
+
* @param context - Host operations of the icon set.
|
|
488
|
+
* @param directory - Absolute directory path.
|
|
489
|
+
* @param prefix - Relative path of `directory` with a trailing `/`, or an empty string for the
|
|
490
|
+
* top directory.
|
|
491
|
+
* @param options - Whether subdirectories are read.
|
|
492
|
+
* @returns Files in name order, with their relative paths without the `.svg` extension.
|
|
493
|
+
* @throws If a directory cannot be listed.
|
|
494
|
+
*/
|
|
495
|
+
async function svgFiles(context, directory, prefix, options) {
|
|
496
|
+
context.watch(directory, "directory");
|
|
497
|
+
const entries = [...await context.list(directory)].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
498
|
+
const files = [];
|
|
499
|
+
for (const entry of entries) {
|
|
500
|
+
const file = join(directory, entry.name);
|
|
501
|
+
if (entry.directory) {
|
|
502
|
+
if (options.recursive) files.push(...await svgFiles(context, file, `${prefix}${entry.name}/`, options));
|
|
503
|
+
} else if (/\.svg$/i.test(entry.name)) files.push({
|
|
504
|
+
file,
|
|
505
|
+
path: prefix + entry.name.slice(0, -4)
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
return files;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Resolves a directory against the project directory. The result keeps the separator style of
|
|
512
|
+
* the project directory, because hosts compare watched paths with the paths that their file
|
|
513
|
+
* watchers report.
|
|
514
|
+
*
|
|
515
|
+
* @param root - Absolute project directory.
|
|
516
|
+
* @param directory - Absolute path, or a path relative to `root`.
|
|
517
|
+
* @returns The absolute directory path.
|
|
518
|
+
*/
|
|
519
|
+
function absolute(root, directory) {
|
|
520
|
+
if (/^(?:[A-Za-z]:)?[\\/]/.test(directory)) return directory;
|
|
521
|
+
let path = root;
|
|
522
|
+
for (const segment of directory.split(/[\\/]/)) if (segment === "..") path = path.replace(/[\\/][^\\/]*$/, "");
|
|
523
|
+
else if (segment && segment !== ".") path = join(path, segment);
|
|
524
|
+
return path;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Appends one entry name to a directory path with the directory's separator style.
|
|
528
|
+
*
|
|
529
|
+
* @param directory - Absolute directory path.
|
|
530
|
+
* @param name - Entry name without separators.
|
|
531
|
+
* @returns The entry path.
|
|
532
|
+
*/
|
|
533
|
+
function join(directory, name) {
|
|
534
|
+
const separator = directory.includes("\\") ? "\\" : "/";
|
|
535
|
+
return directory.endsWith(separator) ? directory + name : directory + separator + name;
|
|
536
|
+
}
|
|
537
|
+
export { defaultPlugin as default, iconify, svgDirectory };
|
|
538
|
+
|
|
539
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/collections.ts","../src/license.ts","../src/icons.ts","../src/plugin.ts","../src/directory.ts"],"sourcesContent":["import type { IconifyJSON } from \"@iconify/types\";\nimport type { PluginContext } from \"@stillwind/config\";\n\n/**\n * A custom icon set: Iconify data, an absolute JSON file path, or a function that\n * returns Iconify data synchronously or asynchronously.\n */\nexport type CollectionSource =\n | IconifyJSON\n | string\n | ((context: CollectionLoadContext) => IconifyJSON | Promise<IconifyJSON>);\n\n/**\n * Set name and host operations that a function source receives. A function source watches\n * each file and directory that it reads, so that a change reloads the design system.\n */\nexport interface CollectionLoadContext extends Pick<\n PluginContext,\n \"root\" | \"watch\" | \"read\" | \"list\"\n> {\n /** Set name that selects the source in `collections`, such as `brand`. */\n readonly prefix: string;\n}\n\n/** Host operations that icon set lookup uses. */\nexport type CollectionContext = Pick<PluginContext, \"root\" | \"watch\" | \"resolve\" | \"read\" | \"list\">;\n\n/** Icon set data and the file that it comes from. */\ninterface LoadedCollection {\n /** Icon set data, or undefined when no source provides the set. */\n data?: IconifyJSON;\n /** Absolute path of the JSON file, or undefined for data that options supply. */\n file?: string;\n /** Metadata file of an individual icon package. */\n infoFile?: string;\n}\n\n/**\n * Parsed icon sets keyed by file path, with the text that they were parsed from. Statements of\n * later loads reuse the data while the text is unchanged, because large sets take long to parse.\n */\nconst parsed = new Map<\n string,\n {\n /** Text of the file when it was parsed. */\n text: string;\n /** Parsed icon set. */\n data: IconifyJSON;\n }\n>();\n\n/**\n * Finds and caches the icon sets of one loaded `@plugin` statement.\n *\n * A set comes from the first source that provides it: the configured sources, then the\n * `@iconify-json/<set>` package, then the `@iconify/json` package. Packages are resolved by the\n * host from the stylesheet that contains the statement. Each lookup registers the set's file with\n * the host, so a changed file reloads the design system, and the new statement context reads the\n * file again.\n */\nexport class Collections {\n readonly #sources: Readonly<Record<string, CollectionSource>>;\n readonly #context: CollectionContext;\n readonly #loaded = new Map<string, Promise<LoadedCollection>>();\n #bundled?: Promise<string[]>;\n\n /**\n * @param sources - Configured icon sets keyed by set prefix.\n * @param context - Project directory and host file operations.\n */\n constructor(sources: Readonly<Record<string, CollectionSource>>, context: CollectionContext) {\n this.#sources = sources;\n this.#context = context;\n }\n\n /**\n * Returns one icon set.\n *\n * @param prefix - Icon set prefix, such as `mdi`.\n * @returns The icon set data, or undefined when no source provides the set.\n * @throws If a configured source fails or a JSON file cannot be read or parsed.\n */\n async get(prefix: string): Promise<IconifyJSON | undefined> {\n let loaded = this.#loaded.get(prefix);\n if (!loaded) {\n loaded = this.#load(prefix);\n this.#loaded.set(prefix, loaded);\n }\n const { data, file, infoFile } = await loaded;\n if (infoFile) {\n this.#context.watch(infoFile);\n }\n if (file) {\n this.#context.watch(file);\n }\n return data;\n }\n\n /**\n * Lists the set prefixes whose icons editors always complete: the configured sets and the\n * `@iconify-json/*` packages in the dependencies of the project's `package.json`. The sets of the\n * `@iconify/json` package are omitted, because that package contains every Iconify set.\n *\n * @returns Set prefixes without duplicates.\n */\n async prefixes(): Promise<string[]> {\n const prefixes = new Set(Object.keys(this.#sources));\n const manifest = `${this.#context.root.replace(/[\\\\/]$/, \"\")}/package.json`;\n this.#context.watch(manifest);\n let json: Record<string, Record<string, string> | undefined>;\n try {\n json = JSON.parse(await this.#context.read(manifest));\n } catch {\n // A project without a readable manifest lists only the configured sets.\n return [...prefixes];\n }\n for (const field of [\"dependencies\", \"devDependencies\", \"optionalDependencies\"]) {\n for (const name of Object.keys(json[field] ?? {})) {\n if (name.startsWith(\"@iconify-json/\")) {\n prefixes.add(name.slice(\"@iconify-json/\".length));\n }\n }\n }\n return [...prefixes];\n }\n\n /**\n * Lists the set prefixes of the `@iconify/json` package from its `collections.json` file, and\n * registers that file with the host.\n *\n * @returns Set prefixes, or an empty array when the package is not installed or its file cannot\n * be read.\n */\n bundledPrefixes(): Promise<string[]> {\n this.#bundled ??= (async () => {\n const file = await this.#context.resolve(\"@iconify/json/collections.json\");\n if (!file) {\n return [];\n }\n this.#context.watch(file);\n try {\n return Object.keys(JSON.parse(await this.#context.read(file)) as Record<string, unknown>);\n } catch {\n // An unreadable list leaves completion with the sets from other sources.\n return [];\n }\n })();\n return this.#bundled;\n }\n\n /**\n * Loads one icon set from the first source that provides it.\n *\n * @param prefix - Icon set prefix.\n * @returns The icon set and its file, or an empty result when no source provides the set.\n * @throws If a configured source fails or a JSON file cannot be read or parsed.\n */\n async #load(prefix: string): Promise<LoadedCollection> {\n const source = Object.hasOwn(this.#sources, prefix) ? this.#sources[prefix] : undefined;\n if (typeof source === \"function\") {\n const context = this.#context;\n return {\n data: await source({\n prefix,\n root: context.root,\n watch: (path, kind) => context.watch(path, kind),\n read: (path) => context.read(path),\n list: (path) => context.list(path),\n }),\n };\n }\n if (typeof source === \"string\") {\n return {\n data: await this.#read(source),\n file: source,\n };\n }\n if (source) {\n return {\n data: source,\n };\n }\n\n if (/[/\\\\]|^\\.*$/.test(prefix)) {\n return {};\n }\n\n for (const request of [\n `@iconify-json/${prefix}/icons.json`,\n `@iconify/json/json/${prefix}.json`,\n ]) {\n const file = await this.#context.resolve(request);\n if (file) {\n const data = await this.#read(file);\n const infoFile = request.startsWith(\"@iconify-json/\")\n ? await this.#context.resolve(`@iconify-json/${prefix}/info.json`)\n : undefined;\n const info = infoFile ? JSON.parse(await this.#context.read(infoFile)) : data.info;\n return {\n data: info\n ? {\n ...data,\n info,\n }\n : data,\n file,\n infoFile,\n };\n }\n }\n\n return {};\n }\n\n /**\n * Reads and parses an icon set JSON file, reusing earlier data for unchanged text.\n *\n * @param file - Absolute file path.\n * @returns The parsed icon set.\n * @throws If reading or parsing fails.\n */\n async #read(file: string): Promise<IconifyJSON> {\n const text = await this.#context.read(file);\n const cached = parsed.get(file);\n if (cached?.text === text) {\n return cached.data;\n }\n const data = JSON.parse(text) as IconifyJSON;\n parsed.set(file, {\n text,\n data,\n });\n return data;\n }\n}\n","import type { IconifyInfo } from \"@iconify/types\";\n\n/**\n * Formats the supplied set information as a preserved CSS notice.\n *\n * @param info - Metadata of the same source that supplied the SVG, or undefined.\n * @returns A banner declaration, or an empty string when no information was provided.\n * @throws If supplied metadata lacks a set name, author, or license title.\n */\nexport function iconLicense(info: IconifyInfo | undefined): string {\n if (!info) {\n return \"\";\n }\n\n if (\n typeof info.name !== \"string\" ||\n !info.name.trim() ||\n typeof info.author?.name !== \"string\" ||\n !info.author.name.trim() ||\n typeof info.license?.title !== \"string\" ||\n !info.license.title.trim()\n ) {\n throw new Error(\"Iconify metadata requires a set name, author, and license title\");\n }\n\n const { author, license } = info;\n for (const value of [author.url, license.spdx, license.url]) {\n if (value !== undefined && typeof value !== \"string\") {\n throw new Error(\"Iconify author and license metadata must contain strings\");\n }\n }\n\n const parts = [\n info.name,\n author.name,\n author.url,\n license.title,\n license.spdx && license.spdx !== license.title ? license.spdx : undefined,\n license.url,\n ].filter((value): value is string => Boolean(value));\n const text = parts.join(\" | \").replaceAll(\"*/\", \"* /\");\n return ` @stillwind-banner { /*! ${text} */ }`;\n}\n","import type { IconifyJSON } from \"@iconify/types\";\nimport { getIconData } from \"@iconify/utils/lib/icon-set/get-icon\";\nimport { iconToSVG } from \"@iconify/utils/lib/svg/build\";\nimport { iconToHTML } from \"@iconify/utils/lib/svg/html\";\nimport { svgToURL } from \"@iconify/utils/lib/svg/url\";\nimport { optimize, type Config } from \"svgo/browser\";\n\nimport { iconLicense } from \"./license.ts\";\n\n/**\n * How an icon utility paints the icon. `mask` paints the element's text color through the icon's\n * shape, and `background` paints the icon's own colors. `auto` selects `mask` for icons whose SVG\n * uses `currentColor`, and `background` for the others.\n */\nexport type IconMode = \"auto\" | \"mask\" | \"background\";\n\n/**\n * Custom property that sets the height of an icon box. Size utilities set it, and icon\n * utilities fall back to {@link IconStyle[\"scale\"]} when it has no value.\n */\nexport const ICON_SIZE = \"--sw-icon-size\";\n\n/** SVGO configuration that minifies the SVG of each icon. */\nexport type SvgoConfig = Config;\n\n/** SVGO configuration that the `svgo` option selects when it is true or omitted. */\nexport const DEFAULT_SVGO: SvgoConfig = {\n multipass: true,\n};\n\n/** Settings that apply to every icon utility of a plugin instance. */\nexport interface IconStyle {\n /** Default icon height in `em`. The width keeps the icon's aspect ratio. */\n readonly scale: number;\n /** Paint method of the icons. */\n readonly mode: IconMode;\n /** Fixed base36 hash length, from 1 to 7 characters. */\n readonly hashLength: number;\n /** SVGO configuration that minifies each icon's SVG, or false to keep the SVG unchanged. */\n readonly svgo: SvgoConfig | false;\n}\n\n/**\n * Generates the Stillwind CSS of one icon utility.\n *\n * @param utility - Utility name, such as `icon-mdi--close` or `icon-[mdi--close]`.\n * @param collection - Icon set that contains the icon.\n * @param name - Icon name or alias in the set.\n * @param style - Size, paint method, and SVG minification.\n * @returns CSS for the icon and its resources, or undefined when the set has no such icon.\n * @throws If SVGO fails to optimize the icon's SVG.\n */\nexport function iconCss(\n utility: string,\n collection: IconifyJSON,\n name: string,\n style: IconStyle,\n): string | undefined {\n const data = getIconData(collection, name);\n if (!data) {\n return undefined;\n }\n\n const svg = iconToSVG(data, {\n height: \"auto\",\n });\n const [, , width, height] = svg.viewBox;\n const html = iconToHTML(svg.body, svg.attributes);\n const url = svgToURL(style.svgo ? optimize(html, style.svgo).data : html);\n const notice = iconLicense(collection.info);\n const asset = assetName(notice ? `${url}\\0${notice}` : url, style.hashLength);\n const mask =\n style.mode === \"mask\" || (style.mode === \"auto\" && svg.body.includes(\"currentColor\"));\n // Each mode resets the other mode's image, so a later icon utility on the same element\n // replaces the earlier icon even when their modes differ.\n const paint = mask\n ? [\n \"background-color: currentColor;\",\n \"background-image: none;\",\n `mask-image: var(${asset});`,\n \"mask-size: 100% 100%;\",\n \"mask-repeat: no-repeat;\",\n ]\n : [\n \"background-color: transparent;\",\n `background-image: var(${asset});`,\n \"background-size: 100% 100%;\",\n \"background-repeat: no-repeat;\",\n \"mask-image: none;\",\n ];\n return [\n `@theme default asset {`,\n ...(notice ? [notice] : []),\n ` ${asset}: ${url};`,\n `}`,\n `@utility ${utility} (implementation) {`,\n ` display: inline-block;`,\n // `max-content` derives the width from the height and the aspect ratio. Unlike `auto`,\n // it keeps a flex or grid container from stretching the box across its cross axis.\n ` width: max-content;`,\n ` height: var(${ICON_SIZE}, ${em(style.scale)});`,\n ` aspect-ratio: ${decimal(width)} / ${decimal(height)};`,\n ...paint.map((declaration) => ` ${declaration}`),\n `}`,\n ``,\n ].join(\"\\n\");\n}\n\nfunction assetName(content: string, length: number): string {\n let hash = 0x811c9dc5;\n for (let index = 0; index < content.length; index++) {\n hash = Math.imul(hash ^ content.charCodeAt(index), 0x01000193);\n }\n return `--sw-icon-svg-${(hash >>> 0).toString(36).padStart(length, \"0\").slice(-length)}`;\n}\n\n/**\n * Formats a length in `em` with at most four fractional digits.\n *\n * @param value - Finite length.\n * @returns CSS length text.\n */\nfunction em(value: number): string {\n return `${decimal(value)}em`;\n}\n\n/**\n * Formats a number with at most four fractional digits.\n *\n * @param value - Finite number.\n * @returns CSS number text.\n */\nfunction decimal(value: number): string {\n return `${Math.round(value * 10_000) / 10_000}`;\n}\n","import type { PluginContext, StillwindPlugin } from \"@stillwind/config\";\n\nimport { Collections, type CollectionSource } from \"./collections.ts\";\nimport {\n DEFAULT_SVGO,\n ICON_SIZE,\n iconCss,\n type IconMode,\n type IconStyle,\n type SvgoConfig,\n} from \"./icons.ts\";\n\n/**\n * Icon name formats. `named` accepts `icon-mdi--close`, `bracket` accepts\n * `icon-[mdi--close]`, and `both` accepts either format.\n */\nexport type IconSyntax = \"both\" | \"named\" | \"bracket\";\n\n/**\n * Options of {@link iconify}. The stylesheet's `@plugin` block overrides `prefix`,\n * `syntax`, `scale`, `mode`, and `hashLength` from these options.\n */\nexport interface IconifyOptions {\n /**\n * Utility prefix made of lowercase letters, digits, and single hyphens, starting\n * with a letter. Defaults to `icon`.\n */\n readonly prefix?: string;\n /** Spellings that select an icon. Defaults to `both`. */\n readonly syntax?: IconSyntax;\n /** Positive, finite icon height in `em` when no size utility applies. Defaults to `1`. */\n readonly scale?: number;\n /** Paint method of the icons. Defaults to `auto`. */\n readonly mode?: IconMode;\n /**\n * Base36 hash length in generated CSS variable names. Accepts integers from 1 to 7.\n * Defaults to `4`.\n * Set `hash-length` in the stylesheet's `@plugin` block.\n */\n readonly hashLength?: number;\n /**\n * Custom icon sets keyed by set prefix, such as `brand`. Accepts data, absolute JSON\n * file paths, or functions that return data, such as the result of `svgDirectory`. These\n * sets override installed packages.\n */\n readonly collections?: Readonly<Record<string, CollectionSource>>;\n /**\n * SVGO minification of each icon's SVG. `true` selects a multipass `preset-default`\n * configuration, an object replaces that configuration, and `false` keeps the SVG that\n * Iconify builds. Defaults to `true`.\n */\n readonly svgo?: boolean | SvgoConfig;\n}\n\n/** Settings of one `@plugin` statement. */\ninterface Settings extends IconStyle {\n /** Utility prefix without the trailing hyphen. */\n readonly prefix: string;\n /** Spellings that select an icon. */\n readonly syntax: IconSyntax;\n}\n\n/** Iconify set prefixes and icon names: lowercase words joined by single hyphens. */\nexport const ICONIFY_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n/** Utility prefixes, which must start a CSS identifier and must not contain `--`. */\nconst PREFIX = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;\n\nconst SYNTAXES: readonly IconSyntax[] = [\"both\", \"named\", \"bracket\"];\n\nconst MODES: readonly IconMode[] = [\"auto\", \"mask\", \"background\"];\n\n/**\n * CSS that every statement shares. The registration keeps an element's icon size from\n * reaching its descendants and its `::before` and `::after` boxes, so each icon box sets\n * its own size.\n */\nconst SIZE_CSS = [\n \"@stillwind-theme-namespace --icon-size-* [length] [percentage];\",\n `@stillwind-property ${ICON_SIZE} {`,\n \" activation: declared;\",\n \" value-for: height;\",\n ' syntax: \"*\";',\n \" inherits: false;\",\n \"}\",\n].join(\"\\n\");\n\n/**\n * Creates an Iconify plugin with custom defaults or icon sets.\n *\n * Enable it in your stylesheet with `@plugin \"@stillwind/plugin-iconify\";`.\n *\n * @param options - Default settings and configured icon sets.\n * @returns The plugin to add to your project's `plugins` list.\n * @throws If `prefix`, `syntax`, `scale`, `mode`, `hashLength`, or `svgo` is invalid.\n */\nexport function iconify(options: IconifyOptions = {}): StillwindPlugin {\n const defaults = settings(options);\n\n const statements = new WeakMap<PluginContext, Collections>();\n /**\n * Returns the icon sets of one statement.\n * @param context - Statement context. The host keeps it for the lifetime of the loaded statement.\n * @returns The statement's icon set cache.\n */\n const collections = (context: PluginContext) => {\n let found = statements.get(context);\n if (!found) {\n found = new Collections(options.collections ?? {}, context);\n statements.set(context, found);\n }\n return found;\n };\n\n return {\n name: \"@stillwind/plugin-iconify\",\n css(context) {\n const { prefix, syntax } = statementSettings(defaults, context);\n return [\n SIZE_CSS,\n `@utility ${prefix}-full {`,\n ` ${ICON_SIZE}: 100%;`,\n `}`,\n `@utility ${prefix}-* {`,\n ` ${ICON_SIZE}: --value(--icon-size-*, [length], [percentage]);`,\n `}`,\n ...(syntax !== \"bracket\" ? [`@stillwind-dynamic ${prefix}-*;`] : []),\n ...(syntax !== \"named\" ? [`@stillwind-dynamic ${prefix}-[*];`] : []),\n \"\",\n ].join(\"\\n\");\n },\n async resolve(candidates, context) {\n const current = statementSettings(defaults, context);\n const rules = await Promise.all(\n candidates.map(async (candidate) => {\n const icon = parseCandidate(candidate, current);\n const collection = icon && (await collections(context).get(icon.set));\n return collection ? iconCss(candidate, collection, icon.name, current) : undefined;\n }),\n );\n return rules.filter((rule) => rule !== undefined).join(\"\");\n },\n async catalog(context, input = \"\") {\n const { prefix, syntax } = statementSettings(defaults, context);\n const store = collections(context);\n const bracket =\n syntax === \"bracket\" || (syntax === \"both\" && input.startsWith(`${prefix}-[`));\n const spell = (set: string, name: string) =>\n bracket ? `${prefix}-[${set}--${name}]` : `${prefix}-${set}--${name}`;\n const listed = await store.prefixes();\n const sets = new Set(listed);\n // An input that names a set completes its icons from any source, including `@iconify/json`.\n const typed = typedSet(input, prefix);\n if (typed && !sets.has(typed) && (await store.get(typed))) {\n sets.add(typed);\n }\n const lists = await Promise.all(\n [...sets].map(async (set) => {\n const collection = await store.get(set);\n return collection\n ? [...Object.keys(collection.icons), ...Object.keys(collection.aliases ?? {})].map(\n (name) => spell(set, name),\n )\n : [];\n }),\n );\n // Before an input names a set, the `@iconify/json` sets complete as incomplete names that\n // end with `--`.\n const names = lists.flat();\n if (!typed && input && (`${prefix}-`.startsWith(input) || input.startsWith(`${prefix}-`))) {\n for (const set of await store.bundledPrefixes()) {\n if (!sets.has(set)) {\n names.push(bracket ? `${prefix}-[${set}--` : `${prefix}-${set}--`);\n }\n }\n }\n return names;\n },\n };\n}\n\n/**\n * Returns the icon set that an editor input names.\n *\n * @param input - Utility text before the cursor, such as `icon-mdi--cl` or `icon-[mdi--`.\n * @param prefix - Utility prefix without the trailing hyphen.\n * @returns The set prefix, or undefined when the input does not contain `<prefix>-<set>--`.\n */\nfunction typedSet(input: string, prefix: string): string | undefined {\n if (!input.startsWith(`${prefix}-`)) {\n return undefined;\n }\n let rest = input.slice(prefix.length + 1);\n if (rest.startsWith(\"[\")) {\n rest = rest.slice(1);\n }\n const separator = rest.indexOf(\"--\");\n const set = rest.slice(0, separator);\n return separator > 0 && ICONIFY_NAME.test(set) ? set : undefined;\n}\n\n/**\n * Splits a candidate into its icon set and icon name.\n *\n * @param candidate - Utility name, such as `icon-mdi--close` or `icon-[mdi--close]`.\n * @param settings - Prefix and the spellings that select an icon.\n * @returns The set and icon names, or undefined when the candidate does not name an icon in\n * an accepted spelling.\n */\nfunction parseCandidate(\n candidate: string,\n { prefix, syntax }: Settings,\n): { set: string; name: string } | undefined {\n if (!candidate.startsWith(`${prefix}-`)) {\n return undefined;\n }\n let rest = candidate.slice(prefix.length + 1);\n const bracket = rest.startsWith(\"[\") && rest.endsWith(\"]\");\n if (bracket ? syntax === \"named\" : syntax === \"bracket\") {\n return undefined;\n }\n if (bracket) {\n rest = rest.slice(1, -1);\n }\n const separator = rest.indexOf(\"--\");\n const set = rest.slice(0, separator);\n const name = rest.slice(separator + 2);\n return separator > 0 && ICONIFY_NAME.test(set) && ICONIFY_NAME.test(name)\n ? { set, name }\n : undefined;\n}\n\n/**\n * Applies a statement's options block to the plugin's defaults.\n *\n * @param defaults - Settings of the plugin instance.\n * @param context - Statement whose options replace the defaults.\n * @returns The settings of the statement.\n * @throws If an option value is invalid.\n */\nfunction statementSettings(defaults: Settings, context: PluginContext): Settings {\n const { prefix, syntax, scale, mode } = context.options;\n const hashLength = context.options[\"hash-length\"];\n return settings({\n prefix: prefix ?? defaults.prefix,\n syntax: (syntax ?? defaults.syntax) as IconSyntax,\n scale: scale === undefined ? defaults.scale : Number(scale),\n mode: (mode ?? defaults.mode) as IconMode,\n hashLength: hashLength === undefined ? defaults.hashLength : Number(hashLength),\n svgo: defaults.svgo,\n });\n}\n\n/**\n * Validates options and fills in defaults.\n *\n * @param options - Options that may omit settings.\n * @returns Complete settings.\n * @throws If the prefix is not a lowercase identifier, the syntax or mode is unknown, or the\n * scale is not a positive finite number, the hash length is not an integer from 1 to 7, or\n * `svgo` is neither a boolean nor an object.\n */\nfunction settings(options: IconifyOptions): Settings {\n const {\n prefix = \"icon\",\n syntax = \"both\",\n scale = 1,\n mode = \"auto\",\n hashLength = 4,\n svgo = true,\n } = options;\n\n if (!PREFIX.test(prefix)) {\n throw new Error(`Invalid Iconify utility prefix: ${prefix}`);\n }\n if (!SYNTAXES.includes(syntax)) {\n throw new Error(`Iconify syntax must be one of ${SYNTAXES.join(\", \")}: ${syntax}`);\n }\n if (!Number.isFinite(scale) || scale <= 0) {\n throw new Error(`Iconify scale must be a positive number: ${scale}`);\n }\n if (!MODES.includes(mode)) {\n throw new Error(`Iconify mode must be one of ${MODES.join(\", \")}: ${mode}`);\n }\n if (!Number.isInteger(hashLength) || hashLength < 1 || hashLength > 7) {\n throw new Error(`Iconify hash length must be an integer from 1 to 7: ${hashLength}`);\n }\n if (typeof svgo !== \"boolean\" && (typeof svgo !== \"object\" || svgo === null)) {\n throw new Error(`Iconify svgo must be a boolean or an SVGO configuration: ${String(svgo)}`);\n }\n\n return {\n prefix,\n syntax,\n scale,\n mode,\n hashLength,\n svgo: svgo === true ? DEFAULT_SVGO : svgo,\n };\n}\n\n/** The plugin with default options, which `@plugin \"@stillwind/plugin-iconify\";` loads. */\nconst defaultPlugin = iconify();\n\nexport default defaultPlugin;\n","import type { IconifyIcon, IconifyInfo, IconifyJSON } from \"@iconify/types\";\nimport { convertParsedSVG, parseSVGContent } from \"@iconify/utils/lib/svg/parse\";\n\nimport type { CollectionLoadContext, CollectionSource } from \"./collections.ts\";\nimport { ICONIFY_NAME } from \"./plugin.ts\";\n\n/**\n * Options of {@link svgDirectory}.\n */\nexport interface SvgDirectoryOptions {\n /** Set information used for the CSS attribution notice. */\n readonly info?: IconifyInfo;\n /**\n * Reads SVG files in subdirectories. The default icon name joins the path segments with `-`,\n * such as `arrows-left` for `arrows/left.svg`. Defaults to `false`.\n */\n readonly recursive?: boolean;\n /**\n * Maps a file to an icon name. The function receives the file path relative to the directory,\n * with `/` separators and without the `.svg` extension, such as `arrows/left`. Returning\n * undefined skips the file. By default, the path segments are joined with `-`.\n */\n readonly name?: (path: string) => string | undefined;\n /** Rewrites the SVG text of each file before the plugin parses it. */\n readonly transform?: (svg: string, name: string) => string | Promise<string>;\n}\n\n/**\n * Creates an icon set from the SVG files in a directory. Each file becomes one icon, and its\n * `viewBox` sets the icon's dimensions. The set watches the directory and its files, so adding,\n * removing, or editing an SVG file reloads the design system.\n *\n * @param directory - Absolute directory path, or a path relative to the project directory.\n * @param options - Settings for reading SVGs and describing the set.\n * @returns A source for the `collections` option of `iconify`.\n */\nexport function svgDirectory(\n directory: string,\n options: SvgDirectoryOptions = {},\n): CollectionSource {\n return async (context) => {\n const files = await svgFiles(context, absolute(context.root, directory), \"\", options);\n const icons: Record<string, IconifyIcon> = {};\n const owners = new Map<string, string>();\n for (const { file, path } of files) {\n const name = options.name ? options.name(path) : path.replaceAll(\"/\", \"-\");\n if (name === undefined) {\n continue;\n }\n if (!ICONIFY_NAME.test(name)) {\n throw new Error(\n `SVG icon ${file} has the invalid icon name \"${name}\". Icon names must consist of lowercase letters and digits separated by single hyphens. Use the name option to rename the file's icon.`,\n );\n }\n const owner = owners.get(name);\n if (owner !== undefined) {\n throw new Error(`SVG icons ${owner} and ${file} have the same icon name \"${name}\"`);\n }\n owners.set(name, file);\n context.watch(file);\n let svg = await context.read(file);\n if (options.transform) {\n svg = await options.transform(svg, name);\n }\n const parsed = parseSVGContent(svg);\n const icon = parsed && convertParsedSVG(parsed);\n if (!icon) {\n throw new Error(`SVG icon ${file} must be an <svg> element with a viewBox attribute`);\n }\n icons[name] = icon;\n }\n return {\n prefix: context.prefix,\n icons,\n ...(options.info\n ? {\n info: options.info,\n }\n : {}),\n } satisfies IconifyJSON;\n };\n}\n\n/**\n * Lists the SVG files of a directory and watches each directory that it lists.\n *\n * @param context - Host operations of the icon set.\n * @param directory - Absolute directory path.\n * @param prefix - Relative path of `directory` with a trailing `/`, or an empty string for the\n * top directory.\n * @param options - Whether subdirectories are read.\n * @returns Files in name order, with their relative paths without the `.svg` extension.\n * @throws If a directory cannot be listed.\n */\nasync function svgFiles(\n context: CollectionLoadContext,\n directory: string,\n prefix: string,\n options: SvgDirectoryOptions,\n): Promise<\n {\n file: string;\n path: string;\n }[]\n> {\n context.watch(directory, \"directory\");\n const entries = [...(await context.list(directory))].sort((a, b) =>\n a.name < b.name ? -1 : a.name > b.name ? 1 : 0,\n );\n const files: {\n file: string;\n path: string;\n }[] = [];\n for (const entry of entries) {\n const file = join(directory, entry.name);\n if (entry.directory) {\n if (options.recursive) {\n files.push(...(await svgFiles(context, file, `${prefix}${entry.name}/`, options)));\n }\n } else if (/\\.svg$/i.test(entry.name)) {\n files.push({\n file,\n path: prefix + entry.name.slice(0, -4),\n });\n }\n }\n return files;\n}\n\n/**\n * Resolves a directory against the project directory. The result keeps the separator style of\n * the project directory, because hosts compare watched paths with the paths that their file\n * watchers report.\n *\n * @param root - Absolute project directory.\n * @param directory - Absolute path, or a path relative to `root`.\n * @returns The absolute directory path.\n */\nfunction absolute(root: string, directory: string): string {\n if (/^(?:[A-Za-z]:)?[\\\\/]/.test(directory)) {\n return directory;\n }\n let path = root;\n for (const segment of directory.split(/[\\\\/]/)) {\n if (segment === \"..\") {\n path = path.replace(/[\\\\/][^\\\\/]*$/, \"\");\n } else if (segment && segment !== \".\") {\n path = join(path, segment);\n }\n }\n return path;\n}\n\n/**\n * Appends one entry name to a directory path with the directory's separator style.\n *\n * @param directory - Absolute directory path.\n * @param name - Entry name without separators.\n * @returns The entry path.\n */\nfunction join(directory: string, name: string): string {\n const separator = directory.includes(\"\\\\\") ? \"\\\\\" : \"/\";\n return directory.endsWith(separator) ? directory + name : directory + separator + name;\n}\n"],"mappings":";;;;;;;;;;;AAyCA,MAAM,yBAAS,IAAI,IAQjB;;;;;;;;;;AAWF,IAAa,cAAb,MAAyB;CACvB;CACA;CACA,0BAAmB,IAAI,IAAuC;CAC9D;;;;;CAMA,YAAY,SAAqD,SAA4B;EAC3F,KAAK,WAAW;EAChB,KAAK,WAAW;CAClB;;;;;;;;CASA,MAAM,IAAI,QAAkD;EAC1D,IAAI,SAAS,KAAK,QAAQ,IAAI,MAAM;EACpC,IAAI,CAAC,QAAQ;GACX,SAAS,KAAK,MAAM,MAAM;G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AAS,IAAI,YAAY,OAAO,YAAY,YAAY;AACpF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stillwind/plugin-iconify",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Iconify icons as Stillwind utilities",
|
|
5
|
+
"homepage": "https://stillwind.dev/",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/SegaraRai/stillwind/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/SegaraRai/stillwind.git",
|
|
13
|
+
"directory": "plugins/iconify"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@iconify/types": "^2.0.0",
|
|
31
|
+
"@iconify/utils": "^3.1.7",
|
|
32
|
+
"@stillwind/config": "0.1.0",
|
|
33
|
+
"svgo": "^4.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@stillwind-internal/tools-workspace": "0.0.0",
|
|
37
|
+
"@stillwind/host": "0.1.0",
|
|
38
|
+
"@stillwind/native": "0.1.0",
|
|
39
|
+
"@types/node": "^26.6.5",
|
|
40
|
+
"stillwind": "0.1.0",
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"vite-plus": "1.4.0"
|
|
43
|
+
}
|
|
6
44
|
}
|