@pantoken/icons 0.1.9 → 0.2.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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { IconResolver } from "@pantoken/model";
1
+ import { IconResolver, PantokenPlugin } from "@pantoken/model";
2
2
  //#region src/index.d.ts
3
3
  /** A pantoken icon, derived from an `<image>` token. */
4
4
  interface PantokenIcon {
@@ -65,5 +65,26 @@ declare function getIcon(name: string): PantokenIcon | undefined;
65
65
  * ```
66
66
  */
67
67
  declare const resolve: IconResolver;
68
+ /** Options shared by the icon-resolving renderers ({@link buildIconResolverChain}). */
69
+ interface IconResolverChainOptions {
70
+ /** An explicit resolver, tried before the built-in pantoken icon set. */
71
+ resolve?: IconResolver;
72
+ /** Plugins whose `rehype` hooks contribute resolvers (tried first). */
73
+ plugins?: readonly PantokenPlugin[];
74
+ }
75
+ /**
76
+ * Build the shared icon-resolver chain: plugin `rehype` resolvers first, then an explicit
77
+ * `resolve`, then the built-in pantoken icon set. Used by `@pantoken/rehype` and
78
+ * `@pantoken/markdown-it` so the resolution order stays identical across renderers.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * import { buildIconResolverChain } from "@pantoken/icons";
83
+ *
84
+ * const resolveIcon = buildIconResolverChain({ plugins: [myBrandIconsPlugin] });
85
+ * resolveIcon("arrow-left"); // { name, svg, viewBox, source } | undefined
86
+ * ```
87
+ */
88
+ declare function buildIconResolverChain(options: IconResolverChainOptions): IconResolver;
68
89
  //#endregion
69
- export { PantokenIcon, getIcon, icons, iconsByName, resolve };
90
+ export { IconResolverChainOptions, PantokenIcon, buildIconResolverChain, getIcon, icons, iconsByName, resolve };
package/dist/index.mjs CHANGED
@@ -84,5 +84,33 @@ const resolve = (code) => {
84
84
  source: icon.source
85
85
  } : void 0;
86
86
  };
87
+ /**
88
+ * Build the shared icon-resolver chain: plugin `rehype` resolvers first, then an explicit
89
+ * `resolve`, then the built-in pantoken icon set. Used by `@pantoken/rehype` and
90
+ * `@pantoken/markdown-it` so the resolution order stays identical across renderers.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import { buildIconResolverChain } from "@pantoken/icons";
95
+ *
96
+ * const resolveIcon = buildIconResolverChain({ plugins: [myBrandIconsPlugin] });
97
+ * resolveIcon("arrow-left"); // { name, svg, viewBox, source } | undefined
98
+ * ```
99
+ */
100
+ function buildIconResolverChain(options) {
101
+ const resolvers = [];
102
+ for (const plugin of options.plugins ?? []) {
103
+ const contributed = plugin.rehype?.({ resolve });
104
+ if (contributed?.resolve) resolvers.push(contributed.resolve);
105
+ }
106
+ if (options.resolve) resolvers.push(options.resolve);
107
+ resolvers.push(resolve);
108
+ return (code) => {
109
+ for (const resolver of resolvers) {
110
+ const hit = resolver(code);
111
+ if (hit) return hit;
112
+ }
113
+ };
114
+ }
87
115
  //#endregion
88
- export { getIcon, icons, iconsByName, resolve };
116
+ export { buildIconResolverChain, getIcon, icons, iconsByName, resolve };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pantoken/icons",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "An ergonomic view over the pantoken IR's <image> tokens: decoded SVGs and per-icon metadata.",
5
5
  "homepage": "https://pantoken.iywahl.com",
6
6
  "bugs": "https://github.com/thedannywahl/pantoken/issues",
@@ -24,15 +24,15 @@
24
24
  "provenance": true
25
25
  },
26
26
  "dependencies": {
27
- "@pantoken/model": "0.3.0",
28
- "@pantoken/tokens": "0.2.4",
29
- "@pantoken/utils": "1.0.0"
27
+ "@pantoken/model": "0.3.1",
28
+ "@pantoken/tokens": "0.3.0",
29
+ "@pantoken/utils": "1.0.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/node": "^24.13.3",
32
+ "@types/node": "^26.3.0",
33
33
  "typescript": "^7.0.2",
34
- "vite": "npm:@voidzero-dev/vite-plus-core@0.2.9",
35
- "vite-plus": "0.2.9"
34
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.0",
35
+ "vite-plus": "0.3.0"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=22.18.0"