magic-glyphs 0.6.2 → 0.7.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/README.md +110 -74
- package/cli/index.js +51 -13
- package/data/index.json +1 -1
- package/docs/cli.md +14 -0
- package/docs/flutter.md +18 -0
- package/docs/frameworks.md +50 -0
- package/docs/jetpack-compose.md +21 -0
- package/docs/licence.md +30 -2
- package/docs/maker.md +64 -0
- package/docs/mcp.md +8 -0
- package/docs/native-lottie.md +8 -0
- package/docs/react-native.md +34 -0
- package/docs/react-vue.md +8 -1
- package/docs/shadcn.md +50 -0
- package/docs/sound.md +79 -0
- package/docs/swiftui.md +22 -0
- package/docs/tauri-rust.md +15 -0
- package/docs/web.md +1 -0
- package/docs/windows.md +23 -0
- package/lib.js +36 -2
- package/licence.js +4 -1
- package/mcp/server.js +1 -1
- package/package.json +37 -8
- package/react/index.d.ts +32 -0
- package/react/index.js +7 -3
- package/shopify/magic-glyph.liquid +8 -6
- package/tools/audio.js +41 -0
- package/tools/native.js +208 -0
- package/vue/index.d.ts +6 -2
- package/vue/index.js +12 -6
- package/web/magic-glyphs.all.js +89 -22
- package/web/runtime.d.ts +35 -1
- package/web/runtime.js +89 -22
- package/wordpress/magic-glyphs/magic-glyphs.all.js +89 -22
- package/wordpress/magic-glyphs/magic-glyphs.php +18 -6
package/README.md
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
# Magic Glyphs
|
|
1
|
+
# Magic Glyphs: animated icons with sound
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**An animated icon library for React, Next.js, Vue, Nuxt, Svelte, Astro, shadcn, plain HTML, WordPress, Shopify, React Native, SwiftUI, Jetpack Compose, Flutter, Windows and Tauri.** Every icon has its own spring animation and a short sound you can shape, in four styles: outline, solid, duotone and glass. It includes an icon maker that turns your own SVG or image into an animated icon, a command line tool, and an MCP server so coding assistants can insert icons for you.
|
|
4
4
|
|
|
5
|
-

|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**[Live demo, docs and free icon browser →](https://magic-glyphs-site.lewisvillamor26.workers.dev)**
|
|
8
8
|
|
|
9
|
-
**
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
- **120 free icons** in this package, free for personal and commercial use.
|
|
10
|
+
- **3,900+ icons** in the full library with a licence key: interface, arrows, files, commerce, devices, media, food, nature, people, travel and flags.
|
|
11
|
+
- **Tiny:** 8.5 KB compressed for the code that draws, animates and plays every icon, about 0.2 KB per icon, and no browser dependencies.
|
|
12
|
+
- **Accessible:** respects reduced motion, takes an accessible label, and sound is easy to mute.
|
|
12
13
|
|
|
13
14
|
## Install
|
|
14
15
|
|
|
@@ -16,46 +17,67 @@ This package includes **120 free icons**. A licence key unlocks the full library
|
|
|
16
17
|
npm install magic-glyphs
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
The command line tool needs Node.js 18 or later. The browser code has no dependencies.
|
|
20
21
|
|
|
21
22
|
## Quick start
|
|
22
23
|
|
|
23
|
-
###
|
|
24
|
+
### HTML, no build step
|
|
24
25
|
|
|
25
26
|
```html
|
|
26
|
-
<script src="
|
|
27
|
+
<script src="https://unpkg.com/magic-glyphs/web/magic-glyphs.all.js" defer></script>
|
|
27
28
|
|
|
28
29
|
<magic-glyph name="heart"></magic-glyph>
|
|
29
30
|
<magic-glyph name="bell" variant="duotone" size="32" sound></magic-glyph>
|
|
31
|
+
<magic-glyphs-sound-toggle></magic-glyphs-sound-toggle> <!-- a mute switch for visitors -->
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
Works the same in Astro, Svelte, SvelteKit, Angular, Solid, Lit, WordPress (plugin included) and Shopify (snippet included). Icons take the text colour, so Tailwind classes like `text-rose-500` work.
|
|
35
|
+
|
|
36
|
+
### React and Next.js
|
|
33
37
|
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
```bash
|
|
39
|
+
npx magic-glyphs add heart bell --format react --out src/icons
|
|
40
|
+
```
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
```tsx
|
|
43
|
+
import HeartGlyph from './icons/HeartGlyph';
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
return <MagicGlyph name="heart" variant="duotone" size={32} label="Like" />;
|
|
42
|
-
}
|
|
45
|
+
<HeartGlyph size={24} label="Like" sound soundOptions={{ pitch: 2 }} />
|
|
43
46
|
```
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
Components are typed in TypeScript projects and marked `'use client'`, so they work inside Next.js server components.
|
|
49
|
+
|
|
50
|
+
### Vue and Nuxt
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx magic-glyphs add heart bell --format vue --out components
|
|
54
|
+
```
|
|
46
55
|
|
|
47
56
|
```vue
|
|
48
|
-
<
|
|
49
|
-
import { MagicGlyph, register } from 'magic-glyphs/vue';
|
|
50
|
-
import icons from 'magic-glyphs/icons.json';
|
|
51
|
-
register(icons);
|
|
52
|
-
</script>
|
|
53
|
-
|
|
54
|
-
<template>
|
|
55
|
-
<MagicGlyph name="heart" variant="duotone" :size="32" label="Like" />
|
|
56
|
-
</template>
|
|
57
|
+
<HeartGlyph :size="24" label="Like" />
|
|
57
58
|
```
|
|
58
59
|
|
|
60
|
+
### shadcn
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx magic-glyphs shadcn
|
|
64
|
+
npx shadcn@latest add @magic-glyphs/heart
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### React Native, SwiftUI, Jetpack Compose, Flutter, Windows
|
|
68
|
+
|
|
69
|
+
One ready-to-use component file per icon, with the animation built in and its sound as a WAV file:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx magic-glyphs add heart --format react-native --sound # or swiftui, compose, flutter, winui
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Lottie files are also available with `--format lottie` for any Lottie player.
|
|
76
|
+
|
|
77
|
+
### Tauri and other web-view apps
|
|
78
|
+
|
|
79
|
+
Use the HTML, React, Vue or Svelte setup above: Tauri, Dioxus and Leptos draw their interface in a web view.
|
|
80
|
+
|
|
59
81
|
## Options
|
|
60
82
|
|
|
61
83
|
| Attribute | Values | Default |
|
|
@@ -64,7 +86,7 @@ register(icons);
|
|
|
64
86
|
| `variant` | `outline`, `solid`, `duotone`, `glass` | `outline` |
|
|
65
87
|
| `size` | Pixels | `24` |
|
|
66
88
|
| `trigger` | `hover`, `click`, `load`, `visible`, `none` | `hover` |
|
|
67
|
-
| `sound` | Present
|
|
89
|
+
| `sound` | Present to play the icon's sound; `off` to keep an icon silent | off |
|
|
68
90
|
| `label` | Accessible name; leave out for decorative icons | none |
|
|
69
91
|
|
|
70
92
|
Icons take their colour from CSS `color`. Three CSS variables tune the other styles:
|
|
@@ -78,29 +100,55 @@ Icons take their colour from CSS `color`. Three CSS variables tune the other sty
|
|
|
78
100
|
}
|
|
79
101
|
```
|
|
80
102
|
|
|
103
|
+
## Sound
|
|
104
|
+
|
|
105
|
+
Every icon has a short synthesized sound matched to its motion, panned left or right by where the icon sits on screen. All sounds are levelled to the same loudness. Shape any icon's sound:
|
|
106
|
+
|
|
107
|
+
```html
|
|
108
|
+
<magic-glyph name="bell" sound sound-pitch="-3" sound-speed="1.2" sound-tone="-0.4"></magic-glyph>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
| Setting | Range |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `sound-name` | any of the 39 sounds |
|
|
114
|
+
| `sound-volume` | 0 to 2 |
|
|
115
|
+
| `sound-pitch` | -12 to 12 semitones |
|
|
116
|
+
| `sound-speed` | 0.5 to 2 |
|
|
117
|
+
| `sound-tone` | -1 (softer) to 1 (brighter) |
|
|
118
|
+
| `sound-pan` | 0 (centred) to 1 (follows the icon) |
|
|
119
|
+
| `sound-delay` | milliseconds, or `auto` to line impact sounds up with the motion |
|
|
120
|
+
|
|
121
|
+
In React and Vue, use `soundOptions`. Browsers allow audio only after the visitor's first click or key press. [Hear every sound.](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/sound/)
|
|
122
|
+
|
|
123
|
+
## Icon maker
|
|
124
|
+
|
|
125
|
+
Paid licences include the **[icon maker](https://magic-glyphs-site.lewisvillamor26.workers.dev/maker/)**. Upload an SVG, paste SVG code, or drop in a PNG or JPG logo to trace it, or remix any library icon. It is fitted to the grid in the same line style. Choose a motion (pop, bounce, drop in, wiggle, swing, spin, slide, shake, float, pulse, tilt), shape its sound, and export SVG, React, Vue, HTML, Lottie, WAV or icon data. Your own icons then work everywhere the library does:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npx magic-glyphs add my-logo --from my-icons/ --format react
|
|
129
|
+
```
|
|
130
|
+
|
|
81
131
|
## Command line tool
|
|
82
132
|
|
|
83
133
|
```bash
|
|
84
134
|
npx magic-glyphs search shopping cart # find icons
|
|
85
135
|
npx magic-glyphs list --free # the free set
|
|
86
136
|
npx magic-glyphs add heart bell --format react --out src/icons
|
|
87
|
-
npx magic-glyphs add rocket --format lottie --
|
|
137
|
+
npx magic-glyphs add rocket --format lottie --sound
|
|
88
138
|
npx magic-glyphs bundle heart bell --out public/magic-glyphs.js
|
|
89
139
|
npx magic-glyphs static --out public/icons # plain SVG files and sprites
|
|
140
|
+
npx magic-glyphs update # newer version and new icons
|
|
90
141
|
```
|
|
91
142
|
|
|
92
|
-
Formats for `add`: `svg`, `react`, `vue`, `html`, `lottie`, `
|
|
93
|
-
|
|
94
|
-
## Sound
|
|
143
|
+
Formats for `add`: `svg`, `react`, `vue`, `html`, `json`, `lottie`, `wav`, `react-native`, `swiftui`, `compose`, `flutter`, `winui`.
|
|
95
144
|
|
|
96
|
-
|
|
145
|
+
## MCP server for coding assistants
|
|
97
146
|
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
<script>MagicGlyphs.sound.enable(true); MagicGlyphs.sound.volume(0.4);</script>
|
|
147
|
+
```bash
|
|
148
|
+
npx -y magic-glyphs-mcp
|
|
101
149
|
```
|
|
102
150
|
|
|
103
|
-
|
|
151
|
+
Lets Claude, Cursor and other MCP clients search the library and insert icons in your project's format. It lives in the separate [`magic-glyphs-mcp`](https://www.npmjs.com/package/magic-glyphs-mcp) package so the icon package stays small.
|
|
104
152
|
|
|
105
153
|
## The full library
|
|
106
154
|
|
|
@@ -108,58 +156,46 @@ Browsers block audio until the visitor clicks or presses a key, so hover sounds
|
|
|
108
156
|
npx magic-glyphs login YOUR-LICENCE-KEY
|
|
109
157
|
```
|
|
110
158
|
|
|
111
|
-
Buy a licence at **[magicscraper.gumroad.com/l/vjaxbp](https://magicscraper.gumroad.com/l/vjaxbp)**.
|
|
159
|
+
Buy a licence at **[magicscraper.gumroad.com/l/vjaxbp](https://magicscraper.gumroad.com/l/vjaxbp)**. `login` checks the purchase and downloads every icon to your computer; every command above then works with the whole library. Plans: Personal (1 person, 3 devices), Team (10 people, 20 devices), Business (50 people, 100 devices). For CI, `npx magic-glyphs build-key` makes a key that does not use a device.
|
|
112
160
|
|
|
113
161
|

|
|
114
162
|
|
|
115
|
-
On a build server, set `MAGIC_GLYPHS_KEY` to the key printed by `npx magic-glyphs licence --show-key`, then run `npx magic-glyphs sync`.
|
|
116
|
-
|
|
117
163
|
## Where it works
|
|
118
164
|
|
|
119
|
-
| Platform | How |
|
|
120
|
-
|
|
121
|
-
| HTML,
|
|
122
|
-
| React, Next.js | `magic-glyphs/react
|
|
123
|
-
| Vue, Nuxt | `magic-glyphs/vue
|
|
124
|
-
|
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
165
|
+
| Platform | How | Tested |
|
|
166
|
+
|---|---|---|
|
|
167
|
+
| HTML, JavaScript, no build step | `<magic-glyph>` tag | yes |
|
|
168
|
+
| React, Next.js | `magic-glyphs/react`, generated components | Vite + TypeScript, Next.js App Router |
|
|
169
|
+
| Vue, Nuxt | `magic-glyphs/vue`, generated components | Vite + TypeScript, Nuxt 4 |
|
|
170
|
+
| Astro, Svelte, Tailwind CSS | `<magic-glyph>` tag | Astro 5, Svelte 5 + Tailwind 4 |
|
|
171
|
+
| shadcn | official registry | shadcn 4 |
|
|
172
|
+
| WordPress | plugin in `wordpress/` | PHP checked |
|
|
173
|
+
| Shopify | snippet in `shopify/` | |
|
|
174
|
+
| React Native | `--format react-native` | type-checked |
|
|
175
|
+
| SwiftUI, Jetpack Compose, Flutter, Windows (WinUI) | `--format swiftui`, `compose`, `flutter`, `winui` | not yet on devices |
|
|
176
|
+
| Tauri, Dioxus, Leptos | web setup | |
|
|
177
|
+
| Any Lottie player | `--format lottie` | checked against an independent renderer |
|
|
178
|
+
| Coding assistants | `magic-glyphs-mcp` | yes |
|
|
129
179
|
|
|
130
180
|
## Limitations
|
|
131
181
|
|
|
132
|
-
- **
|
|
133
|
-
- **
|
|
134
|
-
- **
|
|
135
|
-
- **
|
|
136
|
-
- **Flags** are simplified to fit a small grid.
|
|
137
|
-
- **
|
|
138
|
-
- **Reduced motion:** when a visitor's device asks for reduced motion, icons do not animate.
|
|
139
|
-
- **Seat counts** on Team and Business licences are recorded, not enforced by the software.
|
|
182
|
+
- **Native app components** (SwiftUI, Compose, Flutter, WinUI) are generated from the tested Lottie export but have not yet been run on devices.
|
|
183
|
+
- **Sound in native apps** comes as a separate `.wav` file; Lottie and static SVG themselves are silent.
|
|
184
|
+
- **Glass style** is not available in Lottie, native or static SVG exports.
|
|
185
|
+
- **Icon maker:** SVG text must be converted to outlines first, and stroke widths are replaced by the library's line weight. Image tracing (beta) suits simple, high-contrast artwork, not photos.
|
|
186
|
+
- **Flags** are simplified to fit a small grid.
|
|
187
|
+
- **Reduced motion:** when a device asks for reduced motion, icons do not animate.
|
|
140
188
|
|
|
141
189
|
## Licence
|
|
142
190
|
|
|
143
191
|
- **Free icons:** use them in any personal or commercial project, no attribution needed.
|
|
144
|
-
- **Paid icons:** one-time purchase
|
|
192
|
+
- **Paid icons:** one-time purchase for the people and devices in your plan.
|
|
145
193
|
- **Not allowed:** reselling or redistributing the icons as icons, publishing the paid icons where others can download them, or using them to train or build icon generators.
|
|
146
194
|
|
|
147
|
-
The full terms are in [`LICENSE.md`](https://unpkg.com/magic-glyphs/LICENSE.md)
|
|
195
|
+
The full terms are in [`LICENSE.md`](https://unpkg.com/magic-glyphs/LICENSE.md).
|
|
148
196
|
|
|
149
197
|
## Guides
|
|
150
198
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
| Guide | For |
|
|
154
|
-
|---|---|
|
|
155
|
-
| [Getting started](https://unpkg.com/magic-glyphs/docs/getting-started.md) | Choosing the right install for your project |
|
|
156
|
-
| [Web](https://unpkg.com/magic-glyphs/docs/web.md) | HTML, Angular, WordPress, Shopify, sound |
|
|
157
|
-
| [React and Vue](https://unpkg.com/magic-glyphs/docs/react-vue.md) | Components and per-icon files |
|
|
158
|
-
| [Native through Lottie](https://unpkg.com/magic-glyphs/docs/native-lottie.md) | iOS, macOS, Android, Windows, Flutter |
|
|
159
|
-
| [Theming](https://unpkg.com/magic-glyphs/docs/theming.md) | Colours and the four styles |
|
|
160
|
-
| [Static SVG](https://unpkg.com/magic-glyphs/docs/static.md) | Files and sprites with no JavaScript |
|
|
161
|
-
| [Command line tool](https://unpkg.com/magic-glyphs/docs/cli.md) | Every command and option |
|
|
162
|
-
| [Licence keys](https://unpkg.com/magic-glyphs/docs/licence.md) | Logging in, build servers |
|
|
163
|
-
| [Data format](https://unpkg.com/magic-glyphs/docs/data-format.md) | For writing your own renderer |
|
|
199
|
+
[Getting started](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/getting-started/) · [HTML, WordPress, Shopify](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/web/) · [React, Next.js, Vue, Nuxt](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/react-vue/) · [shadcn](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/shadcn/) · [Astro, Svelte, Tailwind](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/frameworks/) · [React Native](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/react-native/) · [SwiftUI](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/swiftui/) · [Jetpack Compose](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/jetpack-compose/) · [Flutter](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/flutter/) · [Windows](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/windows/) · [Tauri and Rust](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/tauri-rust/) · [Sound](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/sound/) · [CLI](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/cli/) · [MCP](https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/mcp/)
|
|
164
200
|
|
|
165
201
|
Made by Lewis John Villamor.
|
package/cli/index.js
CHANGED
|
@@ -17,10 +17,14 @@ Usage
|
|
|
17
17
|
magic-glyphs login YOUR-KEY | sync | logout | licence paid icons need a licence key; sync re-downloads the full set
|
|
18
18
|
magic-glyphs update check for a newer version and download new paid icons
|
|
19
19
|
magic-glyphs --version
|
|
20
|
+
magic-glyphs shadcn [--env] connect a shadcn project: npx shadcn add @magic-glyphs/<icon>
|
|
21
|
+
magic-glyphs build-key a key for CI and build servers (does not use a device slot)
|
|
20
22
|
magic-glyphs buy open the page where you can buy a licence
|
|
21
23
|
|
|
22
24
|
Options for add
|
|
23
|
-
--format <f> svg (default) | lottie | react | vue | json | html
|
|
25
|
+
--format <f> svg (default) | lottie | react | vue | json | html | wav (the icon's sound)
|
|
26
|
+
react-native | swiftui | compose | flutter | winui (one ready-to-use component file)
|
|
27
|
+
--sound with --format lottie, also write each icon's sound as a .wav file
|
|
24
28
|
--style <s> outline (default) | solid | duotone | glass
|
|
25
29
|
--out <dir> where to write (default ./magic-glyphs)
|
|
26
30
|
--color <hex> main colour (svg default: currentColor, lottie default: #000000)
|
|
@@ -28,16 +32,18 @@ Options for add
|
|
|
28
32
|
--background <hex> colour knocked out of solid icons (default #ffffff)
|
|
29
33
|
--size <px> svg width and height (default 24)
|
|
30
34
|
--ts | --js typed or plain React/Vue components (default: typed when the project has a tsconfig.json)
|
|
35
|
+
--from <path> your own icons: JSON from the icon maker (a file or a folder), no licence needed
|
|
31
36
|
--stdout print a single icon instead of writing a file
|
|
32
37
|
--dry-run show what would be written
|
|
33
38
|
|
|
34
39
|
Examples
|
|
35
40
|
magic-glyphs search shopping cart
|
|
36
41
|
magic-glyphs add heart bell --format react --out src/icons
|
|
42
|
+
magic-glyphs add my-logo --from my-icons/ --format lottie
|
|
37
43
|
magic-glyphs add --category arrows --format lottie --color "#2747f5" --out assets/lottie
|
|
38
44
|
`;
|
|
39
45
|
function parse(argv){const pos=[],opt={};for(let i=0;i<argv.length;i++){const a=argv[i];
|
|
40
|
-
if(a.startsWith('--')){const k=a.slice(2);if(['json','all','stdout','dry-run','help','free','show-key','version','ts','js'].includes(k))opt[k]=true;else{if(i+1>=argv.length)fail('Option --'+k+' needs a value.');opt[k]=argv[++i]}}
|
|
46
|
+
if(a.startsWith('--')){const k=a.slice(2);if(['json','all','stdout','dry-run','help','free','show-key','version','ts','js','sound','env'].includes(k))opt[k]=true;else{if(i+1>=argv.length)fail('Option --'+k+' needs a value.');opt[k]=argv[++i]}}
|
|
41
47
|
else if(a==='-h')opt.help=true;else if(a==='-v')opt.version=true;else pos.push(a)}return{pos,opt}}
|
|
42
48
|
// fetch the full set for a valid key; the server address comes from MAGIC_GLYPHS_API or package.json "magicGlyphs.api"
|
|
43
49
|
const apiBase=()=>(process.env.MAGIC_GLYPHS_API||(require('../package.json').magicGlyphs||{}).api||'').replace(/\/$/,'');
|
|
@@ -49,10 +55,10 @@ async function redeem(gumroadKey){
|
|
|
49
55
|
let d={};try{d=await r.json()}catch(e){}if(!r.ok||!d.key)throw new Error(d.error||'The licence server answered '+r.status+'.');return d.key}
|
|
50
56
|
async function download(force){
|
|
51
57
|
const api=(process.env.MAGIC_GLYPHS_API||(require('../package.json').magicGlyphs||{}).api||'').replace(/\/$/,'');
|
|
52
|
-
if(!force&&L.data.icons.length>=L.
|
|
58
|
+
if(!force&&L.data.icons.length>=L.known.size-L.custom.size&&!process.env.MAGIC_GLYPHS_API)return 0;
|
|
53
59
|
if(!/^https?:\/\//.test(api))throw new Error('no download server is configured');
|
|
54
60
|
const key=process.env.MAGIC_GLYPHS_KEY||JSON.parse(fs.readFileSync(Lic.storeFile(),'utf8')).key;
|
|
55
|
-
const r=await fetch(api+'/v1/icons.json',{headers:{authorization:'Bearer '+key}});
|
|
61
|
+
const r=await fetch(api+'/v1/icons.json',{headers:{authorization:'Bearer '+key,'x-mg-device':Lic.deviceId()}});
|
|
56
62
|
if(!r.ok){let m='server answered '+r.status;try{m=(await r.json()).error||m}catch(e){}throw new Error(m)}
|
|
57
63
|
const text=await r.text(),d=JSON.parse(text);if(!d||!Array.isArray(d.icons))throw new Error('the server sent something unexpected');
|
|
58
64
|
fs.mkdirSync(Lic.home(),{recursive:true});fs.writeFileSync(L.fullFile(),text);return d.icons.length}
|
|
@@ -67,6 +73,8 @@ function openBuy(){const u=buyUrl();if(!u)return false;
|
|
|
67
73
|
try{const ch=cp.spawn(c,a,{stdio:'ignore',detached:true});ch.on('error',()=>{});ch.unref();return true}catch(e){return false}}
|
|
68
74
|
function failBuy(msg){process.stderr.write('magic-glyphs: '+msg+'\n');const b=BUYLINE();if(b)process.stderr.write(b+'\n');process.exit(1)}
|
|
69
75
|
const {pos,opt}=parse(process.argv.slice(2)),cmd=pos.shift();
|
|
76
|
+
// --from: your own icons (JSON exported from the icon maker), a file or a folder; several separated by commas
|
|
77
|
+
if(opt.from)try{const got=L.addCustom(String(opt.from).split(','));if(!got.length)fail('No icons found in '+opt.from+'.')}catch(e){fail(e.message)}
|
|
70
78
|
try{
|
|
71
79
|
if(opt.version||cmd==='version'){console.log(require('../package.json').version);process.exit(0)}
|
|
72
80
|
if(!cmd||opt.help||cmd==='help'){process.stdout.write(HELP);process.exit(cmd||opt.help?0:1)}
|
|
@@ -87,13 +95,19 @@ try{
|
|
|
87
95
|
let names=pos;if(opt.all)names=L.index.map(i=>i.n);else if(opt.category)names=L.index.filter(i=>i.c===opt.category).map(i=>i.n);
|
|
88
96
|
if(!names.length)fail('Name the icons to add, or use --category or --all.');
|
|
89
97
|
const missing=names.filter(n=>!L.known.has(n));if(missing.length)fail('Unknown icon'+(missing.length>1?'s':'')+': '+missing.join(', ')+'. Try: magic-glyphs search '+missing[0]);
|
|
90
|
-
const paid=
|
|
98
|
+
const paid=L.locked(names);if(paid.length)fail(Lic.lockedMessage(paid));
|
|
91
99
|
const away=names.filter(n=>!L.byName.has(n));if(away.length)fail('Your licence is valid, but the full icon set is not on this computer yet. Run: magic-glyphs sync');
|
|
92
100
|
const format=opt.format||'svg',o={style:opt.style,color:opt.color,secondary:opt.secondary,background:opt.background,size:opt.size&&+opt.size};
|
|
93
101
|
// React and Vue components come out typed in TypeScript projects (.tsx, lang="ts") (a tsconfig.json in this folder or above), .jsx otherwise; --ts or --js overrides
|
|
94
102
|
if(format==='react'||format==='vue')o.ts=opt.ts?true:opt.js?false:(()=>{let d=process.cwd();for(;;){if(fs.existsSync(path.join(d,'tsconfig.json')))return true;const up=path.dirname(d);if(up===d)return false;d=up}})();
|
|
95
103
|
if(opt.size&&!(+opt.size>0))fail('--size must be a positive number.');
|
|
96
104
|
for(const k of ['color','secondary','background'])if(opt[k]&&!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(opt[k])&&!(format==='svg'&&/^[a-z]+$/i.test(opt[k])))fail('--'+k+' must be a hex colour such as #2747f5.');
|
|
105
|
+
// wav: the icon's sound as an audio file, for native apps (Lottie and static exports are silent); --sound adds one next to each Lottie file
|
|
106
|
+
if(format==='wav'||(['lottie','react-native','swiftui','compose','flutter','winui'].includes(format)&&opt.sound)){if(opt.stdout)fail('Audio cannot be printed; use --out.');const A=require('../tools/audio.js'),dir=path.resolve(opt.out||'magic-glyphs');
|
|
107
|
+
(async()=>{const files=[];for(const n of names){if(format!=='wav')files.push(L.render(n,format,o));const ic=L.byName.get(n);if(!ic.s){if(format==='wav')console.log(n+' has no sound; skipped.');continue}
|
|
108
|
+
files.push({file:n+'.wav',data:await A.wav(L.MG,n)})}
|
|
109
|
+
if(!opt['dry-run']){fs.mkdirSync(dir,{recursive:true});files.forEach(f=>fs.writeFileSync(path.join(dir,f.file),f.data||f.text))}
|
|
110
|
+
console.log((opt['dry-run']?'Would write ':'Wrote ')+files.length+' file'+(files.length===1?'':'s')+' to '+dir+(files.length<=6?': '+files.map(f=>f.file).join(', '):''))})().catch(e=>fail(e.message));return}
|
|
97
111
|
if(opt.stdout){if(names.length!==1)fail('--stdout prints one icon; name exactly one.');process.stdout.write(L.render(names[0],format,o).text+'\n')}
|
|
98
112
|
else{const dir=path.resolve(opt.out||'magic-glyphs');const files=names.map(n=>L.render(n,format,o));
|
|
99
113
|
if(!opt['dry-run']){fs.mkdirSync(dir,{recursive:true});files.forEach(f=>fs.writeFileSync(path.join(dir,f.file),f.text))}
|
|
@@ -108,6 +122,21 @@ try{
|
|
|
108
122
|
else console.log('You have the latest version ('+mine+').');
|
|
109
123
|
if(!Lic.current().ok){console.log(Lic.FREE.size+' free icons included. '+(BUYLINE()||''));return}
|
|
110
124
|
const n=await download(true).catch(e=>{fail(e.message)});console.log(n?'Icons up to date: '+n+' icons.':'Icons up to date.')})();return}
|
|
125
|
+
// connect a shadcn project to the official registry: npx shadcn add @magic-glyphs/heart
|
|
126
|
+
else if(cmd==='shadcn'){const f=path.resolve(opt.out||'components.json');if(!fs.existsSync(f))fail('No components.json here. Run this in a shadcn project (npx shadcn@latest init), or pass --out path/to/components.json.');
|
|
127
|
+
let cfg;try{cfg=JSON.parse(fs.readFileSync(f,'utf8'))}catch(e){fail('components.json is not valid JSON.')}
|
|
128
|
+
// shadcn refuses every item from a registry whose key variable is missing, so the key header is only added for licensed users
|
|
129
|
+
const lic=Lic.current(),url=apiBase()+'/r/{name}.json';
|
|
130
|
+
cfg.registries=Object.assign({},cfg.registries,{'@magic-glyphs':lic.ok?{url,headers:{Authorization:'Bearer ${MAGIC_GLYPHS_KEY}'}}:url});
|
|
131
|
+
fs.writeFileSync(f,JSON.stringify(cfg,null,2)+'\n');
|
|
132
|
+
console.log('Added the @magic-glyphs registry to '+path.relative(process.cwd(),f)+'.\n\nAdd icons with:\n npx shadcn@latest add @magic-glyphs/heart @magic-glyphs/bell\n');
|
|
133
|
+
if(!lic.ok){console.log('The 120 free icons work now. For the rest, log in (npx magic-glyphs login YOUR-KEY), then run this command again.'+(buyUrl()?'\n'+BUYLINE():''));return}
|
|
134
|
+
const dir=path.dirname(f),envFile=path.join(dir,'.env.local'),key=process.env.MAGIC_GLYPHS_KEY||JSON.parse(fs.readFileSync(Lic.storeFile(),'utf8')).key;
|
|
135
|
+
if(opt.env){let t=fs.existsSync(envFile)?fs.readFileSync(envFile,'utf8'):'';t=t.replace(/^MAGIC_GLYPHS_KEY=.*\n?/m,'');fs.writeFileSync(envFile,(t&&!t.endsWith('\n')?t+'\n':t)+'MAGIC_GLYPHS_KEY='+key+'\n',{mode:0o600});
|
|
136
|
+
const gi=path.join(dir,'.gitignore'),g=fs.existsSync(gi)?fs.readFileSync(gi,'utf8'):'';
|
|
137
|
+
if(!/^\.env(\.local|\*|.*\*)?\s*$/m.test(g)&&!/^\*\.local\s*$/m.test(g)){fs.writeFileSync(gi,(g&&!g.endsWith('\n')?g+'\n':g)+'.env.local\n');console.log('Added .env.local to .gitignore.')}
|
|
138
|
+
console.log('Saved your licence key to .env.local for shadcn. Keep that file out of version control.')}
|
|
139
|
+
else console.log('Paid icons need your licence key where shadcn can read it. Either run this again with --env to save it to .env.local,\nor add this line to .env.local yourself (keep it out of version control):\n MAGIC_GLYPHS_KEY=<the key from: npx magic-glyphs licence --show-key>')}
|
|
111
140
|
else if(cmd==='buy'){const u=buyUrl();if(!u)fail('No buy page is configured.');console.log(u);if(openBuy())console.log('Opened in your browser.')}
|
|
112
141
|
else if(cmd==='login'||cmd==='sync'){
|
|
113
142
|
if(cmd==='login'){if(!pos[0]||/^<.*>$/.test(pos[0])||/gumroad-key|your-.*key|^x{8}(-x{8}){3}$/i.test(pos[0])){const o=openBuy();
|
|
@@ -116,21 +145,30 @@ try{
|
|
|
116
145
|
const p=Lic.login(pos[0]);console.log('Licence saved for '+p.email+' ('+p.plan+', '+p.seats+' seat'+(p.seats>1?'s':'')+').')}
|
|
117
146
|
else if(!Lic.current().ok)fail(Lic.current().reason);
|
|
118
147
|
download().then(n=>console.log(n?'Downloaded the full set: '+n+' icons.':'This copy already has every icon.')).catch(e=>fail('The key is saved, but the full set could not be downloaded ('+e.message+'). Try again with: magic-glyphs sync'));}
|
|
119
|
-
else if(cmd==='logout'){
|
|
148
|
+
else if(cmd==='logout'){let key=null;try{key=JSON.parse(fs.readFileSync(Lic.storeFile(),'utf8')).key}catch(e){}
|
|
149
|
+
// free this computer's device slot on the server too; logging out still works offline
|
|
150
|
+
const done=()=>console.log(Lic.logout()?'Licence key removed from this computer.':'No licence key was stored.');
|
|
151
|
+
const api=apiBase();if(!key||!/^https?:\/\//.test(api)){done();return}
|
|
152
|
+
fetch(api+'/v1/deactivate',{method:'POST',headers:{authorization:'Bearer '+key,'x-mg-device':Lic.deviceId()}}).then(r=>r.json()).then(d=>{done();if(d&&d.cap)console.log('This computer no longer counts towards the licence ('+d.devices+' of '+d.cap+' devices in use).')},()=>{done();console.log('Could not reach the licence server, so this computer still counts as a device until it has been unused for 30 days.')});return}
|
|
153
|
+
else if(cmd==='build-key'){const r=Lic.current();if(!r.ok)failBuy(r.reason);if(r.payload.build)fail('This is already a build key.');
|
|
154
|
+
const api=apiBase();if(!/^https?:\/\//.test(api))fail('No licence server is configured.');
|
|
155
|
+
fetch(api+'/v1/build-key',{method:'POST',headers:{authorization:'Bearer '+(process.env.MAGIC_GLYPHS_KEY||JSON.parse(fs.readFileSync(Lic.storeFile(),'utf8')).key)}}).then(async res=>{const d=await res.json().catch(()=>({}));if(!res.ok||!d.key)fail(d.error||'The licence server answered '+res.status+'.');
|
|
156
|
+
console.log(d.key+'\n\nThis is a build key for CI and build servers. It does not use a device slot.\nStore it as a secret named MAGIC_GLYPHS_KEY, then run: npx magic-glyphs sync');},e=>fail('The licence server could not be reached.'));return}
|
|
120
157
|
else if(cmd==='licence'||cmd==='license'){const r=Lic.current();if(opt['show-key']){if(!r.ok)fail(r.reason);console.log(process.env.MAGIC_GLYPHS_KEY||JSON.parse(fs.readFileSync(Lic.storeFile(),'utf8')).key);process.exit(0)}console.log(r.ok?'Licensed to '+r.payload.email+' ('+r.payload.plan+', '+r.payload.seats+' seat'+(r.payload.seats>1?'s':'')+(r.payload.expires?', until '+r.payload.expires:'')+'). All '+L.total+' icons available.':r.reason+'\n'+Lic.FREE.size+' free icons available: magic-glyphs list --free')}
|
|
121
158
|
else if(cmd==='bundle'){
|
|
122
|
-
|
|
159
|
+
// with --from and no names, only your own icons; otherwise everything this copy may use
|
|
160
|
+
const names=pos.length?pos:opt.from?[...L.custom]:L.index.map(i=>i.n).filter(n=>L.byName.has(n)&&(Lic.current().ok||Lic.isFree(n)||L.custom.has(n)));
|
|
123
161
|
const missing=names.filter(n=>!L.known.has(n));if(missing.length)fail('Unknown icon'+(missing.length>1?'s':'')+': '+missing.join(', '));
|
|
124
|
-
const paid=
|
|
162
|
+
const paid=L.locked(names);if(paid.length)fail(Lic.lockedMessage(paid));
|
|
125
163
|
if(names.some(n=>!L.byName.has(n)))fail('Your licence is valid, but the full icon set is not on this computer yet. Run: magic-glyphs sync');
|
|
126
164
|
const file=path.resolve(opt.out||'magic-glyphs.bundle.js'),d=Object.assign({},L.data,{icons:names.map(n=>L.byName.get(n)),count:names.length});
|
|
127
165
|
fs.mkdirSync(path.dirname(file),{recursive:true});fs.writeFileSync(file,fs.readFileSync(path.join(__dirname,'..','web','runtime.js'),'utf8')+'\nMagicGlyphs.register('+JSON.stringify(d)+');\n');
|
|
128
166
|
console.log('Wrote '+names.length+' icon'+(names.length>1?'s':'')+' to '+file+' ('+(fs.statSync(file).size/1024).toFixed(0)+' KB). Load it with a <script> tag, then use <magic-glyph name="...">.');
|
|
129
|
-
if(!pos.length&&names.length<L.total)console.log('Free set only ('+names.length+' of '+L.total+'). Run magic-glyphs login
|
|
167
|
+
if(!pos.length&&!opt.from&&names.length<L.total)console.log('Free set only ('+names.length+' of '+L.total+'). Run magic-glyphs login YOUR-KEY for the rest.')}
|
|
130
168
|
else if(cmd==='static'||cmd==='registry'){
|
|
131
|
-
const all=L.index.map(i=>i.n),names=all.filter(n=>L.byName.has(n)&&(Lic.current().ok||Lic.isFree(n))),dir=path.resolve(opt.out||(cmd==='static'?'magic-glyphs-static':'magic-glyphs-registry'));
|
|
132
|
-
if(cmd==='static'){const r=require('../tools/static.js').build(L,dir,{names,styles:opt.styles&&opt.styles.split(','),background:opt.background});console.log('Wrote '+r.files+' SVG files and '+r.styles.length+' sprite'+(r.styles.length>1?'s':'')+' for '+r.count+'
|
|
133
|
-
else{const r=require('../tools/registry.js').build(L,dir,{names,homepage:opt.homepage});console.log('Wrote registry.json and '+r.count+'
|
|
134
|
-
if(names.length<all.length)console.log('Free set only ('+names.length+' of '+all.length+'). Run magic-glyphs login
|
|
169
|
+
const all=L.index.map(i=>i.n),names=opt.from?[...L.custom]:all.filter(n=>L.byName.has(n)&&(Lic.current().ok||Lic.isFree(n)||L.custom.has(n))),dir=path.resolve(opt.out||(cmd==='static'?'magic-glyphs-static':'magic-glyphs-registry'));
|
|
170
|
+
if(cmd==='static'){const r=require('../tools/static.js').build(L,dir,{names,styles:opt.styles&&opt.styles.split(','),background:opt.background});console.log('Wrote '+r.files+' SVG files and '+r.styles.length+' sprite'+(r.styles.length>1?'s':'')+' for '+r.count+' icon'+(r.count===1?'':'s')+' to '+dir)}
|
|
171
|
+
else{const r=require('../tools/registry.js').build(L,dir,{names,homepage:opt.homepage});console.log('Wrote registry.json and '+r.count+' item'+(r.count===1?'':'s')+' to '+dir)}
|
|
172
|
+
if(!opt.from&&names.length<all.length)console.log('Free set only ('+names.length+' of '+all.length+'). Run magic-glyphs login YOUR-KEY for the rest.')}
|
|
135
173
|
else fail('Unknown command "'+cmd+'". Run: magic-glyphs --help');
|
|
136
174
|
}catch(e){fail(e.message)}
|