@pantoken/icons 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/README.md +46 -0
- package/dist/index.d.mts +66 -0
- package/dist/index.mjs +87 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @pantoken/icons
|
|
2
|
+
|
|
3
|
+
An ergonomic view over the pantoken IR's `<image>` tokens. It filters the canonical IR from
|
|
4
|
+
`@pantoken/tokens` to the icon tokens and decodes each data-URI back to inline SVG — it's not a
|
|
5
|
+
second source of truth.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @pantoken/icons
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Also available as `pantoken/icons`.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { icons, getIcon, resolve } from "@pantoken/icons";
|
|
19
|
+
|
|
20
|
+
getIcon("arrow-left"); // { name, dataUri, svg, viewBox, bidirectional, source }
|
|
21
|
+
icons.length; // the full set
|
|
22
|
+
|
|
23
|
+
resolve("arrow-left"); // IconResolver — for the plugin / rehype stages
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Each icon carries `bidirectional` (RTL flipping) and `source` (`custom` or `lucide`) metadata,
|
|
27
|
+
plus the decoded `svg` and the original `dataUri`.
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
- **`icons: PantokenIcon[]`** — every pantoken icon, sorted by name.
|
|
32
|
+
- **`iconsByName: Map<string, PantokenIcon>`** — every icon, keyed by name.
|
|
33
|
+
- **`getIcon(name): PantokenIcon | undefined`** — look up one icon by name.
|
|
34
|
+
- **`resolve: IconResolver`** — an `IconResolver` backed by the icon set, for the plugin and rehype
|
|
35
|
+
stages.
|
|
36
|
+
- **`PantokenIcon`** — a decoded icon: `name`, `dataUri`, `svg`, `viewBox`, `bidirectional`, and
|
|
37
|
+
`source`.
|
|
38
|
+
|
|
39
|
+
## Related
|
|
40
|
+
|
|
41
|
+
- Reads the IR from `@pantoken/tokens`.
|
|
42
|
+
- For an installable font of the same glyphs, see `@pantoken/icon-font`.
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { IconResolver } from "@pantoken/model";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/** A pantoken icon, derived from an `<image>` token. */
|
|
5
|
+
interface PantokenIcon {
|
|
6
|
+
/** The icon name, without the `--instui-icon-` prefix (e.g. `arrow-left`). */
|
|
7
|
+
name: string;
|
|
8
|
+
/** The `url('data:image/svg+xml;utf8,…')` value, as stored in the IR. */
|
|
9
|
+
dataUri: string;
|
|
10
|
+
/** The decoded inline SVG markup. */
|
|
11
|
+
svg: string;
|
|
12
|
+
/** The SVG `viewBox`, when known. */
|
|
13
|
+
viewBox?: string;
|
|
14
|
+
/** Whether the icon flips horizontally in right-to-left contexts. */
|
|
15
|
+
bidirectional: boolean;
|
|
16
|
+
/** The glyph origin. */
|
|
17
|
+
source?: "custom" | "lucide";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Every pantoken icon, sorted by name.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { icons } from "@pantoken/icons";
|
|
25
|
+
*
|
|
26
|
+
* icons.length; // the full set
|
|
27
|
+
* icons.filter((i) => i.source === "lucide"); // just the Lucide glyphs
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const icons: PantokenIcon[];
|
|
31
|
+
/**
|
|
32
|
+
* Every pantoken icon, keyed by name.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { iconsByName } from "@pantoken/icons";
|
|
37
|
+
*
|
|
38
|
+
* iconsByName.get("arrow-left")?.svg; // inline SVG markup
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare const iconsByName: Map<string, PantokenIcon>;
|
|
42
|
+
/**
|
|
43
|
+
* Look up an icon by name.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { getIcon } from "@pantoken/icons";
|
|
48
|
+
*
|
|
49
|
+
* const icon = getIcon("arrow-left");
|
|
50
|
+
* icon?.viewBox; // "0 0 24 24"
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function getIcon(name: string): PantokenIcon | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* An {@link IconResolver} backed by the pantoken icon set (for the plugin/rehype stages).
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { resolve } from "@pantoken/icons";
|
|
60
|
+
*
|
|
61
|
+
* resolve("arrow-left"); // { name, svg, viewBox, source } | undefined
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare const resolve: IconResolver;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { PantokenIcon, getIcon, icons, iconsByName, resolve };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { tokens } from "@pantoken/tokens";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* `@pantoken/icons` — an ergonomic view over the IR's `<image>` tokens.
|
|
5
|
+
*
|
|
6
|
+
* This is not a second source; it filters the canonical IR from `@pantoken/tokens` to the icon
|
|
7
|
+
* tokens and decodes each data-URI back to inline SVG, exposing a shape close to the
|
|
8
|
+
* `SimpleIconTokenData` that markdown/rehype consumers already use.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
const DATA_PREFIX = "data:image/svg+xml;utf8,";
|
|
14
|
+
function decode(dataUri) {
|
|
15
|
+
const inner = /^url\(\s*'?(.*?)'?\s*\)$/.exec(dataUri.trim())?.[1] ?? dataUri;
|
|
16
|
+
if (!inner.startsWith(DATA_PREFIX)) return "";
|
|
17
|
+
try {
|
|
18
|
+
return decodeURIComponent(inner.slice(24));
|
|
19
|
+
} catch {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Every pantoken icon, sorted by name.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { icons } from "@pantoken/icons";
|
|
29
|
+
*
|
|
30
|
+
* icons.length; // the full set
|
|
31
|
+
* icons.filter((i) => i.source === "lucide"); // just the Lucide glyphs
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
const icons = tokens.filter((t) => t.meta?.kind === "icon").map((t) => ({
|
|
35
|
+
name: t.name.slice(14),
|
|
36
|
+
dataUri: t.value,
|
|
37
|
+
svg: decode(t.value),
|
|
38
|
+
viewBox: t.meta?.viewBox,
|
|
39
|
+
bidirectional: Boolean(t.meta?.bidirectional),
|
|
40
|
+
source: t.meta?.source
|
|
41
|
+
}));
|
|
42
|
+
/**
|
|
43
|
+
* Every pantoken icon, keyed by name.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { iconsByName } from "@pantoken/icons";
|
|
48
|
+
*
|
|
49
|
+
* iconsByName.get("arrow-left")?.svg; // inline SVG markup
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
const iconsByName = new Map(icons.map((i) => [i.name, i]));
|
|
53
|
+
/**
|
|
54
|
+
* Look up an icon by name.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { getIcon } from "@pantoken/icons";
|
|
59
|
+
*
|
|
60
|
+
* const icon = getIcon("arrow-left");
|
|
61
|
+
* icon?.viewBox; // "0 0 24 24"
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function getIcon(name) {
|
|
65
|
+
return iconsByName.get(name);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* An {@link IconResolver} backed by the pantoken icon set (for the plugin/rehype stages).
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { resolve } from "@pantoken/icons";
|
|
73
|
+
*
|
|
74
|
+
* resolve("arrow-left"); // { name, svg, viewBox, source } | undefined
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
const resolve = (code) => {
|
|
78
|
+
const icon = iconsByName.get(code);
|
|
79
|
+
return icon ? {
|
|
80
|
+
name: icon.name,
|
|
81
|
+
svg: icon.svg,
|
|
82
|
+
viewBox: icon.viewBox,
|
|
83
|
+
source: icon.source
|
|
84
|
+
} : void 0;
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { getIcon, icons, iconsByName, resolve };
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pantoken/icons",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "An ergonomic view over the pantoken IR's <image> tokens: decoded SVGs and per-icon metadata.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.mjs",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@pantoken/model": "0.1.0",
|
|
19
|
+
"@pantoken/tokens": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^24.13.3",
|
|
23
|
+
"typescript": "^6.0.3",
|
|
24
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
25
|
+
"vite-plus": "0.2.4"
|
|
26
|
+
},
|
|
27
|
+
"pantoken": {
|
|
28
|
+
"key": "icons",
|
|
29
|
+
"kind": "namespace"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "vp pack",
|
|
33
|
+
"dev": "vp pack --watch",
|
|
34
|
+
"test": "vp test",
|
|
35
|
+
"check": "vp check"
|
|
36
|
+
}
|
|
37
|
+
}
|