magic-glyphs 0.7.0 → 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.
@@ -0,0 +1,18 @@
1
+ # Flutter
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ flutter pub add lottie audioplayers
7
+ npx magic-glyphs add heart bell --format flutter --sound --out lib/icons
8
+ ```
9
+
10
+ Each icon is one `.dart` file with its animation built in. For sound, move the `.wav` files to `assets/` and list them in `pubspec.yaml`.
11
+
12
+ ## Use
13
+
14
+ ```dart
15
+ const HeartGlyph(size: 28, sound: true, label: 'Like')
16
+ ```
17
+
18
+ > Generated from the same Lottie export as the other platforms, which is checked against an independent Lottie renderer. These component files have not yet been run on real devices; please report anything that does not work.
@@ -0,0 +1,21 @@
1
+ # Jetpack Compose
2
+
3
+ ## Install
4
+
5
+ ```kotlin
6
+ implementation("com.airbnb.android:lottie-compose:6.6.0")
7
+ ```
8
+
9
+ ```bash
10
+ npx magic-glyphs add heart bell --format compose --sound --out app/src/main/java/magicglyphs
11
+ ```
12
+
13
+ Each icon is one `.kt` file with its animation built in. For sound, move the `.wav` files to `res/raw` (dashes become underscores, so `heart.wav` stays `heart.wav`, `chat-reply.wav` becomes `chat_reply.wav`).
14
+
15
+ ## Use
16
+
17
+ ```kotlin
18
+ HeartGlyph(size = 28.dp, sound = true, label = "Like")
19
+ ```
20
+
21
+ > Generated from the same Lottie export as the other platforms, which is checked against an independent Lottie renderer. These component files have not yet been run on real devices; please report anything that does not work.
package/docs/maker.md ADDED
@@ -0,0 +1,64 @@
1
+ # Icon maker guide
2
+
3
+ The icon maker turns your own artwork into an animated icon with motion and sound, in the same style as the library. It is included with every paid licence; you can try it with the sample before unlocking.
4
+
5
+ ## 1. Unlock
6
+
7
+ Paste the licence key from your Gumroad receipt at the top of the [icon maker](https://magic-glyphs-site.lewisvillamor26.workers.dev/maker/) and press **Unlock**. The browser remembers it. Use **Remove key from this browser** on the [icon browser](https://magic-glyphs-site.lewisvillamor26.workers.dev/icons/) when you are on a shared computer.
8
+
9
+ ## 2. Start from your artwork
10
+
11
+ - **Upload SVG or image:** an `.svg` file, or a PNG, JPG or WebP logo. Images are traced into shapes; this works best on simple, high-contrast artwork with a plain background.
12
+ - **Paste SVG code:** straight from Figma, Illustrator or any icon set you own.
13
+ - **Remix a library icon:** type its name, for example `rocket`, and press **Remix**. Its drawing, motion and sound are kept, ready for you to change.
14
+
15
+ The maker fits everything to the 24-pixel grid with a little padding, so it sits nicely next to library icons.
16
+
17
+ ## 3. Shape
18
+
19
+ - **Line icon or filled shape:** line icons are drawn with the library's stroke; filled shapes are solid.
20
+ - **Parts:** each separate shape becomes a part. Untick **Moves** to keep a part still. Tick **Detail** for small inner marks (an eye, a dot) so they stay lines in the solid style.
21
+
22
+ ## 4. Motion
23
+
24
+ Pick a motion: pop, bounce, drop in, wiggle, swing, spin, slide, shake, float, pulse, tilt or still. **Strength** sets how far it moves; **Snappy**, **Normal** and **Bouncy** set the feel.
25
+
26
+ **Give each part its own motion.** Select a part in the list: the motion buttons now apply to that part only. Choose a motion and use **Start after** to delay it, so parts move in sequence. For example, a box that pops while its lid spins in 200 ms later. **Same as all parts** returns a part to the shared motion; **Done with this part** goes back to editing all parts.
27
+
28
+ ## 5. Sound
29
+
30
+ Choose one of 39 sounds, then tune it:
31
+
32
+ | Slider | What it does |
33
+ |---|---|
34
+ | Volume | Louder or quieter than other icons |
35
+ | Pitch | Higher or lower, in semitones |
36
+ | Speed | Faster or slower |
37
+ | Tone | Softer (muffled) to brighter |
38
+ | Stereo | How far the sound follows the icon left and right on screen |
39
+ | Delay | When the sound starts after the motion begins |
40
+
41
+ Press **Hear it**, or the preview itself, to listen. Browsers play sound only after you have clicked on the page.
42
+
43
+ ## 6. Save
44
+
45
+ **Save to My icons** keeps the icon with your licence. Your saved icons appear in any browser where you unlock with the same key, and they are also kept in this browser. Up to 100 icons are kept; delete the ones you no longer need. What you are working on right now is kept in the browser too, so a refresh never loses it.
46
+
47
+ ## 7. Export
48
+
49
+ - **SVG:** a still image.
50
+ - **React (.tsx or .jsx), Vue, HTML:** animated, with your sound settings, using the free `magic-glyphs` package.
51
+ - **Lottie:** the motion, for any Lottie player on iOS, Android, Windows or Flutter.
52
+ - **Sound (.wav):** the sound with your settings, to play alongside Lottie in native apps.
53
+ - **Icon data (JSON):** use your icon everywhere the library works:
54
+
55
+ ```bash
56
+ npx magic-glyphs add my-logo --from my-icons/ --format react # or swiftui, flutter, compose, winui
57
+ MAGIC_GLYPHS_CUSTOM=./my-icons npx -y magic-glyphs-mcp # your coding assistant can use them too
58
+ ```
59
+
60
+ ## Tips
61
+
62
+ - Simpler artwork animates better. Merge tiny shapes in your design tool before importing.
63
+ - Convert text to outlines first; the maker reads shapes, not fonts.
64
+ - Your icons are yours. The maker runs in your browser; only icons you save are stored, with your licence.
@@ -0,0 +1,34 @@
1
+ # React Native
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ npm install lottie-react-native
7
+ npx magic-glyphs add heart bell --format react-native --sound --out src/icons
8
+ ```
9
+
10
+ Each icon is one `.tsx` file with its animation built in. `--sound` also writes `heart.wav` and `bell.wav`.
11
+
12
+ ## Use
13
+
14
+ ```tsx
15
+ import HeartGlyph from './src/icons/HeartGlyph';
16
+
17
+ <HeartGlyph size=28 accessibilityLabel="Like" />
18
+ ```
19
+
20
+ The icon plays when pressed. Props: `size`, `playOnPress`, `onPlay`, `accessibilityLabel`, `style`.
21
+
22
+ ## Sound
23
+
24
+ Play the WAV from `onPlay` with the audio library you already use, for example Expo:
25
+
26
+ ```tsx
27
+ import { useAudioPlayer } from 'expo-audio';
28
+ const player = useAudioPlayer(require('./src/icons/heart.wav'));
29
+ <HeartGlyph onPlay={() => { player.seekTo(0); player.play(); }} />
30
+ ```
31
+
32
+ The generated component type-checks against `react-native` and `lottie-react-native`.
33
+
34
+ > Generated from the same Lottie export as the other platforms, which is checked against an independent Lottie renderer. These component files have not yet been run on real devices; please report anything that does not work.
package/docs/react-vue.md CHANGED
@@ -55,7 +55,7 @@ Each file registers just its own icon, so the bundle contains the 7 KB engine pl
55
55
 
56
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
57
 
58
- Tested with the default Vite React + TypeScript and Vue + TypeScript templates, and with Next.js (App Router).
58
+ Tested with the default Vite React + TypeScript and Vue + TypeScript templates, Next.js (App Router) and Nuxt 4. In Nuxt, generated components in `components/` are picked up automatically, and icons render on the server.
59
59
 
60
60
  ## A mute switch
61
61
 
@@ -0,0 +1,22 @@
1
+ # SwiftUI
2
+
3
+ ## Install
4
+
5
+ Add the [Lottie package](https://github.com/airbnb/lottie-ios) (4.4 or later) to your Xcode project, then:
6
+
7
+ ```bash
8
+ npx magic-glyphs add heart bell --format swiftui --sound --out MyApp/Icons
9
+ ```
10
+
11
+ Each icon is one `.swift` file with its animation built in. Add the `.wav` files to the app bundle for sound.
12
+
13
+ ## Use
14
+
15
+ ```swift
16
+ HeartGlyph(size: 28, label: "Like")
17
+ HeartGlyph(size: 28, sound: false)
18
+ ```
19
+
20
+ The icon plays when tapped, and its sound plays with it if the WAV is in the bundle.
21
+
22
+ > Generated from the same Lottie export as the other platforms, which is checked against an independent Lottie renderer. These component files have not yet been run on real devices; please report anything that does not work.
@@ -0,0 +1,15 @@
1
+ # Tauri and Rust
2
+
3
+ ## Tauri, Dioxus and Leptos
4
+
5
+ These apps draw their interface in a web view, so Magic Glyphs works exactly as on the web, including sound:
6
+
7
+ ```bash
8
+ npm install magic-glyphs
9
+ ```
10
+
11
+ Then use the `<magic-glyph>` tag, or the React, Vue or Svelte setup your front end uses. Everything runs locally; no network access is needed at run time. For paid icons, bundle what you use with `npx magic-glyphs bundle heart bell --out src/magic-glyphs.js` so the app needs no licence check at run time.
12
+
13
+ ## Native Rust interfaces (egui, iced, Slint)
14
+
15
+ Export still icons with `npx magic-glyphs static --out assets/icons` and load the SVG files with your toolkit's SVG support, or export Lottie files for a Lottie player. A native Rust crate with animation is planned.
@@ -0,0 +1,23 @@
1
+ # Windows (WinUI)
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ dotnet add package CommunityToolkit.WinUI.Lottie
7
+ npx magic-glyphs add heart bell --format winui --sound --out Icons
8
+ ```
9
+
10
+ Each icon is one `.cs` control with its animation built in. Add the `.wav` files to the project as Content for sound.
11
+
12
+ ## Use
13
+
14
+ ```csharp
15
+ var heart = new HeartGlyph(28) { Sound = true };
16
+ panel.Children.Add(heart);
17
+ ```
18
+
19
+ The icon plays when tapped. Call `heart.Play()` to play it from code.
20
+
21
+ For WPF, Electron or Tauri on Windows, use the web or Lottie routes instead.
22
+
23
+ > Generated from the same Lottie export as the other platforms, which is checked against an independent Lottie renderer. These component files have not yet been run on real devices; please report anything that does not work.
package/lib.js CHANGED
@@ -12,7 +12,7 @@ const data=loadData();MG.register(data);
12
12
  const idxFile=path.join(__dirname,'data','index.json');
13
13
  const index=(()=>{let ix=null;try{ix=JSON.parse(fs.readFileSync(idxFile,'utf8'))}catch(e){}const own=data.icons.map(i=>({n:i.n,c:i.c,t:i.t}));return ix&&ix.length>own.length?ix:own})();
14
14
  const known=new Set(index.map(i=>i.n)),total=index.length;
15
- const STYLES=['outline','solid','duotone','glass'],FORMATS=['svg','lottie','json','react','vue','html'];
15
+ const STYLES=['outline','solid','duotone','glass'],FORMATS=['svg','lottie','json','react','vue','html','react-native','swiftui','compose','flutter','winui'];
16
16
  const byName=new Map(data.icons.map(i=>[i.n,i]));
17
17
  const categories=()=>{const c={};index.forEach(i=>c[i.c]=(c[i.c]||0)+1);return c};
18
18
  function search(query,opt){
@@ -50,6 +50,9 @@ 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
+ // native apps: one file each, with the Lottie animation inside (see tools/native.js)
54
+ case 'react-native':case 'swiftui':case 'compose':case 'flutter':case 'winui':{if(style==='glass')throw new Error('Native formats support outline, solid and duotone.');
55
+ const f=require('./tools/native.js')[format](ic,Object.assign({},o,{style}));return{ext:f.file.split('.').pop(),file:f.file,text:f.text}}
53
56
  case 'react':{const P=pascal(name),ts=!!o.ts;
54
57
  // "use client" lets the component sit inside a Next.js server component tree; other bundlers ignore it
55
58
  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`}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "magic-glyphs",
3
- "version": "0.7.0",
4
- "description": "Animated icons with spring motion and sound: web component, React, Vue, static SVG, Lottie export and a CLI. 120 icons free.",
3
+ "version": "0.7.1",
4
+ "description": "Animated icon library with sound: spring-animated SVG icons for React, Next.js, Vue, Nuxt, Svelte, Astro, shadcn, HTML, Tailwind, Lottie (iOS, Android, Flutter, Windows) and a CLI and MCP server. 120 icons free.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "Lewis John Villamor",
7
7
  "main": "lib.js",
@@ -66,17 +66,46 @@
66
66
  "keywords": [
67
67
  "icons",
68
68
  "animated icons",
69
- "svg",
70
- "lottie",
71
- "react",
72
- "vue",
69
+ "icon library",
70
+ "svg icons",
71
+ "react icons",
72
+ "vue icons",
73
+ "svelte icons",
74
+ "nextjs",
75
+ "nuxt",
76
+ "astro",
77
+ "shadcn",
78
+ "shadcn icons",
79
+ "tailwind",
73
80
  "web component",
74
- "mcp"
81
+ "custom element",
82
+ "lottie",
83
+ "lottie icons",
84
+ "react native",
85
+ "swiftui",
86
+ "jetpack compose",
87
+ "flutter",
88
+ "micro-interactions",
89
+ "ui sound",
90
+ "sound effects",
91
+ "icon animation",
92
+ "motion",
93
+ "mcp",
94
+ "mcp server",
95
+ "cli",
96
+ "icon maker"
75
97
  ],
76
98
  "magicGlyphs": {
77
99
  "api": "https://magic-glyphs-licence.lewisvillamor26.workers.dev",
78
100
  "buy": "https://magicscraper.gumroad.com/l/vjaxbp"
79
101
  },
80
102
  "homepage": "https://magic-glyphs-site.lewisvillamor26.workers.dev",
81
- "types": "./web/runtime.d.ts"
103
+ "types": "./web/runtime.d.ts",
104
+ "repository": {
105
+ "type": "git",
106
+ "url": "git+https://github.com/lewisjohnvillamor/magic-glyphs.git"
107
+ },
108
+ "bugs": {
109
+ "url": "https://github.com/lewisjohnvillamor/magic-glyphs/issues"
110
+ }
82
111
  }
@@ -1,10 +1,12 @@
1
1
  {%- comment -%}
2
2
  Magic Glyphs snippet. Upload magic-glyphs.all.js to the theme's assets folder, save this file as snippets/magic-glyph.liquid, then:
3
3
  {% render 'magic-glyph', name: 'cart', variant: 'duotone', size: 28, trigger: 'hover', label: 'Cart' %}
4
- The script tag is printed once per page however many icons are rendered.
4
+ Snippets cannot share variables in Shopify, so the script loads itself once per page however many icons are rendered.
5
+ Sound: add sound: true. A mute switch for shoppers: {% render 'magic-glyph', toggle: true %}
5
6
  {%- endcomment -%}
6
- {%- unless magic_glyphs_loaded -%}
7
- <script src="{{ 'magic-glyphs.all.js' | asset_url }}" defer></script>
8
- {%- assign magic_glyphs_loaded = true -%}
9
- {%- endunless -%}
10
- <magic-glyph name="{{ name | escape }}" variant="{{ variant | default: 'outline' | escape }}" size="{{ size | default: 24 | escape }}" trigger="{{ trigger | default: 'hover' | escape }}"{% if label %} label="{{ label | escape }}"{% endif %}></magic-glyph>
7
+ <script>(function(){if(window.__magicGlyphsLoading)return;window.__magicGlyphsLoading=1;var s=document.createElement('script');s.src={{ 'magic-glyphs.all.js' | asset_url | json }};s.defer=true;document.head.appendChild(s)})()</script>
8
+ {%- if toggle -%}
9
+ <magic-glyphs-sound-toggle default="{% if default_on == false %}off{% else %}on{% endif %}"></magic-glyphs-sound-toggle>
10
+ {%- else -%}
11
+ <magic-glyph name="{{ name | escape }}" variant="{{ variant | default: 'outline' | escape }}" size="{{ size | default: 24 | escape }}" trigger="{{ trigger | default: 'hover' | escape }}"{% if label %} label="{{ label | escape }}"{% endif %}{% if sound %} sound{% endif %}></magic-glyph>
12
+ {%- endif -%}
@@ -0,0 +1,208 @@
1
+ // One-file components for native apps. Each embeds the icon's Lottie animation, so there is no asset to copy;
2
+ // if a <name>.wav from `--sound` is bundled with the app, the component plays it with the animation.
3
+ function lottieJson(ic, o) { const { toLottie } = require('./lottie.js'); return JSON.stringify(toLottie(ic, Object.assign({}, o, { color: o.color || '#000000' }))); }
4
+ const pascal = (n) => n.split(/[^a-z0-9]+/i).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join('').replace(/^(\d)/, 'Glyph$1');
5
+ const camel = (n) => { const p = pascal(n); return p[0].toLowerCase() + p.slice(1); };
6
+
7
+ function reactNative(ic, o) {
8
+ const P = pascal(ic.n), j = lottieJson(ic, o);
9
+ return { file: P + 'Glyph.tsx', text: `// Animated "${ic.n}" icon from Magic Glyphs for React Native.
10
+ // Needs: npm install lottie-react-native (sound, optional: npx expo install expo-audio, and bundle ${ic.n}.wav)
11
+ import React, { useRef } from 'react';
12
+ import { Pressable, type StyleProp, type ViewStyle } from 'react-native';
13
+ import LottieView from 'lottie-react-native';
14
+
15
+ const animation = ${j};
16
+
17
+ export type ${P}GlyphProps = {
18
+ size?: number;
19
+ /** Play when pressed (default true). */
20
+ playOnPress?: boolean;
21
+ /** Called when it plays, for example to play its sound with expo-audio. */
22
+ onPlay?: () => void;
23
+ accessibilityLabel?: string;
24
+ style?: StyleProp<ViewStyle>;
25
+ };
26
+
27
+ export default function ${P}Glyph({ size = 24, playOnPress = true, onPlay, accessibilityLabel, style }: ${P}GlyphProps) {
28
+ const ref = useRef<LottieView>(null);
29
+ const play = () => { ref.current?.reset(); ref.current?.play(); onPlay?.(); };
30
+ return (
31
+ <Pressable onPress={playOnPress ? play : undefined} accessibilityRole={accessibilityLabel ? 'button' : undefined}
32
+ accessibilityLabel={accessibilityLabel} accessibilityElementsHidden={!accessibilityLabel} style={style}>
33
+ <LottieView ref={ref} source={animation} autoPlay={false} loop={false} style={{ width: size, height: size }} />
34
+ </Pressable>
35
+ );
36
+ }
37
+ ` };
38
+ }
39
+
40
+ function swiftui(ic, o) {
41
+ const P = pascal(ic.n), j = lottieJson(ic, o);
42
+ return { file: P + 'Glyph.swift', text: `// Animated "${ic.n}" icon from Magic Glyphs for SwiftUI (iOS 15+, macOS 12+).
43
+ // Needs the Lottie package: https://github.com/airbnb/lottie-ios (4.4 or later).
44
+ // Sound, optional: add ${ic.n}.wav to the app bundle and it plays with the animation.
45
+ import SwiftUI
46
+ import Lottie
47
+ import AVFoundation
48
+
49
+ public struct ${P}Glyph: View {
50
+ private static let animation = LottieAnimation.from(data: Data(#"${j}"#.utf8))
51
+ private static var player: AVAudioPlayer? = Bundle.main.url(forResource: "${ic.n}", withExtension: "wav").flatMap { try? AVAudioPlayer(contentsOf: $0) }
52
+ @State private var playback: LottiePlaybackMode = .paused(at: .progress(0))
53
+ var size: CGFloat
54
+ var sound: Bool
55
+ var label: String?
56
+
57
+ public init(size: CGFloat = 24, sound: Bool = true, label: String? = nil) { self.size = size; self.sound = sound; self.label = label }
58
+
59
+ public var body: some View {
60
+ LottieView(animation: Self.animation)
61
+ .playbackMode(playback)
62
+ .animationDidFinish { _ in playback = .paused(at: .progress(0)) } // ready to play again on the next tap
63
+ .frame(width: size, height: size)
64
+ .contentShape(Rectangle())
65
+ .onTapGesture {
66
+ playback = .playing(.fromProgress(0, toProgress: 1, loopMode: .playOnce))
67
+ if sound { Self.player?.currentTime = 0; Self.player?.play() }
68
+ }
69
+ .accessibilityLabel(label ?? "")
70
+ .accessibilityHidden(label == nil)
71
+ }
72
+ }
73
+ ` };
74
+ }
75
+
76
+ function compose(ic, o) {
77
+ const P = pascal(ic.n), j = lottieJson(ic, o).replace(/\$/g, "${'$'}");
78
+ return { file: P + 'Glyph.kt', text: `// Animated "${ic.n}" icon from Magic Glyphs for Jetpack Compose.
79
+ // Needs: implementation("com.airbnb.android:lottie-compose:6.6.0")
80
+ // Sound, optional: put ${ic.n}.wav in res/raw as ${ic.n.replace(/-/g, '_')}.wav and pass sound = true.
81
+ package magicglyphs
82
+
83
+ import android.media.MediaPlayer
84
+ import androidx.compose.foundation.clickable
85
+ import androidx.compose.foundation.layout.size
86
+ import androidx.compose.runtime.*
87
+ import androidx.compose.ui.Modifier
88
+ import androidx.compose.ui.platform.LocalContext
89
+ import androidx.compose.ui.semantics.contentDescription
90
+ import androidx.compose.ui.semantics.semantics
91
+ import androidx.compose.ui.unit.Dp
92
+ import androidx.compose.ui.unit.dp
93
+ import com.airbnb.lottie.compose.*
94
+
95
+ private const val ${camel(ic.n)}Json = """${j}"""
96
+
97
+ @Composable
98
+ fun ${P}Glyph(size: Dp = 24.dp, sound: Boolean = false, label: String? = null, modifier: Modifier = Modifier) {
99
+ val composition by rememberLottieComposition(LottieCompositionSpec.JsonString(${camel(ic.n)}Json))
100
+ var plays by remember { mutableIntStateOf(0) }
101
+ val progress by animateLottieCompositionAsState(composition, isPlaying = plays > 0, restartOnPlay = true, iterations = 1)
102
+ val context = LocalContext.current
103
+ val soundId = remember { context.resources.getIdentifier("${ic.n.replace(/-/g, '_')}", "raw", context.packageName) }
104
+ LottieAnimation(
105
+ composition = composition,
106
+ progress = { if (plays == 0) 0f else progress },
107
+ modifier = modifier.size(size)
108
+ .semantics { if (label != null) contentDescription = label }
109
+ .clickable {
110
+ plays++
111
+ if (sound && soundId != 0) MediaPlayer.create(context, soundId)?.apply { setOnCompletionListener { it.release() }; start() }
112
+ }
113
+ )
114
+ }
115
+ ` };
116
+ }
117
+
118
+ function flutter(ic, o) {
119
+ const P = pascal(ic.n), j = lottieJson(ic, o);
120
+ return { file: ic.n.replace(/-/g, '_') + '_glyph.dart', text: `// Animated "${ic.n}" icon from Magic Glyphs for Flutter.
121
+ // Needs: flutter pub add lottie (sound, optional: flutter pub add audioplayers, and add assets/${ic.n}.wav to pubspec.yaml)
122
+ import 'dart:convert';
123
+ import 'package:flutter/material.dart';
124
+ import 'package:lottie/lottie.dart';
125
+ import 'package:audioplayers/audioplayers.dart';
126
+
127
+ const String _${camel(ic.n)}Json = r'''${j}''';
128
+
129
+ class ${P}Glyph extends StatefulWidget {
130
+ const ${P}Glyph({super.key, this.size = 24, this.sound = false, this.label});
131
+ final double size;
132
+ final bool sound;
133
+ final String? label;
134
+ @override
135
+ State<${P}Glyph> createState() => _${P}GlyphState();
136
+ }
137
+
138
+ class _${P}GlyphState extends State<${P}Glyph> with SingleTickerProviderStateMixin {
139
+ late final AnimationController _controller = AnimationController(vsync: this);
140
+ final AudioPlayer _audio = AudioPlayer();
141
+
142
+ void play() {
143
+ _controller.forward(from: 0);
144
+ if (widget.sound) _audio.play(AssetSource('${ic.n}.wav'));
145
+ }
146
+
147
+ @override
148
+ void dispose() { _controller.dispose(); _audio.dispose(); super.dispose(); }
149
+
150
+ @override
151
+ Widget build(BuildContext context) {
152
+ return Semantics(
153
+ label: widget.label,
154
+ excludeSemantics: widget.label == null,
155
+ button: widget.label != null,
156
+ child: GestureDetector(
157
+ onTap: play,
158
+ child: Lottie.memory(
159
+ utf8.encode(_${camel(ic.n)}Json),
160
+ controller: _controller,
161
+ width: widget.size,
162
+ height: widget.size,
163
+ onLoaded: (c) => _controller.duration = c.duration,
164
+ ),
165
+ ),
166
+ );
167
+ }
168
+ }
169
+ ` };
170
+ }
171
+
172
+ function winui(ic, o) {
173
+ const P = pascal(ic.n), j = lottieJson(ic, o).replace(/"/g, '""');
174
+ return { file: P + 'Glyph.cs', text: `// Animated "${ic.n}" icon from Magic Glyphs for WinUI 3 (Windows App SDK).
175
+ // Needs: dotnet add package CommunityToolkit.WinUI.Lottie
176
+ // Sound, optional: add ${ic.n}.wav to the project as Content and set Sound = true.
177
+ using System;
178
+ using CommunityToolkit.WinUI.Lottie;
179
+ using Microsoft.UI.Xaml.Controls;
180
+ using Windows.Media.Core;
181
+ using Windows.Media.Playback;
182
+
183
+ namespace MagicGlyphs;
184
+
185
+ public sealed class ${P}Glyph : UserControl
186
+ {
187
+ private const string Json = @"${j}";
188
+ private readonly AnimatedVisualPlayer _player = new() { AutoPlay = false };
189
+ private readonly MediaPlayer _audio = new();
190
+ public bool Sound { get; set; }
191
+
192
+ public ${P}Glyph(double size = 24)
193
+ {
194
+ Width = Height = size;
195
+ _player.Source = LottieVisualSource.CreateFromString(Json);
196
+ Content = _player;
197
+ Tapped += (_, _) => Play();
198
+ }
199
+
200
+ public async void Play()
201
+ {
202
+ if (Sound) { _audio.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///${ic.n}.wav")); _audio.Play(); }
203
+ await _player.PlayAsync(0, 1, false);
204
+ }
205
+ }
206
+ ` };
207
+ }
208
+ module.exports = { 'react-native': reactNative, swiftui, compose, flutter, winui };
@@ -1,5 +1,5 @@
1
1
  /*! Magic Glyphs runtime — renders and animates icons from the canonical icon data. No dependencies. */
2
- (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MagicGlyphs=factory()})(typeof self!=='undefined'?self:this,function(){
2
+ (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MagicGlyphs=root.MagicGlyphs&&root.MagicGlyphs.register?root.MagicGlyphs:factory()})(typeof self!=='undefined'?self:this,function(){
3
3
  'use strict';
4
4
  var REG={},uid=0;
5
5
  var STROKE='stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"';
@@ -155,7 +155,8 @@
155
155
  else if(o.tone>0){var hs=c.createBiquadFilter();hs.type='highshelf';hs.frequency.value=2500;hs.gain.value=o.tone*9;g.connect(hs);node=hs}
156
156
  if(c.createStereoPanner&&pan){var p=c.createStereoPanner();p.pan.setValueAtTime(Math.max(-1,Math.min(1,pan)),c.currentTime);node.connect(p);p.connect(dest)}else node.connect(dest);
157
157
  cur={C:c,pm:Math.pow(2,o.pitch/12),sp:o.speed,t0:c.currentTime+o.delay/1000};try{fn(g)}finally{cur=null}return true}
158
- function wantsSound(el){return soundAll||!!(el&&el.hasAttribute&&el.hasAttribute('sound')&&el.getAttribute('sound')!=='off')}
158
+ // sound="off" on an element always wins, so decorative or autoplaying icons stay silent even when sound is on for the page
159
+ function wantsSound(el){if(el&&el.getAttribute&&el.getAttribute('sound')==='off')return false;return soundAll||!!(el&&el.hasAttribute&&el.hasAttribute('sound'))}
159
160
  function playFor(ic,el,extra){if(muted||!unlocked||!ensureAudio())return false;var o=settings(ic,el,extra);if(!o.sound||!o.volume)return false;
160
161
  var pan=0;if(o.pan&&el&&el.getBoundingClientRect&&typeof innerWidth==='number'&&innerWidth>0){var r=el.getBoundingClientRect();pan=((r.left+r.width/2)/innerWidth*2-1)*.85*o.pan}
161
162
  try{return render(ctx,master,o,pan)}catch(e){return false}}
package/web/runtime.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*! Magic Glyphs runtime — renders and animates icons from the canonical icon data. No dependencies. */
2
- (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MagicGlyphs=factory()})(typeof self!=='undefined'?self:this,function(){
2
+ (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MagicGlyphs=root.MagicGlyphs&&root.MagicGlyphs.register?root.MagicGlyphs:factory()})(typeof self!=='undefined'?self:this,function(){
3
3
  'use strict';
4
4
  var REG={},uid=0;
5
5
  var STROKE='stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"';
@@ -155,7 +155,8 @@
155
155
  else if(o.tone>0){var hs=c.createBiquadFilter();hs.type='highshelf';hs.frequency.value=2500;hs.gain.value=o.tone*9;g.connect(hs);node=hs}
156
156
  if(c.createStereoPanner&&pan){var p=c.createStereoPanner();p.pan.setValueAtTime(Math.max(-1,Math.min(1,pan)),c.currentTime);node.connect(p);p.connect(dest)}else node.connect(dest);
157
157
  cur={C:c,pm:Math.pow(2,o.pitch/12),sp:o.speed,t0:c.currentTime+o.delay/1000};try{fn(g)}finally{cur=null}return true}
158
- function wantsSound(el){return soundAll||!!(el&&el.hasAttribute&&el.hasAttribute('sound')&&el.getAttribute('sound')!=='off')}
158
+ // sound="off" on an element always wins, so decorative or autoplaying icons stay silent even when sound is on for the page
159
+ function wantsSound(el){if(el&&el.getAttribute&&el.getAttribute('sound')==='off')return false;return soundAll||!!(el&&el.hasAttribute&&el.hasAttribute('sound'))}
159
160
  function playFor(ic,el,extra){if(muted||!unlocked||!ensureAudio())return false;var o=settings(ic,el,extra);if(!o.sound||!o.volume)return false;
160
161
  var pan=0;if(o.pan&&el&&el.getBoundingClientRect&&typeof innerWidth==='number'&&innerWidth>0){var r=el.getBoundingClientRect();pan=((r.left+r.width/2)/innerWidth*2-1)*.85*o.pan}
161
162
  try{return render(ctx,master,o,pan)}catch(e){return false}}
@@ -1,5 +1,5 @@
1
1
  /*! Magic Glyphs runtime — renders and animates icons from the canonical icon data. No dependencies. */
2
- (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MagicGlyphs=factory()})(typeof self!=='undefined'?self:this,function(){
2
+ (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MagicGlyphs=root.MagicGlyphs&&root.MagicGlyphs.register?root.MagicGlyphs:factory()})(typeof self!=='undefined'?self:this,function(){
3
3
  'use strict';
4
4
  var REG={},uid=0;
5
5
  var STROKE='stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"';
@@ -155,7 +155,8 @@
155
155
  else if(o.tone>0){var hs=c.createBiquadFilter();hs.type='highshelf';hs.frequency.value=2500;hs.gain.value=o.tone*9;g.connect(hs);node=hs}
156
156
  if(c.createStereoPanner&&pan){var p=c.createStereoPanner();p.pan.setValueAtTime(Math.max(-1,Math.min(1,pan)),c.currentTime);node.connect(p);p.connect(dest)}else node.connect(dest);
157
157
  cur={C:c,pm:Math.pow(2,o.pitch/12),sp:o.speed,t0:c.currentTime+o.delay/1000};try{fn(g)}finally{cur=null}return true}
158
- function wantsSound(el){return soundAll||!!(el&&el.hasAttribute&&el.hasAttribute('sound')&&el.getAttribute('sound')!=='off')}
158
+ // sound="off" on an element always wins, so decorative or autoplaying icons stay silent even when sound is on for the page
159
+ function wantsSound(el){if(el&&el.getAttribute&&el.getAttribute('sound')==='off')return false;return soundAll||!!(el&&el.hasAttribute&&el.hasAttribute('sound'))}
159
160
  function playFor(ic,el,extra){if(muted||!unlocked||!ensureAudio())return false;var o=settings(ic,el,extra);if(!o.sound||!o.volume)return false;
160
161
  var pan=0;if(o.pan&&el&&el.getBoundingClientRect&&typeof innerWidth==='number'&&innerWidth>0){var r=el.getBoundingClientRect();pan=((r.left+r.width/2)/innerWidth*2-1)*.85*o.pan}
161
162
  try{return render(ctx,master,o,pan)}catch(e){return false}}
@@ -1,25 +1,37 @@
1
1
  <?php
2
2
  /**
3
3
  * Plugin Name: Magic Glyphs
4
- * Description: Animated icons. Use the shortcode [magic_glyph name="heart" variant="duotone" size="32" trigger="hover" label="Like"].
5
- * Version: 0.1.0
4
+ * Description: Animated icons with sound. Shortcodes: [magic_glyph name="heart" variant="duotone" size="32" trigger="hover" label="Like" sound="yes"] and a mute switch for visitors, [magic_glyphs_sound_toggle].
5
+ * Version: 0.7.0
6
+ * Author: Lewis John Villamor
6
7
  */
7
8
  if (!defined('ABSPATH')) { exit; }
8
9
 
9
10
  add_action('wp_enqueue_scripts', function () {
10
- wp_register_script('magic-glyphs', plugins_url('magic-glyphs.all.js', __FILE__), array(), '0.1.0', true);
11
+ wp_register_script('magic-glyphs', plugins_url('magic-glyphs.all.js', __FILE__), array(), '0.7.0', true);
11
12
  });
12
13
 
13
14
  add_shortcode('magic_glyph', function ($atts) {
14
- $a = shortcode_atts(array('name' => '', 'variant' => 'outline', 'size' => '24', 'trigger' => 'hover', 'label' => ''), $atts, 'magic_glyph');
15
+ $a = shortcode_atts(array('name' => '', 'variant' => 'outline', 'size' => '24', 'trigger' => 'hover', 'label' => '', 'sound' => ''), $atts, 'magic_glyph');
15
16
  if ($a['name'] === '') { return ''; }
16
17
  wp_enqueue_script('magic-glyphs');
17
18
  $label = $a['label'] !== '' ? ' label="' . esc_attr($a['label']) . '"' : '';
18
- return '<magic-glyph name="' . esc_attr($a['name']) . '" variant="' . esc_attr($a['variant']) . '" size="' . esc_attr($a['size']) . '" trigger="' . esc_attr($a['trigger']) . '"' . $label . '></magic-glyph>';
19
+ $sound = in_array(strtolower($a['sound']), array('yes', 'true', '1', 'on'), true) ? ' sound' : '';
20
+ return '<magic-glyph name="' . esc_attr($a['name']) . '" variant="' . esc_attr($a['variant']) . '" size="' . esc_attr($a['size']) . '" trigger="' . esc_attr($a['trigger']) . '"' . $label . $sound . '></magic-glyph>';
21
+ });
22
+
23
+ // A speaker button visitors use to turn icon sounds on or off; their choice is remembered.
24
+ add_shortcode('magic_glyphs_sound_toggle', function ($atts) {
25
+ $a = shortcode_atts(array('default' => 'on'), $atts, 'magic_glyphs_sound_toggle');
26
+ wp_enqueue_script('magic-glyphs');
27
+ return '<magic-glyphs-sound-toggle default="' . ($a['default'] === 'off' ? 'off' : 'on') . '"></magic-glyphs-sound-toggle>';
19
28
  });
20
29
 
21
30
  // Let the element through the editor's HTML filter so it can also be typed directly into a Custom HTML block.
22
31
  add_filter('wp_kses_allowed_html', function ($tags, $context) {
23
- if ($context === 'post') { $tags['magic-glyph'] = array('name' => true, 'variant' => true, 'size' => true, 'trigger' => true, 'label' => true, 'class' => true, 'style' => true); }
32
+ if ($context === 'post') {
33
+ $tags['magic-glyph'] = array('name' => true, 'variant' => true, 'size' => true, 'trigger' => true, 'label' => true, 'class' => true, 'style' => true, 'sound' => true, 'sound-name' => true, 'sound-volume' => true, 'sound-pitch' => true, 'sound-speed' => true, 'sound-tone' => true, 'sound-pan' => true, 'sound-delay' => true);
34
+ $tags['magic-glyphs-sound-toggle'] = array('default' => true, 'size' => true, 'show-label' => true, 'label-on' => true, 'label-off' => true);
35
+ }
24
36
  return $tags;
25
37
  }, 10, 2);