@thesvg/ui-vue 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -60,15 +60,26 @@ import { BellIcon, BellGlassIcon } from "@thesvg/ui-vue/bell";
60
60
  ```
61
61
 
62
62
 
63
- ## Animated icons
63
+ ## Motion
64
64
 
65
- Add `animated` to pop an icon in and draw its strokes, once. It works on every look, and the stroke drawing shows on outline and glass outline.
65
+ Add `animated` to give an icon motion. It works on every look.
66
66
 
67
67
  ```vue
68
68
  <SunIcon animated />
69
+ <LoaderCircleIcon animated="spin" />
70
+ <BellIcon animated="ring" />
69
71
  ```
70
72
 
71
- The motion is plain CSS inside the SVG, so there is no animation library to install, and it stands still for people who prefer reduced motion. Sun, moon and the new `ThemeSystemIcon` are made for theme switchers.
73
+ | `animated` | Motion |
74
+ | --- | --- |
75
+ | `true` or `"draw"` | Pops in with a spring and draws the strokes one after another, once |
76
+ | `"pop"` | The spring only, once |
77
+ | `"bounce"` | A short hop, once |
78
+ | `"ring"` | A swing from the top, once. Made for a bell |
79
+ | `"spin"` | Turns forever. Made for loaders |
80
+ | `"pulse"` | Breathes forever. Made for a heart |
81
+
82
+ It is plain CSS inside the SVG: no animation library, and it stands still for people who prefer reduced motion. Import only the icons you use, for example `import { BellIcon } from "@thesvg/ui-react/bell"`. The motion code is one small helper (about 1.6 KB gzipped) shared by every icon, and an icon you never animate carries no motion CSS.
72
83
 
73
84
  ## Looks
74
85
 
package/dist/_anim.cjs CHANGED
@@ -1,31 +1,83 @@
1
- // Entrance motion for UI icons, in plain CSS inside the svg, so it needs no animation library and works in React, Vue,
2
- // Svelte and in a standalone svg file. The icon pops in with a spring and its strokes draw themselves one after another.
1
+ // Motion for UI icons, in plain CSS inside the svg: no animation library, and it works in React, Vue, Svelte and in a
2
+ // standalone svg file. A preset is a name:
3
+ // draw pop in with a spring and draw the strokes one after another, once (what `animated` alone means)
4
+ // pop the spring only, once
5
+ // bounce a short hop, once
6
+ // ring a swing from the top, once (a bell)
7
+ // spin turns forever (a loader)
8
+ // pulse breathes forever (a heart)
3
9
  // Plain ES module with no dependencies: package-builder copies it into every package as _anim.js.
4
- const ANIMATED_SLUGS = ["sun", "moon", "theme-system"];
10
+ const PRESETS = ["draw", "pop", "bounce", "ring", "spin", "pulse"];
11
+
12
+ // Icons that also ship a ready-made `<look>-animated.svg`, with the preset each one uses.
13
+ const ANIMATED = {
14
+ sun: "draw",
15
+ moon: "draw",
16
+ "theme-system": "draw",
17
+ "loader-circle": "spin",
18
+ "refresh-cw": "spin",
19
+ heart: "pulse",
20
+ bell: "ring",
21
+ };
22
+ const ANIMATED_SLUGS = Object.keys(ANIMATED);
5
23
 
6
24
  const SHAPES = /<(path|circle|rect|line|polyline|polygon|ellipse)(?=[\s/>])/g;
7
25
 
8
- const css = (cls) => {
9
- let delays = "";
10
- for (let i = 1; i <= 12; i++) delays += "." + cls + ">g[stroke]>:nth-child(" + i + "){animation-delay:" + (0.04 + i * 0.045).toFixed(3) + "s}";
11
- return (
12
- "." + cls + "{transform-box:view-box;transform-origin:12px 12px;animation:ua-pop .6s cubic-bezier(.34,1.56,.64,1) both}" +
13
- "." + cls + ">g[stroke]>*{stroke-dasharray:1 1;stroke-dashoffset:1;animation:ua-draw .55s ease-out forwards}" +
14
- delays +
15
- "@keyframes ua-pop{from{transform:scale(0) rotate(-90deg);opacity:0}to{transform:none;opacity:1}}" +
16
- "@keyframes ua-draw{to{stroke-dashoffset:0}}" +
17
- "@media (prefers-reduced-motion:reduce){." + cls + ",." + cls + ">g[stroke]>*{animation:none!important;stroke-dasharray:none!important;stroke-dashoffset:0!important}}"
18
- );
26
+ const FRAMES = {
27
+ pop: "@keyframes ua-pop{from{transform:scale(0) rotate(-90deg);opacity:0}to{transform:none;opacity:1}}",
28
+ bounce: "@keyframes ua-bounce{0%{transform:translateY(0)}35%{transform:translateY(-3.5px)}65%{transform:translateY(.6px)}100%{transform:translateY(0)}}",
29
+ ring: "@keyframes ua-ring{0%{transform:rotate(0)}15%{transform:rotate(16deg)}30%{transform:rotate(-13deg)}45%{transform:rotate(9deg)}60%{transform:rotate(-6deg)}75%{transform:rotate(3deg)}100%{transform:rotate(0)}}",
30
+ spin: "@keyframes ua-spin{to{transform:rotate(360deg)}}",
31
+ pulse: "@keyframes ua-pulse{0%,100%{transform:scale(1)}50%{transform:scale(1.14)}}",
32
+ draw: "@keyframes ua-draw{to{stroke-dashoffset:0}}",
33
+ };
34
+
35
+ const MOTION = {
36
+ draw: "animation:ua-pop .6s cubic-bezier(.34,1.56,.64,1) both",
37
+ pop: "animation:ua-pop .6s cubic-bezier(.34,1.56,.64,1) both",
38
+ bounce: "animation:ua-bounce .7s cubic-bezier(.28,.84,.42,1) both",
39
+ ring: "transform-origin:12px 3px;animation:ua-ring 1s ease-in-out both",
40
+ spin: "animation:ua-spin .9s linear infinite",
41
+ pulse: "animation:ua-pulse 1.4s ease-in-out infinite",
42
+ };
43
+
44
+ const preset = (p) => (PRESETS.includes(p) ? p : "draw");
45
+
46
+ const css = (cls, name) => {
47
+ let out = "." + cls + "{transform-box:view-box;transform-origin:12px 12px;" + MOTION[name] + "}";
48
+ out += "@media (prefers-reduced-motion:reduce){." + cls + "{animation:none!important}";
49
+ if (name === "draw") {
50
+ out += "." + cls + ">g[stroke]>*{animation:none!important;stroke-dasharray:none!important;stroke-dashoffset:0!important}";
51
+ }
52
+ out += "}";
53
+ if (name === "draw") {
54
+ out += "." + cls + ">g[stroke]>*{stroke-dasharray:1 1;stroke-dashoffset:1;animation:ua-draw .55s ease-out forwards}";
55
+ for (let i = 1; i <= 12; i++) out += "." + cls + ">g[stroke]>:nth-child(" + i + "){animation-delay:" + (0.04 + i * 0.045).toFixed(3) + "s}";
56
+ out += FRAMES.draw;
57
+ }
58
+ return out + FRAMES[name === "draw" ? "pop" : name];
19
59
  };
20
60
 
21
- const wrap = (html, cls) => "<style>" + css(cls) + '</style><g class="' + cls + '">' + html.replace(SHAPES, '<$1 pathLength="1"') + "</g>";
61
+ const wrap = (html, cls, name) =>
62
+ "<style>" + css(cls, name) + '</style><g class="' + cls + '">' + (name === "draw" ? html.replace(SHAPES, '<$1 pathLength="1"') : html) + "</g>";
22
63
 
23
- /** Inner markup of an icon, wrapped so it animates. uid keeps two icons on one page from sharing a class. */
24
- const animate = (html, uid) => {
64
+ /**
65
+ * Inner markup of an icon, wrapped so it moves. `kind` is a preset name, or true for draw. uid keeps two icons on a page apart.
66
+ * @param {string} html
67
+ * @param {string | number} uid
68
+ * @param {string | boolean} [kind]
69
+ * @returns {{ cls: string, html: string }}
70
+ */
71
+ const animate = (html, uid, kind = "draw") => {
25
72
  const cls = "ua-" + uid;
26
- return { cls, html: wrap(html, cls) };
73
+ return { cls, html: wrap(html, cls, preset(kind)) };
27
74
  };
28
75
 
29
- /** A whole standalone svg file, animated on load. */
30
- const animateSvg = (svg) => svg.replace(/^(<svg[^>]*>)([\s\S]*)(<\/svg>)\s*$/, (_m, open, body, close) => open + wrap(body, "ua") + close);
31
- module.exports = { animate, animateSvg };
76
+ /**
77
+ * A whole standalone svg file, moving on load.
78
+ * @param {string} svg
79
+ * @param {string} [kind]
80
+ * @returns {string}
81
+ */
82
+ const animateSvg = (svg, kind = "draw") => svg.replace(/^(<svg[^>]*>)([\s\S]*)(<\/svg>)\s*$/, (_m, open, body, close) => open + wrap(body, "ua", preset(kind)) + close);
83
+ module.exports = { animate, animateSvg, ANIMATED, ANIMATED_SLUGS, PRESETS };
package/dist/_anim.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export declare const animate: (html: string, uid: string | number) => { cls: string; html: string };
2
- export declare const animateSvg: (svg: string) => string;
1
+ export declare const animate: (html: string, uid: string | number, kind?: string | boolean) => { cls: string; html: string };
2
+ export declare const animateSvg: (svg: string, kind?: string) => string;
3
3
  export declare const ANIMATED_SLUGS: string[];
4
+ export declare const ANIMATED: Record<string, string>;
5
+ export declare const PRESETS: string[];
package/dist/_anim.js CHANGED
@@ -1,30 +1,82 @@
1
- // Entrance motion for UI icons, in plain CSS inside the svg, so it needs no animation library and works in React, Vue,
2
- // Svelte and in a standalone svg file. The icon pops in with a spring and its strokes draw themselves one after another.
1
+ // Motion for UI icons, in plain CSS inside the svg: no animation library, and it works in React, Vue, Svelte and in a
2
+ // standalone svg file. A preset is a name:
3
+ // draw pop in with a spring and draw the strokes one after another, once (what `animated` alone means)
4
+ // pop the spring only, once
5
+ // bounce a short hop, once
6
+ // ring a swing from the top, once (a bell)
7
+ // spin turns forever (a loader)
8
+ // pulse breathes forever (a heart)
3
9
  // Plain ES module with no dependencies: package-builder copies it into every package as _anim.js.
4
- export const ANIMATED_SLUGS = ["sun", "moon", "theme-system"];
10
+ export const PRESETS = ["draw", "pop", "bounce", "ring", "spin", "pulse"];
11
+
12
+ // Icons that also ship a ready-made `<look>-animated.svg`, with the preset each one uses.
13
+ export const ANIMATED = {
14
+ sun: "draw",
15
+ moon: "draw",
16
+ "theme-system": "draw",
17
+ "loader-circle": "spin",
18
+ "refresh-cw": "spin",
19
+ heart: "pulse",
20
+ bell: "ring",
21
+ };
22
+ export const ANIMATED_SLUGS = Object.keys(ANIMATED);
5
23
 
6
24
  const SHAPES = /<(path|circle|rect|line|polyline|polygon|ellipse)(?=[\s/>])/g;
7
25
 
8
- const css = (cls) => {
9
- let delays = "";
10
- for (let i = 1; i <= 12; i++) delays += "." + cls + ">g[stroke]>:nth-child(" + i + "){animation-delay:" + (0.04 + i * 0.045).toFixed(3) + "s}";
11
- return (
12
- "." + cls + "{transform-box:view-box;transform-origin:12px 12px;animation:ua-pop .6s cubic-bezier(.34,1.56,.64,1) both}" +
13
- "." + cls + ">g[stroke]>*{stroke-dasharray:1 1;stroke-dashoffset:1;animation:ua-draw .55s ease-out forwards}" +
14
- delays +
15
- "@keyframes ua-pop{from{transform:scale(0) rotate(-90deg);opacity:0}to{transform:none;opacity:1}}" +
16
- "@keyframes ua-draw{to{stroke-dashoffset:0}}" +
17
- "@media (prefers-reduced-motion:reduce){." + cls + ",." + cls + ">g[stroke]>*{animation:none!important;stroke-dasharray:none!important;stroke-dashoffset:0!important}}"
18
- );
26
+ const FRAMES = {
27
+ pop: "@keyframes ua-pop{from{transform:scale(0) rotate(-90deg);opacity:0}to{transform:none;opacity:1}}",
28
+ bounce: "@keyframes ua-bounce{0%{transform:translateY(0)}35%{transform:translateY(-3.5px)}65%{transform:translateY(.6px)}100%{transform:translateY(0)}}",
29
+ ring: "@keyframes ua-ring{0%{transform:rotate(0)}15%{transform:rotate(16deg)}30%{transform:rotate(-13deg)}45%{transform:rotate(9deg)}60%{transform:rotate(-6deg)}75%{transform:rotate(3deg)}100%{transform:rotate(0)}}",
30
+ spin: "@keyframes ua-spin{to{transform:rotate(360deg)}}",
31
+ pulse: "@keyframes ua-pulse{0%,100%{transform:scale(1)}50%{transform:scale(1.14)}}",
32
+ draw: "@keyframes ua-draw{to{stroke-dashoffset:0}}",
33
+ };
34
+
35
+ const MOTION = {
36
+ draw: "animation:ua-pop .6s cubic-bezier(.34,1.56,.64,1) both",
37
+ pop: "animation:ua-pop .6s cubic-bezier(.34,1.56,.64,1) both",
38
+ bounce: "animation:ua-bounce .7s cubic-bezier(.28,.84,.42,1) both",
39
+ ring: "transform-origin:12px 3px;animation:ua-ring 1s ease-in-out both",
40
+ spin: "animation:ua-spin .9s linear infinite",
41
+ pulse: "animation:ua-pulse 1.4s ease-in-out infinite",
42
+ };
43
+
44
+ const preset = (p) => (PRESETS.includes(p) ? p : "draw");
45
+
46
+ const css = (cls, name) => {
47
+ let out = "." + cls + "{transform-box:view-box;transform-origin:12px 12px;" + MOTION[name] + "}";
48
+ out += "@media (prefers-reduced-motion:reduce){." + cls + "{animation:none!important}";
49
+ if (name === "draw") {
50
+ out += "." + cls + ">g[stroke]>*{animation:none!important;stroke-dasharray:none!important;stroke-dashoffset:0!important}";
51
+ }
52
+ out += "}";
53
+ if (name === "draw") {
54
+ out += "." + cls + ">g[stroke]>*{stroke-dasharray:1 1;stroke-dashoffset:1;animation:ua-draw .55s ease-out forwards}";
55
+ for (let i = 1; i <= 12; i++) out += "." + cls + ">g[stroke]>:nth-child(" + i + "){animation-delay:" + (0.04 + i * 0.045).toFixed(3) + "s}";
56
+ out += FRAMES.draw;
57
+ }
58
+ return out + FRAMES[name === "draw" ? "pop" : name];
19
59
  };
20
60
 
21
- const wrap = (html, cls) => "<style>" + css(cls) + '</style><g class="' + cls + '">' + html.replace(SHAPES, '<$1 pathLength="1"') + "</g>";
61
+ const wrap = (html, cls, name) =>
62
+ "<style>" + css(cls, name) + '</style><g class="' + cls + '">' + (name === "draw" ? html.replace(SHAPES, '<$1 pathLength="1"') : html) + "</g>";
22
63
 
23
- /** Inner markup of an icon, wrapped so it animates. uid keeps two icons on one page from sharing a class. */
24
- export const animate = (html, uid) => {
64
+ /**
65
+ * Inner markup of an icon, wrapped so it moves. `kind` is a preset name, or true for draw. uid keeps two icons on a page apart.
66
+ * @param {string} html
67
+ * @param {string | number} uid
68
+ * @param {string | boolean} [kind]
69
+ * @returns {{ cls: string, html: string }}
70
+ */
71
+ export const animate = (html, uid, kind = "draw") => {
25
72
  const cls = "ua-" + uid;
26
- return { cls, html: wrap(html, cls) };
73
+ return { cls, html: wrap(html, cls, preset(kind)) };
27
74
  };
28
75
 
29
- /** A whole standalone svg file, animated on load. */
30
- export const animateSvg = (svg) => svg.replace(/^(<svg[^>]*>)([\s\S]*)(<\/svg>)\s*$/, (_m, open, body, close) => open + wrap(body, "ua") + close);
76
+ /**
77
+ * A whole standalone svg file, moving on load.
78
+ * @param {string} svg
79
+ * @param {string} [kind]
80
+ * @returns {string}
81
+ */
82
+ export const animateSvg = (svg, kind = "draw") => svg.replace(/^(<svg[^>]*>)([\s\S]*)(<\/svg>)\s*$/, (_m, open, body, close) => open + wrap(body, "ua", preset(kind)) + close);
package/dist/_make.cjs CHANGED
@@ -11,12 +11,11 @@ const make = (html, name, ids) => {
11
11
  const scope = scoper(ids);
12
12
  return defineComponent({
13
13
  name,
14
- props: { size: { type: [Number, String], default: 24 }, shadow: { type: [Boolean, Number], default: 0 }, animated: { type: Boolean, default: false } },
14
+ props: { size: { type: [Number, String], default: 24 }, shadow: { type: [Boolean, Number], default: 0 }, animated: { type: [Boolean, String], default: false } },
15
15
  setup(props, { attrs }) {
16
16
  const uid = getCurrentInstance()?.uid ?? 0;
17
17
  const plain = scope(html, uid);
18
- const moving = scope(animate(html, uid).html, uid);
19
- return () => h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: props.size, height: props.size, overflow: "visible", style: liftOf(props.shadow, props.size) ? { filter: liftOf(props.shadow, props.size) } : undefined, "aria-hidden": attrs["aria-label"] ? undefined : "true", innerHTML: props.animated ? moving : plain });
18
+ return () => h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: props.size, height: props.size, overflow: "visible", style: liftOf(props.shadow, props.size) ? { filter: liftOf(props.shadow, props.size) } : undefined, "aria-hidden": attrs["aria-label"] ? undefined : "true", innerHTML: props.animated ? scope(animate(html, uid, props.animated).html, uid) : plain });
20
19
  },
21
20
  });
22
21
  };
package/dist/_make.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { DefineComponent } from "vue";
2
- export type UiIcon = DefineComponent<{ size?: number | string; /** Lift shadow under the icon: true, or an opacity from 0 to 1. Works on every look. */ shadow?: boolean | number; /** Pop in and draw the strokes, once. */ animated?: boolean }>;
2
+ export type UiIcon = DefineComponent<{ size?: number | string; /** Lift shadow under the icon: true, or an opacity from 0 to 1. Works on every look. */ shadow?: boolean | number; /** Motion: true or "draw" pops in and draws the strokes once. Also pop, bounce, ring (once) and spin, pulse (forever). */ animated?: boolean | "draw" | "pop" | "bounce" | "ring" | "spin" | "pulse" }>;
3
3
  export declare const make: (html: string, name: string, ids: string[]) => UiIcon;
package/dist/_make.js CHANGED
@@ -11,12 +11,11 @@ export const make = (html, name, ids) => {
11
11
  const scope = scoper(ids);
12
12
  return defineComponent({
13
13
  name,
14
- props: { size: { type: [Number, String], default: 24 }, shadow: { type: [Boolean, Number], default: 0 }, animated: { type: Boolean, default: false } },
14
+ props: { size: { type: [Number, String], default: 24 }, shadow: { type: [Boolean, Number], default: 0 }, animated: { type: [Boolean, String], default: false } },
15
15
  setup(props, { attrs }) {
16
16
  const uid = getCurrentInstance()?.uid ?? 0;
17
17
  const plain = scope(html, uid);
18
- const moving = scope(animate(html, uid).html, uid);
19
- return () => h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: props.size, height: props.size, overflow: "visible", style: liftOf(props.shadow, props.size) ? { filter: liftOf(props.shadow, props.size) } : undefined, "aria-hidden": attrs["aria-label"] ? undefined : "true", innerHTML: props.animated ? moving : plain });
18
+ return () => h("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", width: props.size, height: props.size, overflow: "visible", style: liftOf(props.shadow, props.size) ? { filter: liftOf(props.shadow, props.size) } : undefined, "aria-hidden": attrs["aria-label"] ? undefined : "true", innerHTML: props.animated ? scope(animate(html, uid, props.animated).html, uid) : plain });
20
19
  },
21
20
  });
22
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thesvg/ui-vue",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "Typed Vue 3 components for the UI icons from thesvg.org, one file per icon and one export per look",
5
5
  "type": "module",
6
6
  "sideEffects": false,