magic-glyphs 0.6.1 → 0.6.2

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/cli/index.js CHANGED
@@ -15,6 +15,8 @@ Usage
15
15
  magic-glyphs static [--out <dir>] [--styles outline,solid,duotone] plain SVG files and sprites, no JavaScript
16
16
  magic-glyphs registry [--out <dir>] [--homepage <url>] shadcn registry files to host
17
17
  magic-glyphs login YOUR-KEY | sync | logout | licence paid icons need a licence key; sync re-downloads the full set
18
+ magic-glyphs update check for a newer version and download new paid icons
19
+ magic-glyphs --version
18
20
  magic-glyphs buy open the page where you can buy a licence
19
21
 
20
22
  Options for add
@@ -25,6 +27,7 @@ Options for add
25
27
  --secondary <hex> duotone fill colour
26
28
  --background <hex> colour knocked out of solid icons (default #ffffff)
27
29
  --size <px> svg width and height (default 24)
30
+ --ts | --js typed or plain React/Vue components (default: typed when the project has a tsconfig.json)
28
31
  --stdout print a single icon instead of writing a file
29
32
  --dry-run show what would be written
30
33
 
@@ -34,8 +37,8 @@ Examples
34
37
  magic-glyphs add --category arrows --format lottie --color "#2747f5" --out assets/lottie
35
38
  `;
36
39
  function parse(argv){const pos=[],opt={};for(let i=0;i<argv.length;i++){const a=argv[i];
37
- if(a.startsWith('--')){const k=a.slice(2);if(['json','all','stdout','dry-run','help','free','show-key'].includes(k))opt[k]=true;else{if(i+1>=argv.length)fail('Option --'+k+' needs a value.');opt[k]=argv[++i]}}
38
- else if(a==='-h')opt.help=true;else pos.push(a)}return{pos,opt}}
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]}}
41
+ else if(a==='-h')opt.help=true;else if(a==='-v')opt.version=true;else pos.push(a)}return{pos,opt}}
39
42
  // fetch the full set for a valid key; the server address comes from MAGIC_GLYPHS_API or package.json "magicGlyphs.api"
40
43
  const apiBase=()=>(process.env.MAGIC_GLYPHS_API||(require('../package.json').magicGlyphs||{}).api||'').replace(/\/$/,'');
41
44
  // swap the licence key from a Gumroad receipt for a Magic Glyphs key; the server checks the purchase with Gumroad
@@ -44,9 +47,9 @@ async function redeem(gumroadKey){
44
47
  const api=apiBase();if(!/^https?:\/\//.test(api))throw new Error('no licence server is configured');
45
48
  let r;try{r=await fetch(api+'/v1/redeem',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({licence_key:gumroadKey})})}catch(e){throw new Error('The licence server could not be reached. Check your connection and try again.')}
46
49
  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}
47
- async function download(){
50
+ async function download(force){
48
51
  const api=(process.env.MAGIC_GLYPHS_API||(require('../package.json').magicGlyphs||{}).api||'').replace(/\/$/,'');
49
- if(L.data.icons.length>=L.total&&!process.env.MAGIC_GLYPHS_API)return 0;
52
+ if(!force&&L.data.icons.length>=L.total&&!process.env.MAGIC_GLYPHS_API)return 0;
50
53
  if(!/^https?:\/\//.test(api))throw new Error('no download server is configured');
51
54
  const key=process.env.MAGIC_GLYPHS_KEY||JSON.parse(fs.readFileSync(Lic.storeFile(),'utf8')).key;
52
55
  const r=await fetch(api+'/v1/icons.json',{headers:{authorization:'Bearer '+key}});
@@ -65,6 +68,7 @@ function openBuy(){const u=buyUrl();if(!u)return false;
65
68
  function failBuy(msg){process.stderr.write('magic-glyphs: '+msg+'\n');const b=BUYLINE();if(b)process.stderr.write(b+'\n');process.exit(1)}
66
69
  const {pos,opt}=parse(process.argv.slice(2)),cmd=pos.shift();
67
70
  try{
71
+ if(opt.version||cmd==='version'){console.log(require('../package.json').version);process.exit(0)}
68
72
  if(!cmd||opt.help||cmd==='help'){process.stdout.write(HELP);process.exit(cmd||opt.help?0:1)}
69
73
  if(opt.category&&!L.categories()[opt.category])fail('No category "'+opt.category+'". Run: magic-glyphs categories');
70
74
  if(cmd==='categories'){const c=L.categories();Object.keys(c).sort().forEach(k=>console.log(k.padEnd(12)+String(c[k]).padStart(5)));console.log('total'.padEnd(12)+String(L.total).padStart(5))}
@@ -86,6 +90,8 @@ try{
86
90
  const paid=Lic.locked(names);if(paid.length)fail(Lic.lockedMessage(paid));
87
91
  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');
88
92
  const format=opt.format||'svg',o={style:opt.style,color:opt.color,secondary:opt.secondary,background:opt.background,size:opt.size&&+opt.size};
93
+ // 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
+ 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}})();
89
95
  if(opt.size&&!(+opt.size>0))fail('--size must be a positive number.');
90
96
  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.');
91
97
  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')}
@@ -94,6 +100,14 @@ try{
94
100
  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(', '):''));
95
101
  if(format==='react'||format==='vue')console.log('These components import from the "magic-glyphs" package, so keep it installed.');}
96
102
  }
103
+ else if(cmd==='update'){const mine=require('../package.json').version;
104
+ const newer=(a,b)=>{const x=a.split(/[.-]/).map(Number),y=b.split(/[.-]/).map(Number);for(let i=0;i<3;i++){if((x[i]||0)!==(y[i]||0))return (x[i]||0)>(y[i]||0)}return false};
105
+ (async()=>{let latest=null;try{const r=await fetch('https://registry.npmjs.org/magic-glyphs/latest');if(r.ok)latest=(await r.json()).version}catch(e){}
106
+ if(!latest)console.log('Could not reach npm to check for a newer version. This is '+mine+'.');
107
+ else if(newer(latest,mine))console.log('Version '+latest+' is out (this is '+mine+'). Install it with:\n npm install magic-glyphs@latest\nThen run: npx magic-glyphs update');
108
+ else console.log('You have the latest version ('+mine+').');
109
+ if(!Lic.current().ok){console.log(Lic.FREE.size+' free icons included. '+(BUYLINE()||''));return}
110
+ const n=await download(true).catch(e=>{fail(e.message)});console.log(n?'Icons up to date: '+n+' icons.':'Icons up to date.')})();return}
97
111
  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.')}
98
112
  else if(cmd==='login'||cmd==='sync'){
99
113
  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();
@@ -1,3 +1,3 @@
1
1
  -----BEGIN PUBLIC KEY-----
2
- MCowBQYDK2VwAyEA5tsjyMq4h9oCMM/n+No5T+MiSHyGkGdbK+ZZUyrEJwE=
2
+ MCowBQYDK2VwAyEA6Loi7wNb1K3CwORpFsmkeBzM8VNKMzT8q1eUjBaZUAM=
3
3
  -----END PUBLIC KEY-----
package/docs/cli.md CHANGED
@@ -58,6 +58,8 @@ Files for non-outline styles carry the style in the name, for example `heart.duo
58
58
  ```bash
59
59
  npx magic-glyphs login YOUR-LICENCE-KEY # the key from your Gumroad receipt (no < > around it); downloads the full library
60
60
  npx magic-glyphs buy # opens the page where you can buy a licence
61
+ npx magic-glyphs update # tells you if a newer version is out, then downloads new paid icons
62
+ npx magic-glyphs --version
61
63
  npx magic-glyphs licence # who this computer is licensed to
62
64
  npx magic-glyphs licence --show-key # prints the key to use on a build server
63
65
  npx magic-glyphs sync # download the full library again
package/docs/react-vue.md CHANGED
@@ -53,6 +53,10 @@ import HeartGlyph from './icons/HeartGlyph';
53
53
 
54
54
  Each file registers just its own icon, so the bundle contains the 7 KB engine plus the icons you added.
55
55
 
56
+ In a TypeScript project (one with a `tsconfig.json`), the CLI writes typed components: `.tsx` for React and `<script setup lang="ts">` for Vue, so `tsc` and `vue-tsc` builds pass. Add `--js` or `--ts` to choose yourself. React components start with `'use client'`, so they work inside Next.js server components.
57
+
58
+ Tested with the default Vite React + TypeScript and Vue + TypeScript templates, and with Next.js (App Router).
59
+
56
60
  ## Module format
57
61
 
58
62
  The package is CommonJS today. Vite, webpack, Next.js and Nuxt import it without configuration. A native ES module build is planned.
package/lib.js CHANGED
@@ -50,8 +50,10 @@ function render(name,format,o){
50
50
  case 'lottie':{if(style==='glass')throw new Error('Lottie export supports outline, solid and duotone (glass uses a gradient that Lottie players handle inconsistently).');
51
51
  const {toLottie}=require('./tools/lottie.js');return{ext:'json',file:name+(style==='outline'?'':'.'+style)+'.lottie.json',text:JSON.stringify(toLottie(ic,Object.assign({},o,{color:o.color||'#000000'})))}}
52
52
  case 'json':return{ext:'json',file:name+'.json',text:JSON.stringify(ic)};
53
- case 'react':return{ext:'jsx',file:pascal(name)+'Glyph.jsx',text:`import { MagicGlyph, register } from 'magic-glyphs/react';\n\nregister([${JSON.stringify(ic)}]);\n\n/** Animated "${name}" icon. Props: variant, size, trigger, label, className, style. */\nexport default function ${pascal(name)}Glyph(props) {\n return <MagicGlyph name="${name}" variant="${style}" {...props} />;\n}\n`};
54
- case 'vue':return{ext:'vue',file:pascal(name)+'Glyph.vue',text:`<script setup>\nimport { MagicGlyph, register } from 'magic-glyphs/vue';\n\nregister([${JSON.stringify(ic)}]);\n</script>\n\n<template>\n <MagicGlyph name="${name}" variant="${style}" v-bind="$attrs" />\n</template>\n`};
53
+ case 'react':{const P=pascal(name),ts=!!o.ts;
54
+ // "use client" lets the component sit inside a Next.js server component tree; other bundlers ignore it
55
+ return{ext:ts?'tsx':'jsx',file:P+'Glyph.'+(ts?'tsx':'jsx'),text:`'use client';\nimport { MagicGlyph, register${ts?', type MagicGlyphProps':''} } from 'magic-glyphs/react';\n\nregister([${JSON.stringify(ic)}]);\n\n/** Animated "${name}" icon. Props: variant, size, trigger, label, sound, className, style. */\nexport default function ${P}Glyph(props${ts?": Omit<MagicGlyphProps, 'name'>":''}) {\n return <MagicGlyph name="${name}" variant="${style}" {...props} />;\n}\n`}}
56
+ case 'vue':return{ext:'vue',file:pascal(name)+'Glyph.vue',text:`<script setup${o.ts?' lang="ts"':''}>\nimport { MagicGlyph, register } from 'magic-glyphs/vue';\n\nregister([${JSON.stringify(ic)}]);\n</script>\n\n<template>\n <MagicGlyph name="${name}" variant="${style}" v-bind="$attrs" />\n</template>\n`};
55
57
  case 'html':return{ext:'html',file:name+'.html',text:`<magic-glyph name="${name}"${style==='outline'?'':' variant="'+style+'"'}${o.size?' size="'+o.size+'"':''}></magic-glyph>`};
56
58
  default:throw new Error('Unknown format "'+format+'". Use one of: '+FORMATS.join(', '));
57
59
  }
package/mcp/server.js CHANGED
@@ -24,6 +24,7 @@ server.registerTool('get_icon',{title:'Get icon',
24
24
  color:z.string().regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/).optional().describe('Hex colour for svg and lottie output'),secondary:z.string().regex(/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/).optional().describe('Hex duotone fill colour'),size:z.number().positive().max(2048).optional().describe('Pixel size for svg and html')},
25
25
  annotations:{readOnlyHint:true}},
26
26
  async({name,format,style,color,secondary,size})=>{
27
+ if(!L.byName.has(name)&&L.known.has(name)){const Lic=require('../licence.js');return err(Lic.current().ok?'"'+name+'" is in the paid set. The licence is valid, but the full set is not on this computer yet. Run: npx magic-glyphs sync':Lic.lockedMessage([name])+'\nTell the user this icon needs a Magic Glyphs licence, or pick a free icon instead (search results marked "free").')}
27
28
  if(!L.byName.has(name)){const s=L.search(name,{limit:5}).map(x=>x.name);return err('No icon named "'+name+'".'+(s.length?' Did you mean: '+s.join(', ')+'?':' Use search_icons to find one.'))}
28
29
  {const Lic=require('../licence.js'),paid=Lic.locked([name]);if(paid.length)return err(Lic.lockedMessage(paid))}
29
30
  try{const f=L.render(name,format||'html',{style,color,secondary,size});return text('File: '+f.file+'\n\n'+f.text)}catch(e){return err(e.message)}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magic-glyphs",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Animated icons with spring motion and sound: web component, React, Vue, static SVG, Lottie export and a CLI. 120 icons free.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "Lewis John Villamor",
@@ -9,13 +9,19 @@
9
9
  "magic-glyphs": "cli/index.js"
10
10
  },
11
11
  "exports": {
12
- ".": "./web/runtime.js",
12
+ ".": {
13
+ "types": "./web/runtime.d.ts",
14
+ "default": "./web/runtime.js"
15
+ },
13
16
  "./all": "./web/magic-glyphs.all.js",
14
17
  "./react": {
15
18
  "types": "./react/index.d.ts",
16
19
  "default": "./react/index.js"
17
20
  },
18
- "./vue": "./vue/index.js",
21
+ "./vue": {
22
+ "types": "./vue/index.d.ts",
23
+ "default": "./vue/index.js"
24
+ },
19
25
  "./lottie": "./tools/lottie.js",
20
26
  "./node": "./lib.js",
21
27
  "./icons.json": "./data/icons.json",
@@ -71,5 +77,6 @@
71
77
  "api": "https://magic-glyphs-licence.lewisvillamor26.workers.dev",
72
78
  "buy": "https://magicscraper.gumroad.com/l/vjaxbp"
73
79
  },
74
- "homepage": "https://magic-glyphs-site.lewisvillamor26.workers.dev"
80
+ "homepage": "https://magic-glyphs-site.lewisvillamor26.workers.dev",
81
+ "types": "./web/runtime.d.ts"
75
82
  }
package/react/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  // Magic Glyphs for React. Usage: <MagicGlyph name="heart" variant="duotone" trigger="hover" size={32} label="Like" />
2
3
  // Renders the SVG on the server and the client; animation attaches after mount.
3
4
  const React=require('react');const MG=require('../web/runtime.js');
package/vue/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { DefineComponent } from 'vue';
2
+ export type GlyphVariant = 'outline' | 'solid' | 'duotone' | 'glass';
3
+ export interface MagicGlyphProps {
4
+ name: string;
5
+ variant?: GlyphVariant;
6
+ size?: number | string;
7
+ /** When the animation plays. Default "hover". */
8
+ trigger?: 'hover' | 'click' | 'load' | 'none';
9
+ /** Accessible name. Leave out for decorative icons. */
10
+ label?: string;
11
+ /** Play the icon's sound with its animation. */
12
+ sound?: boolean;
13
+ }
14
+ export const MagicGlyph: DefineComponent<MagicGlyphProps>;
15
+ export function register(icons: unknown): void;
16
+ export const sound: { enable(on?: boolean): void; enabled(): boolean; volume(v?: number): number };
@@ -0,0 +1,27 @@
1
+ // Types for the Magic Glyphs web runtime: import MagicGlyphs from 'magic-glyphs'
2
+ export type GlyphStyle = 'outline' | 'solid' | 'duotone' | 'glass';
3
+ export interface GlyphPlayer { play(): void; }
4
+ export interface GlyphSound {
5
+ /** Turn sound on or off for every icon. Off by default. */
6
+ enable(on?: boolean): void;
7
+ enabled(): boolean;
8
+ /** Get or set the volume, 0 to 1. */
9
+ volume(v?: number): number;
10
+ play(name: string, pan?: number): void;
11
+ names(): string[];
12
+ unlocked(): boolean;
13
+ }
14
+ export interface MagicGlyphsRuntime {
15
+ /** Add icon data, from a generated component or magic-glyphs/icons.json. */
16
+ register(icons: unknown): MagicGlyphsRuntime;
17
+ /** SVG markup for an icon in its resting pose. */
18
+ svg(name: string, options?: { style?: GlyphStyle; size?: number | string; title?: string }): string;
19
+ /** Make an element holding the icon's SVG playable. */
20
+ attach(element: Element, name: string): GlyphPlayer;
21
+ has(name: string): boolean;
22
+ names(): string[];
23
+ sound: GlyphSound;
24
+ [key: string]: unknown;
25
+ }
26
+ declare const MagicGlyphs: MagicGlyphsRuntime;
27
+ export = MagicGlyphs;