@kayjs/icons 2.0.0-alpha.8 → 2.0.0-beta.1
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/package.json +2 -2
- package/src/Icon.tsx +2 -2
- package/src/index.ts +16 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kayjs/icons",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Compile-time Iconify SVG icon plugin (~icons/<set>/<name>) for Kay v2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"directory": "packages/plugin-icons"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"kay": "^2.0.0-
|
|
24
|
+
"@kayjs/kay": "^2.0.0-beta.1"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/Icon.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @jsxImportSource kay */
|
|
1
|
+
/** @jsxImportSource @kayjs/kay */
|
|
2
2
|
import type { IconData } from './types'
|
|
3
3
|
|
|
4
4
|
export interface IconComponentProps {
|
|
@@ -20,7 +20,7 @@ export function Icon({ icon, ...rest }: IconComponentProps) {
|
|
|
20
20
|
aria-hidden={hasLabel ? undefined : 'true'}
|
|
21
21
|
role={hasLabel ? 'img' : undefined}
|
|
22
22
|
{...rest}
|
|
23
|
-
innerHTML={
|
|
23
|
+
innerHTML={icon.body}
|
|
24
24
|
/>
|
|
25
25
|
)
|
|
26
26
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Built strictly on the public KayPlugin API (bunPlugins).
|
|
4
4
|
|
|
5
5
|
import type { BunPlugin } from 'bun'
|
|
6
|
-
import type { KayPlugin } from 'kay/server'
|
|
6
|
+
import type { KayPlugin } from '@kayjs/kay/server'
|
|
7
7
|
import type { IconData, IconifyIcon, IconSet } from './types'
|
|
8
8
|
|
|
9
9
|
export { Icon } from './Icon'
|
|
@@ -11,6 +11,18 @@ export type { IconComponentProps } from './Icon'
|
|
|
11
11
|
export type { IconData, IconifyIcon, IconSet } from './types'
|
|
12
12
|
|
|
13
13
|
const DEFAULT_SIZE = 16
|
|
14
|
+
const ICON_SPEC_RE = /^~icons\/([^/]+)\/(.+)$/
|
|
15
|
+
|
|
16
|
+
function resolveIconSetFile(prefix: string, root: string): string {
|
|
17
|
+
const pkgPath = `@iconify-json/${prefix}/icons.json`
|
|
18
|
+
for (const from of [root, process.cwd()]) {
|
|
19
|
+
try {
|
|
20
|
+
return Bun.resolveSync(pkgPath, from)
|
|
21
|
+
}
|
|
22
|
+
catch {}
|
|
23
|
+
}
|
|
24
|
+
throw new Error(`@kayjs/icons: could not resolve "${pkgPath}". Install @iconify-json/${prefix}.`)
|
|
25
|
+
}
|
|
14
26
|
|
|
15
27
|
function resolveIcon(set: IconSet, name: string, depth: number): IconifyIcon | undefined {
|
|
16
28
|
const own = set.icons[name]
|
|
@@ -77,12 +89,10 @@ export function icons(options: IconsPluginOptions = {}): KayPlugin {
|
|
|
77
89
|
bunPlugins: ({ root }): BunPlugin[] => [{
|
|
78
90
|
name: 'kayjs-icons',
|
|
79
91
|
setup(b) {
|
|
80
|
-
b.onResolve({ filter:
|
|
81
|
-
return { path: args.path, namespace: 'kay-icon' }
|
|
82
|
-
})
|
|
92
|
+
b.onResolve({ filter: ICON_SPEC_RE }, args => ({ path: args.path, namespace: 'kay-icon' }))
|
|
83
93
|
|
|
84
94
|
b.onLoad({ filter: /.*/, namespace: 'kay-icon' }, async (args) => {
|
|
85
|
-
const match =
|
|
95
|
+
const match = ICON_SPEC_RE.exec(args.path)
|
|
86
96
|
if (match === null)
|
|
87
97
|
throw new Error(`@kayjs/icons: invalid specifier "${args.path}" (expected ~icons/<prefix>/<name>)`)
|
|
88
98
|
|
|
@@ -91,20 +101,7 @@ export function icons(options: IconsPluginOptions = {}): KayPlugin {
|
|
|
91
101
|
let set = cache.get(prefix)
|
|
92
102
|
|
|
93
103
|
if (set === undefined) {
|
|
94
|
-
|
|
95
|
-
let resolved: string
|
|
96
|
-
try {
|
|
97
|
-
resolved = Bun.resolveSync(pkgPath, root)
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
try {
|
|
101
|
-
resolved = Bun.resolveSync(pkgPath, process.cwd())
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
throw new Error(`@kayjs/icons: could not resolve "${pkgPath}". Install @iconify-json/${prefix}.`)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
set = await Bun.file(resolved).json() as IconSet
|
|
104
|
+
set = await Bun.file(resolveIconSetFile(prefix, root)).json() as IconSet
|
|
108
105
|
cache.set(prefix, set)
|
|
109
106
|
}
|
|
110
107
|
|