@thesvg/ui-react-native 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/dist/_anim.cjs +73 -21
- package/dist/_anim.d.ts +4 -2
- package/dist/_anim.js +72 -20
- package/package.json +1 -1
package/dist/_anim.cjs
CHANGED
|
@@ -1,31 +1,83 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
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
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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
|
-
/**
|
|
24
|
-
|
|
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
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
//
|
|
2
|
-
//
|
|
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
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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
|
-
/**
|
|
24
|
-
|
|
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
|
-
/**
|
|
30
|
-
|
|
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/package.json
CHANGED