magic-glyphs 0.7.1 → 0.8.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.
Files changed (156) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +25 -11
  3. package/cli/index.js +31 -13
  4. package/cli/video.js +36 -0
  5. package/data/icons/apple.json +1 -0
  6. package/data/icons/arrow-down.json +1 -0
  7. package/data/icons/arrow-left.json +1 -0
  8. package/data/icons/arrow-right.json +1 -0
  9. package/data/icons/arrow-up.json +1 -0
  10. package/data/icons/bag.json +1 -0
  11. package/data/icons/battery.json +1 -0
  12. package/data/icons/bell.json +1 -0
  13. package/data/icons/bike.json +1 -0
  14. package/data/icons/bird.json +1 -0
  15. package/data/icons/bolt.json +1 -0
  16. package/data/icons/book.json +1 -0
  17. package/data/icons/bookmark.json +1 -0
  18. package/data/icons/briefcase.json +1 -0
  19. package/data/icons/bug.json +1 -0
  20. package/data/icons/bus.json +1 -0
  21. package/data/icons/cake.json +1 -0
  22. package/data/icons/calendar.json +1 -0
  23. package/data/icons/camera.json +1 -0
  24. package/data/icons/car.json +1 -0
  25. package/data/icons/card.json +1 -0
  26. package/data/icons/cart.json +1 -0
  27. package/data/icons/cat.json +1 -0
  28. package/data/icons/chat.json +1 -0
  29. package/data/icons/check.json +1 -0
  30. package/data/icons/chevron-down.json +1 -0
  31. package/data/icons/chevron-left.json +1 -0
  32. package/data/icons/chevron-right.json +1 -0
  33. package/data/icons/chevron-up.json +1 -0
  34. package/data/icons/circle-alert.json +1 -0
  35. package/data/icons/circle-check.json +1 -0
  36. package/data/icons/circle-minus.json +1 -0
  37. package/data/icons/circle-plus.json +1 -0
  38. package/data/icons/circle-x.json +1 -0
  39. package/data/icons/clipboard.json +1 -0
  40. package/data/icons/clock.json +1 -0
  41. package/data/icons/cloud.json +1 -0
  42. package/data/icons/code.json +1 -0
  43. package/data/icons/coffee.json +1 -0
  44. package/data/icons/coin.json +1 -0
  45. package/data/icons/copy.json +1 -0
  46. package/data/icons/database.json +1 -0
  47. package/data/icons/dog.json +1 -0
  48. package/data/icons/download.json +1 -0
  49. package/data/icons/drop.json +1 -0
  50. package/data/icons/edit.json +1 -0
  51. package/data/icons/external-link.json +1 -0
  52. package/data/icons/eye-off.json +1 -0
  53. package/data/icons/eye.json +1 -0
  54. package/data/icons/file.json +1 -0
  55. package/data/icons/filter.json +1 -0
  56. package/data/icons/fish.json +1 -0
  57. package/data/icons/flag.json +1 -0
  58. package/data/icons/flame.json +1 -0
  59. package/data/icons/folder.json +1 -0
  60. package/data/icons/frown.json +1 -0
  61. package/data/icons/gift.json +1 -0
  62. package/data/icons/globe.json +1 -0
  63. package/data/icons/hand.json +1 -0
  64. package/data/icons/heart.json +1 -0
  65. package/data/icons/help.json +1 -0
  66. package/data/icons/home.json +1 -0
  67. package/data/icons/image.json +1 -0
  68. package/data/icons/info.json +1 -0
  69. package/data/icons/key.json +1 -0
  70. package/data/icons/laptop.json +1 -0
  71. package/data/icons/laugh.json +1 -0
  72. package/data/icons/leaf.json +1 -0
  73. package/data/icons/link.json +1 -0
  74. package/data/icons/lock.json +1 -0
  75. package/data/icons/mail.json +1 -0
  76. package/data/icons/map.json +1 -0
  77. package/data/icons/menu.json +1 -0
  78. package/data/icons/mic.json +1 -0
  79. package/data/icons/minus.json +1 -0
  80. package/data/icons/monitor.json +1 -0
  81. package/data/icons/moon.json +1 -0
  82. package/data/icons/music.json +1 -0
  83. package/data/icons/package.json +1 -0
  84. package/data/icons/pause.json +1 -0
  85. package/data/icons/pencil.json +1 -0
  86. package/data/icons/phone.json +1 -0
  87. package/data/icons/pin.json +1 -0
  88. package/data/icons/pizza.json +1 -0
  89. package/data/icons/plane.json +1 -0
  90. package/data/icons/play.json +1 -0
  91. package/data/icons/plus.json +1 -0
  92. package/data/icons/printer.json +1 -0
  93. package/data/icons/receipt.json +1 -0
  94. package/data/icons/refresh.json +1 -0
  95. package/data/icons/rocket.json +1 -0
  96. package/data/icons/save.json +1 -0
  97. package/data/icons/search.json +1 -0
  98. package/data/icons/server.json +1 -0
  99. package/data/icons/settings.json +1 -0
  100. package/data/icons/share.json +1 -0
  101. package/data/icons/shield.json +1 -0
  102. package/data/icons/smile.json +1 -0
  103. package/data/icons/star.json +1 -0
  104. package/data/icons/stop.json +1 -0
  105. package/data/icons/store.json +1 -0
  106. package/data/icons/sun.json +1 -0
  107. package/data/icons/tablet.json +1 -0
  108. package/data/icons/tag.json +1 -0
  109. package/data/icons/terminal.json +1 -0
  110. package/data/icons/thumbs-down.json +1 -0
  111. package/data/icons/thumbs-up.json +1 -0
  112. package/data/icons/train.json +1 -0
  113. package/data/icons/trash.json +1 -0
  114. package/data/icons/tree.json +1 -0
  115. package/data/icons/truck.json +1 -0
  116. package/data/icons/upload.json +1 -0
  117. package/data/icons/user.json +1 -0
  118. package/data/icons/users.json +1 -0
  119. package/data/icons/video.json +1 -0
  120. package/data/icons/volume.json +1 -0
  121. package/data/icons/wallet.json +1 -0
  122. package/data/icons/wave.json +1 -0
  123. package/data/icons/wifi.json +1 -0
  124. package/data/icons/wink.json +1 -0
  125. package/data/index.json +1 -1
  126. package/docs/avalonia.md +15 -0
  127. package/docs/cli.md +1 -1
  128. package/docs/figma.md +12 -0
  129. package/docs/godot.md +13 -0
  130. package/docs/images-video.md +42 -0
  131. package/docs/jetpack-compose.md +18 -0
  132. package/docs/maker.md +1 -1
  133. package/docs/maui.md +17 -0
  134. package/docs/more-frameworks.md +49 -0
  135. package/docs/native-lottie.md +5 -0
  136. package/docs/qt.md +26 -0
  137. package/docs/react-vue.md +11 -0
  138. package/docs/rust.md +43 -0
  139. package/docs/site-builders.md +27 -0
  140. package/docs/sound.md +2 -2
  141. package/docs/tauri-rust.md +1 -1
  142. package/docs/unity.md +15 -0
  143. package/lib.js +6 -1
  144. package/mcp/server.js +1 -1
  145. package/package.json +14 -6
  146. package/tools/apng.js +36 -0
  147. package/tools/baked.js +30 -0
  148. package/tools/gif.js +60 -0
  149. package/tools/motion.js +31 -0
  150. package/tools/native.js +1 -1
  151. package/tools/native2.js +432 -0
  152. package/tools/raster.js +139 -0
  153. package/web/magic-glyphs.all.js +1 -1
  154. package/web/runtime.js +1 -1
  155. package/wordpress/magic-glyphs/magic-glyphs.all.js +1 -1
  156. package/wordpress/magic-glyphs/magic-glyphs.php +2 -1
@@ -0,0 +1,15 @@
1
+ # Avalonia
2
+
3
+ Each icon becomes one C# control that draws the icon's own vectors and plays its spring motion. No packages needed.
4
+
5
+ ```bash
6
+ npx magic-glyphs add bell heart --format avalonia --out Glyphs
7
+ ```
8
+
9
+ ```csharp
10
+ var bell = new MagicGlyphs.BellGlyph(size: 32, color: "#2747f5");
11
+ panel.Children.Add(bell);
12
+ bell.Play(); // also plays on hover and click
13
+ ```
14
+
15
+ Styles: add `--style solid` or `--style duotone` (with `secondary:`). Sound: Avalonia has no built-in audio, so export the WAV (`--format wav`) and play it from the `Played` event with the audio library you use.
package/docs/cli.md CHANGED
@@ -57,7 +57,7 @@ Files for non-outline styles carry the style in the name, for example `heart.duo
57
57
 
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
- npx magic-glyphs buy # opens the page where you can buy a licence
60
+ npx magic-glyphs buy # shows the link where you can buy a licence
61
61
  npx magic-glyphs update # tells you if a newer version is out, then downloads new paid icons
62
62
  npx magic-glyphs build-key # a key for CI and build servers that does not use a device
63
63
  npx magic-glyphs shadcn --env # connect a shadcn project (see the shadcn guide)
package/docs/figma.md ADDED
@@ -0,0 +1,12 @@
1
+ # Figma
2
+
3
+ The Magic Glyphs plugin puts icons straight into your designs.
4
+
5
+ - **Search** every icon by name or tag.
6
+ - **Insert as a vector** in outline, solid or duotone, in any colour and size. It lands in the selected frame, ready to edit.
7
+ - **Insert as an animated GIF**, which plays in prototypes and presentations, so stakeholders see the motion.
8
+ - **Unlock the full library** with the licence key from your Gumroad receipt (the 120 free icons work without one).
9
+
10
+ Works in Figma Design, FigJam and Figma Slides.
11
+
12
+ Install it from the Figma Community (search for *Magic Glyphs*). Until it is listed there, a team can import it in the Figma desktop app: **Plugins → Development → Import plugin from manifest**, and choose `manifest.json` from the plugin folder we send you on request (support@magicglyphs.com).
package/docs/godot.md ADDED
@@ -0,0 +1,13 @@
1
+ # Godot
2
+
3
+ Each icon becomes one GDScript file for a `Control` node. It draws the icon's own vectors and plays its spring motion; nothing to install.
4
+
5
+ ```bash
6
+ npx magic-glyphs add bell heart --format godot --out glyphs
7
+ npx magic-glyphs add bell --format wav --out glyphs # optional sound
8
+ ```
9
+
10
+ 1. Add a **Control** node, set its size (for example 32 × 32), and attach `bell_glyph.gd`.
11
+ 2. In the Inspector, set **Color** (and **Secondary** for duotone), and **Sound Stream** to `bell.wav` if you want sound.
12
+
13
+ It plays on hover and click; call `play()` for anything else. For sprite-based games, `--format spritesheet` writes a PNG of every frame plus a JSON file with the timing.
@@ -0,0 +1,42 @@
1
+ # Animated images and video
2
+
3
+ Some places cannot run code: email, slide decks, Canva, Notion, chat emoji and social posts. For those, export a finished animation. Video formats carry the icon's sound.
4
+
5
+ | Format | Best for | Transparency | Sound |
6
+ | --- | --- | --- | --- |
7
+ | GIF | Email, Notion, Google Slides, Canva, anywhere | One-bit (soft edges blend into a colour you choose) | No |
8
+ | Animated PNG | Slack and Discord emoji, Keynote, browsers | Full | No |
9
+ | MP4 | PowerPoint, Keynote, social posts, Canva | No (uses a background colour) | Yes |
10
+ | WebM | Web pages, Discord, OBS overlays | Full | Yes |
11
+
12
+ ## From the icon maker
13
+
14
+ Open the [icon maker](https://magicglyphs.com/maker/), pick a library icon or bring your own, then choose a colour, a background (or transparent) and a size under **Animated image or video**. Everything is drawn in your browser.
15
+
16
+ ## From the command line
17
+
18
+ ```bash
19
+ npx magic-glyphs add rocket --format gif --color "#7c3aed"
20
+ npx magic-glyphs add bell heart --format apng --size 128 # Slack and Discord emoji
21
+ npx magic-glyphs add send --format mp4 --size 1080 --background "#0f0f12" --color "#ffffff"
22
+ npx magic-glyphs add star --format webm # transparent video with sound
23
+ ```
24
+
25
+ | Option | What it does |
26
+ | --- | --- |
27
+ | `--size <px>` | Width and height. Defaults: GIF 256, APNG 128, MP4 and WebM 512 |
28
+ | `--color`, `--secondary`, `--style` | As for every other format (glass needs a background in GIF) |
29
+ | `--background <hex>` | Solid background. Without it GIF, APNG and WebM are transparent |
30
+ | `--matte <hex>` | GIF without a background: the colour soft edges blend into (default white) |
31
+ | `--loop <n>` | GIF and APNG: plays (default 0, forever) |
32
+ | `--hold <s>` | Seconds to hold the final pose (default 0.6) |
33
+ | `--no-sound` | MP4 and WebM without sound |
34
+
35
+ GIF and animated PNG need nothing extra. MP4 and WebM use [ffmpeg](https://ffmpeg.org) if it is installed (`winget install ffmpeg`, `brew install ffmpeg`, `apt install ffmpeg`); otherwise make them in the icon maker.
36
+
37
+ ## Tips
38
+
39
+ - **Slack emoji:** APNG at 128 px, under 128 KB. Short motions (bell, heart, star) fit easily.
40
+ - **Email:** GIF with a background matching the email, so the edges are clean. Some Outlook versions show only the first frame; that frame is the icon at rest, so it still reads.
41
+ - **PowerPoint and Keynote:** MP4 with the slide's background colour, set to play automatically.
42
+ - **Canva:** upload the GIF, or the MP4 if you want the sound.
@@ -19,3 +19,21 @@ HeartGlyph(size = 28.dp, sound = true, label = "Like")
19
19
  ```
20
20
 
21
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.
22
+
23
+ ## Compose Multiplatform
24
+
25
+ For Android, iOS, desktop and web from one Kotlin codebase, export with `--format compose-multiplatform`. The component uses [Compottie](https://github.com/alexzhirkevich/compottie), the multiplatform Lottie player:
26
+
27
+ ```kotlin
28
+ // build.gradle.kts (commonMain)
29
+ implementation("io.github.alexzhirkevich:compottie:2.0.0")
30
+ ```
31
+
32
+ ```bash
33
+ npx magic-glyphs add bell heart --format compose-multiplatform --out shared/src/commonMain/kotlin/glyphs
34
+ ```
35
+
36
+ ```kotlin
37
+ BellGlyph(size = 32.dp, onPlay = { /* play bell.wav with your platform's audio */ })
38
+ ```
39
+
package/docs/maker.md CHANGED
@@ -4,7 +4,7 @@ The icon maker turns your own artwork into an animated icon with motion and soun
4
4
 
5
5
  ## 1. Unlock
6
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.
7
+ Paste the licence key from your Gumroad receipt at the top of the [icon maker](https://magicglyphs.com/maker/) and press **Unlock**. The browser remembers it. Use **Remove key from this browser** on the [icon browser](https://magicglyphs.com/icons/) when you are on a shared computer.
8
8
 
9
9
  ## 2. Start from your artwork
10
10
 
package/docs/maui.md ADDED
@@ -0,0 +1,17 @@
1
+ # .NET MAUI
2
+
3
+ Each icon becomes one C# view that plays the icon's Lottie animation with SkiaSharp.
4
+
5
+ ```bash
6
+ dotnet add package SkiaSharp.Extended.UI.Maui
7
+ npx magic-glyphs add bell heart --format maui --out Glyphs
8
+ ```
9
+
10
+ In `MauiProgram.cs` add `builder.UseSkiaSharp();`, then:
11
+
12
+ ```csharp
13
+ var bell = new MagicGlyphs.BellGlyph(size: 32);
14
+ layout.Children.Add(bell); // plays on tap; call bell.Play() for other triggers
15
+ ```
16
+
17
+ Colours and style are set when you export: `--color "#2747f5" --style duotone`. For sound, add `Plugin.Maui.Audio`, put `bell.wav` (from `--format wav`) under `Resources/Raw`, and set `PlaySound`.
@@ -0,0 +1,49 @@
1
+ # Every other framework
2
+
3
+ Magic Glyphs is a standard web component, `<magic-glyph>`, so it works in every framework that renders HTML. Load it once, then use the tag.
4
+
5
+ ```bash
6
+ npm install magic-glyphs
7
+ ```
8
+
9
+ ```js
10
+ import 'magic-glyphs/all'; // the runtime and the 120 free icons; for paid icons see the CLI's bundle command
11
+ ```
12
+
13
+ Or with no build step:
14
+
15
+ ```html
16
+ <script src="https://unpkg.com/magic-glyphs/web/magic-glyphs.all.js"></script>
17
+ ```
18
+
19
+ ## Solid, Preact, Qwik, Lit, Ember
20
+
21
+ Import once in your entry file and write the tag in your components:
22
+
23
+ ```jsx
24
+ <magic-glyph name="heart" size="24" sound></magic-glyph>
25
+ ```
26
+
27
+ - **Solid, Qwik and Preact:** custom elements pass through untouched. In TypeScript, declare the tag once in a `.d.ts` file if your setup asks for it.
28
+ - **Lit:** use the tag inside your templates; it is a light-DOM element, so your styles reach it.
29
+ - **Ember:** import in `app/app.js`; use the tag in templates.
30
+
31
+ ## Angular
32
+
33
+ Add `CUSTOM_ELEMENTS_SCHEMA` to the component (or module) that uses the tag, and `import 'magic-glyphs/all';` in `main.ts`.
34
+
35
+ ## Alpine.js and htmx
36
+
37
+ The element draws itself whenever it is added to the page, including content swapped in by htmx or shown by Alpine. Bind attributes as usual: `<magic-glyph :name="icon">`.
38
+
39
+ ## Remix, React Router, SvelteKit
40
+
41
+ Follow the [React](https://magicglyphs.com/docs/react-vue/) or [Svelte](https://magicglyphs.com/docs/frameworks/) guides. The element renders on the server as an empty tag and draws in the browser, so there is no hydration mismatch.
42
+
43
+ ## Laravel (Blade), Django, Rails, Phoenix
44
+
45
+ Add the script tag to your base layout once and use `<magic-glyph name="...">` in any template. For paid icons, run `npx magic-glyphs bundle heart bell --out public/magic-glyphs.js` and load that file instead.
46
+
47
+ ## Electron, Ionic and Capacitor
48
+
49
+ These run your web front end, so everything above applies, sound included. Everything is local, with no network calls at run time. Expo apps use the [React Native](https://magicglyphs.com/docs/react-native/) components.
@@ -81,3 +81,8 @@ npx magic-glyphs add bell --format lottie --sound --out assets
81
81
  ## How the export was checked
82
82
 
83
83
  Every icon was converted and rendered at two mid-animation frames with an independent Lottie library, then compared pixel by pixel with the web engine. All 3,947 matched within a small tolerance. The files have **not** yet been played in lottie-ios, lottie-android or Lottie-Windows; try a handful on a device before relying on them.
84
+
85
+ ## After Effects, Webflow, Framer, LottieFiles
86
+
87
+ The Lottie files are standard Bodymovin JSON. Import them into After Effects with a Lottie import plugin to edit the motion further, drop them into Webflow's or Framer's Lottie element, or upload them to LottieFiles.
88
+
package/docs/qt.md ADDED
@@ -0,0 +1,26 @@
1
+ # Qt Quick (QML)
2
+
3
+ Each icon becomes one `.qml` file that draws the icon's own vectors with Qt Quick Shapes and plays its spring motion (pre-computed, so there is nothing to install). Qt 6.6 or newer.
4
+
5
+ ```bash
6
+ npx magic-glyphs add bell heart --format qml --out qml/glyphs
7
+ npx magic-glyphs add bell --format wav --out qml/glyphs # optional sound
8
+ ```
9
+
10
+ ```qml
11
+ import "glyphs"
12
+
13
+ BellGlyph { size: 32; color: "#2747f5" }
14
+ HeartGlyph { size: 32; color: palette.text; trigger: "click"; sound: true }
15
+ ```
16
+
17
+ | Property | Default | |
18
+ | --- | --- | --- |
19
+ | `size` | 24 | Width and height |
20
+ | `color` | black | Line and fill colour |
21
+ | `secondary` | `color` | Duotone fill (`--style duotone`) |
22
+ | `background` | white | Knocked-out details in the solid style |
23
+ | `trigger` | `"hover"` | `hover`, `click` or `none` (then call `play()`) |
24
+ | `sound` | false | Plays `<name>.wav` next to the file, using Qt Multimedia (only loaded when on) |
25
+
26
+ Python apps with PySide6 or PyQt6 load the same files.
package/docs/react-vue.md CHANGED
@@ -39,6 +39,17 @@ Call `play()` through a template ref: `<MagicGlyph ref="g" ... />` then `g.value
39
39
 
40
40
  ## Shipping only the icons you use
41
41
 
42
+ Your bundle only holds the icons you register, never the whole library. Each icon is about 0.2 KB, plus 8 KB for the runtime.
43
+
44
+ - `magic-glyphs/icons.json` registers all 120 free icons at once (about 10 KB gzipped).
45
+ - `magic-glyphs/icons/<name>` imports one free icon:
46
+
47
+ ```jsx
48
+ import heart from 'magic-glyphs/icons/heart';
49
+ import bell from 'magic-glyphs/icons/bell';
50
+ register([heart, bell]);
51
+ ```
52
+
42
53
  The `icons.json` in the package holds the 120 free icons. For paid icons, and to ship only what you use, let the CLI write one small component per icon (after `npx magic-glyphs login`):
43
54
 
44
55
  ```bash
package/docs/rust.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rust
2
+
3
+ ```bash
4
+ cargo add magic-glyphs
5
+ ```
6
+
7
+ The crate has no dependencies (it is `no_std` with `alloc`) and includes the 120 free icons. Each icon has its layers, its sound's name, and its spring motion pre-computed as one 2D matrix per layer per frame.
8
+
9
+ ```rust
10
+ use magic_glyphs::{icons, Style};
11
+
12
+ let bell = icons::BELL; // or icons::by_name("bell")
13
+ let style = Style::duotone().color("#2747f5").size(32);
14
+
15
+ let svg = bell.svg(&style); // the resting icon
16
+ let frame = bell.svg_at(0.12, &style); // 120 ms into its motion
17
+ let done = bell.done(0.12); // redraw each frame until true
18
+ let m = bell.matrix(0, 0.12); // or draw it yourself: [a b c d e f] for layer 0
19
+ ```
20
+
21
+ Draw the SVG with what your toolkit uses: `resvg` + `tiny-skia` for a pixmap, an SVG image loader in **egui**, `svg::Handle` in **iced**, or Slint's image support. Start the motion on hover or click, and draw `svg_at(elapsed)` each frame until `done`.
22
+
23
+ ## Paid icons
24
+
25
+ Log in with your licence key, then generate the icons you use into your project. Each file holds one `pub const ICON: Icon`:
26
+
27
+ ```bash
28
+ npx magic-glyphs login YOUR-LICENCE-KEY
29
+ npx magic-glyphs add rocket heart --format rust --out src/glyphs
30
+ ```
31
+
32
+ ```rust
33
+ mod glyphs { pub mod rocket; pub mod heart; }
34
+ let svg = glyphs::rocket::ICON.svg(&Style::solid());
35
+ ```
36
+
37
+ ## Sound
38
+
39
+ `icon.sound` names the icon's sound. Export it with `npx magic-glyphs add bell --format wav` and play it with `rodio` (or your audio library) when the motion starts.
40
+
41
+ ## Tauri, Dioxus, Leptos, Yew
42
+
43
+ These draw in a web view, so use the [`<magic-glyph>` web component](https://magicglyphs.com/docs/web/), which plays the sound for you. See [Tauri and Rust](https://magicglyphs.com/docs/tauri-rust/).
@@ -0,0 +1,27 @@
1
+ # Webflow, Framer, Wix and other site builders
2
+
3
+ Every builder that accepts custom code can use Magic Glyphs. Add the script once for the whole site, then place icons with an embed. For WordPress and Shopify, see [HTML, WordPress, Shopify](https://magicglyphs.com/docs/web/).
4
+
5
+ The script for the free icons:
6
+
7
+ ```html
8
+ <script src="https://unpkg.com/magic-glyphs/web/magic-glyphs.all.js" defer></script>
9
+ ```
10
+
11
+ For paid icons, make your own file with `npx magic-glyphs bundle heart bell rocket --out magic-glyphs.js`, upload it to the builder's file storage, and point the script at it.
12
+
13
+ An icon anywhere on a page:
14
+
15
+ ```html
16
+ <magic-glyph name="rocket" size="32" sound></magic-glyph>
17
+ ```
18
+
19
+ | Builder | Where the script goes | Where icons go |
20
+ | --- | --- | --- |
21
+ | **Webflow** | Site settings → Custom code → Footer code | An **Embed** element |
22
+ | **Framer** | Site settings → General → Custom code (end of body) | An **Embed** component (HTML) |
23
+ | **Ghost** | Settings → Code injection → Site footer | An **HTML** card |
24
+ | **Squarespace** | Settings → Advanced → Code injection → Footer | A **Code** block |
25
+ | **Wix** | Settings → Custom code → Body end (all pages) | **Embed code** → Embed HTML |
26
+
27
+ Webflow and Framer can also play Lottie files directly: export with `npx magic-glyphs add rocket --format lottie` or from the [icon maker](https://magicglyphs.com/maker/) and use their Lottie element (without sound). Where scripts are not allowed at all, use an [animated GIF or video](https://magicglyphs.com/docs/images-video/).
package/docs/sound.md CHANGED
@@ -45,7 +45,7 @@ MagicGlyphs.sound.defaults({ volume: 0.8, pan: 0.5 });
45
45
  MagicGlyphs.sound.volume(0.4); // master volume, 0 to 1
46
46
  ```
47
47
 
48
- Icons you make or remix in the [icon maker](https://magic-glyphs-site.lewisvillamor26.workers.dev/maker/) carry their sound settings with them, so the exported React, Vue and HTML play exactly what you chose.
48
+ Icons you make or remix in the [icon maker](https://magicglyphs.com/maker/) carry their sound settings with them, so the exported React, Vue and HTML play exactly what you chose.
49
49
 
50
50
  ## A mute switch for visitors
51
51
 
@@ -76,4 +76,4 @@ All sounds are measured with the same hearing-weighted loudness curve used for b
76
76
 
77
77
  Give visitors a mute control if you turn sound on for a whole page, and keep it off for icons people see constantly, like navigation.
78
78
 
79
- Hear every sound on the website: https://magic-glyphs-site.lewisvillamor26.workers.dev/docs/sound/
79
+ Hear every sound on the website: https://magicglyphs.com/docs/sound/
@@ -12,4 +12,4 @@ Then use the `<magic-glyph>` tag, or the React, Vue or Svelte setup your front e
12
12
 
13
13
  ## Native Rust interfaces (egui, iced, Slint)
14
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.
15
+ Use the [magic-glyphs crate](https://magicglyphs.com/docs/rust/): `cargo add magic-glyphs`. It gives you each icon's SVG at any moment of its motion, with no dependencies.
package/docs/unity.md ADDED
@@ -0,0 +1,15 @@
1
+ # Unity
2
+
3
+ Unity gets each icon as a sprite sheet (every frame of the motion on one PNG) and a small component that plays it.
4
+
5
+ ```bash
6
+ npx magic-glyphs add bell heart --format unity --size 128 --color "#ffffff" --out Assets/Glyphs
7
+ npx magic-glyphs add bell heart --format wav --out Assets/Glyphs # optional sound
8
+ ```
9
+
10
+ 1. Select `bell.sheet.png` and set **Texture Type** to *Sprite (2D and UI)*.
11
+ 2. Add **BellGlyph** to a GameObject with an **Image** (UI) or a **SpriteRenderer**, and drag the sheet to **Sheet** (and `bell.wav` to **Sound**).
12
+
13
+ It plays on hover and click (UI needs an EventSystem; 2D objects need a collider), or call `Play()`. Pick `--size` for the largest size you show it at.
14
+
15
+ Other engines (Defold, Bevy, Phaser, GameMaker) can use `--format spritesheet`: a PNG grid plus JSON with the frame size, count and timing.
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','react-native','swiftui','compose','flutter','winui'];
15
+ const STYLES=['outline','solid','duotone','glass'],FORMATS=['svg','lottie','json','react','vue','html','react-native','swiftui','compose','flutter','winui','gif','apng','webm','mp4','wav','maui','avalonia','qml','godot','unity','compose-multiplatform','rust','spritesheet'];
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){
@@ -53,6 +53,11 @@ function render(name,format,o){
53
53
  // native apps: one file each, with the Lottie animation inside (see tools/native.js)
54
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
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}}
56
+ // more native targets (tools/native2.js); unity and spritesheet also write a PNG sprite sheet
57
+ case 'maui':case 'avalonia':case 'qml':case 'godot':case 'unity':case 'compose-multiplatform':case 'rust':{if(style==='glass')throw new Error('Native formats support outline, solid and duotone.');
58
+ const f=require('./tools/native2.js')[format](ic,Object.assign({},o,{style,MG}));return{ext:f.file.split('.').pop(),file:f.file,text:f.text,extra:f.extra}}
59
+ case 'spritesheet':{if(style==='glass')throw new Error('Sprite sheets support outline, solid and duotone.');
60
+ const s=require('./tools/native2.js').spritesheet(ic,Object.assign({},o,{style,MG,size:o.size||128}));return{ext:'png',file:name+'.sheet.png',data:s.png,extra:[{file:name+'.sheet.json',data:JSON.stringify(s.meta,null,2)}]}}
56
61
  case 'react':{const P=pascal(name),ts=!!o.ts;
57
62
  // "use client" lets the component sit inside a Next.js server component tree; other bundlers ignore it
58
63
  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/mcp/server.js CHANGED
@@ -20,7 +20,7 @@ server.registerTool('list_categories',{title:'List categories',description:'List
20
20
  async()=>{const c=L.categories();return text(Object.keys(c).sort().map(k=>k+': '+c[k]).join('\n')+'\ntotal: '+L.total)});
21
21
  server.registerTool('get_icon',{title:'Get icon',
22
22
  description:'Get one icon ready to use. format: "html" (custom element tag, needs the magic-glyphs script on the page), "react" or "vue" (component file source, needs the magic-glyphs npm package), "svg" (static SVG markup, no animation), "lottie" (animated Lottie JSON for iOS, Android, Windows, macOS and Flutter), "json" (raw icon data). Returns the suggested file name and the content.',
23
- inputSchema:{name:z.string().describe('Exact icon name from search_icons'),format:z.enum(L.FORMATS).optional().describe('Default "html"'),style:z.enum(L.STYLES).optional().describe('Default "outline"'),
23
+ inputSchema:{name:z.string().describe('Exact icon name from search_icons'),format:z.enum(L.FORMATS.filter(f=>!['gif','apng','webm','mp4','wav','spritesheet','unity'].includes(f))).optional().describe('Default "html"'),style:z.enum(L.STYLES).optional().describe('Default "outline"'),
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})=>{
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "magic-glyphs",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
4
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
- "author": "Lewis John Villamor",
6
+ "author": {
7
+ "name": "Magic Glyphs",
8
+ "url": "https://magicglyphs.com"
9
+ },
7
10
  "main": "lib.js",
8
11
  "bin": {
9
12
  "magic-glyphs": "cli/index.js"
@@ -23,8 +26,12 @@
23
26
  "default": "./vue/index.js"
24
27
  },
25
28
  "./lottie": "./tools/lottie.js",
29
+ "./gif": "./tools/gif.js",
30
+ "./apng": "./tools/apng.js",
31
+ "./raster": "./tools/raster.js",
26
32
  "./node": "./lib.js",
27
33
  "./icons.json": "./data/icons.json",
34
+ "./icons/*": "./data/icons/*.json",
28
35
  "./package.json": "./package.json",
29
36
  "./licence": "./licence.js",
30
37
  "./mcp": "./mcp/server.js"
@@ -96,16 +103,17 @@
96
103
  "icon maker"
97
104
  ],
98
105
  "magicGlyphs": {
99
- "api": "https://magic-glyphs-licence.lewisvillamor26.workers.dev",
106
+ "api": "https://api.magicglyphs.com",
100
107
  "buy": "https://magicscraper.gumroad.com/l/vjaxbp"
101
108
  },
102
- "homepage": "https://magic-glyphs-site.lewisvillamor26.workers.dev",
109
+ "homepage": "https://magicglyphs.com",
103
110
  "types": "./web/runtime.d.ts",
104
111
  "repository": {
105
112
  "type": "git",
106
- "url": "git+https://github.com/lewisjohnvillamor/magic-glyphs.git"
113
+ "url": "git+https://github.com/lewisjohnvillamor/magicglyphs.git"
107
114
  },
108
115
  "bugs": {
109
- "url": "https://github.com/lewisjohnvillamor/magic-glyphs/issues"
116
+ "url": "https://github.com/lewisjohnvillamor/magicglyphs/issues",
117
+ "email": "support@magicglyphs.com"
110
118
  }
111
119
  }
package/tools/apng.js ADDED
@@ -0,0 +1,36 @@
1
+ // A small animated PNG (APNG) encoder: full alpha, exact timing, no dependencies.
2
+ // encode({width, height, frames:[RGBA], delays:[seconds], loop}, deflate) -> Promise<Uint8Array>
3
+ // `deflate(bytes)` must return zlib-format data (Node: zlib.deflateSync; browsers: CompressionStream('deflate')).
4
+ // Frames that repeat the previous one are merged into a longer delay.
5
+ (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MGApng=factory()})(this,function(){
6
+ const CRC=new Uint32Array(256);for(let n=0;n<256;n++){let c=n;for(let k=0;k<8;k++)c=c&1?0xEDB88320^(c>>>1):c>>>1;CRC[n]=c>>>0}
7
+ const crc=(b)=>{let c=0xFFFFFFFF;for(let i=0;i<b.length;i++)c=CRC[(c^b[i])&255]^(c>>>8);return(c^0xFFFFFFFF)>>>0};
8
+ function chunk(type,data){const out=new Uint8Array(12+data.length),v=new DataView(out.buffer);v.setUint32(0,data.length);
9
+ for(let i=0;i<4;i++)out[4+i]=type.charCodeAt(i);out.set(data,8);v.setUint32(8+data.length,crc(out.subarray(4,8+data.length)));return out}
10
+ const u32=(v,a,o)=>new DataView(a.buffer).setUint32(o,v),u16=(v,a,o)=>new DataView(a.buffer).setUint16(o,v);
11
+ function same(a,b){if(a.length!==b.length)return false;for(let i=0;i<a.length;i++)if(a[i]!==b[i])return false;return true}
12
+ // PNG rows with the "sub" filter (good for flat icon art)
13
+ function rows(f,W,H){const out=new Uint8Array(H*(W*4+1));for(let y=0;y<H;y++){const o=y*(W*4+1),s=y*W*4;out[o]=1;
14
+ for(let x=0;x<W*4;x++)out[o+1+x]=(f[s+x]-(x>=4?f[s+x-4]:0))&255}return out}
15
+ async function encode(o,deflate){
16
+ const W=o.width,H=o.height,fr=[],dl=[];
17
+ o.frames.forEach((f,i)=>{if(fr.length&&same(f,fr[fr.length-1]))dl[dl.length-1]+=o.delays[i];else{fr.push(f);dl.push(o.delays[i])}});
18
+ const parts=[new Uint8Array([137,80,78,71,13,10,26,10])];
19
+ const ih=new Uint8Array(13);u32(W,ih,0);u32(H,ih,4);ih[8]=8;ih[9]=6;parts.push(chunk('IHDR',ih));
20
+ const ac=new Uint8Array(8);u32(fr.length,ac,0);u32(o.loop===undefined?0:o.loop,ac,4);parts.push(chunk('acTL',ac));
21
+ let seq=0;
22
+ for(let i=0;i<fr.length;i++){
23
+ // after the first frame only the rectangle that changed is stored; it replaces those pixels (blend "source")
24
+ let x0=0,y0=0,x1=W,y1=H;
25
+ if(i>0){const a=fr[i],b=fr[i-1];x0=W;y0=H;x1=0;y1=0;for(let y=0;y<H;y++)for(let x=0;x<W;x++){const j=(y*W+x)*4;if(a[j]!==b[j]||a[j+1]!==b[j+1]||a[j+2]!==b[j+2]||a[j+3]!==b[j+3]){if(x<x0)x0=x;if(x>=x1)x1=x+1;if(y<y0)y0=y;if(y>=y1)y1=y+1}}}
26
+ const cw=x1-x0,chh=y1-y0,sub=new Uint8Array(cw*chh*4);for(let y=0;y<chh;y++)sub.set(fr[i].subarray(((y0+y)*W+x0)*4,((y0+y)*W+x1)*4),y*cw*4);
27
+ const fc=new Uint8Array(26);u32(seq++,fc,0);u32(cw,fc,4);u32(chh,fc,8);u32(x0,fc,12);u32(y0,fc,16);
28
+ // delay as a fraction of a second in milliseconds
29
+ u16(Math.max(1,Math.round(dl[i]*1000)),fc,20);u16(1000,fc,22);fc[24]=0;fc[25]=0;parts.push(chunk('fcTL',fc));
30
+ const z=await deflate(rows(sub,cw,chh));
31
+ if(i===0)parts.push(chunk('IDAT',z));else{const d=new Uint8Array(4+z.length);u32(seq++,d,0);d.set(z,4);parts.push(chunk('fdAT',d))}}
32
+ parts.push(chunk('IEND',new Uint8Array(0)));
33
+ let n=0;for(const p of parts)n+=p.length;const out=new Uint8Array(n);let k=0;for(const p of parts){out.set(p,k);k+=p.length}return out;
34
+ }
35
+ return{encode};
36
+ });
package/tools/baked.js ADDED
@@ -0,0 +1,30 @@
1
+ // The motion of an icon pre-computed for platforms without a spring engine or a Lottie player:
2
+ // per layer, a 2D matrix [a,b,c,d,e,f] per frame (x' = a·x + c·y + e, y' = b·x + d·y + f), sampled at `fps`,
3
+ // plus what each path paints. Players step through the frames and interpolate between them.
4
+ const R=require('./raster.js');
5
+ const r3=v=>Math.round(v*1000)/1000;
6
+ function matrix(v,oR,oS){
7
+ if(!v)return[1,0,0,1,0,0];
8
+ const kx=1+v.s+v.sx,ky=1+v.s+v.sy,t=v.r*Math.PI/180,c=Math.cos(t),s=Math.sin(t);
9
+ // S about oS, then R about oR, then translate
10
+ const S=[kx,0,0,ky,oS[0]*(1-kx),oS[1]*(1-ky)],Rm=[c,s,-s,c,oR[0]-c*oR[0]+s*oR[1],oR[1]-s*oR[0]-c*oR[1]];
11
+ const mul=(A,B)=>[A[0]*B[0]+A[2]*B[1],A[1]*B[0]+A[3]*B[1],A[0]*B[2]+A[2]*B[3],A[1]*B[2]+A[3]*B[3],A[0]*B[4]+A[2]*B[5]+A[4],A[1]*B[4]+A[3]*B[5]+A[5]];
12
+ const M=mul(Rm,S);M[4]+=v.tx;M[5]+=v.ty;return M.map(r3);
13
+ }
14
+ // paint per layer kind and style, as {fill, stroke, fillOpacity} with colour roles: 'fg' | 'bg' | 'sec' | null
15
+ function paint(style,k){
16
+ if(k==='f')return{fill:'fg'};if(k==='d')return{fill:style==='solid'?'bg':'fg'};
17
+ if(k==='o')return{stroke:'fg'};if(k==='i')return{stroke:style==='solid'?'bg':'fg'};
18
+ if(style==='solid')return{fill:'fg',stroke:'fg'};if(style==='duotone')return{fill:'sec',fillOpacity:.18,stroke:'fg'};
19
+ return{stroke:'fg'};
20
+ }
21
+ function bake(MG,ic,o){
22
+ o=o||{};const fps=o.fps||30,style=o.style||'outline',org=MG.origins(ic),samples=R.sample(MG,ic,fps);
23
+ const layers=ic.L.map(l=>{
24
+ const oR=org[l.i+'|r']||org[l.i+'|s']||[12,12],oS=org[l.i+'|s']||org[l.i+'|r']||[12,12];
25
+ const m=samples.map(f=>matrix(f[l.i],oR,oS)),still=m.every(x=>x.join()===m[0].join())&&m[0].join()==='1,0,0,1,0,0';
26
+ return{id:l.i,paint:paint(style,l.k),paths:l.p.map(p=>({d:p.d,r:p.r||null,fill:p.f||null,polys:o.polys?R.flatten(p.d,p.r,.05).map(q=>({pts:q.pts.map(r3),closed:q.closed})):undefined})),m:still?null:m};
27
+ });
28
+ return{name:ic.n,fps,frames:samples.length,layers,sound:ic.s||null};
29
+ }
30
+ module.exports={bake,matrix,paint};
package/tools/gif.js ADDED
@@ -0,0 +1,60 @@
1
+ // A small animated GIF encoder (no dependencies; runs in Node and in browsers).
2
+ // encode({width, height, frames:[RGBA], delays:[seconds], loop:0 forever | n, background:[r,g,b] 0..255 or null for transparent})
3
+ // GIF has one bit of transparency, so transparent exports blend soft edges onto `matte` (default white) and keep
4
+ // pixels at least half covered. With a background, unchanged areas between frames are skipped to keep files small.
5
+ (function(root,factory){if(typeof module==='object'&&module.exports)module.exports=factory();else root.MGGif=factory()})(this,function(){
6
+ // median cut on a 5-bit-per-channel histogram, at most `max` colours
7
+ function palette(hist,max){
8
+ let boxes=[{c:[]}];for(let i=0;i<hist.length;i++)if(hist[i])boxes[0].c.push(i);
9
+ if(!boxes[0].c.length)return[[0,0,0]];
10
+ const ch=(i,k)=>k===0?i>>10:k===1?(i>>5)&31:i&31;
11
+ const range=b=>{let best=-1,bk=0;for(let k=0;k<3;k++){let lo=99,hi=-1;for(const i of b.c){const v=ch(i,k);if(v<lo)lo=v;if(v>hi)hi=v}if(hi-lo>best){best=hi-lo;bk=k}}return[best,bk]};
12
+ while(boxes.length<max){let bi=-1,bv=0;boxes.forEach((b,i)=>{if(b.c.length<2)return;const r=range(b),w=r[0]*Math.log2(1+b.c.reduce((s,i)=>s+hist[i],0));if(r[0]>0&&w>bv){bv=w;bi=i}});
13
+ if(bi<0)break;const b=boxes[bi],k=range(b)[1];b.c.sort((x,y)=>ch(x,k)-ch(y,k));
14
+ const tot=b.c.reduce((s,i)=>s+hist[i],0);let acc=0,cut=1;for(let j=0;j<b.c.length-1;j++){acc+=hist[b.c[j]];if(acc>=tot/2){cut=j+1;break}}
15
+ boxes.splice(bi,1,{c:b.c.slice(0,cut)},{c:b.c.slice(cut)})}
16
+ return boxes.map(b=>{let n=0,r=0,g=0,bl=0;for(const i of b.c){const w=hist[i];n+=w;r+=(i>>10)*w;g+=((i>>5)&31)*w;bl+=(i&31)*w}return[r/n*255/31+.5|0,g/n*255/31+.5|0,bl/n*255/31+.5|0]});
17
+ }
18
+ function lzw(idx,minBits){
19
+ const out=[];let cur=0,bits=0;const put=(code,size)=>{cur|=code<<bits;bits+=size;while(bits>=8){out.push(cur&255);cur>>=8;bits-=8}};
20
+ const clear=1<<minBits,eoi=clear+1;let size=minBits+1,next=eoi+1,dict=new Map();
21
+ put(clear,size);let w=idx[0];
22
+ for(let i=1;i<idx.length;i++){const k=idx[i],key=w*4096+k,hit=dict.get(key);
23
+ if(hit!==undefined){w=hit;continue}
24
+ put(w,size);
25
+ if(next<4096){dict.set(key,next++);if(next>(1<<size)&&size<12)size++}
26
+ else{put(clear,size);dict=new Map();size=minBits+1;next=eoi+1}
27
+ w=k}
28
+ put(w,size);put(eoi,size);if(bits>0)out.push(cur&255);
29
+ const blocks=[];for(let i=0;i<out.length;i+=255){const n=Math.min(255,out.length-i);blocks.push(n);for(let j=0;j<n;j++)blocks.push(out[i+j])}blocks.push(0);return blocks;
30
+ }
31
+ function encode(o){
32
+ const W=o.width,H=o.height,bg=o.background||null,matte=o.matte||[255,255,255],N=W*H;
33
+ // flatten every frame to opaque colours (or "transparent") first
34
+ const flat=o.frames.map(f=>{const c=new Int32Array(N);for(let i=0,j=0;i<N;i++,j+=4){const a=f[j+3]/255;
35
+ if(bg){c[i]=((f[j]*a+bg[0]*(1-a))>>3<<10)|((f[j+1]*a+bg[1]*(1-a))>>3<<5)|((f[j+2]*a+bg[2]*(1-a))>>3)}
36
+ else if(a<.5)c[i]=-1;else c[i]=((f[j]*a+matte[0]*(1-a))>>3<<10)|((f[j+1]*a+matte[1]*(1-a))>>3<<5)|((f[j+2]*a+matte[2]*(1-a))>>3)}return c});
37
+ const hist=new Uint32Array(32768);for(const c of flat)for(let i=0;i<N;i++)if(c[i]>=0)hist[c[i]]++;
38
+ const pal=palette(hist,bg?256:255),T=bg?-1:pal.length,cache=new Int16Array(32768).fill(-1);
39
+ const near=k=>{if(cache[k]>=0)return cache[k];const r=(k>>10)*255/31,g=((k>>5)&31)*255/31,b=(k&31)*255/31;let bi=0,bd=1e9;
40
+ pal.forEach((p,i)=>{const d=(p[0]-r)**2*.3+(p[1]-g)**2*.59+(p[2]-b)**2*.11;if(d<bd){bd=d;bi=i}});return cache[k]=bi};
41
+ let n=pal.length+(bg?0:1),bitsz=1;while((1<<bitsz)<n)bitsz++;const PS=1<<bitsz;
42
+ const B=[];const s=t=>{for(let i=0;i<t.length;i++)B.push(t.charCodeAt(i))},u16=v=>B.push(v&255,v>>8);
43
+ s('GIF89a');u16(W);u16(H);B.push(0xF0|(bitsz-1),0,0);
44
+ for(let i=0;i<PS;i++){const p=pal[i]||[0,0,0];B.push(p[0],p[1],p[2])}
45
+ const loop=o.loop===undefined?0:o.loop;if(loop!==1){B.push(0x21,0xFF,11);s('NETSCAPE2.0');B.push(3,1);u16(loop===0?0:loop-1);B.push(0)}
46
+ let prev=null;
47
+ flat.forEach((c,fi)=>{
48
+ let x0=0,y0=0,x1=W,y1=H;
49
+ // with a solid background only the changed rectangle is written
50
+ if(bg&&prev){x0=W;y0=H;x1=0;y1=0;for(let y=0;y<H;y++)for(let x=0;x<W;x++){const i=y*W+x;if(c[i]!==prev[i]){if(x<x0)x0=x;if(x>=x1)x1=x+1;if(y<y0)y0=y;if(y>=y1)y1=y+1}}if(x1<=x0){x0=0;y0=0;x1=1;y1=1}}
51
+ const cs=Math.max(2,Math.round((o.delays[fi]||.02)*100));
52
+ B.push(0x21,0xF9,4,(bg?1:2)<<2|(bg?0:1));u16(cs);B.push(bg?0:T,0);
53
+ B.push(0x2C);u16(x0);u16(y0);u16(x1-x0);u16(y1-y0);B.push(0);
54
+ const idx=new Uint8Array((x1-x0)*(y1-y0));let k=0;for(let y=y0;y<y1;y++)for(let x=x0;x<x1;x++){const v=c[y*W+x];idx[k++]=v<0?T:near(v)}
55
+ const mb=Math.max(2,bitsz);B.push(mb);const data=lzw(idx,mb);for(let i=0;i<data.length;i++)B.push(data[i]);
56
+ prev=c});
57
+ B.push(0x3B);return new Uint8Array(B);
58
+ }
59
+ return{encode};
60
+ });
@@ -0,0 +1,31 @@
1
+ // Animated image and video exports for places that cannot run code: email, slides, Canva, Notion, chat emoji, social posts.
2
+ // gif works everywhere, one bit of transparency (soft edges are blended onto --matte or the background)
3
+ // apng full transparency and exact timing (Slack, Discord, browsers, Keynote)
4
+ // webm VP9 video with transparency and the sound baked in } need ffmpeg on this computer
5
+ // mp4 H.264 video with the sound baked in (solid background) } (or export them from the icon maker)
6
+ const R=require('./raster.js');
7
+ const DEF={gif:{size:256,fps:50},apng:{size:128,fps:60},webm:{size:512,fps:60},mp4:{size:512,fps:60}};
8
+
9
+ function frames(L,name,format,o){
10
+ const ic=L.byName.get(name),d=DEF[format];
11
+ if((o.style||'outline')==='glass'&&format==='gif'&&!(o.background&&o.background!=='transparent'))throw new Error('GIF cannot hold the glass style\'s see-through gradient on a transparent background. Add --background, or use --format apng or webm.');
12
+ const bg=o.background||(format==='mp4'?'#ffffff':'transparent');
13
+ return R.render(L.MG,ic,{size:o.size||d.size,style:o.style,color:o.color||'#000000',secondary:o.secondary,background:bg,fps:d.fps,hold:o.hold,lead:o.lead});
14
+ }
15
+ const rgb=c=>{const h=R.hex(c,null);return h&&h.map(v=>Math.round(v*255))};
16
+
17
+ async function gif(L,name,o){const r=frames(L,name,'gif',o);
18
+ return require('./gif.js').encode({width:r.width,height:r.height,frames:r.frames,delays:r.delays,loop:o.loop===undefined?0:+o.loop,background:o.background&&o.background!=='transparent'?rgb(o.background):null,matte:rgb(o.matte||'#ffffff')})}
19
+ async function apng(L,name,o){const r=frames(L,name,'apng',o),z=require('zlib');
20
+ return require('./apng.js').encode({width:r.width,height:r.height,frames:r.frames,delays:r.delays,loop:o.loop===undefined?0:+o.loop},b=>z.deflateSync(b,{level:9}))}
21
+
22
+ // the icon's sound, placed where the motion starts, as 16-bit stereo PCM covering the whole clip
23
+ async function soundtrack(L,name,seconds,lead){
24
+ const ic=L.byName.get(name);if(!ic||!ic.s)return null;
25
+ const A=require('./audio.js'),buf=await L.MG.sound.render(name,{},A.OfflineContext),sr=buf.sampleRate,n=Math.ceil(seconds*sr),off=Math.round(lead*sr);
26
+ const Lc=buf.getChannelData(0),Rc=buf.getChannelData(1),pcm=Buffer.alloc(n*4);
27
+ for(let i=0;i<Lc.length&&i+off<n;i++){pcm.writeInt16LE(Math.max(-1,Math.min(1,Lc[i]))*32767|0,(i+off)*4);pcm.writeInt16LE(Math.max(-1,Math.min(1,Rc[i]))*32767|0,(i+off)*4+2)}
28
+ return{pcm,sr};
29
+ }
30
+
31
+ module.exports={DEF,frames,gif,apng,soundtrack,FORMATS:['gif','apng','webm','mp4']};
package/tools/native.js CHANGED
@@ -205,4 +205,4 @@ public sealed class ${P}Glyph : UserControl
205
205
  }
206
206
  ` };
207
207
  }
208
- module.exports = { 'react-native': reactNative, swiftui, compose, flutter, winui };
208
+ module.exports = { 'react-native': reactNative, swiftui, compose, flutter, winui, lottieJson };